Esempio n. 1
0
    def _waitbox(self, method):
        """
        Creates a waitbox while the app is running.
        This prevents the app from hanging.
        """
        # Basic tasks to set up the waitbox Toplevel widget.
        top = Toplevel(self.parent)
        top.title("Please wait...")
        top.resizable(0, 0)
        fr = Frame(top)
        fr.pack()

        # pack the Label with the correct working mode.
        ttk.Label(
            fr,
            text=messages.waitbox_msg.format(method=method),
        ).pack(anchor='center')

        if self.parent.iconname() is not None:
            top.iconbitmap(self.parent.iconname())

        # User cannot destroy windows manually while program is running
        top.protocol('WM_DELETE_WINDOW', lambda: None)
        self.parent.protocol('WM_DELETE_WINDOW', lambda: None)
        top.transient(self.parent)
        top.focus_set()
        top.grab_set()
        return top
Esempio n. 2
0
    def messageWindow(self, title, prompt, opts=None, height=8, width=52):
        win = Toplevel(self)
        win.title(title)
        win.geometry("+%d+%d" % (self.text.winfo_rootx() + 50, self.text.winfo_rooty() + 50))
        f = Frame(win)
        # pack the button first so that it doesn't disappear with resizing
        b = Button(win, text=_('OK'), width=10, command=win.destroy, default='active', pady=2)
        b.pack(side='bottom', fill=tkinter.NONE, expand=0, pady=0)
        win.bind('<Return>', (lambda e, b=b: b.invoke()))
        win.bind('<Escape>', (lambda e, b=b: b.invoke()))
        tkfixedfont = tkFont.nametofont("TkFixedFont")
        if 'fontsize_fixed' in self.loop.options and self.loop.options['fontsize_fixed']:
            tkfixedfont.configure(size=self.loop.options['fontsize_fixed'])

        t = ReadOnlyText(
            f, wrap="word", padx=2, pady=2, bd=2, relief="sunken",
            font=tkfixedfont,
            height=height,
            width=width,
            takefocus=False)
        t.insert("0.0", prompt)
        t.pack(side='left', fill=tkinter.BOTH, expand=1, padx=0, pady=0)
        if height > 1:
            ysb = ttk.Scrollbar(f, orient='vertical', command=t.yview)
            ysb.pack(side='right', fill=tkinter.Y, expand=0, padx=0, pady=0)
            t.configure(state="disabled", yscroll=ysb.set)
            t.configure(yscroll=ysb.set)
        f.pack(padx=2, pady=2, fill=tkinter.BOTH, expand=1)

        win.focus_set()
        win.grab_set()
        win.transient(self)
        win.wait_window(win)
class ModalWindow():
    def __init__(self, tab):
        self.toplevel = Toplevel(tab.tk)
        self.toplevel.transient(tab.tk)
        self.toplevel.withdraw()
        self.toplevel.grab_release()
        self.toplevel.protocol('WM_DELETE_WINDOW', self.hide)

    def show(self):
        self.centering()
        self.toplevel.deiconify()
        self.toplevel.tkraise()
        self.toplevel.grab_set()
        self.toplevel.focus_set()

    def hide(self):
        self.toplevel.grab_release()
        self.toplevel.withdraw()

    def centering(self):
        sw = self.toplevel.winfo_screenwidth()
        rw = self.toplevel.winfo_reqwidth()
        x = (sw - rw) // 2
        sw = self.toplevel.winfo_screenheight()
        rw = self.toplevel.winfo_reqheight()
        y = (sw - rw) // 2
        self.toplevel.wm_geometry('+%i+%i' % (x, y))
Esempio n. 4
0
    def show(self):
        """ Prints the logs for the day
        """
        x = self.master.winfo_x()
        y = self.master.winfo_y()
        w = self.master.winfo_width()
        h = self.master.winfo_height()

        root_h = self.master.winfo_height()
        frame_h = self.frame.winfo_height()

        toplevel = Toplevel()
        toplevel.title("Viewer")
        toplevel.configure(width=w, bg=self.bg)
        toplevel.resizable(width=False, height=False)

        base = self.settings.getLocation()
        filename = strftime("%Y-%d-%m") + ".txt"
        filepath = path.join(base, filename)

        # WIP ---
        if path.isfile(filepath):
            text = ""
            with open(filepath, 'r') as fp:
                for line in fp:
                    text += line
            print(text)
        else:
            toplevel.geometry("%dx%d%+d%+d" %
                              (w, h, x, y + root_h + frame_h + 2))
            Label(toplevel,
                  text="File does not exist.",
                  bg=self.bg,
                  fg=self.fg).grid()
            toplevel.focus_set()
Esempio n. 5
0
def ask_scatter_properties():
    win = Toplevel()
    win.title("Scatter Properties")

    widgets_desc = [common_prop_panel, scatter_prop_panel]
    widgets = hywidgets_to_tk(win, widgets_desc)

    color, marker, alpha = handle_common_properties(widgets)
    marker.set("o")

    widgets["ok_btn"]["command"] = win.quit

    win.protocol("WM_DELETE_WINDOW", win.quit)
    win.focus_set()
    win.grab_set()
    win.mainloop()
    win.destroy()

    marker = marker.get()

    return {
        "color": color[0],
        "marker": marker if marker else None,
        "alpha": alpha.get()
    }
Esempio n. 6
0
def _object_browser(parent):  # htest #
    import sys
    from tkinter import Toplevel
    top = Toplevel(parent)
    top.title("Test debug object browser")
    width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
    top.geometry("+%d+%d"%(x + 100, y + 175))
    top.configure(bd=0, bg="yellow")
    top.focus_set()
    sc = ScrolledCanvas(top, 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.update()
Esempio n. 7
0
def popup_settings() -> None:
    """Открывает окно 'Настройки'."""
    popup = Toplevel()
    log_var = BooleanVar()
    launchicon = PhotoImage(file = 'data/imgs/20ok.png')
    center_x_pos = int(popup.winfo_screenwidth() / 2) - POPUP_WIDTH
    center_y_pos = int(popup.winfo_screenheight() / 2) - POPUP_HEIGHT

    popup.geometry(f'{POPUP_WIDTH}x{POPUP_HEIGHT}+'
                   f'{center_x_pos}+{center_y_pos}')
    popup.title(_('Settings'))
    popup.resizable(False, False)
    frame_settings = LabelFrame(popup, text = _('Settings'))
    frame_settings.grid(sticky = 'NWSE', column = 0, row = 0,
                        ipadx = 5, padx = 5, pady = 5)

    lang_label = Label(frame_settings, text = _('Localisation'))
    lang_label.grid(column = 0, row = 0, ipadx = 5)

    logs_label = Label(frame_settings, text = _('Logging'))
    logs_label.grid(column = 0, row = 1, ipadx = 5)

    lang_vars = Combobox(frame_settings, state = 'readonly',
                         values = check_langs(), width = 4)
    lang_vars.current(current_lang())
    lang_vars.grid(column = 1, row = 0)
    log_settings = Checkbutton(frame_settings,
                               variable = log_var, onvalue = True,
                               offvalue = False)

    log_settings.grid(column = 1, row = 1)

    if getconfig()['settings']['logging'] == 'True':
        log_var.set(True)
    elif getconfig()['settings']['logging'] == 'False':
        log_var.set(False)

    apply_button = Button(popup, text = _('Apply'), width = 20,
                          compound = 'left', image = launchicon,
                          command = lambda: apply(
                                                  lang_vars.get(),
                                                  popup, log_var.get()
                                                  )
                          )
    apply_button.grid(column = 0, row = 1)

    popup.grab_set()
    popup.focus_set()
    popup.wait_window()
Esempio n. 8
0
        def askgridprop():
            win = Toplevel()
            color = ['#000000', '#000000']

            propvars = [StringVar() for i in range(4)]
            guidata = (
                {
                    'linestyle': ('Major Line Style', propvars[0], None),
                    'linewidth': ('Major Line Width', propvars[1], check_nonnegative_float)
                },
                {
                    'linestyle': ('Minor Line Style', propvars[2], None),
                    'linewidth': ('Minor Line Width', propvars[3], check_nonnegative_float)
                }
            )

            for d in guidata:
                for key in d:
                    pitem = LabeledEntry(win)
                    pitem.pack()
                    pitem.label_text = d[key][0]
                    pitem.entry['textvariable'] = d[key][1]
                    if d[key][2]:
                        pitem.checker_function = d[key][2]

            def setmajorcolor():
                c = askcolor()
                color[0] = c[1]

            def setminorcolor():
                c = askcolor()
                color[1] = c[1]
                
            Button(win, text='Major Line Color', command=setmajorcolor).pack()
            Button(win, text='Minor Line Color', command=setminorcolor).pack()

            win.protocol('WM_DELETE_WINDOW', win.quit)
            win.focus_set()
            win.grab_set()
            win.mainloop()
            win.destroy()
            
            c_major = StringVar(); c_major.set(color[0])
            c_minor = StringVar(); c_minor.set(color[1])
            guidata[0]['color'] = ('Major Line Color', c_major, None)
            guidata[1]['color'] = ('Minor Line Color', c_minor, None)
            return guidata
Esempio n. 9
0
def ask_dvplane(window_node):
    win = Toplevel()
    win.title("Select a window")

    root_node = window_node.root_node

    widgets_desc = [to_dvplane_frm]
    widgets = hywidgets_to_tk(win, widgets_desc)

    sel_exist = False

    winid_var = StringVar()

    def on_exist_dvplane():
        nonlocal sel_exist
        sel_exist = True
        win.quit()

    widgets["ok_btn"]["command"] = on_exist_dvplane

    def on_new_dvplane():
        nonlocal sel_exist
        sel_exist = False
        win.quit()

    widgets["new_btn"]["command"] = on_new_dvplane

    dvplanes = [wid \
        for wid, window in root_node.gui.windows.items() \
            if isinstance(window, PlaneWindow)]
    id_cmb = widgets["id_cmb"]
    id_cmb["textvariable"] = winid_var
    id_cmb["value"] = dvplanes
    if dvplanes:
        id_cmb.current(0)
    else:
        widgets["ok_btn"]["state"] = "disabled"

    win.protocol("WM_DELETE_WINDOW", win.quit)
    win.focus_set()
    win.grab_set()
    win.mainloop()
    win.destroy()

    return sel_exist, winid_var.get()
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()
Esempio n. 11
0
def _dyn_option_menu(parent):  # htest #
    from tkinter import Toplevel # + StringVar, Button

    top = Toplevel(parent)
    top.title("Tets dynamic option menu")
    x, y = map(int, parent.geometry().split('+')[1:])
    top.geometry("200x100+%d+%d" % (x + 250, y + 175))
    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()
Esempio n. 12
0
def ask_drawmode():
    win = Toplevel()
    win.title("Draw mode")
    Label(win, text="Select draw mode:").pack()
    drawmode = StringVar()
    drawmode.set("plot")
    modes = ["plot", "stem", "simple scatter", "scatter"]
    for mode in modes:
        Radiobutton(win, text=mode, value=mode,
                    variable=drawmode).pack(anchor="nw")
    Button(win, text="OK", command=win.quit).pack()

    win.protocol("WM_DELETE_WINDOW", win.quit)
    win.focus_set()
    win.grab_set()
    win.mainloop()
    win.destroy()
    return drawmode.get()
Esempio n. 13
0
def ask_class_name():
    win = Toplevel()
    
    module_name  = StringVar()
    class_name   = StringVar()
    
    module_item  = LabeledEntry(win)
    module_item.label_text    = 'Module Name'
    module_item.pack()
    module_item.entry_variable     = module_name
    
    class_item   = LabeledEntry(win)
    class_item.label_text     = 'Class Name'
    class_item.pack()
    class_item.entry_variable      = class_name
    
    Button(win, text='OK', command=win.quit).pack()

    win.protocol('WM_DELETE_WINDOW', win.quit)
    win.focus_set()
    win.grab_set()
    win.mainloop()
    win.destroy()
    return module_name.get(), class_name.get()
Esempio n. 14
0
 def askSpan(orient='v'):
     win = Toplevel()
     pxmin = LabeledEntry(win)
     pxmin.pack()
     pxmin.label_text = 'xmin' if orient=='v' else 'ymin'
     pxmax = LabeledEntry(win)
     pxmax.pack()
     pxmax.label_text = 'xmax' if orient=='v' else 'ymax'
     def formatter(val):
         val = float(val)
         val /= 100.
         return '{0:0.2f}'.format(val)
     alphaScale = LabeledScale(win, from_=0, to=100, name='alpha', formatter=formatter)
     alphaScale.set(50.0)
     alphaScale.pack()
     win.protocol('WM_DELETE_WINDOW', win.quit)
     win.focus_set()
     win.grab_set()
     win.mainloop()
     xmin    = pxmin.entry.get()
     xmax    = pxmax.entry.get()
     alpha   = alphaScale.get() / 100.
     win.destroy()
     return map(float, (xmin, xmax, alpha))