
Hi everyone, I'm working with a undergraduate computer science student, Shuto Araki, on a Chimera development project that involves creating a GUI. I'm not a programmer, and he's learning Python as he goes- so we've run into the inevitable snag, and we're looking for some help. Here's how Shuto describes the issue: ---- I am trying to create a Chimera GUI extension that asks Chimera to fetch a PDB ID and then to highlight residue positions within the structure, with the PDB and positions taken from a CSV file. I started with a Python script, and it works as intended if I import it from IDLE. However, when I tried to create a GUI using this guide https://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/ Examples/Main_ExtensionUI.html I ran into an error. When I click on the button that I added on toolbar, the callback function does not seem to work properly. It just pops up an empty window with OK, Apply and Cancel buttons. The code snippet is as follows: ############################################################## class MutationDialog(ModelessDialog): name = "mutation highlighter" title = "Rare Genetic Mutation Highlighter” master = Tk() master.title("Rare Genetic Disease Mutation Highlighter") master.geometry('{}x{}'.format(500, 100)) global var var = StringVar(master) var.set(proteinNames[0]) # proteinNames is a list of protein options that a user chooses options = OptionMenu(master, var, *proteinNames) options.pack() def Apply(): # this functionality works protein_num = proteinMap[var.get()] mh.highlightMutation(filename, protein_num) button = Button(master, text = "Apply", command = Apply) button.pack() chimera.dialogs.register(MutationDialog.name, MutationDialog) dir, file = os.path.split(__file__) icon = os.path.join(dir, 'ExtensionUI.tiff') chimera.tkgui.app.toolbar.add(icon, lambda d=chimera.dialogs.display, n=MutationDialog.name: d(n), 'Highlight Mutations', None) ############################################################## I suspect that MutationDialog class is not working as a proper callback class. *Do you have any suggestions for the proper structure of the class?* We're also Sincerely, Shuto --- Thanks for any advice! Dan ____________________________ Daniel Gurnon, Ph. D. Associate Professor of Chemistry and Biochemistry Director, Science Research Fellows Program DePauw University Greencastle, IN 46135

On Oct 26, 2017, at 10:29 AM, Daniel Gurnon <danielgurnon@depauw.edu> wrote:
Hi everyone,
Hi Dan, Shuto,
I'm working with a undergraduate computer science student, Shuto Araki, on a Chimera development project that involves creating a GUI. I'm not a programmer, and he's learning Python as he goes- so we've run into the inevitable snag, and we're looking for some help.
Here's how Shuto describes the issue: ----
I am trying to create a Chimera GUI extension that asks Chimera to fetch a PDB ID and then to highlight residue positions within the structure, with the PDB and positions taken from a CSV file. I started with a Python script, and it works as intended if I import it from IDLE.
However, when I tried to create a GUI using this guide https://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/Main_Extensi... <https://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/Main_Extensi...> I ran into an error. When I click on the button that I added on toolbar, the callback function does not seem to work properly. It just pops up an empty window with OK, Apply and Cancel buttons.
The code snippet is as follows:
##############################################################
class MutationDialog(ModelessDialog):
name = "mutation highlighter" title = "Rare Genetic Mutation Highlighter”
So far so good, but this is where you begin to go off the rails. As per the example you were trying to follow, the creation of your custom user interface happens in the ‘fillInUI’ method, and your widgets should be children of the ‘parent’ argument that is passed into that method. So the next line should be: def fillInUI(self, parent):
master = Tk() master.title("Rare Genetic Disease Mutation Highlighter") master.geometry('{}x{}'.format(500, 100))
Don’t need any of the above three lines. Take them out.
global var var = StringVar(master) var.set(proteinNames[0])
# proteinNames is a list of protein options that a user chooses options = OptionMenu(master, var, *proteinNames) options.pack()
The above lines are okay, but instead of ‘master’ use ‘parent’.
def Apply(): # this functionality works protein_num = proteinMap[var.get()] mh.highlightMutation(filename, protein_num)
button = Button(master, text = "Apply", command = Apply) button.pack()
Okay, sort of, but no. :-) The ModelessDialog class will automatically create OK, Apply, and Close buttons (though that behavior can be overridden). All you have to do is define a class method named Apply and that method will be called when OK or Apply is clicked. So: def Apply(self): # rest of what you were doing in Apply is okay… You definitely don’t need the code that explicitly creates an Apply button.
chimera.dialogs.register(MutationDialog.name, MutationDialog)
dir, file = os.path.split(__file__) icon = os.path.join(dir, 'ExtensionUI.tiff') chimera.tkgui.app.toolbar.add(icon, lambda d=chimera.dialogs.display, n=MutationDialog.name: d(n), 'Highlight Mutations', None)
The rest of the code is fine. Let me know if you run into further problems. —Eric Eric Pettersen UCSF Computer Graphics Lab
##############################################################
I suspect that MutationDialog class is not working as a proper callback class.
Do you have any suggestions for the proper structure of the class? We're also
Sincerely,
Shuto
---
Thanks for any advice! Dan ____________________________
Daniel Gurnon, Ph. D. Associate Professor of Chemistry and Biochemistry Director, Science Research Fellows Program DePauw University Greencastle, IN 46135 _______________________________________________ Chimera-dev mailing list Chimera-dev@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-dev

Thank you Eric! ____________________________ Daniel Gurnon, Ph. D. Associate Professor of Chemistry and Biochemistry Director, Science Research Fellows Program DePauw University Greencastle, IN 46135 On Thu, Oct 26, 2017 at 7:17 PM, Eric Pettersen <pett@cgl.ucsf.edu> wrote:
On Oct 26, 2017, at 10:29 AM, Daniel Gurnon <danielgurnon@depauw.edu> wrote:
Hi everyone,
Hi Dan, Shuto,
I'm working with a undergraduate computer science student, Shuto Araki, on a Chimera development project that involves creating a GUI. I'm not a programmer, and he's learning Python as he goes- so we've run into the inevitable snag, and we're looking for some help.
Here's how Shuto describes the issue: ----
I am trying to create a Chimera GUI extension that asks Chimera to fetch a PDB ID and then to highlight residue positions within the structure, with the PDB and positions taken from a CSV file. I started with a Python script, and it works as intended if I import it from IDLE.
However, when I tried to create a GUI using this guide https://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Exam ples/Main_ExtensionUI.html I ran into an error. When I click on the button that I added on toolbar, the callback function does not seem to work properly. It just pops up an empty window with OK, Apply and Cancel buttons.
The code snippet is as follows:
##############################################################
class MutationDialog(ModelessDialog):
name = "mutation highlighter" title = "Rare Genetic Mutation Highlighter”
So far so good, but this is where you begin to go off the rails. As per the example you were trying to follow, the creation of your custom user interface happens in the ‘fillInUI’ method, and your widgets should be children of the ‘parent’ argument that is passed into that method. So the next line should be:
def fillInUI(self, parent):
master = Tk() master.title("Rare Genetic Disease Mutation Highlighter") master.geometry('{}x{}'.format(500, 100))
Don’t need any of the above three lines. Take them out.
global var var = StringVar(master) var.set(proteinNames[0])
# proteinNames is a list of protein options that a user chooses options = OptionMenu(master, var, *proteinNames) options.pack()
The above lines are okay, but instead of ‘master’ use ‘parent’.
def Apply(): # this functionality works protein_num = proteinMap[var.get()] mh.highlightMutation(filename, protein_num)
button = Button(master, text = "Apply", command = Apply) button.pack()
Okay, sort of, but no. :-) The ModelessDialog class will automatically create OK, Apply, and Close buttons (though that behavior can be overridden). All you have to do is define a class method named Apply and that method will be called when OK or Apply is clicked. So:
def Apply(self): # rest of what you were doing in Apply is okay…
You definitely don’t need the code that explicitly creates an Apply button.
chimera.dialogs.register(MutationDialog.name, MutationDialog)
dir, file = os.path.split(__file__) icon = os.path.join(dir, 'ExtensionUI.tiff') chimera.tkgui.app.toolbar.add(icon, lambda d=chimera.dialogs.display, n=MutationDialog.name: d(n), 'Highlight Mutations', None)
The rest of the code is fine. Let me know if you run into further problems.
—Eric
Eric Pettersen UCSF Computer Graphics Lab
##############################################################
I suspect that MutationDialog class is not working as a proper callback class.
*Do you have any suggestions for the proper structure of the class?* We're also
Sincerely,
Shuto
---
Thanks for any advice! Dan ____________________________
Daniel Gurnon, Ph. D. Associate Professor of Chemistry and Biochemistry Director, Science Research Fellows Program DePauw University Greencastle, IN 46135 _______________________________________________ Chimera-dev mailing list Chimera-dev@cgl.ucsf.edu http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-dev
participants (2)
-
Daniel Gurnon
-
Eric Pettersen