コード例 #1
0
ファイル: concordance_app.py プロジェクト: wurentidai/nltk
 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)
コード例 #2
0
ファイル: nemo_app.py プロジェクト: zlpmichelle/nltk
 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])
コード例 #3
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)
コード例 #4
0
ファイル: cfg.py プロジェクト: EricChh20/EZ-Mail
    def _init_prodframe(self):
        self._prodframe = Frame(self._top)

        # Create the basic Text widget & scrollbar.
        self._textwidget = Text(self._prodframe, background='#e0e0e0',
                                exportselection=1)
        self._textscroll = Scrollbar(self._prodframe, takefocus=0,
                                     orient='vertical')
        self._textwidget.config(yscrollcommand = self._textscroll.set)
        self._textscroll.config(command=self._textwidget.yview)
        self._textscroll.pack(side='right', fill='y')
        self._textwidget.pack(expand=1, fill='both', side='left')

        # Initialize the colorization tags.  Each nonterminal gets its
        # own tag, so they aren't listed here.
        self._textwidget.tag_config('terminal', foreground='#006000')
        self._textwidget.tag_config('arrow', font='symbol')
        self._textwidget.tag_config('error', background='red')

        # Keep track of what line they're on.  We use that to remember
        # to re-analyze a line whenever they leave it.
        self._linenum = 0

        # Expand "->" to an arrow.
        self._top.bind('>', self._replace_arrows)

        # Re-colorize lines when appropriate.
        self._top.bind('<<Paste>>', self._analyze)
        self._top.bind('<KeyPress>', self._check_analyze)
        self._top.bind('<ButtonPress>', self._check_analyze)

        # Tab cycles focus. (why doesn't this work??)
        def cycle(e, textwidget=self._textwidget):
            textwidget.tk_focusNext().focus()
        self._textwidget.bind('<Tab>', cycle)

        prod_tuples = [(p.lhs(),[p.rhs()]) for p in self._cfg.productions()]
        for i in range(len(prod_tuples)-1,0,-1):
            if (prod_tuples[i][0] == prod_tuples[i-1][0]):
                if () in prod_tuples[i][1]: continue
                if () in prod_tuples[i-1][1]: continue
                print(prod_tuples[i-1][1])
                print(prod_tuples[i][1])
                prod_tuples[i-1][1].extend(prod_tuples[i][1])
                del prod_tuples[i]

        for lhs, rhss in prod_tuples:
            print(lhs, rhss)
            s = '%s ->' % lhs
            for rhs in rhss:
                for elt in rhs:
                    if isinstance(elt, Nonterminal): s += ' %s' % elt
                    else: s += ' %r' % elt
                s += ' |'
            s = s[:-2] + '\n'
            self._textwidget.insert('end', s)

        self._analyze()
コード例 #5
0
    def __init__(self, conv, *a, **kw):
        Frame.__init__(self, *a, **kw)

        self._conv = conv
        self._s_conv = s_conv = sorted(conv, key = lambda i : i["date"])

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

        self._text = text = Text(self, wrap = WORD)
        text.grid(row = 0, column = 0, sticky = "NESW")

        add_scrollbars(self, text)

        # incoming
        text.tag_config("itime",
            foreground = "grey",
            background = "#eeeeee",
            selectbackground = "SystemHighlight",
            selectforeground = "SystemHighlightText"
        )
        text.tag_config("imessage",
            rmargin = 100
        )

        text.tag_config("otime",
            justify = RIGHT,
            foreground = "grey",
            background = "#eeeeee",
            selectbackground = "SystemHighlight",
            selectforeground = "SystemHighlightText"
        )
        text.tag_config("omessage",
            lmargin1 = 100,
            lmargin2 = 100,
            background = "#f8f8f8",
            selectbackground = "SystemHighlight",
        )

        # separator
        text.tag_config("sep",
            font = ("Arial", 1),
            background = "#dddddd",
            selectbackground = "SystemHighlight",
        )

        for item in s_conv:
            prefix = "i" if item.incoming else "o"

            text.insert(END,
                item.datetime.strftime("%Y.%m.%d %H:%M:%S") + "\n",
                prefix + "time"
            )
            text.insert(END, item.message + "\n", prefix + "message")
            text.insert(END, "\n", "sep")

        text.config(state = DISABLED)
        text.see("end-1c")
コード例 #6
0
ファイル: watchapp.py プロジェクト: caiespin/python-bits
    def fill_body(self, content):
        scrollbar = Scrollbar(self.body)
        scrollbar.pack(side=RIGHT, fill=Y)

        text = Text(self.body, yscrollcommand=scrollbar.set)
        text.pack(side=LEFT, fill=BOTH)
        text.config(state=NORMAL)
        text.delete(1.0, END)
        text.insert(END, content)
        text.config(state=DISABLED)

        scrollbar.config(command=text.yview)
コード例 #7
0
ファイル: gui_text.py プロジェクト: dimas3452/qdt
    def __init__(self, **kw):
        read_only = False
        try:
            state = kw["state"]
        except:
            pass
        else:
            if state == READONLY:
                read_only = True
                kw["state"] = NORMAL

        Text.__init__(self, **kw)

        self.redirector = WidgetRedirector(self)

        if read_only:
            self.__read_only = True
            """ Note that software editing is still possible by calling those
            "insert" and "delete". """
            self.insert = self.redirector.register("insert", _break)
            self.delete = self.redirector.register("delete", _break)
コード例 #8
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
コード例 #9
0
 def _start(self):
     super(GUIScreen, self)._start()
     self.root = Tk()
     self.root.geometry("%sx%s" % (self.size[0] * 7, self.size[1] * 15))
     self.root.bind("<Configure>", self.resize)
     if platform.system() == 'Windows':
         self.root.bind("<Control-MouseWheel>", self.change_font)
     else:
         self.root.bind("<Control-4>", self.change_font)
         self.root.bind("<Control-5>", self.change_font)
     self.root.protocol("WM_DELETE_WINDOW", self.closed_window)
     self.text = Text(self.root,
                      font="TkFixedFont",
                      wrap=Tkinter.NONE,
                      state=Tkinter.DISABLED,
                      background="black",
                      foreground="light gray")
     self.text.pack(side=Tkinter.LEFT,
                    fill=Tkinter.BOTH,
                    expand=Tkinter.YES)
     self.font = tkFont.Font(self.root, self.text.cget("font"))
     self.text.config(font=self.font)
     self.__prepare_tags()
コード例 #10
0
ファイル: tk_events.py プロジェクト: windsmell/qdt
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()
コード例 #11
0
ファイル: canvas_frame_test.py プロジェクト: windsmell/qdt
    root = Tk()

    root.rowconfigure(0, weight = 1)
    root.columnconfigure(0, weight = 1)

    cnv = CanvasDnD(root, bg = "white", width = 400, height = 400)
    cnv.grid(row = 0, column = 0, sticky = "NESW")

    cf = CanvasFrame(cnv, 100, 100)

    cnv.itemconfig(cf.id, width = 150, height = 150)

    Label(cf, text = "Test").pack(fill = BOTH, expand = 0)

    f2 = Frame(cf, bg = "white", width = 100, height = 100)
    f2.pack(fill = BOTH, expand = 1)

    def on_motion(e):
        print (e.x, e.y)

    f2.bind("<Motion>", on_motion, "+")

    cf2 = CanvasFrame(cnv, 200, 200)

    Text(cf2,
        width = 10, # characters
        height = 3
    ).pack(fill = BOTH, expand = 1)

    root.mainloop()
コード例 #12
0
ファイル: cfg.py プロジェクト: zlpmichelle/nltk
    def _init_prodframe(self):
        self._prodframe = Frame(self._top)

        # Create the basic Text widget & scrollbar.
        self._textwidget = Text(self._prodframe,
                                background="#e0e0e0",
                                exportselection=1)
        self._textscroll = Scrollbar(self._prodframe,
                                     takefocus=0,
                                     orient="vertical")
        self._textwidget.config(yscrollcommand=self._textscroll.set)
        self._textscroll.config(command=self._textwidget.yview)
        self._textscroll.pack(side="right", fill="y")
        self._textwidget.pack(expand=1, fill="both", side="left")

        # Initialize the colorization tags.  Each nonterminal gets its
        # own tag, so they aren't listed here.
        self._textwidget.tag_config("terminal", foreground="#006000")
        self._textwidget.tag_config("arrow", font="symbol")
        self._textwidget.tag_config("error", background="red")

        # Keep track of what line they're on.  We use that to remember
        # to re-analyze a line whenever they leave it.
        self._linenum = 0

        # Expand "->" to an arrow.
        self._top.bind(">", self._replace_arrows)

        # Re-colorize lines when appropriate.
        self._top.bind("<<Paste>>", self._analyze)
        self._top.bind("<KeyPress>", self._check_analyze)
        self._top.bind("<ButtonPress>", self._check_analyze)

        # Tab cycles focus. (why doesn't this work??)
        def cycle(e, textwidget=self._textwidget):
            textwidget.tk_focusNext().focus()

        self._textwidget.bind("<Tab>", cycle)

        prod_tuples = [(p.lhs(), [p.rhs()]) for p in self._cfg.productions()]
        for i in range(len(prod_tuples) - 1, 0, -1):
            if prod_tuples[i][0] == prod_tuples[i - 1][0]:
                if () in prod_tuples[i][1]:
                    continue
                if () in prod_tuples[i - 1][1]:
                    continue
                print(prod_tuples[i - 1][1])
                print(prod_tuples[i][1])
                prod_tuples[i - 1][1].extend(prod_tuples[i][1])
                del prod_tuples[i]

        for lhs, rhss in prod_tuples:
            print(lhs, rhss)
            s = "%s ->" % lhs
            for rhs in rhss:
                for elt in rhs:
                    if isinstance(elt, Nonterminal):
                        s += " %s" % elt
                    else:
                        s += " %r" % elt
                s += " |"
            s = s[:-2] + "\n"
            self._textwidget.insert("end", s)

        self._analyze()