def fillInUI(self, parent): label = Tk.Label(parent, text="Warning: clipping is turned on (see Side View" " tool) and will severely slow down POV-Ray raytracing.", justify='left', height=2) import tkFont font = tkFont.Font(root=parent, font=label.cget('font')) label.config(wraplength=(self.text_width * font.measure('n'))) label.grid(row=0, columnspan=2, sticky=Tk.W, pady=5) off = Tk.Button(parent, text="Turn off clipping", command=self.__turnOff) off.grid(row=1, column=0, pady=1) if ClipWarning.__dsVar is None: ClipWarning.__dsVar = Tk.IntVar(chimera.tkgui.app) ClipWarning.__dsVar.set(False) ds = Tk.Checkbutton(parent, variable=ClipWarning.__dsVar, text="Don't show dialog again") from tkFont import Font font = Font(font=ds.cget('font')) font.config(size=int(0.75*float(font.cget('size'))+0.5), weight='normal') ds.config(font=font) ds.grid(row=1, column=1, sticky=Tk.SE, pady=1) parent.rowconfigure(0, weight=1) parent.columnconfigure(0, weight=1)
def __init__(self, parent): Tkinter.Frame.__init__(self, parent) self.menu = Pmw.OptionMenu(self, items=self.ambiguity, label_text="Ambiguity codes:", labelpos='w', command=self._configureInfo) self.menu.grid(row=0) self.label = Tkinter.Label(self, bd=0, padx=0, pady=0) from tkFont import Font font = Font(font=self.label.cget('font')) font.config(size=int(0.75*float(font.cget('size'))+0.5), weight="normal") self.label.config(font=font) self.label.grid(row=1)
def __init__(self, parent): Tkinter.Frame.__init__(self, parent) self.menu = Pmw.OptionMenu(self, items=self.ambiguity, label_text="Ambiguity codes:", labelpos='w', command=self._configureInfo) self.menu.grid(row=0) self.label = Tkinter.Label(self, bd=0, padx=0, pady=0) from tkFont import Font font = Font(font=self.label.cget('font')) font.config(size=int(0.75 * float(font.cget('size')) + 0.5), weight="normal") self.label.config(font=font) self.label.grid(row=1)
def __init__(self, master=None, title=None, buttons=None, default=None, help=None, oneshot=None, highlight=None, keepShown=None, resizable=True, *args, **kw): if master == None: from tkgui import app master = app else: self.overMaster = True self._master = master self._toplevel = Tk.Toplevel(master, *args, **kw) self._toplevel.wm_group(master) if not self.overMaster: self._idleWaits = 0 #self._toplevel.bind("<Map>", self._initialPosition) self._toplevel.after_idle(self._initialPosition) if title: self.title = title if not self.title: self.title = self.name if self.title: self._toplevel.title(self.title) if buttons: self.buttons = buttons if highlight and not default: default = highlight if default: self.default = default if not help is None: self.help = help if oneshot: self.oneshot = oneshot if keepShown: self.keepShown = keepShown if not resizable: self._toplevel.wm_resizable(0, 0) # 'OK' needs to be able to delay 'oneshot' destruction # until after the user-callback returns... self.delayOneshot = False #sys.__stderr__.write('Create dialog: %s %s\n' % # (self.title, str(self._toplevel))) #self._toplevel.bind("<Destroy>", self.Destroy) self._toplevel.protocol('WM_DELETE_WINDOW', self.Cancel) if isinstance(self.buttons, basestring): # compensate for common error of buttons # not being a sequence. self.buttons = (self.buttons,) if Cancel in self.buttons: self._toplevel.bind("<Escape>", lambda e, c=self.Cancel: c()) elif Close in self.buttons: self._toplevel.bind("<Escape>", lambda e, c=self.Close: c()) bot = Tk.Frame(self._toplevel) bot.pack(side=Tk.BOTTOM, fill=Tk.X) hr = Tk.Frame(self._toplevel, relief=Tk.GROOVE, borderwidth=1, height=2) hr.pack(side=Tk.BOTTOM, fill=Tk.X) if self.keepShown: self.__ksVar = Tkinter.IntVar(bot) self.__ksVar.set(False) ckbut = Tkinter.Checkbutton(bot, variable=self.__ksVar, text="Keep dialog up after %s" % self.keepShown, command=self.__keepShownCB) from tkFont import Font font = Font(font=ckbut.cget('font')) font.config(size=int(0.75*float(font.cget('size'))+0.5), weight='normal') ckbut.config(font=font) ckbut.pack(side=Tk.TOP, anchor=Tk.SE) self.__keepShownCB() # set up initial button assignment if hasattr(self, 'provideStatus') and self.provideStatus: slkw = { 'anchor': 'w', 'justify': 'left' } if self.statusWidth: slkw['width'] = self.statusWidth if self.statusPosition == "above": slMaster = self._toplevel else: slMaster = bot self.statusLine = Tk.Label(slMaster, **slkw) self._statusBlankHandle = None if not self.statusResizing: self.statusLine.bind('<Map>', self._statusMapCB) if self.statusPosition == "above": self.statusLine.pack(side=Tk.BOTTOM, fill=Tk.X, expand=Tk.NO) else: self.statusLine.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=Tk.YES) if self.help: import help help.register(self._toplevel, self.help) self.buttonWidgets = {} if resizable: sg = Ttk.Sizegrip(bot) sg.pack(anchor=Tk.SE, side=Tk.RIGHT) self.addSpecialButtons(bot) buttons = list(self.buttons[:]) # don't destroy original buttons # if Cancel or Close is present, it should be next to Help if Cancel in buttons: buttons.remove(Cancel) self.buttonWidgets[Cancel] = self.__addButton(bot, Cancel, self.default is Cancel) if Close in buttons: buttons.remove(Close) self.buttonWidgets[Close] = self.__addButton(bot, Close, self.default is Close) buttons.reverse() for b in buttons: self.buttonWidgets[b] = self.__addButton(bot, b, self.default == b) if self.name: import dialogs dialogs.reregister(self.name, self) # pack last, so that resizing dialog will not occlude # action buttons self.__top = Tk.Frame(self._toplevel) self.__top.pack(side=Tk.TOP, anchor=Tk.W, expand=1, fill=Tk.BOTH) # do this after pack so that fillInUI can show progress if # necessary self.fillInUI(self.__top)
class DrtGlueDemo(object): def __init__(self, examples): # Set up the main window. self._top = Tk() self._top.title('DRT Glue Demo') # Set up key bindings. self._init_bindings() # Initialize the fonts.self._error = None self._init_fonts(self._top) self._examples = examples self._readingCache = [None for example in examples] # The user can hide the grammar. self._show_grammar = IntVar(self._top) self._show_grammar.set(1) # Set the data to None self._curExample = -1 self._readings = [] self._drs = None self._drsWidget = None self._error = None self._init_glue() # Create the basic frames. self._init_menubar(self._top) self._init_buttons(self._top) self._init_exampleListbox(self._top) self._init_readingListbox(self._top) self._init_canvas(self._top) # Resize callback self._canvas.bind('<Configure>', self._configure) ######################################### ## Initialization Helpers ######################################### def _init_glue(self): tagger = RegexpTagger( [('^(David|Mary|John)$', 'NNP'), ('^(walks|sees|eats|chases|believes|gives|sleeps|chases|persuades|tries|seems|leaves)$', 'VB'), ('^(go|order|vanish|find|approach)$', 'VB'), ('^(a)$', 'ex_quant'), ('^(every)$', 'univ_quant'), ('^(sandwich|man|dog|pizza|unicorn|cat|senator)$', 'NN'), ('^(big|gray|former)$', 'JJ'), ('^(him|himself)$', 'PRP') ]) depparser = MaltParser(tagger=tagger) self._glue = DrtGlue(depparser=depparser, remove_duplicates=False) def _init_fonts(self, root): # See: <http://www.astro.washington.edu/owen/ROTKFolklore.html> self._sysfont = Font(font=Button()["font"]) root.option_add("*Font", self._sysfont) # TWhat's our font size (default=same as sysfont) self._size = IntVar(root) self._size.set(self._sysfont.cget('size')) self._boldfont = Font(family='helvetica', weight='bold', size=self._size.get()) self._font = Font(family='helvetica', size=self._size.get()) if self._size.get() < 0: big = self._size.get()-2 else: big = self._size.get()+2 self._bigfont = Font(family='helvetica', weight='bold', size=big) def _init_exampleListbox(self, parent): self._exampleFrame = listframe = Frame(parent) self._exampleFrame.pack(fill='both', side='left', padx=2) self._exampleList_label = Label(self._exampleFrame, font=self._boldfont, text='Examples') self._exampleList_label.pack() self._exampleList = Listbox(self._exampleFrame, selectmode='single', relief='groove', background='white', foreground='#909090', font=self._font, selectforeground='#004040', selectbackground='#c0f0c0') self._exampleList.pack(side='right', fill='both', expand=1) for example in self._examples: self._exampleList.insert('end', (' %s' % example)) self._exampleList.config(height=min(len(self._examples), 25), width=40) # Add a scrollbar if there are more than 25 examples. if len(self._examples) > 25: listscroll = Scrollbar(self._exampleFrame, orient='vertical') self._exampleList.config(yscrollcommand = listscroll.set) listscroll.config(command=self._exampleList.yview) listscroll.pack(side='left', fill='y') # If they select a example, apply it. self._exampleList.bind('<<ListboxSelect>>', self._exampleList_select) def _init_readingListbox(self, parent): self._readingFrame = listframe = Frame(parent) self._readingFrame.pack(fill='both', side='left', padx=2) self._readingList_label = Label(self._readingFrame, font=self._boldfont, text='Readings') self._readingList_label.pack() self._readingList = Listbox(self._readingFrame, selectmode='single', relief='groove', background='white', foreground='#909090', font=self._font, selectforeground='#004040', selectbackground='#c0f0c0') self._readingList.pack(side='right', fill='both', expand=1) # Add a scrollbar if there are more than 25 examples. listscroll = Scrollbar(self._readingFrame, orient='vertical') self._readingList.config(yscrollcommand = listscroll.set) listscroll.config(command=self._readingList.yview) listscroll.pack(side='right', fill='y') self._populate_readingListbox() def _populate_readingListbox(self): # Populate the listbox with integers self._readingList.delete(0, 'end') for i in range(len(self._readings)): self._readingList.insert('end', (' %s' % (i+1))) self._readingList.config(height=min(len(self._readings), 25), width=5) # If they select a example, apply it. self._readingList.bind('<<ListboxSelect>>', self._readingList_select) def _init_bindings(self): # Key bindings are a good thing. self._top.bind('<Control-q>', self.destroy) self._top.bind('<Control-x>', self.destroy) self._top.bind('<Escape>', self.destroy) self._top.bind('n', self.next) self._top.bind('<space>', self.next) self._top.bind('p', self.prev) self._top.bind('<BackSpace>', self.prev) def _init_buttons(self, parent): # Set up the frames. self._buttonframe = buttonframe = Frame(parent) buttonframe.pack(fill='none', side='bottom', padx=3, pady=2) Button(buttonframe, text='Prev', background='#90c0d0', foreground='black', command=self.prev,).pack(side='left') Button(buttonframe, text='Next', background='#90c0d0', foreground='black', command=self.next,).pack(side='left') def _configure(self, event): self._autostep = 0 (x1, y1, x2, y2) = self._cframe.scrollregion() y2 = event.height - 6 self._canvas['scrollregion'] = '%d %d %d %d' % (x1,y1,x2,y2) self._redraw() def _init_canvas(self, parent): self._cframe = CanvasFrame(parent, background='white', #width=525, height=250, closeenough=10, border=2, relief='sunken') self._cframe.pack(expand=1, fill='both', side='top', pady=2) canvas = self._canvas = self._cframe.canvas() # Initially, there's no tree or text self._tree = None self._textwidgets = [] self._textline = None def _init_menubar(self, parent): menubar = Menu(parent) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label='Exit', underline=1, command=self.destroy, accelerator='q') menubar.add_cascade(label='File', underline=0, menu=filemenu) actionmenu = Menu(menubar, tearoff=0) actionmenu.add_command(label='Next', underline=0, command=self.next, accelerator='n, Space') actionmenu.add_command(label='Previous', underline=0, command=self.prev, accelerator='p, Backspace') menubar.add_cascade(label='Action', underline=0, menu=actionmenu) optionmenu = Menu(menubar, tearoff=0) optionmenu.add_checkbutton(label='Remove Duplicates', underline=0, variable=self._glue.remove_duplicates, command=self._toggle_remove_duplicates, accelerator='r') menubar.add_cascade(label='Options', underline=0, menu=optionmenu) viewmenu = Menu(menubar, tearoff=0) viewmenu.add_radiobutton(label='Tiny', variable=self._size, underline=0, value=10, command=self.resize) viewmenu.add_radiobutton(label='Small', variable=self._size, underline=0, value=12, command=self.resize) viewmenu.add_radiobutton(label='Medium', variable=self._size, underline=0, value=14, command=self.resize) viewmenu.add_radiobutton(label='Large', variable=self._size, underline=0, value=18, command=self.resize) viewmenu.add_radiobutton(label='Huge', variable=self._size, underline=0, value=24, command=self.resize) menubar.add_cascade(label='View', underline=0, menu=viewmenu) helpmenu = Menu(menubar, tearoff=0) helpmenu.add_command(label='About', underline=0, command=self.about) menubar.add_cascade(label='Help', underline=0, menu=helpmenu) parent.config(menu=menubar) ######################################### ## Main draw procedure ######################################### def _redraw(self): canvas = self._canvas # Delete the old DRS, widgets, etc. if self._drsWidget is not None: self._drsWidget.clear() if self._drs: self._drsWidget = DrsWidget( self._canvas, self._drs ) self._drsWidget.draw() if self._error: self._drsWidget = DrsWidget( self._canvas, self._error ) self._drsWidget.draw() ######################################### ## Button Callbacks ######################################### def destroy(self, *e): self._autostep = 0 if self._top is None: return self._top.destroy() self._top = None def prev(self, *e): selection = self._readingList.curselection() readingListSize = self._readingList.size() # there are readings if readingListSize > 0: # if one reading is currently selected if len(selection) == 1: index = int(selection[0]) # if it's on (or before) the first item if index <= 0: self._select_previous_example() else: self._readingList_store_selection(index-1) else: #select its first reading self._readingList_store_selection(readingListSize-1) else: self._select_previous_example() def _select_previous_example(self): #if the current example is not the first example if self._curExample > 0: self._exampleList_store_selection(self._curExample-1) else: #go to the last example self._exampleList_store_selection(len(self._examples)-1) def next(self, *e): selection = self._readingList.curselection() readingListSize = self._readingList.size() # if there are readings if readingListSize > 0: # if one reading is currently selected if len(selection) == 1: index = int(selection[0]) # if it's on (or past) the last item if index >= (readingListSize-1): self._select_next_example() else: self._readingList_store_selection(index+1) else: #select its first reading self._readingList_store_selection(0) else: self._select_next_example() def _select_next_example(self): #if the current example is not the last example if self._curExample < len(self._examples)-1: self._exampleList_store_selection(self._curExample+1) else: #go to the first example self._exampleList_store_selection(0) def about(self, *e): ABOUT = ("NLTK Discourse Representation Theory (DRT) Glue Semantics Demo\n"+ "Written by Daniel H. Garrette") TITLE = 'About: NLTK DRT Glue Demo' try: from tkMessageBox import Message Message(message=ABOUT, title=TITLE).show() except: ShowText(self._top, TITLE, ABOUT) def postscript(self, *e): self._autostep = 0 self._cframe.print_to_file() def mainloop(self, *args, **kwargs): """ Enter the Tkinter mainloop. This function must be called if this demo is created from a non-interactive program (e.g. from a secript); otherwise, the demo will close as soon as the script completes. """ if in_idle(): return self._top.mainloop(*args, **kwargs) def resize(self, size=None): if size is not None: self._size.set(size) size = self._size.get() self._font.configure(size=-(abs(size))) self._boldfont.configure(size=-(abs(size))) self._sysfont.configure(size=-(abs(size))) self._bigfont.configure(size=-(abs(size+2))) self._redraw() def _toggle_remove_duplicates(self): self._glue.remove_duplicates = not self._glue.remove_duplicates self._exampleList.selection_clear(0, 'end') self._readings = [] self._populate_readingListbox() self._readingCache = [None for ex in self._examples] self._curExample = -1 self._error = None self._drs = None self._redraw() def _exampleList_select(self, event): selection = self._exampleList.curselection() if len(selection) != 1: return self._exampleList_store_selection(int(selection[0])) def _exampleList_store_selection(self, index): self._curExample = index example = self._examples[index] self._exampleList.selection_clear(0, 'end') if example: cache = self._readingCache[index] if cache: if isinstance(cache, list): self._readings = cache self._error = None else: self._readings = [] self._error = cache else: try: self._readings = self._glue.parse_to_meaning(example) self._error = None self._readingCache[index] = self._readings except Exception, e: self._readings = [] self._error = DrtVariableExpression(Variable('Error: ' + str(e))) self._readingCache[index] = self._error #add a star to the end of the example self._exampleList.delete(index) self._exampleList.insert(index, (' %s *' % example)) self._exampleList.config(height=min(len(self._examples), 25), width=40) self._populate_readingListbox() self._exampleList.selection_set(index) self._drs = None self._redraw()
class DrtGlueDemo(object): def __init__(self, examples): # Set up the main window. self._top = Tk() self._top.title('DRT Glue Demo') # Set up key bindings. self._init_bindings() # Initialize the fonts.self._error = None self._init_fonts(self._top) self._examples = examples self._readingCache = [None for example in examples] # The user can hide the grammar. self._show_grammar = IntVar(self._top) self._show_grammar.set(1) # Set the data to None self._curExample = -1 self._readings = [] self._drs = None self._drsWidget = None self._error = None self._init_glue() # Create the basic frames. self._init_menubar(self._top) self._init_buttons(self._top) self._init_exampleListbox(self._top) self._init_readingListbox(self._top) self._init_canvas(self._top) # Resize callback self._canvas.bind('<Configure>', self._configure) ######################################### ## Initialization Helpers ######################################### def _init_glue(self): tagger = RegexpTagger([ ('^(David|Mary|John)$', 'NNP'), ('^(walks|sees|eats|chases|believes|gives|sleeps|chases|persuades|tries|seems|leaves)$', 'VB'), ('^(go|order|vanish|find|approach)$', 'VB'), ('^(a)$', 'ex_quant'), ('^(every)$', 'univ_quant'), ('^(sandwich|man|dog|pizza|unicorn|cat|senator)$', 'NN'), ('^(big|gray|former)$', 'JJ'), ('^(him|himself)$', 'PRP') ]) depparser = MaltParser(tagger=tagger) self._glue = DrtGlue(depparser=depparser, remove_duplicates=False) def _init_fonts(self, root): # See: <http://www.astro.washington.edu/owen/ROTKFolklore.html> self._sysfont = Font(font=Button()["font"]) root.option_add("*Font", self._sysfont) # TWhat's our font size (default=same as sysfont) self._size = IntVar(root) self._size.set(self._sysfont.cget('size')) self._boldfont = Font(family='helvetica', weight='bold', size=self._size.get()) self._font = Font(family='helvetica', size=self._size.get()) if self._size.get() < 0: big = self._size.get() - 2 else: big = self._size.get() + 2 self._bigfont = Font(family='helvetica', weight='bold', size=big) def _init_exampleListbox(self, parent): self._exampleFrame = listframe = Frame(parent) self._exampleFrame.pack(fill='both', side='left', padx=2) self._exampleList_label = Label(self._exampleFrame, font=self._boldfont, text='Examples') self._exampleList_label.pack() self._exampleList = Listbox(self._exampleFrame, selectmode='single', relief='groove', background='white', foreground='#909090', font=self._font, selectforeground='#004040', selectbackground='#c0f0c0') self._exampleList.pack(side='right', fill='both', expand=1) for example in self._examples: self._exampleList.insert('end', (' %s' % example)) self._exampleList.config(height=min(len(self._examples), 25), width=40) # Add a scrollbar if there are more than 25 examples. if len(self._examples) > 25: listscroll = Scrollbar(self._exampleFrame, orient='vertical') self._exampleList.config(yscrollcommand=listscroll.set) listscroll.config(command=self._exampleList.yview) listscroll.pack(side='left', fill='y') # If they select a example, apply it. self._exampleList.bind('<<ListboxSelect>>', self._exampleList_select) def _init_readingListbox(self, parent): self._readingFrame = listframe = Frame(parent) self._readingFrame.pack(fill='both', side='left', padx=2) self._readingList_label = Label(self._readingFrame, font=self._boldfont, text='Readings') self._readingList_label.pack() self._readingList = Listbox(self._readingFrame, selectmode='single', relief='groove', background='white', foreground='#909090', font=self._font, selectforeground='#004040', selectbackground='#c0f0c0') self._readingList.pack(side='right', fill='both', expand=1) # Add a scrollbar if there are more than 25 examples. listscroll = Scrollbar(self._readingFrame, orient='vertical') self._readingList.config(yscrollcommand=listscroll.set) listscroll.config(command=self._readingList.yview) listscroll.pack(side='right', fill='y') self._populate_readingListbox() def _populate_readingListbox(self): # Populate the listbox with integers self._readingList.delete(0, 'end') for i in range(len(self._readings)): self._readingList.insert('end', (' %s' % (i + 1))) self._readingList.config(height=min(len(self._readings), 25), width=5) # If they select a example, apply it. self._readingList.bind('<<ListboxSelect>>', self._readingList_select) def _init_bindings(self): # Key bindings are a good thing. self._top.bind('<Control-q>', self.destroy) self._top.bind('<Control-x>', self.destroy) self._top.bind('<Escape>', self.destroy) self._top.bind('n', self.next) self._top.bind('<space>', self.next) self._top.bind('p', self.prev) self._top.bind('<BackSpace>', self.prev) def _init_buttons(self, parent): # Set up the frames. self._buttonframe = buttonframe = Frame(parent) buttonframe.pack(fill='none', side='bottom', padx=3, pady=2) Button( buttonframe, text='Prev', background='#90c0d0', foreground='black', command=self.prev, ).pack(side='left') Button( buttonframe, text='Next', background='#90c0d0', foreground='black', command=self.next, ).pack(side='left') def _configure(self, event): self._autostep = 0 (x1, y1, x2, y2) = self._cframe.scrollregion() y2 = event.height - 6 self._canvas['scrollregion'] = '%d %d %d %d' % (x1, y1, x2, y2) self._redraw() def _init_canvas(self, parent): self._cframe = CanvasFrame( parent, background='white', #width=525, height=250, closeenough=10, border=2, relief='sunken') self._cframe.pack(expand=1, fill='both', side='top', pady=2) canvas = self._canvas = self._cframe.canvas() # Initially, there's no tree or text self._tree = None self._textwidgets = [] self._textline = None def _init_menubar(self, parent): menubar = Menu(parent) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label='Exit', underline=1, command=self.destroy, accelerator='q') menubar.add_cascade(label='File', underline=0, menu=filemenu) actionmenu = Menu(menubar, tearoff=0) actionmenu.add_command(label='Next', underline=0, command=self.next, accelerator='n, Space') actionmenu.add_command(label='Previous', underline=0, command=self.prev, accelerator='p, Backspace') menubar.add_cascade(label='Action', underline=0, menu=actionmenu) optionmenu = Menu(menubar, tearoff=0) optionmenu.add_checkbutton(label='Remove Duplicates', underline=0, variable=self._glue.remove_duplicates, command=self._toggle_remove_duplicates, accelerator='r') menubar.add_cascade(label='Options', underline=0, menu=optionmenu) viewmenu = Menu(menubar, tearoff=0) viewmenu.add_radiobutton(label='Tiny', variable=self._size, underline=0, value=10, command=self.resize) viewmenu.add_radiobutton(label='Small', variable=self._size, underline=0, value=12, command=self.resize) viewmenu.add_radiobutton(label='Medium', variable=self._size, underline=0, value=14, command=self.resize) viewmenu.add_radiobutton(label='Large', variable=self._size, underline=0, value=18, command=self.resize) viewmenu.add_radiobutton(label='Huge', variable=self._size, underline=0, value=24, command=self.resize) menubar.add_cascade(label='View', underline=0, menu=viewmenu) helpmenu = Menu(menubar, tearoff=0) helpmenu.add_command(label='About', underline=0, command=self.about) menubar.add_cascade(label='Help', underline=0, menu=helpmenu) parent.config(menu=menubar) ######################################### ## Main draw procedure ######################################### def _redraw(self): canvas = self._canvas # Delete the old DRS, widgets, etc. if self._drsWidget is not None: self._drsWidget.clear() if self._drs: self._drsWidget = DrsWidget(self._canvas, self._drs) self._drsWidget.draw() if self._error: self._drsWidget = DrsWidget(self._canvas, self._error) self._drsWidget.draw() ######################################### ## Button Callbacks ######################################### def destroy(self, *e): self._autostep = 0 if self._top is None: return self._top.destroy() self._top = None def prev(self, *e): selection = self._readingList.curselection() readingListSize = self._readingList.size() # there are readings if readingListSize > 0: # if one reading is currently selected if len(selection) == 1: index = int(selection[0]) # if it's on (or before) the first item if index <= 0: self._select_previous_example() else: self._readingList_store_selection(index - 1) else: #select its first reading self._readingList_store_selection(readingListSize - 1) else: self._select_previous_example() def _select_previous_example(self): #if the current example is not the first example if self._curExample > 0: self._exampleList_store_selection(self._curExample - 1) else: #go to the last example self._exampleList_store_selection(len(self._examples) - 1) def next(self, *e): selection = self._readingList.curselection() readingListSize = self._readingList.size() # if there are readings if readingListSize > 0: # if one reading is currently selected if len(selection) == 1: index = int(selection[0]) # if it's on (or past) the last item if index >= (readingListSize - 1): self._select_next_example() else: self._readingList_store_selection(index + 1) else: #select its first reading self._readingList_store_selection(0) else: self._select_next_example() def _select_next_example(self): #if the current example is not the last example if self._curExample < len(self._examples) - 1: self._exampleList_store_selection(self._curExample + 1) else: #go to the first example self._exampleList_store_selection(0) def about(self, *e): ABOUT = ( "NLTK Discourse Representation Theory (DRT) Glue Semantics Demo\n" + "Written by Daniel H. Garrette") TITLE = 'About: NLTK DRT Glue Demo' try: from tkMessageBox import Message Message(message=ABOUT, title=TITLE).show() except: ShowText(self._top, TITLE, ABOUT) def postscript(self, *e): self._autostep = 0 self._cframe.print_to_file() def mainloop(self, *args, **kwargs): """ Enter the Tkinter mainloop. This function must be called if this demo is created from a non-interactive program (e.g. from a secript); otherwise, the demo will close as soon as the script completes. """ if in_idle(): return self._top.mainloop(*args, **kwargs) def resize(self, size=None): if size is not None: self._size.set(size) size = self._size.get() self._font.configure(size=-(abs(size))) self._boldfont.configure(size=-(abs(size))) self._sysfont.configure(size=-(abs(size))) self._bigfont.configure(size=-(abs(size + 2))) self._redraw() def _toggle_remove_duplicates(self): self._glue.remove_duplicates = not self._glue.remove_duplicates self._exampleList.selection_clear(0, 'end') self._readings = [] self._populate_readingListbox() self._readingCache = [None for ex in self._examples] self._curExample = -1 self._error = None self._drs = None self._redraw() def _exampleList_select(self, event): selection = self._exampleList.curselection() if len(selection) != 1: return self._exampleList_store_selection(int(selection[0])) def _exampleList_store_selection(self, index): self._curExample = index example = self._examples[index] self._exampleList.selection_clear(0, 'end') if example: cache = self._readingCache[index] if cache: if isinstance(cache, list): self._readings = cache self._error = None else: self._readings = [] self._error = cache else: try: self._readings = self._glue.parse_to_meaning(example) self._error = None self._readingCache[index] = self._readings except Exception, e: self._readings = [] self._error = DrtVariableExpression( Variable('Error: ' + str(e))) self._readingCache[index] = self._error #add a star to the end of the example self._exampleList.delete(index) self._exampleList.insert(index, (' %s *' % example)) self._exampleList.config(height=min( len(self._examples), 25), width=40) self._populate_readingListbox() self._exampleList.selection_set(index) self._drs = None self._redraw()
def fillInUI(self, parent): import Pmw, Tkinter self.buttonWidgets['OK']['state'] = 'disabled' self.buttonWidgets['Apply']['state'] = 'disabled' from chimera.widgets import ModelScrolledListBox self.surfListBox = ModelScrolledListBox( parent, labelpos='n', label_text='Surfaces to color by ESP:', listbox_selectmode="extended", filtFunc=lambda m: isinstance(m, chimera.MSMSModel), selectioncommand=self._selSurfCB) self.surfListBox.grid(row=0, column=0, sticky="nsew", columnspan=2) Pmw.OptionMenu(parent, command=self._menuCB, initialitem="3", items=[str(x) for x in range(2, 12)], labelpos='w', label_text="Number of colors/values:").grid( row=1, column=0, columnspan=2) f = self.interpFrame = Tkinter.Frame(parent) f.grid(row=2, column=0, columnspan=2) self.wells = [] self.values = [] self._entryOpts = { 'validate': 'real', 'entry_justify': 'center', 'entry_width': 6 } from CGLtk.color.ColorWell import ColorWell for color, value in [("red", -10), ("white", 0), ("blue", 10)]: well = ColorWell(f, color=color) well.grid(row=0, column=len(self.wells)) self.wells.append(well) entry = Pmw.EntryField(f, value=str(value), **self._entryOpts) entry.grid(row=1, column=len(self.values)) self.values.append(entry) from chimera.tkoptions import FloatOption, BooleanOption self.distDep = BooleanOption( parent, 3, "Distance-dependent dielectric", True, None, balloon="If true, charge falls off with distance squared to\n" "simulate solvent screening effects") self.dielectric = FloatOption(parent, 4, "Dielectric constant", 4.0, None) self.surfDist = FloatOption(parent, 5, "Distance from surface", 1.4, None, balloon="Potential at this distance from\n" "the surface is used for coloring") self.hisGroup = Pmw.Group(parent, hull_padx=2, tag_text="Implicit Histidine Protonation") self.hisGroup.grid(row=6, column=0, columnspan=2, sticky="nsew") self.hisProtVar = Tkinter.StringVar(parent) self.hisProtVar.set("name") interior = self.hisGroup.interior() interior.columnconfigure(0, weight=1) lab = Tkinter.Label( interior, text="Assumed histidine " "protonation for\nstructures without explicit hydrogens") from tkFont import Font font = Font(font=lab.cget('font')) font.config(size=int(0.75 * float(font.cget('size'))), slant='italic') lab.config(font=font) lab.grid(row=0) Tkinter.Radiobutton(interior, variable=self.hisProtVar, value="name", text="Residue name-based", command=self._switchHisList).grid(row=1, sticky='w') f = Tkinter.Frame(interior) f.grid(row=2) Tkinter.Label(f, text="HID/HIE/HIP = delta/epsilon/both").grid(row=0, sticky='w') self.hisDefault = Pmw.OptionMenu( f, initialitem=self.HB, items=[self.HB, "delta", "epsilon", "both"], labelpos='w', label_text="HIS = ", command=lambda a, s=self: setattr(s, 'hisChanged', True)) self.hisDefault.grid(row=1, sticky='w') self._pickText = Tkinter.StringVar(parent) self._pickText.set("Specified individually...") Tkinter.Radiobutton(interior, variable=self.hisProtVar, value="pick", textvariable=self._pickText, command=self._switchHisList).grid(row=3, sticky='w') Tkinter.Button(parent, pady=0, command=self._colorKeyCB, text="Create corresponding color key").grid( row=7, column=0, columnspan=2) self.hisChanged = False
def fillInUI(self, parent): import Pmw, Tkinter self.buttonWidgets['OK']['state'] = 'disabled' self.buttonWidgets['Apply']['state'] = 'disabled' from chimera.widgets import ModelScrolledListBox self.surfListBox = ModelScrolledListBox(parent, labelpos='n', label_text='Surfaces to color by ESP:', listbox_selectmode="extended", filtFunc=lambda m: isinstance(m, chimera.MSMSModel), selectioncommand=self._selSurfCB) self.surfListBox.grid(row=0, column=0, sticky="nsew", columnspan=2) Pmw.OptionMenu(parent, command=self._menuCB, initialitem="3", items=[str(x) for x in range(2, 12)], labelpos='w', label_text="Number of colors/values:").grid(row=1, column=0, columnspan=2) f = self.interpFrame = Tkinter.Frame(parent) f.grid(row=2, column=0, columnspan=2) self.wells = [] self.values = [] self._entryOpts = { 'validate': 'real', 'entry_justify': 'center', 'entry_width': 6 } from CGLtk.color.ColorWell import ColorWell for color, value in [("red", -10), ("white", 0), ("blue", 10)]: well = ColorWell(f, color=color) well.grid(row=0, column=len(self.wells)) self.wells.append(well) entry = Pmw.EntryField(f, value=str(value), **self._entryOpts) entry.grid(row=1, column=len(self.values)) self.values.append(entry) from chimera.tkoptions import FloatOption, BooleanOption self.distDep = BooleanOption(parent, 3, "Distance-dependent dielectric", True, None, balloon= "If true, charge falls off with distance squared to\n" "simulate solvent screening effects") self.dielectric = FloatOption(parent, 4, "Dielectric constant", 4.0, None) self.surfDist = FloatOption(parent, 5, "Distance from surface", 1.4, None, balloon="Potential at this distance from\n" "the surface is used for coloring") self.hisGroup = Pmw.Group(parent, hull_padx=2, tag_text="Implicit Histidine Protonation") self.hisGroup.grid(row=6, column=0, columnspan=2, sticky="nsew") self.hisProtVar = Tkinter.StringVar(parent) self.hisProtVar.set("name") interior = self.hisGroup.interior() interior.columnconfigure(0, weight=1) lab = Tkinter.Label(interior, text="Assumed histidine " "protonation for\nstructures without explicit hydrogens") from tkFont import Font font = Font(font=lab.cget('font')) font.config(size=int(0.75 * float(font.cget('size'))), slant='italic') lab.config(font=font) lab.grid(row=0) Tkinter.Radiobutton(interior, variable=self.hisProtVar, value="name", text="Residue name-based", command= self._switchHisList).grid(row=1, sticky='w') f = Tkinter.Frame(interior) f.grid(row=2) Tkinter.Label(f, text="HID/HIE/HIP = delta/epsilon/both").grid( row=0, sticky='w') self.hisDefault = Pmw.OptionMenu(f, initialitem=self.HB, items=[self.HB, "delta", "epsilon", "both"], labelpos='w', label_text="HIS = ", command=lambda a, s=self: setattr(s, 'hisChanged', True)) self.hisDefault.grid(row=1, sticky='w') self._pickText = Tkinter.StringVar(parent) self._pickText.set("Specified individually...") Tkinter.Radiobutton(interior, variable=self.hisProtVar, value="pick", textvariable=self._pickText, command=self._switchHisList).grid(row=3, sticky='w') Tkinter.Button(parent, pady=0, command=self._colorKeyCB, text="Create corresponding color key").grid(row=7, column=0, columnspan=2) self.hisChanged = False
import Tkinter from tkFont import Font # weight/slant NORMAL = "normal" BOLD = "bold" ITALIC = "italic" root = Tkinter.Tk() def families(root=None): "Get font families (as a tuple)" if not root: root = Tkinter._default_root return root.tk.splitlist(root.tk.call("font", "families")) def names(root=None): "Get names of defined fonts (as a tuple)" if not root: root = Tkinter._default_root return root.tk.splitlist(root.tk.call("font", "names")) # create a font f = Font(family="times", size=30, weight=NORMAL) print f.actual() print f.actual("family") print f.actual("weight") print f.config() print f.cget("family") print f.cget("weight") print names()
def __init__(self, master=None, title=None, buttons=None, default=None, help=None, oneshot=None, highlight=None, keepShown=None, resizable=True, *args, **kw): if master == None: from tkgui import app master = app else: self.overMaster = True self._master = master self._toplevel = Tk.Toplevel(master, *args, **kw) self._toplevel.wm_group(master) if not self.overMaster: self._idleWaits = 0 #self._toplevel.bind("<Map>", self._initialPosition) self._toplevel.after_idle(self._initialPosition) if title: self.title = title if not self.title: self.title = self.name if self.title: self._toplevel.title(self.title) if buttons: self.buttons = buttons if highlight and not default: default = highlight if default: self.default = default if not help is None: self.help = help if oneshot: self.oneshot = oneshot if keepShown: self.keepShown = keepShown if not resizable: self._toplevel.wm_resizable(0, 0) # 'OK' needs to be able to delay 'oneshot' destruction # until after the user-callback returns... self.delayOneshot = False #sys.__stderr__.write('Create dialog: %s %s\n' % # (self.title, str(self._toplevel))) #self._toplevel.bind("<Destroy>", self.Destroy) self._toplevel.protocol('WM_DELETE_WINDOW', self.Cancel) if isinstance(self.buttons, basestring): # compensate for common error of buttons # not being a sequence. self.buttons = (self.buttons, ) if Cancel in self.buttons: self._toplevel.bind("<Escape>", lambda e, c=self.Cancel: c()) elif Close in self.buttons: self._toplevel.bind("<Escape>", lambda e, c=self.Close: c()) bot = Tk.Frame(self._toplevel) bot.pack(side=Tk.BOTTOM, fill=Tk.X) hr = Tk.Frame(self._toplevel, relief=Tk.GROOVE, borderwidth=1, height=2) hr.pack(side=Tk.BOTTOM, fill=Tk.X) if self.keepShown: self.__ksVar = Tkinter.IntVar(bot) self.__ksVar.set(False) ckbut = Tkinter.Checkbutton(bot, variable=self.__ksVar, text="Keep dialog up after %s" % self.keepShown, command=self.__keepShownCB) from tkFont import Font font = Font(font=ckbut.cget('font')) font.config(size=int(0.75 * float(font.cget('size')) + 0.5), weight='normal') ckbut.config(font=font) ckbut.pack(side=Tk.TOP, anchor=Tk.SE) self.__keepShownCB() # set up initial button assignment if hasattr(self, 'provideStatus') and self.provideStatus: slkw = {'anchor': 'w', 'justify': 'left'} if self.statusWidth: slkw['width'] = self.statusWidth if self.statusPosition == "above": slMaster = self._toplevel else: slMaster = bot self.statusLine = Tk.Label(slMaster, **slkw) self._statusBlankHandle = None if not self.statusResizing: self.statusLine.bind('<Map>', self._statusMapCB) if self.statusPosition == "above": self.statusLine.pack(side=Tk.BOTTOM, fill=Tk.X, expand=Tk.NO) else: self.statusLine.pack(side=Tk.LEFT, fill=Tk.BOTH, expand=Tk.YES) if self.help: import help help.register(self._toplevel, self.help) self.buttonWidgets = {} if resizable: sg = Ttk.Sizegrip(bot) sg.pack(anchor=Tk.SE, side=Tk.RIGHT) self.addSpecialButtons(bot) buttons = list(self.buttons[:]) # don't destroy original buttons # if Cancel or Close is present, it should be next to Help if Cancel in buttons: buttons.remove(Cancel) self.buttonWidgets[Cancel] = self.__addButton( bot, Cancel, self.default is Cancel) if Close in buttons: buttons.remove(Close) self.buttonWidgets[Close] = self.__addButton( bot, Close, self.default is Close) buttons.reverse() for b in buttons: self.buttonWidgets[b] = self.__addButton(bot, b, self.default == b) if self.name: import dialogs dialogs.reregister(self.name, self) # pack last, so that resizing dialog will not occlude # action buttons self.__top = Tk.Frame(self._toplevel) self.__top.pack(side=Tk.TOP, anchor=Tk.W, expand=1, fill=Tk.BOTH) # do this after pack so that fillInUI can show progress if # necessary self.fillInUI(self.__top)
def fillInUI(self, parent): self._handlers = {} desigGroup = Pmw.Group(parent, tag_text="Atoms to Check", hull_padx=2) desigGroup.grid(row=0, sticky="ew") from chimera.tkgui import windowSystem Tkinter.Button(desigGroup.interior(), command=self._desigCB, text="Designate").grid(row=0, column=0, sticky='e') Tkinter.Label(desigGroup.interior(), text="currently selected" " atoms for checking").grid(row=0, column=1, sticky='w') self.desigStatus = Tkinter.Label(desigGroup.interior()) from tkFont import Font font = Font(font=self.desigStatus.cget('font')) size = int(font.cget('size')) if size > 2: font.config(size=size - 2) font.config(weight='normal') self.desigStatus.config(font=font) from chimera.selection import ItemizedSelection self.designated = ItemizedSelection( selChangedCB=self._updateDesigStatus) self.desigStatus.grid(row=1, column=0, columnspan=2) self.designated2 = ItemizedSelection(selChangedCB=self._locButtonCB) if windowSystem == 'aqua': pady = None else: pady = 0 Tkinter.Button(desigGroup.interior(), command=self._desig2CB, pady=pady, text="Designate selection as second set").grid(row=3, column=1) self.desig2Status = Tkinter.Label(desigGroup.interior()) if size > 4: font2 = Font(font=font) font2.config(size=size - 4) else: font2 = font self.desig2Status.config(font=font2) self.desig2Status.grid(row=4, column=1) self.checkLocButtons = Pmw.RadioSelect( desigGroup.interior(), pady=0, orient='vertical', buttontype='radiobutton', labelpos='w', label_text="Check designated\natoms" " against:", command=self._locButtonCB) self.checkLocButtons.grid(row=2, column=0, columnspan=2) self.checkLocButtons.add("themselves") self.checkLocButtons.add("all other atoms") self.checkLocButtons.add("other atoms in same model") self.checkLocButtons.add(self.CHECK_SET) self.checkLocButtons.invoke(1) defGroup = Pmw.Group(parent, tag_text="Clash/Contact Parameters", hull_padx=2) defGroup.grid(row=1, sticky='ew') self.clashDef = ClashDef(defGroup.interior(), command=self._checkContinuous, value=str(prefs[CLASH_THRESHOLD])) self.clashDef.grid(row=0, sticky='w') self.hbondAllow = HbondAllow(defGroup.interior(), command=self._checkContinuous, value=str(prefs[HBOND_ALLOWANCE])) self.hbondAllow.grid(row=1, sticky='w') defaultsFrame = Tkinter.Frame(defGroup.interior()) defaultsFrame.grid(row=2) Tkinter.Label(defaultsFrame, text="Default").grid(row=0, column=0) Tkinter.Button(defaultsFrame, text="clash", pady=pady, command=self._clashDefaultsCB).grid(row=0, column=1) Tkinter.Label(defaultsFrame, text="/").grid(row=0, column=2) Tkinter.Button(defaultsFrame, text="contact", pady=pady, command=self._contactDefaultsCB).grid(row=0, column=3) Tkinter.Label(defaultsFrame, text="criteria").grid(row=0, column=4) bondsFrame = Tkinter.Frame(defGroup.interior()) bondsFrame.grid(row=3, sticky='w') self.bondsApart = Pmw.OptionMenu(bondsFrame, labelpos='w', label_text="Ignore contacts of pairs", command=self._checkContinuous, initialitem=str( prefs[BOND_SEPARATION]), items=[str(i + 2) for i in range(4)]) self.bondsApart.grid(row=0, column=0) Tkinter.Label(bondsFrame, text="or fewer bonds apart").grid(row=0, column=1) self.ignoreIntraResVar = Tkinter.IntVar(parent) self.ignoreIntraResVar.set(prefs[IGNORE_INTRA_RES]) Tkinter.Checkbutton(defGroup.interior(), text="Ignore intra-" "residue contacts", variable=self.ignoreIntraResVar, command=self._checkContinuous).grid(row=4) actionGroup = Pmw.Group(parent, tag_text="Treatment of Clash/Contact Atoms", hull_padx=2) actionGroup.grid(row=2, sticky='ew') self.actionSelVar = Tkinter.IntVar(parent) self.actionSelVar.set(prefs[ACTION_SELECT]) Tkinter.Checkbutton(actionGroup.interior(), text="Select", command=self._checkContinuous, variable=self.actionSelVar).grid(row=0, sticky='w') self.actionColorVar = Tkinter.IntVar(parent) self.actionColorVar.set(prefs[ACTION_COLOR]) f = Tkinter.Frame(actionGroup.interior()) f.grid(row=1, sticky='w') Tkinter.Checkbutton(f, text="Color", command=self._checkContinuous, variable=self.actionColorVar).grid(row=0, column=0) from CGLtk.color.ColorWell import ColorWell self.clashColorWell = ColorWell(f, noneOkay=True, callback=self._checkContinuous, color=prefs[CLASH_COLOR]) self.clashColorWell.grid(row=0, column=1) Tkinter.Label(f, text=" (and color all other atoms").grid(row=0, column=2) self.nonclashColorWell = ColorWell(f, noneOkay=True, callback=self._checkContinuous, color=prefs[NONCLASH_COLOR]) self.nonclashColorWell.grid(row=0, column=3) Tkinter.Label(f, text=")").grid(row=0, column=4) self.actionPBVar = Tkinter.IntVar(parent) self.actionPBVar.set(prefs[ACTION_PSEUDOBONDS]) f = Tkinter.Frame(actionGroup.interior()) f.grid(row=2, sticky='w') Tkinter.Checkbutton(f, text="Draw pseudobonds of color", command=self._checkContinuous, variable=self.actionPBVar).grid(row=0, column=0) from CGLtk.color.ColorWell import ColorWell self.pbColorWell = ColorWell(f, noneOkay=False, callback=self._checkContinuous, color=prefs[PB_COLOR]) self.pbColorWell.grid(row=0, column=1) self.pbWidthEntry = Pmw.EntryField(f, labelpos='w', label_text=" and width", validate={ 'validator': 'real', 'min': 0.01 }, entry_width=4, entry_justify="center", command=self._checkContinuous, value=str(prefs[PB_WIDTH])) self.pbWidthEntry.grid(row=0, column=2) self.actionAttrVar = Tkinter.IntVar(parent) self.actionAttrVar.set(prefs[ACTION_ATTR]) self.assignAttrButton = Tkinter.Checkbutton( actionGroup.interior(), text="Assign 'overlap' attribute", variable=self.actionAttrVar) self.assignAttrButton.grid(row=3, sticky='w') self.actionWriteInfoVar = Tkinter.IntVar(parent) self.actionWriteInfoVar.set(prefs[ACTION_WRITEINFO]) self.writeInfoButton = Tkinter.Checkbutton( actionGroup.interior(), text="Write information to" " file", variable=self.actionWriteInfoVar) self.writeInfoButton.grid(row=4, sticky='w') self.actionLogInfoVar = Tkinter.IntVar(parent) self.actionLogInfoVar.set(prefs[ACTION_REPLYLOG]) self.logInfoButton = Tkinter.Checkbutton( actionGroup.interior(), text="Write information to" " reply log", variable=self.actionLogInfoVar) self.logInfoButton.grid(row=5, sticky='w') freqGroup = Pmw.Group(parent, tag_text="Frequency of Checking", hull_padx=2) freqGroup.grid(row=3, sticky="ew") self.freqButtons = Pmw.RadioSelect(freqGroup.interior(), pady=0, orient='vertical', buttontype='radiobutton', labelpos='w', label_text="Check...", command=self._freqChangeCB) self.freqButtons.grid(sticky='w') self.freqButtons.add(self.FREQ_APPLY) self.freqButtons.add(self.FREQ_MOTION) self.freqButtons.add(self.FREQ_CONTINUOUS) self.freqButtons.invoke(0) self._updateDesigStatus()
def fillInUI(self, parent): self._handlers = {} desigGroup = Pmw.Group(parent, tag_text="Atoms to Check", hull_padx=2) desigGroup.grid(row=0, sticky="ew") from chimera.tkgui import windowSystem Tkinter.Button(desigGroup.interior(), command=self._desigCB, text="Designate").grid(row=0, column=0, sticky='e') Tkinter.Label(desigGroup.interior(), text="currently selected" " atoms for checking").grid(row=0, column=1, sticky='w') self.desigStatus = Tkinter.Label(desigGroup.interior()) from tkFont import Font font = Font(font=self.desigStatus.cget('font')) size = int(font.cget('size')) if size > 2: font.config(size=size-2) font.config(weight='normal') self.desigStatus.config(font=font) from chimera.selection import ItemizedSelection self.designated = ItemizedSelection( selChangedCB=self._updateDesigStatus) self.desigStatus.grid(row=1, column=0, columnspan=2) self.designated2 = ItemizedSelection(selChangedCB=self._locButtonCB) if windowSystem == 'aqua': pady = None else: pady = 0 Tkinter.Button(desigGroup.interior(), command=self._desig2CB, pady=pady, text="Designate selection as second set" ).grid(row=3, column=1) self.desig2Status = Tkinter.Label(desigGroup.interior()) if size > 4: font2 = Font(font=font) font2.config(size=size-4) else: font2 = font self.desig2Status.config(font=font2) self.desig2Status.grid(row=4, column=1) self.checkLocButtons = Pmw.RadioSelect(desigGroup.interior(), pady=0, orient='vertical', buttontype='radiobutton', labelpos='w', label_text="Check designated\natoms" " against:", command=self._locButtonCB) self.checkLocButtons.grid(row=2, column=0, columnspan=2) self.checkLocButtons.add("themselves") self.checkLocButtons.add("all other atoms") self.checkLocButtons.add("other atoms in same model") self.checkLocButtons.add(self.CHECK_SET) self.checkLocButtons.invoke(1) defGroup = Pmw.Group(parent, tag_text="Clash/Contact Parameters", hull_padx=2) defGroup.grid(row=1, sticky='ew') self.clashDef = ClashDef(defGroup.interior(), command=self._checkContinuous, value=str(prefs[CLASH_THRESHOLD])) self.clashDef.grid(row=0, sticky='w') self.hbondAllow = HbondAllow(defGroup.interior(), command=self._checkContinuous, value=str(prefs[HBOND_ALLOWANCE])) self.hbondAllow.grid(row=1, sticky='w') defaultsFrame = Tkinter.Frame(defGroup.interior()) defaultsFrame.grid(row=2) Tkinter.Label(defaultsFrame, text="Default").grid( row=0, column=0) Tkinter.Button(defaultsFrame, text="clash", pady=pady, command=self._clashDefaultsCB).grid(row=0, column=1) Tkinter.Label(defaultsFrame, text="/").grid(row=0, column=2) Tkinter.Button(defaultsFrame, text="contact", pady=pady, command=self._contactDefaultsCB).grid(row=0, column=3) Tkinter.Label(defaultsFrame, text="criteria").grid( row=0, column=4) bondsFrame = Tkinter.Frame(defGroup.interior()) bondsFrame.grid(row=3, sticky='w') self.bondsApart = Pmw.OptionMenu(bondsFrame, labelpos='w', label_text="Ignore contacts of pairs", command=self._checkContinuous, initialitem=str(prefs[BOND_SEPARATION]), items=[str(i+2) for i in range(4)]) self.bondsApart.grid(row=0, column=0) Tkinter.Label(bondsFrame, text="or fewer bonds apart").grid( row=0, column=1) self.ignoreIntraResVar = Tkinter.IntVar(parent) self.ignoreIntraResVar.set(prefs[IGNORE_INTRA_RES]) Tkinter.Checkbutton(defGroup.interior(), text="Ignore intra-" "residue contacts", variable=self.ignoreIntraResVar, command=self._checkContinuous ).grid(row=4) actionGroup = Pmw.Group(parent, tag_text= "Treatment of Clash/Contact Atoms", hull_padx=2) actionGroup.grid(row=2, sticky='ew') self.actionSelVar = Tkinter.IntVar(parent) self.actionSelVar.set(prefs[ACTION_SELECT]) Tkinter.Checkbutton(actionGroup.interior(), text="Select", command=self._checkContinuous, variable=self.actionSelVar).grid(row=0, sticky='w') self.actionColorVar = Tkinter.IntVar(parent) self.actionColorVar.set(prefs[ACTION_COLOR]) f = Tkinter.Frame(actionGroup.interior()) f.grid(row=1, sticky='w') Tkinter.Checkbutton(f, text="Color", command=self._checkContinuous, variable=self.actionColorVar).grid(row=0, column=0) from CGLtk.color.ColorWell import ColorWell self.clashColorWell = ColorWell(f, noneOkay=True, callback=self._checkContinuous, color=prefs[CLASH_COLOR]) self.clashColorWell.grid(row=0, column=1) Tkinter.Label(f, text=" (and color all other atoms").grid(row=0, column=2) self.nonclashColorWell = ColorWell(f, noneOkay=True, callback=self._checkContinuous, color=prefs[NONCLASH_COLOR]) self.nonclashColorWell.grid(row=0, column=3) Tkinter.Label(f, text=")").grid(row=0, column=4) self.actionPBVar = Tkinter.IntVar(parent) self.actionPBVar.set(prefs[ACTION_PSEUDOBONDS]) f = Tkinter.Frame(actionGroup.interior()) f.grid(row=2, sticky='w') Tkinter.Checkbutton(f, text="Draw pseudobonds of color", command=self._checkContinuous, variable=self.actionPBVar).grid(row=0, column=0) from CGLtk.color.ColorWell import ColorWell self.pbColorWell = ColorWell(f, noneOkay=False, callback=self._checkContinuous, color=prefs[PB_COLOR]) self.pbColorWell.grid(row=0, column=1) self.pbWidthEntry = Pmw.EntryField(f, labelpos='w', label_text=" and width", validate={'validator': 'real', 'min': 0.01}, entry_width=4, entry_justify="center", command=self._checkContinuous, value=str(prefs[PB_WIDTH])) self.pbWidthEntry.grid(row=0, column=2) self.actionAttrVar = Tkinter.IntVar(parent) self.actionAttrVar.set(prefs[ACTION_ATTR]) self.assignAttrButton = Tkinter.Checkbutton( actionGroup.interior(), text="Assign 'overlap' attribute", variable=self.actionAttrVar) self.assignAttrButton.grid(row=3, sticky='w') self.actionWriteInfoVar = Tkinter.IntVar(parent) self.actionWriteInfoVar.set(prefs[ACTION_WRITEINFO]) self.writeInfoButton = Tkinter.Checkbutton( actionGroup.interior(), text="Write information to" " file", variable=self.actionWriteInfoVar) self.writeInfoButton.grid(row=4, sticky='w') self.actionLogInfoVar = Tkinter.IntVar(parent) self.actionLogInfoVar.set(prefs[ACTION_REPLYLOG]) self.logInfoButton = Tkinter.Checkbutton( actionGroup.interior(), text="Write information to" " reply log", variable=self.actionLogInfoVar) self.logInfoButton.grid(row=5, sticky='w') freqGroup = Pmw.Group(parent, tag_text="Frequency of Checking", hull_padx=2) freqGroup.grid(row=3, sticky="ew") self.freqButtons = Pmw.RadioSelect(freqGroup.interior(), pady=0, orient='vertical', buttontype='radiobutton', labelpos='w', label_text= "Check...", command=self._freqChangeCB) self.freqButtons.grid(sticky='w') self.freqButtons.add(self.FREQ_APPLY) self.freqButtons.add(self.FREQ_MOTION) self.freqButtons.add(self.FREQ_CONTINUOUS) self.freqButtons.invoke(0) self._updateDesigStatus()
import Tkinter from tkFont import Font # weight/slant NORMAL = "normal" BOLD = "bold" ITALIC = "italic" root = Tkinter.Tk() def families(root=None): "Get font families (as a tuple)" if not root: root = Tkinter._default_root return root.tk.splitlist(root.tk.call("font", "families")) def names(root=None): "Get names of defined fonts (as a tuple)" if not root: root = Tkinter._default_root return root.tk.splitlist(root.tk.call("font", "names")) # create a font f = Font(family="times", size=30, weight=NORMAL) print f.actual() print f.actual("family") print f.actual("weight") print f.config() print f.cget("family") print f.cget("weight") print names() print f.measure("hello"), f.metrics("linespace")