Ejemplo n.º 1
0
 def _init_startframe(self):
     frame = self._startframe = Frame(self._top)
     self._start = Entry(frame)
     self._start.pack(side="right")
     Label(frame, text="Start Symbol:").pack(side="right")
     Label(frame, text="Productions:").pack(side="left")
     self._start.insert(0, self._cfg.start().symbol())
Ejemplo n.º 2
0
 def _init_startframe(self):
     frame = self._startframe = Frame(self._top)
     self._start = Entry(frame)
     self._start.pack(side='right')
     Label(frame, text='Start Symbol:').pack(side='right')
     Label(frame, text='Productions:').pack(side='left')
     self._start.insert(0, self._cfg.start().symbol())
Ejemplo n.º 3
0
 def _init_feedback(self, parent):
     self._feedbackframe = feedbackframe = Frame(parent)
     feedbackframe.pack(fill='x', side='bottom', padx=3, pady=3)
     self._lastoper_label = Label(feedbackframe, text='Last Operation:',
                                  font=self._font)
     self._lastoper_label.pack(side='left')
     lastoperframe = Frame(feedbackframe, relief='sunken', border=1)
     lastoperframe.pack(fill='x', side='right', expand=1, padx=5)
     self._lastoper1 = Label(lastoperframe, foreground='#007070',
                             background='#f0f0f0', font=self._font)
     self._lastoper2 = Label(lastoperframe, anchor='w', width=30,
                             foreground='#004040', background='#f0f0f0',
                             font=self._font)
     self._lastoper1.pack(side='left')
     self._lastoper2.pack(side='left', fill='x', expand=1)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
 def _init_results_box(self, parent):
     innerframe = Frame(parent)
     i1 = Frame(innerframe)
     i2 = Frame(innerframe)
     vscrollbar = Scrollbar(i1, borderwidth=1)
     hscrollbar = Scrollbar(i2, borderwidth=1, orient="horiz")
     self.results_box = Text(
         i1,
         font=Font(family="courier", size="16"),
         state="disabled",
         borderwidth=1,
         yscrollcommand=vscrollbar.set,
         xscrollcommand=hscrollbar.set,
         wrap="none",
         width="40",
         height="20",
         exportselection=1,
     )
     self.results_box.pack(side="left", fill="both", expand=True)
     vscrollbar.pack(side="left", fill="y", anchor="e")
     vscrollbar.config(command=self.results_box.yview)
     hscrollbar.pack(side="left", fill="x", expand=True, anchor="w")
     hscrollbar.config(command=self.results_box.xview)
     # there is no other way of avoiding the overlap of scrollbars while using pack layout manager!!!
     Label(i2, text="   ",
           background=self._BACKGROUND_COLOUR).pack(side="left", anchor="e")
     i1.pack(side="top", fill="both", expand=True, anchor="n")
     i2.pack(side="bottom", fill="x", anchor="s")
     innerframe.pack(side="top", fill="both", expand=True)
Ejemplo n.º 6
0
 def _init_results_box(self, parent):
     innerframe = Frame(parent)
     i1 = Frame(innerframe)
     i2 = Frame(innerframe)
     vscrollbar = Scrollbar(i1, borderwidth=1)
     hscrollbar = Scrollbar(i2, borderwidth=1, orient='horiz')
     self.results_box = Text(i1,
                             font=Font(family='courier', size='16'),
                             state='disabled',
                             borderwidth=1,
                             yscrollcommand=vscrollbar.set,
                             xscrollcommand=hscrollbar.set,
                             wrap='none',
                             width='40',
                             height='20',
                             exportselection=1)
     self.results_box.pack(side='left', fill='both', expand=True)
     self.results_box.tag_config(self._HIGHLIGHT_WORD_TAG,
                                 foreground=self._HIGHLIGHT_WORD_COLOUR)
     self.results_box.tag_config(self._HIGHLIGHT_LABEL_TAG,
                                 foreground=self._HIGHLIGHT_LABEL_COLOUR)
     vscrollbar.pack(side='left', fill='y', anchor='e')
     vscrollbar.config(command=self.results_box.yview)
     hscrollbar.pack(side='left', fill='x', expand=True, anchor='w')
     hscrollbar.config(command=self.results_box.xview)
     #there is no other way of avoiding the overlap of scrollbars while using pack layout manager!!!
     Label(i2, text='   ',
           background=self._BACKGROUND_COLOUR).pack(side='left', anchor='e')
     i1.pack(side='top', fill='both', expand=True, anchor='n')
     i2.pack(side='bottom', fill='x', anchor='s')
     innerframe.pack(side='top', fill='both', expand=True)
Ejemplo n.º 7
0
def demo():
    from nltk import Nonterminal, CFG
    nonterminals = 'S VP NP PP P N Name V Det'
    (S, VP, NP, PP, P, N, Name, V, Det) = [Nonterminal(s)
                                           for s in nonterminals.split()]

    grammar = CFG.fromstring("""
    S -> NP VP
    PP -> P NP
    NP -> Det N
    NP -> NP PP
    VP -> V NP
    VP -> VP PP
    Det -> 'a'
    Det -> 'the'
    Det -> 'my'
    NP -> 'I'
    N -> 'dog'
    N -> 'man'
    N -> 'park'
    N -> 'statue'
    V -> 'saw'
    P -> 'in'
    P -> 'up'
    P -> 'over'
    P -> 'with'
    """)

    def cb(grammar): print(grammar)
    top = Tk()
    editor = CFGEditor(top, grammar, cb)
    Label(top, text='\nTesting CFG Editor\n').pack()
    Button(top, text='Quit', command=top.destroy).pack()
    top.mainloop()
Ejemplo n.º 8
0
    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()
Ejemplo n.º 9
0
    def _init_corpus_select(self, parent):
        innerframe = Frame(parent, background=self._BACKGROUND_COLOUR)
        self.var = StringVar(innerframe)
        self.var.set(self.model.DEFAULT_CORPUS)
        Label(
            innerframe,
            justify=LEFT,
            text=' Corpus: ',
            background=self._BACKGROUND_COLOUR,
            padx=2,
            pady=1,
            border=0,
        ).pack(side='left')

        other_corpora = list(self.model.CORPORA.keys()).remove(
            self.model.DEFAULT_CORPUS)
        om = OptionMenu(innerframe,
                        self.var,
                        self.model.DEFAULT_CORPUS,
                        command=self.corpus_selected,
                        *self.model.non_default_corpora())
        om['borderwidth'] = 0
        om['highlightthickness'] = 1
        om.pack(side='left')
        innerframe.pack(side='top', fill='x', anchor='n')
Ejemplo n.º 10
0
    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()
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    def doGUI(self, hostname=None):
        self.master = Tk()
        self.master.title('Blessclient - MFA')
        textmsg = 'Enter your AWS MFA code: '
        if hostname:
            textmsg = 'Enter your AWS MFA code to connect to {}: '.format(
                hostname)
        Label(self.master, text=textmsg).grid(row=0)
        self.e1 = Entry(self.master)
        self.e1.grid(row=0, column=1, padx=4)
        Button(self.master,
               text='OK',
               command=self.show_entry_fields,
               default=ACTIVE).grid(row=3, column=0, sticky=W, pady=4)
        Button(self.master, text='Cancel', command=self.quit).grid(row=3,
                                                                   column=1,
                                                                   sticky=W,
                                                                   pady=4)

        self.center()
        self.master.bind('<Return>', self.show_entry_fields)
        self.master.lift()
        self.master.attributes('-topmost', True)
        self.master.focus_force()
        self.e1.focus_set()

        if platform.system() == 'Darwin':
            # Hack to get the GUI dialog focused in OSX
            # https://stackoverflow.com/questions/1892339/how-to-make-a-tkinter-window-jump-to-the-front/37235492#37235492
            tmpl = 'tell application "System Events" to set frontmost of every process whose unix id is {} to true'
            script = tmpl.format(os.getpid())
            subprocess.check_call(['/usr/bin/osascript', '-e', script])

        mainloop()
Ejemplo n.º 13
0
    def _init_grammar(self, parent):
        # Grammar view.
        self._prodframe = listframe = Frame(parent)
        self._prodframe.pack(fill='both', side='left', padx=2)
        self._prodlist_label = Label(
            self._prodframe, font=self._boldfont, text='Available Expansions'
        )
        self._prodlist_label.pack()
        self._prodlist = Listbox(
            self._prodframe,
            selectmode='single',
            relief='groove',
            background='white',
            foreground='#909090',
            font=self._font,
            selectforeground='#004040',
            selectbackground='#c0f0c0',
        )

        self._prodlist.pack(side='right', fill='both', expand=1)

        self._productions = list(self._parser.grammar().productions())
        for production in self._productions:
            self._prodlist.insert('end', ('  %s' % production))
        self._prodlist.config(height=min(len(self._productions), 25))

        # Add a scrollbar if there are more than 25 productions.
        if len(self._productions) > 25:
            listscroll = Scrollbar(self._prodframe, orient='vertical')
            self._prodlist.config(yscrollcommand=listscroll.set)
            listscroll.config(command=self._prodlist.yview)
            listscroll.pack(side='left', fill='y')

        # If they select a production, apply it.
        self._prodlist.bind('<<ListboxSelect>>', self._prodlist_select)
Ejemplo n.º 14
0
    def doGUI(self, hostname=None):
        self.master = Tk()
        self.master.title('Blessclient - MFA')
        textmsg = 'Enter your AWS MFA code: '
        if hostname:
            textmsg = 'Enter your AWS MFA code to connect to {}: '.format(
                hostname)
        Label(self.master, text=textmsg).grid(row=0)
        self.e1 = Entry(self.master)
        self.e1.grid(row=0, column=1, padx=4)
        Button(self.master,
               text='OK',
               command=self.show_entry_fields,
               default=ACTIVE).grid(row=3, column=0, sticky=W, pady=4)
        Button(self.master, text='Cancel', command=self.quit).grid(row=3,
                                                                   column=1,
                                                                   sticky=W,
                                                                   pady=4)

        self.center()
        self.master.bind('<Return>', self.show_entry_fields)
        self.master.lift()
        self.master.attributes('-topmost', True)
        self.master.focus_force()
        self.e1.focus_set()

        if platform.system() == 'Darwin':
            # Hack to get the GUI dialog focused in OSX
            os.system(
                '/usr/bin/osascript -e \'tell app "Finder" to set frontmost of process "python" to true\''
            )

        mainloop()
Ejemplo n.º 15
0
    def _init_grammar(self, parent):
        # Grammar view.
        self._prodframe = listframe = Frame(parent)
        self._prodframe.pack(fill="both", side="left", padx=2)
        self._prodlist_label = Label(self._prodframe,
                                     font=self._boldfont,
                                     text="Available Expansions")
        self._prodlist_label.pack()
        self._prodlist = Listbox(
            self._prodframe,
            selectmode="single",
            relief="groove",
            background="white",
            foreground="#909090",
            font=self._font,
            selectforeground="#004040",
            selectbackground="#c0f0c0",
        )

        self._prodlist.pack(side="right", fill="both", expand=1)

        self._productions = list(self._parser.grammar().productions())
        for production in self._productions:
            self._prodlist.insert("end", ("  %s" % production))
        self._prodlist.config(height=min(len(self._productions), 25))

        # Add a scrollbar if there are more than 25 productions.
        if len(self._productions) > 25:
            listscroll = Scrollbar(self._prodframe, orient="vertical")
            self._prodlist.config(yscrollcommand=listscroll.set)
            listscroll.config(command=self._prodlist.yview)
            listscroll.pack(side="left", fill="y")

        # If they select a production, apply it.
        self._prodlist.bind("<<ListboxSelect>>", self._prodlist_select)
Ejemplo n.º 16
0
 def _create_body(self, message, value, **extra):
     frame = Frame(self)
     Label(frame, text=message, anchor=W, justify=LEFT,
           wraplength=800).pack(fill=BOTH)
     selector = self._create_selector(frame, value, **extra)
     if selector:
         selector.pack(fill=BOTH)
         selector.focus_set()
     frame.pack(padx=5, pady=5, expand=1, fill=BOTH)
Ejemplo n.º 17
0
 def _init_status(self, parent):
     self.status = Label(parent,
                         justify=LEFT,
                         relief=SUNKEN,
                         background=self._BACKGROUND_COLOUR,
                         border=0,
                         padx=1,
                         pady=0)
     self.status.pack(side='top', anchor='sw')
    def _create_ui(self):
        '''Create all UI objects.'''

        #self._tl = Label(self, text="Staged Ship", f)
        self._sl = Label(self, textvariable=self._ship_name)
        self._c = Canvas(self)
        self._c.config(width=self.CANVAS_WIDTH)
        self._rb = Button(self,
                          text="Rotate",
                          command=self.rotate_current_ship)

        self.pack_ui()
Ejemplo n.º 19
0
    def _add_grids(self):
        '''Create UI containers for the player grids.'''

        self.my_grid_frame = PlayerGridFrame(self)
        self.my_grid_frame.place(x=self.X_PADDING + self.SHIP_PANEL_WIDTH,
                                 y=self.Y_PADDING)
        l1 = Label(self.my_grid_frame, text="Your Grid")
        l1.pack()
        self.my_grid = ShipGrid(self.my_grid_frame, True)
        self.my_grid.pack(side=LEFT, pady=20)

        self.their_grid_frame = PlayerGridFrame(self)
        self.their_grid_frame.place(x=self.my_grid.size + self.X_PADDING * 2 +
                                    self.SHIP_PANEL_WIDTH,
                                    y=self.Y_PADDING)
        self.their_grid_label = Label(self.their_grid_frame,
                                      text="Opponent's Grid")
        self.their_grid_label.pack()
        self.their_grid = ShipGrid(self.their_grid_frame, False)
        self.their_grid.pack(side=LEFT, pady=20)

        self._add_grid_events()
Ejemplo n.º 20
0
 def _init_feedback(self, parent):
     self._feedbackframe = feedbackframe = Frame(parent)
     feedbackframe.pack(fill="x", side="bottom", padx=3, pady=3)
     self._lastoper_label = Label(feedbackframe,
                                  text="Last Operation:",
                                  font=self._font)
     self._lastoper_label.pack(side="left")
     lastoperframe = Frame(feedbackframe, relief="sunken", border=1)
     lastoperframe.pack(fill="x", side="right", expand=1, padx=5)
     self._lastoper1 = Label(lastoperframe,
                             foreground="#007070",
                             background="#f0f0f0",
                             font=self._font)
     self._lastoper2 = Label(
         lastoperframe,
         anchor="w",
         width=30,
         foreground="#004040",
         background="#f0f0f0",
         font=self._font,
     )
     self._lastoper1.pack(side="left")
     self._lastoper2.pack(side="left", fill="x", expand=1)
Ejemplo n.º 21
0
    def _append(self, heading, content):
        inner = self._inner

        inner.rowconfigure(self._next_row, weight=0)
        inner.rowconfigure(self._next_row + 1, weight=1)

        Label(inner, text=heading).grid(row=self._next_row,
                                        column=0,
                                        sticky="NSW")
        t = Text(inner, wrap=WORD)
        t.grid(row=self._next_row + 1, column=0, sticky="NESW")
        t.insert(END, content)
        t.config(state=DISABLED)

        self._next_row += 2
Ejemplo n.º 22
0
 def __init__(self, image, initialField, initialText):
     frm = Frame(root)
     frm.config(background="white")
     self.image = PhotoImage(format="gif", data=images[image.upper()])
     self.imageDimmed = PhotoImage(format="gif", data=images[image])
     self.img = Label(frm)
     self.img.config(borderwidth=0)
     self.img.pack(side="left")
     self.fld = Text(frm, **fieldParams)
     self.initScrollText(frm, self.fld, initialField)
     frm = Frame(root)
     self.txt = Text(frm, **textParams)
     self.initScrollText(frm, self.txt, initialText)
     for i in range(2):
         self.txt.tag_config(colors[i], background=colors[i])
         self.txt.tag_config("emph" + colors[i], foreground=emphColors[i])
Ejemplo n.º 23
0
    def _create_ui(self):
        '''Create the UI elements.'''

        self.ship_labels = {}
        i = 0

        for short_name, full_name in Ship.NAMES.items():
            self.ship_labels[short_name] = Label(
                self,
                text=full_name.title(),
                fg=self.SHIP_ALIVE,
                justify=LEFT,
            )
            self.ship_labels[short_name].grid(row=i,
                                              column=0,
                                              sticky=W,
                                              ipady=5)
            i += 1
Ejemplo n.º 24
0
    def append_row_to_grid(self, grid, rows, mio):
        # update delete button
        if not rows:
            bt_del = getattr(self, "bt_del_" + mio)
            bt_del.config(state="normal")

        row = len(rows)

        l = Label(grid, text=str(row) + ":")
        l.grid(row=row, column=0, sticky="NES")

        v = StringVar()
        e = HKEntry(grid, textvariable=v)
        e.grid(row=row, column=1, sticky="NEWS")

        row_desc = (l, e, v)

        rows.append(row_desc)

        return row_desc
Ejemplo n.º 25
0
def show_qr(path):
    import platform
    try:
        from six.moves.tkinter import Tk, Label
    except ImportError:
        raise SystemError('缺少Tkinter模块, 可使用sudo pip install Tkinter尝试安装')
    try:
        from PIL import ImageTk, Image
    except ImportError:
        raise SystemError('缺少PIL模块, 可使用sudo pip install PIL尝试安装')

    system = platform.system()
    if system == 'Darwin':  # 如果是Mac OS X
        img = Image.open(path)
        img.show()
    else:
        root = Tk()
        img = ImageTk.PhotoImage(Image.open(path))
        panel = Label(root, image=img)
        panel.pack(side="bottom", fill="both", expand="yes")
        root.mainloop()
Ejemplo n.º 26
0
    def __init__(self, parent, app):
        parent.title('Auth window')

        self.parent = parent
        self.root = app

        # Widget Initialization
        self._label_header = Label(
            parent,
            font="{Segoe UI} 20 bold",
            foreground="#ff0000",
            text="Trakt Account Authorization",
        )
        self._button_get_code = Button(
            parent,
            font="{MS Sans Serif} 12 bold",
            text="Get PIN Code",
        )
        self._label_enter_code = Label(
            parent,
            font="{MS Sans Serif} 14",
            text="Enter the code:",
        )
        self._label_click = Label(
            parent,
            font="{MS Sans Serif} 14",
            text="Click the button to get a code:",
        )
        self.pin_code = StringVar()
        self._entry_code = Entry(
            parent,
            font="{MS Sans Serif} 14 bold",
            width=10,
            justify="center",
            textvariable=self.pin_code,
            state="disabled",
        )
        self._button_done = Button(
            parent,
            borderwidth=3,
            font="{MS Sans Serif} 12 bold",
            text="Done",
            state="disabled",
        )

        # widget commands
        self._button_get_code.configure(command=self.button_get_code_command)
        self._button_done.configure(command=self.button_done_command)

        # Geometry Management
        self._label_header.grid(in_=parent,
                                column=1,
                                row=1,
                                columnspan=1,
                                ipadx=0,
                                ipady=0,
                                padx=0,
                                pady=0,
                                rowspan=1,
                                sticky="ew")
        self._label_click.grid(in_=parent,
                               column=1,
                               row=2,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=0,
                               pady=0,
                               rowspan=1,
                               sticky="")
        self._button_get_code.grid(in_=parent,
                                   column=1,
                                   row=3,
                                   columnspan=1,
                                   ipadx=0,
                                   ipady=0,
                                   padx=0,
                                   pady=0,
                                   rowspan=1,
                                   sticky="")
        self._label_enter_code.grid(in_=parent,
                                    column=1,
                                    row=4,
                                    columnspan=1,
                                    ipadx=0,
                                    ipady=0,
                                    padx=0,
                                    pady=0,
                                    rowspan=1,
                                    sticky="")
        self._entry_code.grid(in_=parent,
                              column=1,
                              row=5,
                              columnspan=1,
                              ipadx=5,
                              ipady=0,
                              padx=5,
                              pady=0,
                              rowspan=1,
                              sticky="")
        self._button_done.grid(in_=parent,
                               column=1,
                               row=6,
                               columnspan=1,
                               ipadx=0,
                               ipady=0,
                               padx=0,
                               pady=0,
                               rowspan=1,
                               sticky="")

        # Resize Behavior
        parent.resizable(False, False)
        parent.grid_rowconfigure(1, weight=1, minsize=40, pad=10)
        parent.grid_rowconfigure(2, weight=1, minsize=40, pad=10)
        parent.grid_rowconfigure(3, weight=1, minsize=40, pad=10)
        parent.grid_rowconfigure(4, weight=1, minsize=40, pad=10)
        parent.grid_rowconfigure(5, weight=1, minsize=50, pad=10)
        parent.grid_rowconfigure(6, weight=1, minsize=50, pad=10)
        parent.grid_columnconfigure(1, weight=1, minsize=0, pad=10)
Ejemplo n.º 27
0
    def __init__(self, *args, **kw):
        GUIFrame.__init__(self, *args, **kw)

        # Empty status bar still must get its space in parent widget.
        self.padding = Label(self)
        self.padding.pack(fill=FILL_X, expand=1, side=SIDE_RIGHT)
Ejemplo n.º 28
0
    def __init__(self, master, columns, column_weights=None, cnf={}, **kw):
        """
        Construct a new multi-column listbox widget.

        :param master: The widget that should contain the new
            multi-column listbox.

        :param columns: Specifies what columns should be included in
            the new multi-column listbox.  If ``columns`` is an integer,
            the it is the number of columns to include.  If it is
            a list, then its length indicates the number of columns
            to include; and each element of the list will be used as
            a label for the corresponding column.

        :param cnf, kw: Configuration parameters for this widget.
            Use ``label_*`` to configure all labels; and ``listbox_*``
            to configure all listboxes.  E.g.:

                >>> mlb = MultiListbox(master, 5, label_foreground='red')
        """
        # If columns was specified as an int, convert it to a list.
        if isinstance(columns, int):
            columns = list(range(columns))
            include_labels = False
        else:
            include_labels = True

        if len(columns) == 0:
            raise ValueError("Expected at least one column")

        # Instance variables
        self._column_names = tuple(columns)
        self._listboxes = []
        self._labels = []

        # Pick a default value for column_weights, if none was specified.
        if column_weights is None:
            column_weights = [1] * len(columns)
        elif len(column_weights) != len(columns):
            raise ValueError('Expected one column_weight for each column')
        self._column_weights = column_weights

        # Configure our widgets.
        Frame.__init__(self, master, **self.FRAME_CONFIG)
        self.grid_rowconfigure(1, weight=1)
        for i, label in enumerate(self._column_names):
            self.grid_columnconfigure(i, weight=column_weights[i])

            # Create a label for the column
            if include_labels:
                l = Label(self, text=label, **self.LABEL_CONFIG)
                self._labels.append(l)
                l.grid(column=i, row=0, sticky='news', padx=0, pady=0)
                l.column_index = i

            # Create a listbox for the column
            lb = Listbox(self, **self.LISTBOX_CONFIG)
            self._listboxes.append(lb)
            lb.grid(column=i, row=1, sticky='news', padx=0, pady=0)
            lb.column_index = i

            # Clicking or dragging selects:
            lb.bind('<Button-1>', self._select)
            lb.bind('<B1-Motion>', self._select)
            # Scroll whell scrolls:
            lb.bind('<Button-4>', lambda e: self._scroll(-1))
            lb.bind('<Button-5>', lambda e: self._scroll(+1))
            lb.bind('<MouseWheel>', lambda e: self._scroll(e.delta))
            # Button 2 can be used to scan:
            lb.bind('<Button-2>', lambda e: self.scan_mark(e.x, e.y))
            lb.bind('<B2-Motion>', lambda e: self.scan_dragto(e.x, e.y))
            # Dragging outside the window has no effect (diable
            # the default listbox behavior, which scrolls):
            lb.bind('<B1-Leave>', lambda e: 'break')
            # Columns can be resized by dragging them:
            l.bind('<Button-1>', self._resize_column)

        # Columns can be resized by dragging them.  (This binding is
        # used if they click on the grid between columns:)
        self.bind('<Button-1>', self._resize_column)

        # Set up key bindings for the widget:
        self.bind('<Up>', lambda e: self.select(delta=-1))
        self.bind('<Down>', lambda e: self.select(delta=1))
        self.bind('<Prior>', lambda e: self.select(delta=-self._pagesize()))
        self.bind('<Next>', lambda e: self.select(delta=self._pagesize()))

        # Configuration customizations
        self.configure(cnf, **kw)
Ejemplo n.º 29
0
    def init_gui(self):
        """init helper"""

        window = PanedWindow(self.root, orient="vertical")
        window.pack(side=TOP, fill=BOTH, expand=True)

        top_pane = Frame(window)
        window.add(top_pane)
        mid_pane = Frame(window)
        window.add(mid_pane)
        bottom_pane = Frame(window)
        window.add(bottom_pane)

        #setting up frames
        top_frame = Frame(top_pane)
        mid_frame = Frame(top_pane)
        history_frame = Frame(top_pane)
        radio_frame = Frame(mid_pane)
        rating_frame = Frame(mid_pane)
        res_frame = Frame(mid_pane)
        check_frame = Frame(bottom_pane)
        msg_frame = Frame(bottom_pane)
        btn_frame = Frame(bottom_pane)
        top_frame.pack(side=TOP, fill=X)
        mid_frame.pack(side=TOP, fill=X)
        history_frame.pack(side=TOP, fill=BOTH, expand=True)
        radio_frame.pack(side=TOP, fill=X)
        rating_frame.pack(side=TOP, fill=X)
        res_frame.pack(side=TOP, fill=BOTH, expand=True)
        check_frame.pack(side=TOP, fill=X)
        msg_frame.pack(side=TOP, fill=BOTH, expand=True)
        btn_frame.pack(side=TOP, fill=X)

        # Binding F5 application-wide to run lint
        self.root.bind('<F5>', self.run_lint)

        #Message ListBox
        rightscrollbar = Scrollbar(msg_frame)
        rightscrollbar.pack(side=RIGHT, fill=Y)
        bottomscrollbar = Scrollbar(msg_frame, orient=HORIZONTAL)
        bottomscrollbar.pack(side=BOTTOM, fill=X)
        self.lb_messages = Listbox(msg_frame,
                                   yscrollcommand=rightscrollbar.set,
                                   xscrollcommand=bottomscrollbar.set,
                                   bg="white")
        self.lb_messages.bind("<Double-Button-1>", self.show_sourcefile)
        self.lb_messages.pack(expand=True, fill=BOTH)
        rightscrollbar.config(command=self.lb_messages.yview)
        bottomscrollbar.config(command=self.lb_messages.xview)

        #History ListBoxes
        rightscrollbar2 = Scrollbar(history_frame)
        rightscrollbar2.pack(side=RIGHT, fill=Y)
        bottomscrollbar2 = Scrollbar(history_frame, orient=HORIZONTAL)
        bottomscrollbar2.pack(side=BOTTOM, fill=X)
        self.showhistory = Listbox(history_frame,
                                   yscrollcommand=rightscrollbar2.set,
                                   xscrollcommand=bottomscrollbar2.set,
                                   bg="white")
        self.showhistory.pack(expand=True, fill=BOTH)
        rightscrollbar2.config(command=self.showhistory.yview)
        bottomscrollbar2.config(command=self.showhistory.xview)
        self.showhistory.bind('<Double-Button-1>', self.select_recent_file)
        self.set_history_window()

        #status bar
        self.status = Label(self.root, text="", bd=1, relief=SUNKEN, anchor=W)
        self.status.pack(side=BOTTOM, fill=X)

        #labelbl_ratingls
        lbl_rating_label = Label(rating_frame, text='Rating:')
        lbl_rating_label.pack(side=LEFT)
        lbl_rating = Label(rating_frame, textvariable=self.rating)
        lbl_rating.pack(side=LEFT)
        Label(mid_frame, text='Recently Used:').pack(side=LEFT)
        Label(top_frame, text='Module or package').pack(side=LEFT)

        #file textbox
        self.txt_module = Entry(top_frame, background='white')
        self.txt_module.bind('<Return>', self.run_lint)
        self.txt_module.pack(side=LEFT, expand=True, fill=X)

        #results box
        rightscrollbar = Scrollbar(res_frame)
        rightscrollbar.pack(side=RIGHT, fill=Y)
        bottomscrollbar = Scrollbar(res_frame, orient=HORIZONTAL)
        bottomscrollbar.pack(side=BOTTOM, fill=X)
        self.results = Listbox(res_frame,
                               yscrollcommand=rightscrollbar.set,
                               xscrollcommand=bottomscrollbar.set,
                               bg="white",
                               font="Courier")
        self.results.pack(expand=True, fill=BOTH, side=BOTTOM)
        rightscrollbar.config(command=self.results.yview)
        bottomscrollbar.config(command=self.results.xview)

        #buttons
        Button(top_frame, text='Open', command=self.file_open).pack(side=LEFT)
        Button(top_frame,
               text='Open Package',
               command=(lambda: self.file_open(package=True))).pack(side=LEFT)

        self.btnRun = Button(top_frame, text='Run', command=self.run_lint)
        self.btnRun.pack(side=LEFT)
        Button(btn_frame, text='Quit', command=self.quit).pack(side=BOTTOM)

        #radio buttons
        self.information_box = IntVar()
        self.convention_box = IntVar()
        self.refactor_box = IntVar()
        self.warning_box = IntVar()
        self.error_box = IntVar()
        self.fatal_box = IntVar()
        i = Checkbutton(check_frame,
                        text="Information",
                        fg=COLORS['(I)'],
                        variable=self.information_box,
                        command=self.refresh_msg_window)
        c = Checkbutton(check_frame,
                        text="Convention",
                        fg=COLORS['(C)'],
                        variable=self.convention_box,
                        command=self.refresh_msg_window)
        r = Checkbutton(check_frame,
                        text="Refactor",
                        fg=COLORS['(R)'],
                        variable=self.refactor_box,
                        command=self.refresh_msg_window)
        w = Checkbutton(check_frame,
                        text="Warning",
                        fg=COLORS['(W)'],
                        variable=self.warning_box,
                        command=self.refresh_msg_window)
        e = Checkbutton(check_frame,
                        text="Error",
                        fg=COLORS['(E)'],
                        variable=self.error_box,
                        command=self.refresh_msg_window)
        f = Checkbutton(check_frame,
                        text="Fatal",
                        fg=COLORS['(F)'],
                        variable=self.fatal_box,
                        command=self.refresh_msg_window)
        i.select()
        c.select()
        r.select()
        w.select()
        e.select()
        f.select()
        i.pack(side=LEFT)
        c.pack(side=LEFT)
        r.pack(side=LEFT)
        w.pack(side=LEFT)
        e.pack(side=LEFT)
        f.pack(side=LEFT)

        #check boxes
        self.box = StringVar()
        # XXX should be generated
        report = Radiobutton(radio_frame,
                             text="Report",
                             variable=self.box,
                             value="Report",
                             command=self.refresh_results_window)
        raw_met = Radiobutton(radio_frame,
                              text="Raw metrics",
                              variable=self.box,
                              value="Raw metrics",
                              command=self.refresh_results_window)
        dup = Radiobutton(radio_frame,
                          text="Duplication",
                          variable=self.box,
                          value="Duplication",
                          command=self.refresh_results_window)
        ext = Radiobutton(radio_frame,
                          text="External dependencies",
                          variable=self.box,
                          value="External dependencies",
                          command=self.refresh_results_window)
        stat = Radiobutton(radio_frame,
                           text="Statistics by type",
                           variable=self.box,
                           value="Statistics by type",
                           command=self.refresh_results_window)
        msg_cat = Radiobutton(radio_frame,
                              text="Messages by category",
                              variable=self.box,
                              value="Messages by category",
                              command=self.refresh_results_window)
        msg = Radiobutton(radio_frame,
                          text="Messages",
                          variable=self.box,
                          value="Messages",
                          command=self.refresh_results_window)
        source_file = Radiobutton(radio_frame,
                                  text="Source File",
                                  variable=self.box,
                                  value="Source File",
                                  command=self.refresh_results_window)
        report.select()
        report.grid(column=0, row=0, sticky=W)
        raw_met.grid(column=1, row=0, sticky=W)
        dup.grid(column=2, row=0, sticky=W)
        msg.grid(column=3, row=0, sticky=W)
        stat.grid(column=0, row=1, sticky=W)
        msg_cat.grid(column=1, row=1, sticky=W)
        ext.grid(column=2, row=1, sticky=W)
        source_file.grid(column=3, row=1, sticky=W)

        #dictionary for check boxes and associated error term
        self.msg_type_dict = {
            'I': lambda: self.information_box.get() == 1,
            'C': lambda: self.convention_box.get() == 1,
            'R': lambda: self.refactor_box.get() == 1,
            'E': lambda: self.error_box.get() == 1,
            'W': lambda: self.warning_box.get() == 1,
            'F': lambda: self.fatal_box.get() == 1
        }
        self.txt_module.focus_set()
Ejemplo n.º 30
0
def main():
    root = Tk()

    frame = add_scrollbars(root, Frame, wheel=True)

    if False:

        def event_break(e):
            print("breaking %r" % e)
            return "break"

        frame.bind_all("<Button-4>", event_break, "+")

    lb = Label(frame, text="Label")
    lb.pack(fill=BOTH, side=TOP)

    cb = Combobox(frame, values=("1", "2", "3"))
    cb.pack(fill=BOTH, side=TOP)

    text = Text(frame)
    text.pack(fill=BOTH, expand=True, side=TOP)
    text.insert(END, "A\nMultiline\nMessage")

    for i in range(3, 100):
        text.insert(END, "line %d\n" % i)

    text2 = Text(frame)
    text2.pack(fill=BOTH, expand=True, side=TOP)

    for i in range(1, 200):
        text2.insert(END, "line %d\n" % i)

    bt1 = Button(frame, text="Bt#1")
    bt1.pack(side=LEFT)

    bt2 = Button(frame, text="Bt#2")
    bt2.pack(side=RIGHT)

    root.rowconfigure(2, weight=0)
    Label(root, text="Outer label").grid(row=2,
                                         column=0,
                                         columnspan=2,
                                         sticky="EW")

    if False:

        def event(e):
            print("event %r" % e)

        frame.bind("<Button-4>", event, "+")

    scrollable = set(["TCombobox", "Scrollbar", "Text"])

    def event_all(e):
        w = e.widget

        m = e.widget
        while m is not None:
            if m is frame:
                break
            m = m.master
        else:
            print("Outer widget")
            return

        cls = w.winfo_class()
        print("cls = " + cls)
        if cls in scrollable:
            return
        # scroll here

    bind_all_mouse_wheel(frame, event_all, "+")

    root.mainloop()