Make a toggle-button with image on in GeDialog
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/10/2011 at 03:31, xxxxxxxx wrote:
I cant find how I am supposed to make AddBitmapButton in Python or how to toggle a button.
Actually I also want to add the standard toggeling buttons: Move/Scale/Rotate and so on to the GUI of my Script.
I try to build my own toggling button and I found I can get hold of a standard icon by gui.GetIcon(c4d.RESOURCEIMAGE_MOVE) but I dont find how to apply it on buttons in CreateLayout()
Ofc I can use simple labels on my buttons but I still dont find how to make a button that is Toggle-able. I try to use BaseSelect.Toggle() for that but first I need to find the object associated with the id of my button? -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 05/10/2011 at 13:26, xxxxxxxx wrote:
I'm not sure if you can do this in R12. Because SetImage() was not supported yet.
But it does work in R13.Here's a complete dialog plugin example:
import c4d, os, sys from c4d import plugins, utils, bitmaps, gui, documents Plugin_ID=1000009 # Testing id ONLY!!!!!!! #enums myBitButton = 100010 class MyDialog_Gui(gui.GeDialog) : def CreateLayout(self) : bc = c4d.BaseContainer() #Create a new container to store the image we will load for the button later on self.GroupBegin(0, c4d.BFH_SCALEFIT|c4d.BFH_SCALEFIT, 1, 1, "Bitmap Example",0) #id, flags, columns, rows, grouptext, groupflags self.GroupBorder(c4d.BORDER_BLACK) bc.SetLong(c4d.BITMAPBUTTON_BORDER, c4d.BORDER_OUT) #Sets the border to look like a button bc.SetBool(c4d.BITMAPBUTTON_BUTTON, True) fn = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path path = os.path.join(fn,'image1.jpg') #The path to the image file bc.SetFilename(100010, path) #Fill the empty container with the id#, and the image's location(string value) #Lets check our container to see if the image's ID# and location are now stored in it properly image = bc.GetData(100010) print image for i in bc: print i self.myBitButton=self.AddCustomGui(100010, c4d.CUSTOMGUI_BITMAPBUTTON, "Bitmap Button", c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 30, 30, bc) self.myBitButton.SetImage(path, False) self.LayoutChanged(10042) #Updates the custom gizmo changes made to the GUI self.GroupEnd() return True def InitValues(self) : self.SetString(4002,"Waiting") #Sets the text inside of the field when the plugin opens self.SetString(4003,"Waiting") #Sets the text inside of the field when the plugin opens self.SetReal(1002, 0, 0,100,1) #Sets the slider's value to 0... With a range of 0-100... Step=1 return True def Command(self, id, msg) : doc = documents.GetActiveDocument() if id == 100010: print"Bitmap Button was Pushed" self.myBitButton.SetToggleState(True) fn2 = c4d.storage.GeGetC4DPath(c4d.C4D_PATH_DESKTOP) #Gets the desktop path path = os.path.join(fn2,'image2.jpg') #The path to the image file self.myBitButton.SetImage(fn2, False) #This does not work like in C++ !!! self.LayoutChanged(10042) #Updates the custom gizmo changes made to the GUI c4d.EventAdd() return True #--------------------------------------------------------------- # MyDialog_Main --- Where the plugin stuff happens--Don't edit #--------------------------------------------------------------- class myDialog_Main(plugins.CommandData) : dialog = None def Execute(self, doc) : # create the dialog if self.dialog is None: self.dialog = MyDialog_Gui() return self.dialog.Open(dlgtype=c4d.DLG_TYPE_ASYNC, pluginid=Plugin_ID, defaultw=200, defaulth=150, xpos=-1, ypos=-1) def RestoreLayout(self, sec_ref) : # manage nonmodal dialog if self.dialog is None: self.dialog = MyDialog_Gui() return self.dialog.Restore(pluginid=Plugin_ID, secret=sec_ref) if __name__ == "__main__": path, fn = os.path.split(__file__) bmp = bitmaps.BaseBitmap() bmp.InitWith(os.path.join(path, "res/icons/", "None")) plugins.RegisterCommandPlugin(Plugin_ID, "myPythonDialog",0,None,"", myDialog_Main())
Make sure you change the image references to image files you have on your desktop.
Or change the paths to where you want them to look for the button images.As you can see. One thing I'm having trouble with is swapping the button's image when it's clicked.
This works perfectly in C++. But I can't get it to work with Python in R13.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/10/2011 at 07:42, xxxxxxxx wrote:
I really don't understand why you always create ids but not use them..
Unfortunately this codedoes not workdoes only work in R13. Why not use a GeUserArea ? There it is also easy to swap the images.See this example code.
Cheers,
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/10/2011 at 08:47, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Unfortunately this code does not work in R13.
Other than the image swapping part. It works just fine for me.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/10/2011 at 08:59, xxxxxxxx wrote:
Oh
I meant R12, sorry -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/10/2011 at 09:13, xxxxxxxx wrote:
You had me worried there for moment.
I was thinking about posting a UA example too. But the guy was asking for help with SetImage() & GetIcon() functions. So I didn't think he wanted to use a UA.
I'd still like to know why my images don't swap using those functions like it does in C++.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/10/2011 at 07:15, xxxxxxxx wrote:
ScottA: hum... SetToggleState([True/False]) dont give me any visual feedback at all it looks like the button is stuck even if the event is triggered. In the new R13 documentation there is now a mentioning of BITMAPBUTTON_ICONID1 and BITMAPBUTTON_ICONID2 but I don't get my head around how they should be used or if they would help in your example.
Nux95: even if GeUserArea is not a button and it is a lot of extra code to setup... but it does work!
Tnx! -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/10/2011 at 09:19, xxxxxxxx wrote:
It's hard to say for sure because the documentation is so limited on this subject.
But it looks like a bug.The reason I say it's a bug is twofold:
1- It works properly in C++
2- self.myBitButton.SetToggleState(False) & self.myBitButton.SetToggleState(True) both return: None-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/02/2012 at 08:36, xxxxxxxx wrote:
Hi every 1 just jioned here yesterday and just started python copied and pasted the code you put up Scotta but im getting this error code can you give me any tips why the error is on this line of code
path, fn = os.path.split(__file__)
it says
NameError:name'_file_'is not defined
cheers.
Ray. -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/02/2012 at 08:37, xxxxxxxx wrote:
The code is not for the script-manager, put it into a *.pyp file and save it in Cinema 4D's plugin-folder.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/02/2012 at 08:40, xxxxxxxx wrote:
Cheers bud much great help.
Ray.