<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Oct 26, 2017, at 10:29 AM, Daniel Gurnon <<a href="mailto:danielgurnon@depauw.edu" class="">danielgurnon@depauw.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi everyone,</div></div></blockquote><div><br class=""></div>Hi Dan, Shuto,</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">Here's how Shuto describes the issue:</div><div class="">----</div><div class=""><br class=""></div><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div style="font-size:12.8px;word-wrap:break-word" class=""><div class="">I am trying to create a Chimera GUI extension that asks <span style="font-size:12.8px" class="">Chimera to fetch a PDB ID and then to highlight residue positions within the structure, with the PDB and positions </span><span style="font-size:12.8px" class="">taken from a CSV file.</span><span style="font-size:12.8px" class=""> </span>I started with a Python script, and it works <span style="font-size:12.8px" class="">as intended if I import it from IDLE.</span></div><div class=""><br class=""></div><div class=""><span style="font-size:12.8px" class="">However, when I tried to create a GUI using this guide</span></div><div class=""><span style="font-size:12.8px" class=""> </span><a href="https://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/Examples/Main_ExtensionUI.html" target="_blank" style="font-size:12.8px" class="">https://www.cgl.ucsf.edu/<wbr class="">chimera/docs/ProgrammersGuide/<wbr class="">Examples/Main_ExtensionUI.html</a><span style="font-size:12.8px" class=""><br class=""></span></div><div class="">I ran into an error.<span style="font-size:12.8px" class=""> 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.</span></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">The code snippet is as follows:</div><div class=""><br class=""></div><div class="">##############################<wbr class="">##############################<wbr class="">##</div><div class=""><br class=""></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class="">class MutationDialog(ModelessDialog)<wbr class="">:</div><div class=""><br class=""></div><div class=""> name = "mutation highlighter"</div><div class=""> title = "Rare Genetic Mutation Highlighter”</div></blockquote></div></div></div></div></div></div></div></div></div></blockquote><div><br class=""></div>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:</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>def fillInUI(self, parent):</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div style="font-size:12.8px;word-wrap:break-word" class=""><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><br class=""></div><div class=""><strike class=""> master = Tk()</strike></div><div class=""><strike class=""> master.title("Rare Genetic Disease Mutation Highlighter")</strike></div><div class=""><strike class=""> master.geometry('{}x{}'.<wbr class="">format(500, 100))</strike></div></blockquote></div></div></div></div></div></div></div></div></div></blockquote><div><br class=""></div>Don’t need any of the above three lines. Take them out.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div style="font-size:12.8px;word-wrap:break-word" class=""><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><br class=""></div><div class=""><br class=""></div><div class=""> global var</div><div class=""> var = StringVar(master)</div><div class=""> var.set(proteinNames[0])</div><div class=""><br class=""></div><div class=""> # proteinNames is a list of protein options that a user chooses</div><div class=""> options = OptionMenu(master, var, *proteinNames)</div><div class=""> options.pack()</div></blockquote></div></div></div></div></div></div></div></div></div></blockquote><div><br class=""></div>The above lines are okay, but instead of ‘master’ use ‘parent’.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div style="font-size:12.8px;word-wrap:break-word" class=""><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""> def Apply():</div><div class=""> # this functionality works</div><div class=""> protein_num = proteinMap[var.get()]</div><div class=""> mh.highlightMutation(filename, protein_num)</div><div class=""><br class=""></div><div class=""> button = Button(master, text = "Apply", command = Apply)</div><div class=""> button.pack()</div></blockquote></div></div></div></div></div></div></div></div></div></blockquote><div><br class=""></div>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:</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre"> </span>def Apply(self):</div><div><span class="Apple-tab-span" style="white-space:pre"> </span># rest of what you were doing in Apply is okay…</div><div><br class=""></div><div>You definitely don’t need the code that explicitly creates an Apply button.</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div style="font-size:12.8px;word-wrap:break-word" class=""><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><br class=""></div><div class="">chimera.dialogs.register(<wbr class="">MutationDialog.name, MutationDialog)</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">dir, file = os.path.split(__file__)</div><div class="">icon = os.path.join(dir, 'ExtensionUI.tiff')</div><div class="">chimera.tkgui.app.toolbar.add(<wbr class="">icon, lambda d=chimera.dialogs.display,</div><div class="">n=MutationDialog.name: d(n), 'Highlight Mutations', None)</div></blockquote></div></div></div></div></div></div></div></div></div></blockquote><div><br class=""></div>The rest of the code is fine. Let me know if you run into further problems.</div><div><br class=""></div><div>—Eric</div><div><br class=""></div><div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>Eric Pettersen</div><div class=""><span class="Apple-tab-span" style="white-space: pre;"> </span>UCSF Computer Graphics Lab</div></div></div><br class=""><div><blockquote type="cite" class=""></blockquote></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div style="font-size:12.8px;word-wrap:break-word" class=""><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px" class=""><div class=""><br class=""></div></blockquote>##############################<wbr class="">##############################<wbr class="">##<div class=""><br class=""></div><div class="">I suspect that MutationDialog class is not working as a proper callback class.</div><div class=""><br class=""></div><div class=""><b class="">Do you have any suggestions for the proper structure of the class?</b></div><div class="">We're also </div><div class=""><br class=""></div><div class="">Sincerely, </div></div><br style="font-size:12.8px" class=""><div style="font-size:12.8px;word-wrap:break-word" class=""><div class=""></div><div class="">Shuto</div><div class=""><br class=""></div><div class="">---</div><div class=""><br class=""></div><div class="">Thanks for any advice!</div><div class="">Dan</div></div></div><div dir="ltr" class=""><span style="font-size:12.8px" class="">_</span><span style="font-size:12.8px" class="">_</span><span style="font-size:12.8px" class="">__________________________</span><br class=""></div><div dir="ltr" class=""><br class=""></div><div dir="ltr" class="">Daniel Gurnon, Ph. D.<div class="">Associate Professor of Chemistry and Biochemistry</div><div class="">Director, Science Research Fellows Program<br class="">DePauw University<br class=""></div><div class="">Greencastle, IN 46135</div></div></div></div></div></div>
</div></div>
_______________________________________________<br class="">Chimera-dev mailing list<br class=""><a href="mailto:Chimera-dev@cgl.ucsf.edu" class="">Chimera-dev@cgl.ucsf.edu</a><br class="">http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-dev<br class=""></div></blockquote></div><br class=""></body></html>