def underline(self, *args):  # Works only if text is selected
     try:
         current_tags = self.text.tag_names("sel.first")
         if "underline" in current_tags:
             self.text.tag_remove("underline", "sel.first", "sel.last")
         else:
             self.text.tag_add("underline", "sel.first", "sel.last")
             underline_font = Font(self.text, self.text.cget("font"))
             underline_font.configure(underline=1)
             self.text.tag_configure("underline", font=underline_font)
     except:
         pass
 def overstrike(self, *args):  # Works only if text is selected
     try:
         current_tags = self.text.tag_names("sel.first")
         if "overstrike" in current_tags:
             self.text.tag_remove("overstrike", "sel.first", "sel.last")
         else:
             self.text.tag_add("overstrike", "sel.first", "sel.last")
             overstrike_font = Font(self.text, self.text.cget("font"))
             overstrike_font.configure(overstrike=1)
             self.text.tag_configure("overstrike", font=overstrike_font)
     except:
         pass
 def bold(self, *args):  # Works only if text is selected
     try:
         current_tags = self.text.tag_names("sel.first")
         if "bold" in current_tags:
             self.text.tag_remove("bold", "sel.first", "sel.last")
         else:
             self.text.tag_add("bold", "sel.first", "sel.last")
             bold_font = Font(self.text, self.text.cget("font"))
             bold_font.configure(weight="bold")
             self.text.tag_configure("bold", font=bold_font)
     except:
         pass
 def italic(self, *args):  # Works only if text is selected
     try:
         current_tags = self.text.tag_names("sel.first")
         if "italic" in current_tags:
             self.text.tag_remove("italic", "sel.first", "sel.last")
         else:
             self.text.tag_add("italic", "sel.first", "sel.last")
             italic_font = Font(self.text, self.text.cget("font"))
             italic_font.configure(slant="italic")
             self.text.tag_configure("italic", font=italic_font)
     except:
         pass
Esempio n. 5
0
 def __init__(self, text, regexp=False, nocase=False):
     self.text = text
     self.pattern = tkinter.StringVar()
     self.regexp = tkinter.IntVar(int(regexp))
     self.nocase = tkinter.IntVar(int(nocase))
     self.prev_pattern = ""
     self.prev_regexp = regexp
     self.prev_nocase = nocase
     self.findings = []
     self.current = -1
     self.text.tag_config("search", background='yellow', foreground="black")
     bold_font = Font(self.text)
     bold_font.configure(weight="bold")
     self.text.tag_config("search_current", font=bold_font)
def main(root, text, menubar):
    objFormat = Format(text)

    fontoptions = families(root)
    font = Font(family="Verdana", size=10)

    formatMenu = Menu(menubar)

    fsubmenu = Menu(formatMenu, tearoff=0)
    ssubmenu = Menu(formatMenu, tearoff=0)

    for option in fontoptions:
        fsubmenu.add_command(label=option,
                             command=lambda: font.configure(family=option))
    for value in range(1, 31):
        ssubmenu.add_command(label=str(value),
                             command=lambda: font.configure(size=value))

    formatMenu.add_command(label="Change Background",
                           command=objFormat.changeBg)
    formatMenu.add_command(label="Change Font Color",
                           command=objFormat.changeFg)
    formatMenu.add_cascade(label="Font", underline=0, menu=fsubmenu)
    formatMenu.add_cascade(label="Size", underline=0, menu=ssubmenu)
    formatMenu.add_command(label="Bold",
                           command=objFormat.bold,
                           accelerator="Ctrl+B")
    formatMenu.add_command(label="Italic",
                           command=objFormat.italic,
                           accelerator="Ctrl+I")
    formatMenu.add_command(label="Underline",
                           command=objFormat.underline,
                           accelerator="Ctrl+U")
    formatMenu.add_command(label="Overstrike",
                           command=objFormat.overstrike,
                           accelerator="Ctrl+T")
    formatMenu.add_command(label="Add Date", command=objFormat.addDate)
    menubar.add_cascade(label="Format", menu=formatMenu)

    root.bind_all("<Control-b>", objFormat.bold)
    root.bind_all("<Control-i>", objFormat.italic)
    root.bind_all("<Control-u>", objFormat.underline)
    root.bind_all("<Control-T>", objFormat.overstrike)

    root.grid_columnconfigure(0, weight=1)
    root.resizable(True, True)

    root.config(menu=menubar)
Esempio n. 7
0
def bold():
    s = text.selection_get()
    length = len(s)
    try:
        string = text.tag_names("sel.first")

        if "bold" in string:
            text.tag_remove("bold", "sel.first",
                            "%s + %sc" % ("sel.first", length))

        else:
            text.tag_add("bold", "sel.first",
                         "%s + %sc" % ("sel.first", length))
            bold_font = Font(text, text.cget("font"))
            bold_font.configure(weight="bold")
            text.tag_configure("bold", font=bold_font)

    except:
        pass
Esempio n. 8
0
def underline():
    s = text.selection_get()
    length = len(s)

    try:
        string = text.tag_names("sel.first")

        if "underline" in string:
            text.tag_remove("underline", "sel.first",
                            "%s + %sc" % ("sel.first", length))

        else:
            text.tag_add("underline", "sel.first",
                         "%s + %sc" % ("sel.first", length))
            underline_font = Font(text, text.cget("font"))
            underline_font.configure(underline=1)
            text.tag_configure("underline", font=underline_font)

    except:
        pass
Esempio n. 9
0
def italic():
    s = text.selection_get()
    length = len(s)

    try:
        string = text.tag_names("sel.first")

        if "italic" in string:
            text.tag_remove("italic", "sel.first",
                            "%s + %sc" % ("sel.first", length))

        else:
            text.tag_add("italic", "sel.first",
                         "%s + %sc" % ("sel.first", length))
            italic_font = Font(text, text.cget("font"))
            italic_font.configure(slant="italic")
            text.tag_configure("italic", font=italic_font)

    except:
        pass
Esempio n. 10
0
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()
Esempio n. 11
0
class TextTable(Frame,object):
	def __init__(self,parent,frames=None,aligns=None,weights=None,**kwargs):
		Frame.__init__(self,parent,**kwargs)
		self.numberOfRows=0
		self.aligns = aligns
		if not self.aligns:
			self.aligns = ["left","left","left","left","left","left"]
		if not weights:
			weights=[1,1,1,1]
		if frames==None:
			self.frames=["one","two","three","four","five","six"]
		else:
			self.frames=frames
		# for i in range(0,len(self.frames)):
		# 	self.frames[i]=Frame(self)
		# 	self.frames[i].grid(side=LEFT,expand=1,fill=BOTH)

		self.textBoxes=[]
		for i in range(0,len(self.frames)):
			self.textBoxes.append(Text(self,bd=0,width=0,state='disabled'))
			self.textBoxes[-1].grid(row=0,column=i,sticky=W+E+N+S)
			self.textBoxes[-1].tag_configure("right",justify="right",wrap=NONE)
			self.textBoxes[-1].tag_configure("center",justify="center",wrap=NONE)
			self.textBoxes[-1].tag_configure("left",justify="left",wrap=NONE)
			self.textBoxes[-1].tag_configure("underline",underline=True)
			self.grid_columnconfigure(i,weight=weights[i])
		self.grid_rowconfigure(0,weight=1)
		self.boldFont = Font(self.textBoxes[0],self.textBoxes[0].cget('font'))
		self.boldFont.configure(weight='bold')
		for i in self.textBoxes:
			i.tag_configure("bold",font=self.boldFont)


	def fixAligns(self):
		for i in range(0,len(self.textBoxes)):
			self.textBoxes[i]['state']='normal'
			self.textBoxes[i].tag_add(self.aligns[i],'1.0','end')
			self.textBoxes[i]['state']='disabled'

	def addRow(self,values,uls=None,bolds=None):
		self.numberOfRows+=1
		for i in range(0,len(self.textBoxes)):
			self.textBoxes[i]['state']='normal'
			if self.numberOfRows==1:
				self.textBoxes[i].insert(self.textBoxes[i].index("end"),values[i])
			else:
				self.textBoxes[i].insert(self.textBoxes[i].index("end"),"\n"+values[i])
			self.textBoxes[i]['state']='disabled'

		if uls:
			for i in range(0,len(uls)):
				if uls[i]:
					self.textBoxes[i]['state']='normal'
					self.textBoxes[i].tag_add("underline",'end - 1 line','end -1 line lineend')
					self.textBoxes[i]['state']='disabled'
		if bolds:
			for i in range(0,len(bolds)):
				if bolds[i]:
					self.textBoxes[i]['state']='normal'
					self.textBoxes[i].tag_add("bold","end -1 line",'end -1 line lineend')
					self.textBoxes[i]['state']='disabled'
		self.fixAligns()
		for i in self.textBoxes:
			i.configure(height=self.numberOfRows)

	def clear(self):
		for i in self.textBoxes:
			i['state']='normal'
			i.delete("1.0","end")
			i['state']='disabled'
		self.numberOfRows=0

	def getLine(self,index):
		vals = []
		for i in self.textBoxes:
			vals.append(i.get(str(index)+".0",str(index)+".end"))

		return vals
Esempio n. 12
0
    def create_content(self):

        self.pop = Toplevel(self.master, bg="white")
        self.pop.grab_set()  # when you show the popup

        self.pop.wm_title(' ' * 5 + self._title_)
        self.pop.geometry('{:d}x{:d}+{:d}+{:d}'.format(*self._vertex_))

        leftcolumn = Frame(self.pop, bg="white")
        Label(leftcolumn, bg="white").pack(side="top", fill="both", pady=30)
        Label(leftcolumn,
              bg="white", image=self.im_logo2).pack(side="top",
                                                    fill="both",
                                                    padx=10)  #side= LEFT,
        leftcolumn.pack(side="left", fill='both', padx=1)

        rightcolumn = Frame(self.pop, bg="white")
        firstrow = Frame(rightcolumn, bg="white")
        Frame(rightcolumn, bg="white").pack(side="top", pady=10, padx=0)

        Label(firstrow,
              text="GROTOLAM",
              fg="Gray13",
              bg="white",
              font="Verdana 13 bold").pack(side="left", pady=20)
        Label(firstrow, text='', bg="white").pack(side="left", padx=40)
        firstrow.pack(side="top", padx=0)

        secrow = Frame(rightcolumn, bg="white")
        Label(secrow,
              text="v " + __version__.split()[2],
              fg="Gray13",
              bg="white",
              font="Verdana 10").pack(side="left")
        Label(secrow, text='', bg="white").pack(side="left", padx=75)
        secrow.pack(side="top", padx=0)

        # lets create space to do some stuff ...
        Frame(rightcolumn, bg="white").pack(side="top", pady=20, padx=0)

        thirdrow = Frame(rightcolumn, bg="white")

        Label(thirdrow,
              text="2018 Python version by",
              fg="Gray13",
              bg="white",
              font="Verdana 10").pack(side="left")
        Label(thirdrow, text='', bg="white").pack(side="left", padx=16)
        thirdrow.pack(side="top", padx=0)

        fourthrow = Frame(rightcolumn, bg="white")
        Label(fourthrow,
              text="Hernan Chavez Thielemann",
              fg="Gray13",
              bg="white",
              font="Verdana 10").pack(side="left")
        Label(fourthrow, text='', bg="white").pack(side="left", padx=1)
        fourthrow.pack(side="top", padx=0)

        fifthrow = Frame(rightcolumn, bg="white")
        Label(fifthrow, bg="white", image=self.im_smlogo).pack(side="left",
                                                               fill="both",
                                                               padx=10)
        fifthrow.pack(side="top", padx=0)

        sixthrow = Frame(rightcolumn, bg="white")
        href = Label(sixthrow,
                     bg="white",
                     font="Verdana 10",
                     text="Small web page",
                     fg="blue",
                     cursor="hand2")
        f = Font(href, href.cget("font"))
        f.configure(underline=True)
        href.configure(font=f)
        href.pack(side="left")
        href.bind("<Button-1>", self.callback)

        Label(sixthrow, text='', bg="white").pack(side="left", padx=40)
        sixthrow.pack(side="top", padx=0)

        lastrow = Frame(rightcolumn, bg="white")
        self.bottom_button_row(lastrow)
        rightcolumn.pack(side="right", fill='both', padx=5)
Esempio n. 13
0
    def __init__(self, parent):

        #--- main frame
        main_bg = "black"
        main_fg = "white"

        #--- labels
        labFont = Font(family="Courier", size=11)
        labFont.configure(weight="bold")

        #--- pulsanti
        butFont = Font(family="Helvetica", size=11)
        butFont.configure(weight="bold")
        but_width = 10
        but_height = 0
        but_padx = "3m"
        but_pady = "1m"
        but_relief = FLAT
        but_borderwidth = 1
        but_hlcol = "red"
        but_hlbg = "red"
        but_bg = "#8B0000"
        but_fg = "white"
        but_actbg = "red"
        but_actfg = "white"

        #--------------------- fine costanti ----------------

        self.myParent = parent

        #--------------------- FRAMES -----------------------
        ### Il quadro principale si chiama 'myBox1'
        self.myBox1 = Frame(
            parent,
            background=main_bg,
        )
        self.myBox1.pack(
            side=TOP,
            fill=BOTH,
            expand=YES,
        )

        # Il quadro dei pulsanti alto
        self.button_square = Frame(
            self.myBox1,
            background=main_bg,
            #relief=RAISED, borderwidth=1
        )
        self.button_square.pack(
            side=TOP,
            padx=5,
            pady=5,
            fill=BOTH,
            expand=YES,
        )

        # quadro centrale
        self.central_square = Frame(
            self.myBox1,
            background=main_bg,
            relief=FLAT,
            borderwidth=1,
            padx=5,
            pady=5,
        )
        self.central_square.pack(
            side=TOP,
            fill=BOTH,
            expand=YES,
            ipadx=5,
            ipady=5,
        )

        # Il quadro dei pulsanti basso
        self.bottom_square = Frame(
            self.myBox1,
            padx=5,
            pady=5,
            background=main_bg,
            #relief=RAISED, borderwidth=1
        )
        self.bottom_square.pack(
            side=TOP,
            fill=BOTH,
            expand=YES,
        )

        # quadro sinistra
        self.left_square = Frame(
            self.central_square,
            background=main_bg,
            #borderwidth = 5,
            #relief = RIDGE,
        )
        self.left_square.pack(
            side=LEFT,
            fill=BOTH,
            expand=YES,
        )

        # quadro destra
        self.right_square = Frame(
            self.central_square,
            background=main_bg,
            #borderwidth = 5,
            #relief = RIDGE,
        )
        self.right_square.pack(
            side=RIGHT,
            fill=BOTH,
            expand=YES,
        )
        #--------------------- FIXED LABELS -----------------------
        # etichette sinistra
        # IP
        self.label1 = Label(
            self.left_square,
            background=main_bg,
            foreground=main_fg,
            text="IP: ",
            anchor='w',
            font=labFont,
        )
        self.label1.pack(fill=X, expand=YES)

        # Temp
        self.label2 = Label(
            self.left_square,
            background=main_bg,
            foreground=main_fg,
            text="Temp: ",
            anchor='w',
            font=labFont,
        )
        self.label2.pack(fill=X, expand=YES)

        # Date
        self.label3 = Label(
            self.left_square,
            background=main_bg,
            foreground=main_fg,
            text="Date: ",
            anchor='w',
            font=labFont,
        )
        self.label3.pack(fill=X, expand=YES)

        # Volts
        self.label4 = Label(
            self.left_square,
            background=main_bg,
            foreground=main_fg,
            text="Core: ",
            anchor='w',
            font=labFont,
        )
        self.label4.pack(fill=X, expand=YES)

        # Clock
        self.label5 = Label(
            self.left_square,
            background=main_bg,
            foreground=main_fg,
            text="Clock: ",
            anchor='w',
            font=labFont,
        )
        self.label5.pack(fill=X, expand=YES)

        #--------------------- VAR LABELS -----------------------
        # etichette destra
        self.label1var = Label(
            self.right_square,
            background=main_bg,
            foreground=main_fg,
            text=get_ip(),
            anchor='w',
            font=labFont,
        )
        self.label1var.pack(fill=X, expand=YES)

        #var_temp = StringVar();
        #var_temp.set(get_temp());
        self.label2var = Label(
            self.right_square,
            background=main_bg,
            foreground=main_fg,
            #textvariable=var_temp,
            anchor='w',
            font=labFont,
        )
        self.label2var.pack(fill=X, expand=YES)

        #var_date = StringVar()
        #var_date.set(get_date())
        self.label3var = Label(
            self.right_square,
            background=main_bg,
            foreground=main_fg,
            #	textvariable=var_date,
            anchor='w',
            font=labFont,
        )
        self.label3var.pack(fill=X, expand=YES)
        self.label4var = Label(
            self.right_square,
            background=main_bg,
            foreground=main_fg,
            text=get_volts(),
            anchor='w',
            font=labFont,
        )
        self.label4var.pack(fill=X, expand=YES)
        self.label5var = Label(
            self.right_square,
            background=main_bg,
            foreground=main_fg,
            text=get_clock(),
            anchor='w',
            font=labFont,
        )
        self.label5var.pack(fill=X, expand=YES)

        # Vengono ora aggiunti i pulsanti a 'button_square'
        #--------------------- TOP BUTTONS -----------------------
        self.pulsante1 = Button(self.button_square, command=self.buttonPress1)
        self.pulsante1.configure(text="STARTX")
        self.pulsante1.configure(
            width=but_width,
            height=but_height,
            padx=but_padx,
            pady=but_pady,
            relief=but_relief,
            borderwidth=but_borderwidth,
            highlightbackground=but_hlbg,
            highlightcolor=but_hlcol,
            activebackground=but_actbg,
            activeforeground=but_actfg,
            background=but_bg,
            foreground=but_fg,
            font=butFont,
        )
        self.pulsante1.pack(side=LEFT)
        self.pulsante1.bind("<Return>", self.buttonPress1_a)

        self.pulsante2 = Button(self.button_square, command=self.buttonPress2)
        self.pulsante2.configure(text="EXIT")
        # default focus
        self.pulsante2.focus_force()
        self.pulsante2.configure(
            width=but_width,
            height=but_height,
            padx=but_padx,
            pady=but_pady,
            relief=but_relief,
            borderwidth=but_borderwidth,
            highlightbackground=but_hlbg,
            highlightcolor=but_hlcol,
            activebackground=but_actbg,
            activeforeground=but_actfg,
            background=but_bg,
            foreground=but_fg,
            font=butFont,
        )
        self.pulsante2.pack(side=RIGHT)
        self.pulsante2.bind("<Return>", self.buttonPress2_a)

        #-------------------- BOTTOM BUTTONS ----------------------
        self.pulsante3 = Button(self.bottom_square, command=self.buttonPress3)
        self.pulsante3.configure(text="REBOOT")
        self.pulsante3.configure(
            width=but_width,
            height=but_height,
            padx=but_padx,
            pady=but_pady,
            relief=but_relief,
            borderwidth=but_borderwidth,
            highlightbackground=but_hlbg,
            highlightcolor=but_hlcol,
            activebackground=but_actbg,
            activeforeground=but_actfg,
            background=but_bg,
            foreground=but_fg,
            font=butFont,
        )
        self.pulsante3.pack(side=LEFT)
        self.pulsante3.bind("<Return>", self.buttonPress3_a)

        self.pulsante4 = Button(self.bottom_square, command=self.buttonPress4)
        self.pulsante4.configure(text="SHUTDOWN")
        self.pulsante4.configure(
            width=but_width,
            height=but_height,
            padx=but_padx,
            pady=but_pady,
            relief=but_relief,
            borderwidth=but_borderwidth,
            highlightbackground=but_hlbg,
            highlightcolor=but_hlcol,
            activebackground=but_actbg,
            activeforeground=but_actfg,
            background=but_bg,
            foreground=but_fg,
            font=butFont,
        )
        self.pulsante4.pack(side=RIGHT)
        self.pulsante4.bind("<Return>", self.buttonPress4_a)
    def BuildDialog(self):
        def AddCmdKey(text):
            bg = EvenOdd(self.even)
            strs = text.split(':')
            self.text.insert(END, strs[0], ("KeyboardCommand", "Indent", bg))
            strs = strs[1].split('~')
            self.text.insert(END, strs[0], bg)
            if len(strs) > 1:
                self.text.insert(END, strs[1][0], ("CmdKey", bg))
                self.text.insert(END, strs[1][1:], (bg))
            self.even = not self.even

        self.MainFrame.rowconfigure(0, weight=1)
        self.MainFrame.columnconfigure(0, weight=1)

        self.iconKeyboard = ImageTk.PhotoImage(
            PIL.Image.open("Assets/keyboard.gif"))
        Label(self.MainFrame, image=self.iconKeyboard).grid(row=0,
                                                            column=0,
                                                            sticky='W')

        self.sb = Scrollbar(self.MainFrame, orient='vertical')
        self.sb.grid(row=1, column=1, sticky='NS')
        self.text = Text(self.MainFrame,
                         height=30,
                         width=60,
                         wrap='word',
                         yscrollcommand=self.sb.set)
        self.text.grid(row=1, column=0, sticky='NSEW')
        self.text.bind("<Key>", lambda e: "break")  # ignore all keypress
        self.sb.config(command=self.text.yview)

        ## Tags for various text formats
        boldFont = Font(self.text, self.text.cget("font"))
        boldFont.configure(weight="bold")
        boldUnderlineFont = Font(self.text, self.text.cget("font"))
        boldUnderlineFont.configure(weight="bold", underline=True)
        self.text.tag_configure("Bold", font=boldFont)
        self.text.tag_configure("Title", font=("Arial", 14, "bold"))
        self.text.tag_configure("KeyboardCommand",
                                font=boldFont,
                                foreground='blue')
        self.text.tag_configure("Center", justify=CENTER)
        self.text.tag_configure("Indent", lmargin1='1c', lmargin2='1c')
        self.text.tag_configure("CmdKey", font=boldUnderlineFont)
        self.text.tag_configure("odd", background='white')
        self.text.tag_configure("even", background='#f0f0ff')
        self.even = True

        self.text.insert(END, "\nKeyboard shortcuts\n\n", ("Center", "Title"))

        self.text.insert(END, "Photo viewer pane\n\n", "Bold")
        self.even = True
        AddCmdKey("LeftMouse:\t\t\t\tPan image\n")
        AddCmdKey("Ctrl+MouseWheel Up/Down:\t\t\t\tZoom in/out\n")
        AddCmdKey("Ctrl+LeftMouse:\t\t\t\tShow zoomed area on preview\n")

        self.text.insert(END, "\nNotepad traversal shorcuts\n\n", "Bold")
        self.even = True
        AddCmdKey("Ctrl+TAB:\t\tSelects the next tab.\n")
        AddCmdKey("Ctrl+SHIFT+TAB:\t\t\tSelects the previous tab.\n")
        AddCmdKey("ALT+B:\t\tSelect ~Basic commands tab\n")
        AddCmdKey("ALT+E:\t\tSelect ~Exposure commands tab\n")
        AddCmdKey("ALT+C:\t\tSelect Finer ~Control commands tab\n")
        AddCmdKey("ALT+A:\t\tSelect ~Annotate/EXIF Metadata commands tab\n")
        AddCmdKey("ALT+T:\t\tSelect ~Time lapse commands tab\n")

        self.text.insert(END, "\nPhoto / Video commands\n\n", "Bold")
        self.even = True
        AddCmdKey("Right Click:\tPopup menu\n")
        AddCmdKey("Ctrl+P:\t\tTake ~picture\n")
        AddCmdKey("Ctrl+V:\t\tToggle capture ~video on/off\n")
        AddCmdKey("Ctrl+C:\t\t~Clear picture or video in pane\n")
        AddCmdKey("Ctrl+R:\t\t~Reset all camera setups to defaults\n")

        self.text.insert(END, "\nUser Interface\n\n", "Bold")
        self.even = True
        AddCmdKey("TAB:\t\tSelects the next active control.\n")
        AddCmdKey("Shift+TAB:\t\tSelects the previous active control.\n")
        AddCmdKey("Alt+F:\t\tDrop down ~File menu\n")
        AddCmdKey("Alt+V:\t\tDrop down ~View menu\n")
        AddCmdKey("Alt+P:\t\tDrop down ~Photo menu\n")
        AddCmdKey("Alt+H:\t\tDrop down ~Help menu\n")
        AddCmdKey("Ctrl+Shift+C:\t\tShow/hide ~Cursors\n")
        AddCmdKey("Ctrl+Shift+A:\t\tShow/hide Image ~Attributes pane\n")
        AddCmdKey("Ctrl+Shift+P:\t\tShow/hide ~Preview pane\n")

        self.text.insert(END, "\nGeneral commands\n\n", "Bold")
        self.even = True
        AddCmdKey("Ctrl+Q:\t\t~Quit program\n")
Esempio n. 15
0
    def init_UI(self):

        self.parent.title('Liquid Thermal Shock Tester v0.2')
        self.pack(fill=BOTH, expand=True)
        options_frame = Frame(self, background='gray', pady=5, padx=5)
        options_frame.pack(side=LEFT, fill=BOTH, expand=True)

        options_label = Label(options_frame,
                              text='Test Setup',
                              background='gray',
                              font=('Courier', 22, 'bold'),
                              justify=LEFT)
        ul_bold_font = Font(options_label, options_label.cget('font'))
        ul_bold_font.configure(underline=True)
        options_label.configure(font=ul_bold_font)
        options_label.pack(anchor=CENTER, side=TOP, padx=5, pady=5)

        cycles_frame = Frame(options_frame, background='gray', pady=5)
        cycles_frame.pack(side=TOP, fill=BOTH, expand=True)

        cycles_label = Label(cycles_frame,
                             text='# of cycles',
                             background='gray',
                             font=('Courier', 12),
                             justify=CENTER)
        cycles_label.grid(row=0,
                          column=0,
                          rowspan=1,
                          columnspan=2,
                          sticky='news')
        ul_plain_font = Font(cycles_label, cycles_label.cget('font'))
        ul_plain_font.configure(underline=True)
        cycles_label.configure(font=ul_plain_font)

        self.cycles_select_disp = Label(cycles_frame,
                                        text='5',
                                        background='white',
                                        font=('Courier', 32))
        self.cycles_select_disp.grid(row=1,
                                     column=0,
                                     rowspan=2,
                                     columnspan=1,
                                     sticky='wens',
                                     padx=5,
                                     pady=5)

        self.cycles_increase_button = Button(cycles_frame,
                                             text=u'\u25b2',
                                             font=('Courier', 18, 'bold'),
                                             command=self.cycles_increment)
        self.cycles_increase_button.grid(row=1,
                                         column=1,
                                         rowspan=1,
                                         columnspan=1,
                                         sticky='wens',
                                         padx=5,
                                         pady=5)

        self.cycles_decrease_button = Button(cycles_frame,
                                             text=u'\u25BC',
                                             font=('Courier', 18, 'bold'),
                                             command=self.cycles_decrement)
        self.cycles_decrease_button.grid(row=2,
                                         column=1,
                                         rowspan=1,
                                         columnspan=1,
                                         sticky='wens',
                                         padx=5,
                                         pady=5)

        self.fix_grid(cycles_frame)

        soak_time_frame = Frame(options_frame, background='gray', pady=5)
        soak_time_frame.pack(side=TOP, fill=BOTH, expand=True)

        soak_time_label = Label(soak_time_frame,
                                text='Minutes per Soak',
                                background='gray',
                                font=('Courier', 12),
                                justify=CENTER)
        soak_time_label.grid(row=0,
                             column=0,
                             rowspan=1,
                             columnspan=2,
                             sticky='news')
        soak_time_label.configure(font=ul_plain_font)

        self.soak_time_disp = Label(soak_time_frame,
                                    text='5',
                                    background='white',
                                    font=('Courier', 32))
        self.soak_time_disp.grid(row=1,
                                 column=0,
                                 rowspan=2,
                                 columnspan=1,
                                 sticky='wens',
                                 padx=5,
                                 pady=5)

        self.soak_time_increment_button = Button(
            soak_time_frame,
            text=u'\u25b2',
            font=('Courier', 18, 'bold'),
            command=self.soak_time_increment)
        self.soak_time_increment_button.grid(row=1,
                                             column=1,
                                             rowspan=1,
                                             columnspan=1,
                                             sticky='wens',
                                             padx=5,
                                             pady=5)

        self.soak_time_decrement_button = Button(
            soak_time_frame,
            text=u'\u25BC',
            font=('Courier', 18, 'bold'),
            command=self.soak_time_decrement)
        self.soak_time_decrement_button.grid(row=2,
                                             column=1,
                                             rowspan=1,
                                             columnspan=1,
                                             sticky='wens',
                                             padx=5,
                                             pady=5)

        self.fix_grid(soak_time_frame)

        controls_frame = Frame(self, background='gray')
        controls_frame.pack(side=LEFT, fill=BOTH, expand=True)

        run_pause_frame = Frame(controls_frame, background='gray')
        run_pause_frame.pack(side=TOP, fill=BOTH, expand=True, pady=5)

        self.run_button = Button(run_pause_frame,
                                 text='RUN',
                                 background='green',
                                 activebackground='green',
                                 font=('Courier', 30, 'bold'),
                                 width=5,
                                 command=self.run_init)
        self.run_button.grid(row=0, column=0, sticky='wens', padx=5, pady=5)

        self.pause_button = Button(run_pause_frame,
                                   text='PAUSE',
                                   background='orange',
                                   activebackground='orange',
                                   font=('Courier', 30, 'bold'),
                                   width=5,
                                   command=self.pause_button_pressed)
        self.pause_button.grid(row=0, column=1, sticky='wens', padx=5, pady=5)

        self.fix_grid(run_pause_frame)

        stop_button = Button(controls_frame,
                             text='STOP',
                             background='red',
                             activebackground='red',
                             font=('Courier', 36, 'bold'),
                             command=self.stop_test)
        stop_button.pack(side=TOP, fill=BOTH, expand=True, padx=5)

        jog_frame = Frame(controls_frame, background='gray')
        jog_frame.pack(side=TOP, fill=BOTH, expand=True, pady=5)

        jog_label = Label(jog_frame,
                          text='Motor\rjog',
                          font=('Courier', 12, 'bold'),
                          background='gray')
        jog_label.grid(row=1, column=1)

        self.jog_up_button = Button(jog_frame,
                                    text=u'\u25b2',
                                    font=('Courier', 18, 'bold'))
        self.jog_up_button.grid(row=0,
                                column=1,
                                rowspan=1,
                                columnspan=1,
                                sticky='wens',
                                padx=5,
                                pady=5)
        self.jog_up_button.bind("<Button-1>", self.jog_up_on)
        self.jog_up_button.bind("<ButtonRelease-1>", self.jog_off)

        self.jog_left_button = Button(jog_frame,
                                      text=u'\u25C4',
                                      font=('Courier', 18, 'bold'))
        self.jog_left_button.grid(row=1,
                                  column=0,
                                  rowspan=1,
                                  columnspan=1,
                                  sticky='wens',
                                  padx=5,
                                  pady=5)
        self.jog_left_button.bind("<Button-1>", self.jog_left_on)
        self.jog_left_button.bind("<ButtonRelease-1>", self.jog_off)

        self.jog_right_button = Button(jog_frame,
                                       text=u'\u25BA',
                                       font=('Courier', 18, 'bold'))
        self.jog_right_button.grid(row=1,
                                   column=2,
                                   rowspan=1,
                                   columnspan=1,
                                   sticky='wens',
                                   padx=5,
                                   pady=5)
        self.jog_right_button.bind("<Button-1>", self.jog_right_on)
        self.jog_right_button.bind("<ButtonRelease-1>", self.jog_off)

        self.jog_down_button = Button(jog_frame,
                                      text=u'\u25BC',
                                      font=('Courier', 18, 'bold'))
        self.jog_down_button.grid(row=2,
                                  column=1,
                                  rowspan=1,
                                  columnspan=1,
                                  sticky='wens',
                                  padx=5,
                                  pady=5)
        self.jog_down_button.bind("<Button-1>", self.jog_down_on)
        self.jog_down_button.bind("<ButtonRelease-1>", self.jog_off)

        self.fix_grid(jog_frame)

        status_frame = Frame(self, background='gray')
        status_frame.pack(side=LEFT, fill=BOTH, expand=True, padx=5, pady=5)

        status_label = Label(status_frame,
                             text='Tester Status',
                             background='gray',
                             font=('Courier', 22, 'bold'),
                             justify=LEFT)
        status_label.configure(font=ul_bold_font)
        status_label.pack(anchor=CENTER, side=TOP, padx=5, pady=5)

        self.status_disp = Text(status_frame)
        self.status_disp.pack(side=TOP, fill=BOTH, padx=5, pady=5)
        self.status_disp.configure(state='disabled')

        self.power_button = Button(status_frame,
                                   text='POWER OFF',
                                   font=('Courier', 24, 'bold'),
                                   background="red",
                                   activebackground="red",
                                   command=self.shutdown,
                                   height=2)
        self.power_button.pack(side=TOP, fill=BOTH, padx=5, pady=5)
Esempio n. 16
0
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()
Esempio n. 17
0
  def __init__(self, parent):

	#--- main frame
	main_bg = "black"
	main_fg = "white"
	
	#--- labels
	labFont = Font(family="Courier", size=11)
	labFont.configure(weight = "bold")
	
	#--- pulsanti
	butFont = Font(family="Helvetica", size=11)
	butFont.configure(weight = "bold")
	but_width = 10
	but_height = 0
	but_padx = "3m"
	but_pady = "1m"
	but_relief = FLAT
	but_borderwidth = 1
	but_hlcol = "red"
	but_hlbg = "red"
	but_bg = "#8B0000"
	but_fg = "white"
	but_actbg = "red"
	but_actfg = "white"
	
	#--------------------- fine costanti ----------------

	self.myParent = parent
	
	#--------------------- FRAMES -----------------------
	### Il quadro principale si chiama 'myBox1'
	self.myBox1 = Frame(parent, 
		background=main_bg,
	)
	self.myBox1.pack(side = TOP,
	  fill = BOTH,
	  expand = YES,
	)

	# Il quadro dei pulsanti alto
	self.button_square = Frame(self.myBox1,
		background=main_bg,
		#relief=RAISED, borderwidth=1
	)
	self.button_square.pack(side = TOP,
	  padx=5,
	  pady=5,
	  fill = BOTH,
	  expand = YES,
	)

	# quadro centrale
	self.central_square = Frame(self.myBox1,
		background=main_bg,
		relief=FLAT, borderwidth=1,
		padx = 5,
		pady = 5,
	)
	self.central_square.pack(side = TOP,
	  fill = BOTH,
	  expand = YES,
	  ipadx = 5,
	  ipady = 5,
	)

	# Il quadro dei pulsanti basso
	self.bottom_square = Frame(self.myBox1,
		padx=5,
		pady=5,
		background=main_bg,
		#relief=RAISED, borderwidth=1
	)
	self.bottom_square.pack(side = TOP,
	  fill = BOTH,
	  expand = YES,
	)
	
	# quadro sinistra
	self.left_square = Frame(self.central_square,
		background=main_bg,
		#borderwidth = 5,
		#relief = RIDGE,
	)
	self.left_square.pack(side = LEFT,
	  fill = BOTH,
	  expand = YES,
	)

	# quadro destra
	self.right_square = Frame(self.central_square, 
		background=main_bg,
		#borderwidth = 5,
		#relief = RIDGE,
	)
	self.right_square.pack(side = RIGHT,
	  fill = BOTH,
	  expand = YES,
	)
	#--------------------- FIXED LABELS -----------------------
	# etichette sinistra
	# IP
	self.label1 = Label(self.left_square, 
		background=main_bg, foreground=main_fg,
		text="IP: ", 
		anchor='w', 
		font=labFont,
	)
	self.label1.pack(
		fill=X, 
		expand = YES
	)
	
	# Temp
	self.label2 = Label(self.left_square, 
		background=main_bg, foreground=main_fg,
		text="Temp: ", 
		anchor='w', 
		font=labFont,
	)
	self.label2.pack(
		fill=X, 
		expand = YES
	)
	
	# Date
	self.label3 = Label(self.left_square, 
		background=main_bg, foreground=main_fg,
		text="Date: ", 
		anchor='w', 
		font=labFont,
	)
	self.label3.pack(
		fill=X, 
		expand = YES
	)
	
	# Volts
	self.label4 = Label(self.left_square, 
		background=main_bg, foreground=main_fg,
		text="Core: ", 
		anchor='w', 
		font=labFont,
	)
	self.label4.pack(
		fill=X, 
		expand = YES
	)
	
	# Clock
	self.label5 = Label(self.left_square, 
		background=main_bg, foreground=main_fg,
		text="Clock: ", 
		anchor='w', 
		font=labFont,
	)
	self.label5.pack(
		fill=X, 
		expand = YES
	)
	

	#--------------------- VAR LABELS -----------------------
	# etichette destra
	self.label1var = Label(self.right_square, 
		background=main_bg, foreground=main_fg,
		text=get_ip(), 
		anchor='w', 
		font=labFont,
	)
	self.label1var.pack(
		fill=X, 
		expand = YES
	)
	
	#var_temp = StringVar();
	#var_temp.set(get_temp());
	self.label2var = Label(self.right_square, 
		background=main_bg, foreground=main_fg,
		#textvariable=var_temp, 
		anchor='w', 
		font=labFont,
	)
	self.label2var.pack(
		fill=X, 
		expand = YES
	)
	
	#var_date = StringVar()
	#var_date.set(get_date())
	self.label3var = Label(self.right_square, 
		background=main_bg, foreground=main_fg,
	#	textvariable=var_date, 
		anchor='w', 
		font=labFont,
	)
	self.label3var.pack(
		fill=X, 
		expand = YES
	)
	self.label4var = Label(self.right_square, 
		background=main_bg, foreground=main_fg,
		text=get_volts(), 
		anchor='w', 
		font=labFont,
	)
	self.label4var.pack(
		fill=X, 
		expand = YES
	)
	self.label5var = Label(self.right_square, 
		background=main_bg, foreground=main_fg,
		text=get_clock(), 
		anchor='w', 
		font=labFont,
	)
	self.label5var.pack(
		fill=X, 
		expand = YES
	)
	
	# Vengono ora aggiunti i pulsanti a 'button_square'
	#--------------------- TOP BUTTONS -----------------------
	self.pulsante1 = Button(self.button_square, command = self.buttonPress1)
	self.pulsante1.configure(text = "STARTX")
	self.pulsante1.configure(
	  width = but_width, height = but_height,
	  padx = but_padx, pady = but_pady,
	  relief = but_relief, borderwidth = but_borderwidth, 
	  highlightbackground = but_hlbg, highlightcolor = but_hlcol,
	  activebackground = but_actbg, activeforeground = but_actfg,
	  background = but_bg, foreground = but_fg,
	  font=butFont,
	  )
	self.pulsante1.pack(side = LEFT)
	self.pulsante1.bind("<Return>", self.buttonPress1_a)

	self.pulsante2 = Button(self.button_square, command = self.buttonPress2)
	self.pulsante2.configure(text = "EXIT")
	# default focus
	self.pulsante2.focus_force()
	self.pulsante2.configure(
	  width = but_width, height = but_height,
	  padx = but_padx, pady = but_pady,
	  relief = but_relief, borderwidth = but_borderwidth, 
	  highlightbackground = but_hlbg, highlightcolor = but_hlcol,
	  activebackground = but_actbg, activeforeground = but_actfg,
	  background = but_bg, foreground = but_fg,
	  font=butFont,
	  )
	self.pulsante2.pack(side = RIGHT)
	self.pulsante2.bind("<Return>", self.buttonPress2_a)

	#-------------------- BOTTOM BUTTONS ----------------------
	self.pulsante3 = Button(self.bottom_square, command = self.buttonPress3)
	self.pulsante3.configure(text = "REBOOT")
	self.pulsante3.configure(
	  width = but_width, height = but_height,
	  padx = but_padx, pady = but_pady,
	  relief = but_relief, borderwidth = but_borderwidth, 
	  highlightbackground = but_hlbg, highlightcolor = but_hlcol,
	  activebackground = but_actbg, activeforeground = but_actfg,
	  background = but_bg, foreground = but_fg,
	  font=butFont,
	  )
	self.pulsante3.pack(side = LEFT)
	self.pulsante3.bind("<Return>", self.buttonPress3_a)

	self.pulsante4 = Button(self.bottom_square, command = self.buttonPress4)
	self.pulsante4.configure(text = "SHUTDOWN")
	self.pulsante4.configure(
	  width = but_width, height = but_height,
	  padx = but_padx, pady = but_pady,
	  relief = but_relief, borderwidth = but_borderwidth, 
	  highlightbackground = but_hlbg, highlightcolor = but_hlcol,
	  activebackground = but_actbg, activeforeground = but_actfg,
	  background = but_bg, foreground = but_fg,
	  font=butFont,
	  )
	self.pulsante4.pack(side = RIGHT)
	self.pulsante4.bind("<Return>", self.buttonPress4_a)