Beiträge: 8
Themen: 1
Registriert seit: Jul 2015
Bewertung:
0
Hi guys,
could someone give me an example code in AmiBlitz on how to detect that a MuiCycle gadget was pressed and which MuiCycle option was selected, please?
There are very few examples about using AmiBlitz in conjunction with MUI on the internet and I didn´t found one about MUICycle within AmiBlitz
Beiträge: 396
Themen: 8
Registriert seit: Sep 2013
Bewertung:
0
You should look this up in the MUI documentation. This is not AmiBlitz specific. If you can post it in C code, I can easily point you out the Amiblitz code.
Beiträge: 8
Themen: 1
Registriert seit: Jul 2015
Bewertung:
0
Beiträge: 396
Themen: 8
Registriert seit: Sep 2013
Bewertung:
0
Hm.. but I remember darkly that there was an issue with the MuiCycle. This has come up several times. Don't remember what the solution was.
Maybe you need to work your way around with the MUI*_ functions. All functions with "_" at the end map directly to the library functions. So you can port 1:1 the code you would see in C. BlitzBasic functions without underscore may have some convenient code around it, that makes it easier but often introduces limitations or bugs. Same with GadTools. If you need 100% access to GadTools, you will need the library functions directly.
Beiträge: 42
Themen: 8
Registriert seit: May 2014
Bewertung:
0
I have some code that works around a couple of issues with MUICycle, I'll dig it out when I get a chance. It is possible, but I ended up calling the class directly using MUINewObject and setting it up that way. Notifications are handled like any other gadget, MUINotifyApp works fine here. And to get the current item I used MUIGet and the relevant tags instead of the MUICycle commands.
Again, I'll post some code when I have a chance, just not near my Amiga at the moment...
Edit: As an aside, I'm working on updating the AmiBlitz section of amigacoding.com, and will add a section on using MUI there as a few people (including myself) have looked for examples like that.
Beiträge: 8
Themen: 1
Registriert seit: Jul 2015
Bewertung:
0
Hi Daedalus,
thanks for reply.
I already tried some code around "MUIGetCycle" and "MUINotify...#MUIA_Cycle_Active" but had no success in detecting the MUICycle pressed and then getting the option selected and also there are no snippets about it in AmiBlitz so I almost give it up because I have not much time.
Daedalus schrieb:I'll post some code when I have a chance, just not near my Amiga at the moment...
I will apreciate it, thanks in advance 8-)
Daedalus schrieb:I'm working on updating the AmiBlitz section of amigacoding.com, and will add a section on using MUI there as a few people (including myself) have looked for examples like that.
I´m sure that will be much usefull to many people because there are very few examples of AmiBlitz and MUI around...
Beiträge: 42
Themen: 8
Registriert seit: May 2014
Bewertung:
0
Okay, I've had a look through my code, and using the built-in commands works fine for the cycle gadget, provided it doesn't have too many entries. It appears that there is a fixed amount of space allocated by the MUICycle command, and adding too many options causes trashed memory and usually a crash. I don't know what that number is or if it changes based on length of entries or what, but for up to 10 entries it should be safe and this code works fine for me:
Code: WBStartup
WbToScreen 0
optimize 5
Syntax 2
; *** MUI Object Constants
#main_window=0
#main_app=1
#main_group=2
#main_cycle=3
#main_vspace=4
#main_quit=5
; *** MUI Event Constants
#ev_main_close=-1
#ev_main_cycle=1
#ev_main_quit=2
; *** End of MUI Constants
MUIApplicationTitle "MUI Cycle Test"
MUIApplicationVersion "$VER: MUICycleTest 1.0 (15.08.2015)"
MUIApplicationCopyright "(c)2015, Rob Cranley"
MUIApplicationAuthor "Rob Cranley"
MUIApplicationDescription "MUI Cycle Gadget Test"
MUIApplicationBase "MUICYCLETEST"
; *** Create MUI gadgets for main window
NPrint "Creating main window gadgets..."
MUICycle #main_cycle,"Test 1","Cycle Option 2","Option 3","Something something","5th Option"
MUIVSpace #main_vspace,0
MUIKeyButton #main_quit,"Quit","q"
NPrint "Creating overall group..."
MUIAddObjsVGroup #main_group,#main_cycle,#main_vspace,#main_quit
MUICreateVGroup #main_group
NPrint "Creating main window..."
MUIAddTags #main_window,#MUIA_Window_AppWindow,1
MUICreateWindow #main_window,"MUI Cycle Test","MAIN",#main_group
MUIAddSubWindow #main_window
If MUICreateApplication=False Then NPrint "Unable to create MUI application!!":End
MUIApplicationObj #main_app
; *** MUI Notifies
NPrint "Setting up notifies"
MUINotifyApp #main_window,#MUIA_Window_CloseRequest,1,#ev_main_close
MUINotifyApp #main_cycle,#MUIA_Cycle_Active,#MUIV_EveryTime,#ev_main_cycle
MUINotifyApp #main_quit,#MUIA_Pressed,0,#ev_main_close
NPrint "Opening main window..."
If MUIOpenWindow(#main_window)=False Then NPrint "Error opening window":End
; *** Main Loop
Repeat
ev.l=MUIWaitEvent
If ev
NPrint "MUI Event: ",ev
Select ev
Case #ev_main_cycle
Print "Cycle option changed to "
NPrint MUIGetCycle(#main_cycle)
Case #ev_main_close
quit.b=True
End Select
End If
Until quit
MUICloseWindow #main_window
End
For more entries, you need to call the muicycle custom class directly, and that's a little bit more complicated. I use this code instead of MUICycle for longer lists of options:
Code: MUINewObject #main_cycle,"Cycle.mui",#MUIA_Cycle_Entries,&*cycleoptionaddrs(0)
*cycleoptionaddrs(0) is a primitive array containing the addresses of each entry in an array containing the text of each of the entries required. It's messy, but this code can be used to define the entries, where the constant #maxoptions is the number of options, and option$ is an array containing the options required:
Code: For i=0 To #maxoptions-1
Read x$
option$(i)=x$
*cycleoptionaddrs(i)=&option$(i)
Next i
option$(#maxoptions)="Null!" ; Not necessary but good to catch bugs in case the option count is too big
*steptypeaddrs(#maxoptions)=Null ; Marks the end of the list for MUI
Data$ "Entry 1","Option 2","Cycle list 3" ; Add #maxoptions of strings here.
Setting up a notify is no problem, similar to any other gadget but using the cycle gadget specific constant #MUIA_Cycle_Active which you set up to trigger every time the active entry changes. MUINotifyApp works fine here.
Finally, reading the active entry seems to work fine for me with MUIGetCycle, but it can also be read by using:
Code: result=MUIGet(#main_cycle,#MUIA_Cycle_Active)
This is the generic way of reading the attribute of any MUI object. Setting the active entry in the cycle gadget however caused me problems in the past using MUISetCycle, so I always just use:
Code: MUISet #main_cycle,#MUIA_Cycle_Active,entry
where entry is the item to be selected. This will also trigger an event that says your cycle gadget was changed, so if this might cause a problem for your code, disable the notification for the update by adding the NoNotify tag:
Code: MUISet #main_cycle,#MUIA_NoNotify,1,#MUIA_Cycle_Active,entry
The MUI Autodocs contain descriptions of al lthe constants that apply for each object type. They're quite well laid out and while the code will look a little different to the C examples, the basics are the same, and the constants are the same too except they have a # in front of the name in Blitz but not in C. General rule for the MUI constants, those starting with #MUIA_ are attributes, #MUIM_ are methods, #MUIV_ are special values specific to the objects in question, and #MUII_ are MUI images.
Hope that helps!
Beiträge: 8
Themen: 1
Registriert seit: Jul 2015
Bewertung:
0
Hi Daedalus,
Many thanks for your effort in giving me this detailed information with the examples, later I will analyse your examples so I can see if they help me solving my code problem.
Daedalus schrieb:For more entries, you need to call the muicycle custom class directly, and that's a little bit more complicated.
I only need 4 entries in each of 2 cycle gadgets I will need, so no problem with that.
Daedalus schrieb:Setting up a notify is no problem, similar to any other gadget but using the cycle gadget specific constant #MUIA_Cycle_Active which you set up to trigger every time the active entry changes. MUINotifyApp works fine here.
Setting up the notify is my problem, I had tried various forms of coding the notify (all with MUINotify instead of MUINotifyApp) but with no luck. The one I choosed was:
Code: MUINotify 2,#MUIA_Cycle_Active,#MUIV_EveryTime,2,#MUIM_Set,MyChoice
It works well at first but give me problems in the selection of the choice of the 2nd cycle gadget
Next I post the code I created so could test the 2 cycle gadgets, if you run it will see that all works well but it never gives the selection in the 2nd cycle gadget:
Code: WBStartup
Dim PageName$(2)
PageName$(0)="Page 1"
PageName$(1)="Page 2"
MUILabel 0,"MyCycle 1",#MUIO_Label_DoubleFrame
MUILabel 1,"MyCycle 2",#MUIO_Label_DoubleFrame
MUICycle 2,"CyTest 1","CyTest 2","CyTest 3"
MUICycle 3,"CyTest 4","CyTest 5","CyTest 6"
MUISimpleButton 4,"Simple Button A"
MUISimpleButton 5,"Simple Button B"
MUIAddObjsHGroup 6,0,2
MUICreateHGroup 6
MUIAddObjsVGroup 7,6,4
MUICreateVGroup 7
MUIAddObjsHGroup 8,1,3
MUICreateHGroup 8
MUIAddObjsVGroup 9,8,5
MUICreateVGroup 9
MUIAddObjsPage 10,7,9
MUICreatePage 10,"Page 1","Page 2"
MUICreateWindow 11,"MyWin","TEST",10
MUIAddSubWindow 11
If MUICreateApplication <> True Then End
MUINotifyApp 11,#MUIA_Window_CloseRequest,1,-11
MUINotify 2,#MUIA_Cycle_Active,#MUIV_EveryTime,2,#MUIM_Set,MyChoice
MUINotify 3,#MUIA_Cycle_Active,#MUIV_EveryTime,3,#MUIM_Set,MyChoice2
success=MUIOpenWindow (11)
Repeat
ev.l=MUIWaitEvent
Select ev
Case MyChoice
cy=MUIGetCycle (2)
NPrint "MyChoice is CyTest ",cy+1
Case MyChoice2
cy=MUIGetCycle (3)
NPrint "MyChoice is CyTest ",cy+4
End Select
Until ev=-11
MUICloseWindow 11
End
Daedalus schrieb:Hope that helps!
It will help for sure, again, thanks for your effort.
Beiträge: 42
Themen: 8
Registriert seit: May 2014
Bewertung:
0
Okay, there are some strange things with your program for me. First off is that MUIWaitEvent is a little bit broken, and program flow continues even if no event has occurred. I don't know why that is but I suspect a bug in the MUI library that makes it behave identically to MUIEvent. This means that the loop runs constantly, which it should not. This in itself still isn't a real problem, except that you're checking the event code for the value of MyChoice, but that's always going to be zero as well. MyChoice2 is also going to be zero, but once one Case of a Select is triggered, all the other Cases are ignored. Because the event is triggered constantly with a 0, and MyChoice is also 0, it's always the first entry that triggers. That works correctly though, displaying the value of the entry in the first cycle gadget. It means that the code for reading the second cycle gadget should work but never gets to run.
You'll notice that the value is displayed even when the notifies for the cycle gadgets are commented out. Again, this is because your loop is running constantly and always triggering the first Case with 0 = 0. I'm not sure exactly what you were trying to do with the notifies, but the MUISet method requires two arguments following it: the attribute to set and the value to set it to. It doesn't set a variable contents, and you need to use a special #MUIV_ constant to set an attribute to the value of another gadget. That would be used for automatically setting a string gadget to the value of a slider for example, but can't be used for setting variables. so those notifies are effectively doing nothing (and maybe writing garbage to memory in some cases so be careful...)
What you need to do is first set up your loop so it only responds to event codes other than zero, then you need to either use MUINotifyApp to send the events to the application, or use MUINotify with the application object as a target (which is just what MUINotifyApp does anyway). So swap this code for the second part of your program and see the difference:
Code: MUINotifyApp 11,#MUIA_Window_CloseRequest,1,-11
MUINotifyApp 2,#MUIA_Cycle_Active,#MUIV_EveryTime,2
MUINotifyApp 3,#MUIA_Cycle_Active,#MUIV_EveryTime,3
success=MUIOpenWindow (11)
Repeat
ev.l=MUIWaitEvent
Select ev
Case 2
cy=MUIGetCycle (2)
NPrint "MyChoice is CyTest ",cy+1
Case 3
cy=MUIGetCycle (3)
NPrint "MyChoice is CyTest ",cy+4
End Select
Until ev=-11
MUICloseWindow 11
End
It works for me with the rest of your program untouched, and I think it's what you're looking for. The notifies set up an event code of 2 for the first cycle gadget and 3 for the second cycle gadget. The main loop then only responds on a 2 or a 3. It should never respond on a 0, because that means no event occurred.
Beiträge: 8
Themen: 1
Registriert seit: Jul 2015
Bewertung:
0
Hi Daedalus,
You´re right, everything you wrote is correct.
This is the first time I used MUI and I want to make an application that uses 2 cycle gadgets, so I wanted to understand how cycle gadgets are detected by the code but I never got do the Notify works as it should. This is because I always used the MUINotify instead of MUINotifyApp.
My app is at the begining of coding (I was only testing how MUI works) and I was stuck with the Notify but, with your help, I reached my goal and now the code works well:
Code: WBStartup
Dim PageName$(2)
PageName$(0)="Oscillator"
PageName$(1)="Timer"
#MyCycle1=11
#MyCycle2=22
MUIApplicationTitle "ChipCalc 555"
MUIApplicationVersion "$VER: ChipCalc 555 0.1 (10.08.2015)"
MUIApplicationCopyright "(c)2015 C.Domingues"
MUIApplicationAuthor "C.Domingues"
MUIApplicationDescription "555 calculator"
MUIApplicationBase "CHIPCALC"
MUILabel 0,"Calculate the",#MUIO_Label_DoubleFrame
MUILabel 1,"Calculate the",#MUIO_Label_DoubleFrame
MUICycle 2,"Resistor value","Capacitor value","Time periode"
MUICycle 3,"Resistor 1 value","Resistor 2 value","Frequency value"
MUISimpleButton 4,"Simple Button A"
MUISimpleButton 5,"Simple Button B"
MUIAddObjsHGroup 6,0,2
MUICreateHGroup 6
MUIAddObjsVGroup 7,6,4
MUICreateVGroup 7
MUIAddObjsHGroup 8,1,3
MUICreateHGroup 8
MUIAddObjsVGroup 9,8,5
MUICreateVGroup 9
MUIAddObjsPage 10,7,9
MUICreatePage 10,"Timer","Oscillator"
MUICreateWindow 11,"ChipCalc","PAGE",10
MUIAddSubWindow 11
If MUICreateApplication <> True Then End
MUINotifyApp 11,#MUIA_Window_CloseRequest,1,-11
MUINotifyApp 2,#MUIA_Cycle_Active,#MUIV_EveryTime,#MyCycle1
MUINotifyApp 3,#MUIA_Cycle_Active,#MUIV_EveryTime,#MyCycle2
success=MUIOpenWindow (11)
Repeat
ev.l=MUIWaitEvent
Select ev
Case #MyCycle1
cy=MUIGetCycle (2)
NPrint "MyChoice is Cycle1: ",cy
Case #MyCycle2
cy=MUIGetCycle (3)
NPrint "MyChoice is Cycle2: ",cy
End Select
Until ev=-11
MUICloseWindow 11
End
|