Exemplo n.º 1
0
def error_popup(text):
  win = Toplevel()
  Button(win, text='OK', command=win.destroy).pack(side=BOTTOM)
  Label(win, text=text, anchor=W, justify=LEFT).pack(side=LEFT)
# Refuse to let the user do anything until window is dismissed
  win.focus_set()
  win.grab_set()
  win.wait_window()
def error_popup(text):
    win = Toplevel()
    Button(win, text='OK', command=win.destroy).pack(side=BOTTOM)
    Label(win, text=text, anchor=W, justify=LEFT).pack(side=LEFT)
    # Refuse to let the user do anything until window is dismissed
    win.focus_set()
    win.grab_set()
    win.wait_window()
Exemplo n.º 3
0
def test():
    from Tkinter import Toplevel
    import PyShell
    root = Toplevel(PyShell.root)
    root.configure(bd=0, bg="yellow")
    root.focus_set()
    sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
    sc.frame.pack(expand=1, fill="both")
    item = FileTreeItem("C:/windows/desktop")
    node = TreeNode(sc.canvas, None, item)
    node.expand()
Exemplo n.º 4
0
def test():
    from Tkinter import Toplevel
    import PyShell
    root = Toplevel(PyShell.root)
    root.configure(bd=0, bg="yellow")
    root.focus_set()
    sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
    sc.frame.pack(expand=1, fill="both")
    item = FileTreeItem("C:/windows/desktop")
    node = TreeNode(sc.canvas, None, item)
    node.expand()
Exemplo n.º 5
0
def test():
    import sys
    from Tkinter import Toplevel
    import PyShell
    root = Toplevel(PyShell.root)
    root.configure(bd=0, bg="yellow")
    root.focus_set()
    sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
    sc.frame.pack(expand=1, fill="both")
    item = make_objecttreeitem("sys", sys)
    node = TreeNode(sc.canvas, None, item)
    node.expand()
Exemplo n.º 6
0
def test():
    import sys
    from Tkinter import Toplevel
    import PyShell
    root = Toplevel(PyShell.root)
    root.configure(bd=0, bg="yellow")
    root.focus_set()
    sc = ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
    sc.frame.pack(expand=1, fill="both")
    item = make_objecttreeitem("sys", sys)
    node = TreeNode(sc.canvas, None, item)
    node.expand()
Exemplo n.º 7
0
def _dyn_option_menu(parent):  # htest #
    from Tkinter import Toplevel

    top = Toplevel()
    top.title("Tets dynamic option menu")
    top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200,
                  parent.winfo_rooty() + 150))
    top.focus_set()

    var = StringVar(top)
    var.set("Old option set") #Set the default value
    dyn = DynOptionMenu(top,var, "old1","old2","old3","old4")
    dyn.pack()

    def update():
        dyn.SetMenu(["new1","new2","new3","new4"], value="new option set")
    button = Button(top, text="Change option set", command=update)
    button.pack()
Exemplo n.º 8
0
    def help_about(self):

        """Shows an 'about' modal dialog.

        Callback method called by tk.

        """

        about_win = Toplevel(self.root)

        # Set up dialog

        lbl = Label(about_win, text="Video Poker")
        lbl.grid(row=0, column=0, padx=10, pady=(10, 0), sticky=W + N)
        lbl = Label(about_win, text="by Paul Griffiths")
        lbl.grid(row=1, column=0, padx=10, pady=(0, 7), sticky=W + N)
        lbl = Label(about_win, text="Written in Python, with tkinter.")
        lbl.grid(row=2, column=0, padx=10, pady=7, sticky=W + N)
        lbl = Label(about_win, text="Copyright 2013 Paul Griffiths")
        lbl.grid(row=4, column=0, padx=10, pady=(7, 0), sticky=W + N)
        lbl = Label(about_win, text="Email: [email protected]")
        lbl.grid(row=5, column=0, padx=10, pady=(0, 21), sticky=W + N)
        lbl = Label(about_win, text="This program is free software: you can " +
            "redistribute it and/or modify it under the terms")
        lbl.grid(row=6, column=0, columnspan=2,
                 padx=10, pady=0, sticky=W + N)
        lbl = Label(about_win, text="of the GNU General Public License as " +
            "published by the Free Software Foundation, either")
        lbl.grid(row=7, column=0, columnspan=2,
                 padx=10, pady=(0, 0), sticky=W + N)
        lbl = Label(about_win, text="version 3 of the License, or " +
            "(at your option) any later version.")
        lbl.grid(row=8, column=0, columnspan=2,
                 padx=10, pady=(0, 21), sticky=W + N)
        lbl = Label(about_win, text="This program is distributed in " +
            "the hope that it will be useful, but WITHOUT ANY WARRANTY;")
        lbl.grid(row=9, column=0, columnspan=2,
                 padx=10, pady=0, sticky=W + N)
        lbl = Label(about_win, text="without even the implied " +
            "warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR")
        lbl.grid(row=10, column=0, columnspan=2,
                 padx=10, pady=(0, 0), sticky=W + N)
        lbl = Label(about_win, text="PURPOSE. See the " +
            "GNU General Public License for more details.")
        lbl.grid(row=11, column=0, columnspan=2,
                 padx=10, pady=(0, 21), sticky=W + N)
        lbl = Label(about_win, text="You should have received a " +
            "copy of the GNU General Public License along with this")
        lbl.grid(row=12, column=0, columnspan=2,
                 padx=10, pady=(0, 0), sticky=W + N)
        lbl = Label(about_win, text="program. If not, see " +
            "<http://www.gnu.org/licenses/>.")
        lbl.grid(row=13, column=0, columnspan=2,
                 padx=10, pady=(0, 21), sticky=W + N)
        img = PhotoImage(file="{0}27.gif".format(self.gifdir))
        lbl = Label(about_win, image=img)
        lbl.grid(row=0, column=1, rowspan=5, padx=10, pady=10, sticky=N + E)

        btn = Button(about_win, text="OK", command=about_win.quit)
        btn.grid(row=14, column=0, columnspan=2,
                 padx=0, pady=(0, 10), ipadx=30, ipady=3)

        # Show dialog

        about_win.transient(self.root)
        about_win.parent = self.root
        about_win.protocol("WM_DELETE_WINDOW", about_win.destroy)
        about_win.geometry("+{0}+{1}".format(self.root.winfo_rootx() + 50,
                                           self.root.winfo_rooty() + 50))
        about_win.title("About Video Poker")
        about_win.focus_set()
        about_win.grab_set()
        about_win.mainloop()
        about_win.destroy()
Exemplo n.º 9
0
    def help_about(self):

        """Shows an 'about' modal dialog.

        Callback method called by tk.

        """

        about_win = Toplevel(self.root)

        # Set up dialog

        lbl = Label(about_win, text="Video Poker")
        lbl.grid(row=0, column=0, padx=10, pady=(10, 0), sticky=W + N)
        lbl = Label(about_win, text="by Charles Raymond Smith")
        lbl.grid(row=1, column=0, padx=10, pady=(0, 7), sticky=W + N)
        lbl = Label(about_win, text="Adapted from video poker by Paul Griffiths")
        lbl.grid(row=2, column=0, padx=10, pady=(0, 7), sticky=W + N)
        lbl = Label(about_win, text="Written in Python, with tkinter.")
        lbl.grid(row=3, column=0, padx=10, pady=7, sticky=W + N)
        lbl = Label(about_win, text="Copyright 2017 Charles Raymond Smith")
        lbl.grid(row=4, column=0, padx=10, pady=(7, 0), sticky=W + N)
        lbl = Label(about_win, text="Email: [email protected]")
        lbl.grid(row=5, column=0, padx=10, pady=(0, 21), sticky=W + N)
        lbl = Label(about_win, text="This program is free software: you can " +
            "redistribute it and/or modify it under the terms")
        lbl.grid(row=6, column=0, columnspan=2,
                 padx=10, pady=0, sticky=W + N)
        lbl = Label(about_win, text="of the GNU General Public License as " +
            "published by the Free Software Foundation, either")
        lbl.grid(row=7, column=0, columnspan=2,
                 padx=10, pady=(0, 0), sticky=W + N)
        lbl = Label(about_win, text="version 3 of the License, or " +
            "(at your option) any later version.")
        lbl.grid(row=8, column=0, columnspan=2,
                 padx=10, pady=(0, 21), sticky=W + N)
        lbl = Label(about_win, text="This program is distributed in " +
            "the hope that it will be useful, but WITHOUT ANY WARRANTY;")
        lbl.grid(row=9, column=0, columnspan=2,
                 padx=10, pady=0, sticky=W + N)
        lbl = Label(about_win, text="without even the implied " +
            "warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR")
        lbl.grid(row=10, column=0, columnspan=2,
                 padx=10, pady=(0, 0), sticky=W + N)
        lbl = Label(about_win, text="PURPOSE. See the " +
            "GNU General Public License for more details.")
        lbl.grid(row=11, column=0, columnspan=2,
                 padx=10, pady=(0, 21), sticky=W + N)
        lbl = Label(about_win, text="You should have received a " +
            "copy of the GNU General Public License along with this")
        lbl.grid(row=12, column=0, columnspan=2,
                 padx=10, pady=(0, 0), sticky=W + N)
        lbl = Label(about_win, text="program. If not, see " +
            "<http://www.gnu.org/licenses/>.")
        lbl.grid(row=13, column=0, columnspan=2,
                 padx=10, pady=(0, 21), sticky=W + N)
        img = PhotoImage(file="{0}27.gif".format(self.gifdir))
        lbl = Label(about_win, image=img)
        lbl.grid(row=0, column=1, rowspan=5, padx=10, pady=10, sticky=N + E)

        btn = Button(about_win, text="OK", command=about_win.quit)
        btn.grid(row=14, column=0, columnspan=2,
                 padx=0, pady=(0, 10), ipadx=30, ipady=3)

        # Show dialog

        about_win.transient(self.root)
        about_win.parent = self.root
        about_win.protocol("WM_DELETE_WINDOW", about_win.destroy)
        about_win.geometry("+{0}+{1}".format(self.root.winfo_rootx() + 50,
                                           self.root.winfo_rooty() + 50))
        about_win.title("About Video Poker")
        about_win.focus_set()
        about_win.grab_set()
        about_win.mainloop()
        about_win.destroy()
Exemplo n.º 10
0
class Docview:
    def __init__(self, master, fn, **kwargs):

        self.file = fn
        self.widget = None
        self.text = Text()
        self.frame = master
        self.location = kwargs.get('location', None)
        self.wait = kwargs.get('wait', None)
        self.find = kwargs.get('find', None)
        self.delete_img = PhotoImage(file='delete.pbm')
        self.up_img = PhotoImage(file='1uparrow.pbm')
        self.down_img = PhotoImage(file='1downarrow.pbm')
        self.upbutn = Button()
        self.dnbutn = Button()
        self.deletebutn = Button()
        self.entry = None
        self.doc = ''

    def Search(self, pattern):
        '''
        normal top-down search
        :param pattern:
        :return:
        '''
        try:
            self.text.tag_remove('hilight', '1.0', 'end')
            ind = self.text.search(pattern,
                                   '1.0',
                                   stopindex="end",
                                   nocase=True)
            self.text.mark_set("insert", ind)
            self.text.see("insert")
            nchar = len(pattern)
            self.text.tag_add('hilight', ind, ind + "+{}c".format(nchar))

        except:
            pass

    def RecursiveSearch(self, pattern, upward=False):
        '''
        Search forward from current position.  Search backward if upward is True.
        :param pattern: search pattern
        :param upward: reverse search if true
        :return: Null
        '''
        if len(pattern) == 0:
            ind = '1.0' if upward else 'end'
            self.text.mark_set("insert", ind)
            self.text.see("insert")
            return
        try:

            insert = self.text.index("insert")
            if upward:
                point = insert + "-1c"
                ind = self.text.search(pattern,
                                       point,
                                       stopindex="1.0",
                                       backwards=True,
                                       nocase=True)
            else:
                point = insert + "+1c"
                ind = self.text.search(pattern,
                                       point,
                                       stopindex="end",
                                       nocase=True)

            self.text.mark_set("insert", ind)
            self.text.see("insert")
            self.text.tag_remove('hilight', '1.0', 'end')
            nchar = len(pattern)
            self.text.tag_add('hilight', ind, ind + "+{}c".format(nchar))
            self.text.update()
        except:
            pass

    def SearchUp(self):
        pattern = str(self.entry.get())
        self.RecursiveSearch(pattern, True)

    def SearchDn(self):
        pattern = str(self.entry.get())
        self.RecursiveSearch(pattern, False)

    def FindEntry(self, event):
        '''triggered by keyrelease event in find entry box'''
        pattern = str(self.entry.get())
        nchar = len(pattern)
        self.text.tag_remove('hilight', '1.0', 'end')
        if nchar == 0:
            return
        try:
            ind = self.text.search(pattern,
                                   "1.0",
                                   stopindex="end",
                                   nocase=True)
            self.text.mark_set("insert", ind)
            self.text.see("insert")
            self.text.tag_add('hilight', ind, ind + "+{}c".format(nchar))
            self.text.update()
        except:
            pass

    def DeleteSearch(self):
        self.entry.delete(0, 'end')
        self.text.tag_remove('hilight', '1.0', 'end')

    def Popup(self):

        if not self.doc:
            with open(self.file, 'r') as fh:
                self.doc = fh.read()

        if self.widget:  # widget already open
            if self.frame:
                self.widget.lift(aboveThis=self.frame)
            return

        #print 'length of doc ', len(self.doc)

        self.widget = Toplevel()
        if self.find:
            self.sframe = Frame(self.widget)
            self.sframe.pack()
            self.upbutn = Button(self.sframe,
                                 width=17,
                                 command=self.SearchUp,
                                 image=self.up_img)
            self.upbutn.pack(side='left')
            self.dnbutn = Button(self.sframe,
                                 width=17,
                                 command=self.SearchDn,
                                 image=self.down_img)
            self.dnbutn.pack(side='left')
            self.entry = Entry(self.sframe, width=50)
            self.entry.bind('<KeyRelease>', self.FindEntry)
            self.entry.pack(side='left')
            self.deletebutn = Button(self.sframe,
                                     width=17,
                                     command=self.DeleteSearch)
            self.deletebutn.config(image=self.delete_img)
            self.deletebutn.pack(side='left')

        width = max([len(line) for line in self.doc.split('\n')])
        height = min([self.doc.count('\n') + 1, 40])
        self.text = Text(self.widget, width=width, height=height)
        self.text.tag = self.text.tag_configure('hilight',
                                                background='#ffff00')
        self.text.insert("1.0", self.doc)
        self.text.pack()

        if self.location and self.frame:
            dx, dy = self.location
            w = self.text.winfo_width()
            h = self.text.winfo_height()
            x = self.frame.winfo_x()
            y = self.frame.winfo_y()
            loc = "%dx%d+%d+%d" % (600, 400, x + dx, y + dy)
            self.widget.geometry(loc)

        if self.wait:
            self.widget.focus_set()
            self.widget.grab_set()
            if self.frame:
                self.widget.transient(master=self.frame)
            self.widget.wait_window(self.widget)

        if self.frame:
            self.widget.lift(aboveThis=self.frame)

        self.widget.protocol("WM_DELETE_WINDOW", self.Kill)

    def Kill(self):
        self.widget.destroy()
        self.widget = None