[chimera-dev] creating an extension

Eric Pettersen pett at cgl.ucsf.edu
Mon Dec 9 12:07:22 PST 2013


Yeah, I think you want a button on the left (or right) next to each entry rather than across the bottom of the dialog which is what you're getting now.  Something like this block of code in your fillInUI routine:

self.stringVars = []
for row in range(10): #10 buttons/entries
	self.stringVars.append(Tkinter.StringVar(parent))
	Tkinter.Button(parent, text="Execute", command=lambda bn=butNum: self._execute(bn)).grid(row=row, column=0)
	Tkinter.Entry(parent, textvariable=self.stringVars[row], width=40).grid(row=row, column=1)

and the _execute routine would be:

def _execute(self, num):
	chimera.runCommand(self.stringVars[num].get())

--Eric

On Dec 9, 2013, at 10:45 AM, Conrad Huang <conrad at cgl.ucsf.edu> wrote:

> Personally, I would just stick with a standard Python GUI like Pmw. There's example code that work and it's well documented.  Perhaps http://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/Main_ExtensionUI.html might help.
> 
> Conrad
> 
> On 12/7/2013 3:03 PM, Dougherty, Matthew T wrote:
>> Hi,
>> 
>> I am trying to create a simple extension that has a column of buttons
>> (qty 10-20) having a corresponding column of user defined text
>> blocks. When I push a button, the corresponding text string will be
>> read and processed as a command string (eg, "reset default", "rock X
>> 3", "move Z 2000")
>> 
>> I started with VolumePlanes and whittled it down to the nub to figure
>> out what it was doing relative to what I want; below. I am realizing
>> the buttons defined by this example extension uses some specific
>> chimera GUI strategies. My going with a row of buttons would work as
>> in this volumeplanes example, but is second preference on layout.
>> More visually intuitive to have it side by side. Not sure this is
>> possible with another dozen lines of code, or if I would need to go
>> about it another route using different CGLTk api's and scrap using
>> this volumeplane extension as a boiler plate.
>> 
>> 
>> So I am realizing that this is putting me into the intricacies of
>> CGLtk.  An alternate would be to go with std python gui code.  I also
>> know you are reinventing chimera, one reason being the tk libraries,
>> which opens up a third approach.  So I am at a crossroad as to how to
>> proceed.  Because the code is relatively small, a rewrite for
>> chimera2 does not seem an issue.  Also there are some issues with
>> parenting I am unfamiliar with (eg, t.withdraw(), columnconfigure).
>> 
>> I am thinking this might be a good example of an extension for a
>> beginner, so writing it as such might be useful for others.
>> Particularly for new developers trying to sort out the boundaries
>> between python, chimera, tk, and the extension linkages.
>> 
>> Need some direction as to which way to go for the least amount of
>> work of coding.
>> 
>> thanks,
>> 
>> Matthew Dougherty National Center for Macromolecular Imaging Baylor
>> College of Medicine
>> 
>> 
>> ===========
>> 
>> #
>> -----------------------------------------------------------------------------
>> 
>> 
> import chimera
>> from chimera.baseDialog import ModelessDialog import ButtonCommands
>> 
>> #
>> -----------------------------------------------------------------------------
>> 
>> 
> class Button_Commands_Dialog(ModelessDialog):
>> title = 'Button Commands' name = 'button commands' buttons = ('C1',
>> 'C2', 'C3','Close',)
>> 
>> #
>> ---------------------------------------------------------------------------
>> 
>> 
> # ---------------------------------------------------------------------------
>> def fillInUI(self, parent): t = parent.winfo_toplevel()
>> self.toplevel_widget = t t.withdraw()
>> 
>> parent.columnconfigure(2, weight = 2)
>> 
>> from CGLtk import Hybrid
>> 
>> ps = Hybrid.Scale(parent, 'Cmd1', 0, 10, 1, 0) ps.frame.grid(row = 2,
>> column = 0, sticky = 'ew')
>> 
>> ps.callback(self.change_plane_cb) ps.entry.bind('<KeyPress-Return>',
>> self.change_plane_cb) self.plane = ps
>> 
>> def change_plane_cb(self, full_size = False): return
>> 
>> #
>> ---------------------------------------------------------------------------
>> 
>> 
> # ---------------------------------------------------------------------------
>> def C1(self): c_1='echo c1' chimera.runCommand(c_1)
>> 
>> def C2(self): c_2='echo c2' chimera.runCommand(c_2)
>> 
>> def C3(self): c_3='echo c3' chimera.runCommand(c_3)
>> 
>> #
>> -----------------------------------------------------------------------------
>> 
>> 
> def Button_Commands_dialog(create = False):
>> from chimera import dialogs return
>> dialogs.find(Button_Commands_Dialog.name, create=create)
>> 
>> #
>> -----------------------------------------------------------------------------
>> 
>> 
> def show_button_commands_dialog():
>> from chimera import dialogs return
>> dialogs.display(Button_Commands_Dialog.name)
>> 
>> #
>> -----------------------------------------------------------------------------
>> 
>> 
> from chimera import dialogs
>> dialogs.register(Button_Commands_Dialog.name, Button_Commands_Dialog,
>> replace = True)
>> 
>> _______________________________________________ Chimera-dev mailing
>> list Chimera-dev at cgl.ucsf.edu
>> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev
>> 
> _______________________________________________
> Chimera-dev mailing list
> Chimera-dev at cgl.ucsf.edu
> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev





More information about the Chimera-dev mailing list