Exemplo n.º 1
0
def update_qrcode(*args):
    global app
    global qrcode_label
    global parsed_data

    #qrcode = pyqrcode.create('http://google.com/maps/place/' + parsed_data[3][1].get() + "," + parsed_data[4][1].get())
    qrcode = pyqrcode.create('geo:' + parsed_data[3][1].get() + "," +
                             parsed_data[4][1].get())

    # Create XBM image
    qr_xbm = qrcode.xbm(scale=2)

    # Create Tkinter Bitmap
    qr_bmp = tk.BitmapImage(data=qr_xbm)

    # Update image
    qrcode_label.image = qr_bmp
    qrcode_label.config(image=qr_bmp)
Exemplo n.º 2
0
def initialise():
    global _initialised, font, flagup, earthris, emptyimage, \
            stringvar, floatvar, root, reliefs
    if not _initialised:
        root = Tkinter.Tk(className='PmwTest')
        root.withdraw()
        if os.name == 'nt':
            size = 16
        else:
            size = 12
        Pmw.initialise(root, size=size, fontScheme='pmw2')
        font = {}
        font['small'] = '6x13'
        font['large'] = '10x20'
        font['variable'] = '-Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*'
        flagup = Tkinter.BitmapImage(file='flagup.bmp')
        earthris = Tkinter.PhotoImage(file='earthris.gif')
        emptyimage = Tkinter.PhotoImage()
        stringvar = Tkinter.StringVar()
        stringvar.set('this is some text')
        floatvar = Tkinter.DoubleVar()
        floatvar.set(50.0)
        if haveBlt():
            global vectorSize, vector_x, vector_y
            vector_x = Pmw.Blt.Vector()
            vector_y = []
            for y in range(3):
                vector_y.append(Pmw.Blt.Vector())
            vectorSize = 50
            for index in range(vectorSize):
                vector_x.append(index)
                vector_y[0].append(random() % 100)
                vector_y[1].append(random() % 200)
                vector_y[2].append(random() % 100 + 300)

        # "solid" relief type was added to 8.0
        if Tkinter.TkVersion >= 8.0:
            reliefs = 'flat, groove, raised, ridge, solid, or sunken'
        else:
            reliefs = 'flat, groove, raised, ridge, or sunken'

        _initialised = 1
Exemplo n.º 3
0
def test_xbm_with_tkinter():
    """Test XBM renderer is compatible with Tkinter
    """
    #Under TOX tkinter testing does not work, skip if tox environemnt
    if not os.getenv('DISPLAY'):
        raise nose.SkipTest()

    #Python 2 vs 3
    try:
        import Tkinter as tkinter
    except:
        import tkinter

    code = pyqrcode.create('Test')
    code_size = code.get_png_size(scale=1)
    code_xbm = code.xbm(scale=1)

    top = tkinter.Tk()
    bitmap = tkinter.BitmapImage(data=code_xbm)

    eq_(bitmap.width(), code_size)
    eq_(bitmap.height(), code_size)
Exemplo n.º 4
0
    def __init__(self, image=None, **kw):

        # Tk compatibility: file or data
        if image is None:
            if "file" in kw:
                image = Image.open(kw["file"])
                del kw["file"]
            elif "data" in kw:
                from StringIO import StringIO
                image = Image.open(StringIO(kw["data"]))
                del kw["data"]

        self.__mode = image.mode
        self.__size = image.size

        if _pilbitmap_check():
            # fast way (requires the pilbitmap booster patch)
            image.load()
            kw["data"] = "PIL:%d" % image.im.id
            self.__im = image # must keep a reference
        else:
            # slow but safe way
            kw["data"] = image.tobitmap()
        self.__photo = Tkinter.BitmapImage(**kw)
Exemplo n.º 5
0
    def __init__(self, balloonmaster=None, master=None, name=None, icon1=None,
                 icon2=None, command=None, balloonhelp='',
                 statushelp='', height=20, width=21,
                 bd=1, activebackground='lightgrey', padx=0, pady=0,
                 state='normal', bg=None, iconpath=None):

        assert master is not None

        # this list stores the buttons
        if not hasattr(master, 'toolbarButtonDict'):
            master.toolbarButtonDict = {}
        # assert the button name doesn't exist already
        assert not master.toolbarButtonDict.has_key(name), name

        self.activebackground = activebackground
        self.name = name
        self.icommand = command
        self.command  = self.activate
        self.buttonPressed = 0  # 0 if button not pressed, 1 if pressed
        self.buttonFocus = 0    # 0 if cursor not over button, 1 if over button
        
        Tkinter.Label.__init__(self, master, height=height, width=width,
                       relief='flat', bd=bd, bg=bg)

        if iconpath is None:
            from mglutil.util.packageFilePath import findFilePath
            iconpath = findFilePath('Tk','mglutil.gui.BasicWidgets')
            iconpath = os.path.join(iconpath,'icons' )
            #iconpath = 'mglutil.gui.BasicWidgets.Tk.icons'
        if icon1 is not None:
            ICONPATH1 = os.path.join(iconpath, icon1)
            if string.splitfields(icon1, '.')[1] == 'bmp':
                self.icon1 = Tkinter.BitmapImage(file=ICONPATH1, master=master)
            else:
                self.icon1 = Tkinter.PhotoImage(file=ICONPATH1, master=master)
        else:
            self.icon1 = None

        if icon2 is not None:
            ICONPATH2 = os.path.join(iconpath, icon2)
            if string.splitfields(icon2, '.')[1] == 'bmp':
                self.icon2 = Tkinter.BitmapImage(file=ICONPATH2, master=master)
            else:
                self.icon2 = Tkinter.PhotoImage(file=ICONPATH2, master=master)
        else:
            self.icon2 = self.icon1

        self.config(image=self.icon1)

        # to prevent binding of the balloon overriding the binding of
        # Leave and Enter events, first the balloon is bound

        if balloonmaster is None:
            master.balloons = Pmw.Balloon(master, yoffset=0)
            balloonmaster = master

        if balloonhelp or statushelp:
            if hasattr(balloonmaster, 'balloons'):
                balloonmaster.balloons.bind(self, balloonhelp, statushelp)

        # a little trick: the '+' adds this binding, otherwise it might
        # be overwritten
        self.bind("<Enter>",           self.buttonEnter, '+')
        self.bind("<Leave>",           self.buttonLeave, '+')
        self.bind("<ButtonPress-1>",   self.buttonDown)
        self.bind("<ButtonRelease-1>", self.buttonUp)
        self.pack(side='left', anchor=Tkinter.NW, padx=padx, pady=pady)
        self.state = state    

        # add the button to the list stored in the master
        master.toolbarButtonDict[name] = self

        if bg is None:
            self.bg = self.configure()['background'][-1]
        else:
            self.bg = bg
Exemplo n.º 6
0
    def __init__(self, master):

        self.ser = serial.Serial('/dev/cu.wchusbserial1490')
        sleep(3)

        self.holdofftime = config.getint('querytime') + companion.holdoff
        self.session = companion.Session()
        self.edsm = edsm.EDSM()

        self.w = master
        self.w.title(applongname)
        self.w.rowconfigure(0, weight=1)
        self.w.columnconfigure(0, weight=1)

        plug.load_plugins()

        if platform != 'darwin':
            if platform == 'win32':
                self.w.wm_iconbitmap(default='EDMarketConnector.ico')
            else:
                from PIL import Image, ImageTk
                self.w.tk.call(
                    'wm', 'iconphoto', self.w, '-default',
                    ImageTk.PhotoImage(Image.open("EDMarketConnector.png")))
            self.theme_icon = tk.PhotoImage(
                data=
                'R0lGODlhFAAQAMZVAAAAAAEAAAIBAAMBAAQCAAYDAAcDAAkEAAoEAAwGAQ8IARAIAREJARYKABkLARsMASMQASgSAiUUAy0UAjAVAioXBDIWAy4YBC4ZBS8ZBTkZA0EdBDsgBkUfA0MkB00iA1AjA1IlBFQmBE4qCFgoBVkoBFArCF0qBVQtCGUrBGMtBWYtBWA0Cm8xBW8xBm8yBXMzBXU1Bms5C3s1BXs2BXw2BX02BXw4B4A5B3Q/DIJGDYNGDYJHDoNHDYdJDppGCItLD4xLDo5MDo5MD5hSD59VEKdaEbJgErtlE7tlFLxlE8BpFMJpFMNpFMZrFdFxFtl1F995GOB6GOF6GP+LG////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEKAH8ALAAAAAAUABAAAAejgACCgiODhoeGBABPPgACj48DA4gAk00cSRUYGZycEogBAE4LCUM8Oj2pOzlQBAKHSBeKlABKBq+DHkS0g0wJiCZFvABHJBuHBSxADFRTUs/PUUsiKhaIKEZBKTM13TU0Nj8IIRqThjJCK8MnFIgKMMMAJRGGAQUvvAIPLocBAjgdPggcKMLAgRi0GjxYyNBBCwjwQoEKQLEiABA3HMU7NOFQIAA7'
            )
            self.theme_minimize = tk.BitmapImage(
                data=
                '#define im_width 16\n#define im_height 16\nstatic unsigned char im_bits[] = {\n   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f,\n   0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\n'
            )
            self.theme_close = tk.BitmapImage(
                data=
                '#define im_width 16\n#define im_height 16\nstatic unsigned char im_bits[] = {\n   0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x1c, 0x38, 0x38, 0x1c, 0x70, 0x0e,\n   0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0x70, 0x0e, 0x38, 0x1c,\n   0x1c, 0x38, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x00 };\n'
            )

        frame = tk.Frame(self.w, name=appname.lower())
        frame.grid(sticky=tk.NSEW)
        frame.columnconfigure(1, weight=1)

        self.cmdr_label = tk.Label(frame)
        self.ship_label = tk.Label(frame)
        self.system_label = tk.Label(frame)
        self.station_label = tk.Label(frame)

        self.cmdr_label.grid(row=1, column=0, sticky=tk.W)
        self.ship_label.grid(row=2, column=0, sticky=tk.W)
        self.system_label.grid(row=3, column=0, sticky=tk.W)
        self.station_label.grid(row=4, column=0, sticky=tk.W)

        self.cmdr = tk.Label(frame, anchor=tk.W)
        self.ship = HyperlinkLabel(frame, url=self.shipyard_url)
        self.system = HyperlinkLabel(frame,
                                     compound=tk.RIGHT,
                                     url=self.system_url,
                                     popup_copy=True)
        self.station = HyperlinkLabel(
            frame,
            url=self.station_url,
            popup_copy=lambda x: x != self.STATION_UNDOCKED)

        self.cmdr.grid(row=1, column=1, sticky=tk.EW)
        self.ship.grid(row=2, column=1, sticky=tk.EW)
        self.system.grid(row=3, column=1, sticky=tk.EW)
        self.station.grid(row=4, column=1, sticky=tk.EW)

        for plugname in plug.PLUGINS:
            appitem = plug.get_plugin_app(plugname, frame)
            if appitem:
                if isinstance(appitem, tuple) and len(appitem) == 2:
                    row = frame.grid_size()[1]
                    appitem[0].grid(row=row, column=0, sticky=tk.W)
                    appitem[1].grid(row=row, column=1, sticky=tk.EW)
                else:
                    appitem.grid(columnspan=2, sticky=tk.W)

        self.button = ttk.Button(
            frame,
            text=_('Update'),
            width=28,
            default=tk.ACTIVE,
            state=tk.DISABLED)  # Update button in main window
        self.theme_button = tk.Label(frame,
                                     width=platform == 'darwin' and 32 or 28,
                                     state=tk.DISABLED)
        self.status = tk.Label(frame, name='status', anchor=tk.W)

        row = frame.grid_size()[1]
        self.button.grid(row=row, columnspan=2, sticky=tk.NSEW)
        self.theme_button.grid(row=row, columnspan=2, sticky=tk.NSEW)
        theme.register_alternate((self.button, self.theme_button), {
            'row': row,
            'columnspan': 2,
            'sticky': tk.NSEW
        })
        self.status.grid(columnspan=2, sticky=tk.EW)
        self.button.bind('<Button-1>', self.getandsend)
        theme.button_bind(self.theme_button, self.getandsend)

        for child in frame.winfo_children():
            child.grid_configure(padx=5, pady=(platform != 'win32' and 2 or 0))

        self.menubar = tk.Menu()
        if platform == 'darwin':
            # Can't handle (de)iconify if topmost is set, so suppress iconify button
            # http://wiki.tcl.tk/13428 and p15 of https://developer.apple.com/legacy/library/documentation/Carbon/Conceptual/HandlingWindowsControls/windowscontrols.pdf
            root.call('tk::unsupported::MacWindowStyle', 'style', root,
                      'document', 'closeBox horizontalZoom resizable')

            # https://www.tcl.tk/man/tcl/TkCmd/menu.htm
            self.system_menu = tk.Menu(self.menubar, name='apple')
            self.system_menu.add_command(
                command=lambda: self.w.call('tk::mac::standardAboutPanel'))
            self.system_menu.add_command(
                command=lambda: self.updater.checkForUpdates())
            self.menubar.add_cascade(menu=self.system_menu)
            self.file_menu = tk.Menu(self.menubar, name='file')
            self.file_menu.add_command(command=self.save_raw)
            self.menubar.add_cascade(menu=self.file_menu)
            self.edit_menu = tk.Menu(self.menubar, name='edit')
            self.edit_menu.add_command(accelerator='Command-c',
                                       state=tk.DISABLED,
                                       command=self.copy)
            self.menubar.add_cascade(menu=self.edit_menu)
            self.w.bind('<Command-c>', self.copy)
            self.view_menu = tk.Menu(self.menubar, name='view')
            self.view_menu.add_command(command=lambda: stats.StatsDialog(self))
            self.menubar.add_cascade(menu=self.view_menu)
            window_menu = tk.Menu(self.menubar, name='window')
            self.menubar.add_cascade(menu=window_menu)
            self.w['menu'] = self.menubar
            # https://www.tcl.tk/man/tcl/TkCmd/tk_mac.htm
            self.w.call('set', 'tk::mac::useCompatibilityMetrics', '0')
            self.w.createcommand(
                'tkAboutDialog',
                lambda: self.w.call('tk::mac::standardAboutPanel'))
            self.w.createcommand("::tk::mac::Quit", self.onexit)
            self.w.createcommand(
                "::tk::mac::ShowPreferences",
                lambda: prefs.PreferencesDialog(self.w, self.postprefs))
            self.w.createcommand(
                "::tk::mac::ReopenApplication",
                self.w.deiconify)  # click on app in dock = restore
            self.w.protocol("WM_DELETE_WINDOW",
                            self.w.withdraw)  # close button shouldn't quit app
        else:
            self.file_menu = self.view_menu = tk.Menu(self.menubar,
                                                      tearoff=tk.FALSE)
            self.file_menu.add_command(command=lambda: stats.StatsDialog(self))
            self.file_menu.add_command(command=self.save_raw)
            self.file_menu.add_command(
                command=lambda: self.updater.checkForUpdates())
            self.file_menu.add_command(command=lambda: prefs.PreferencesDialog(
                self.w, self.postprefs))
            self.file_menu.add_separator()
            self.file_menu.add_command(command=self.onexit)
            self.menubar.add_cascade(menu=self.file_menu)
            self.edit_menu = tk.Menu(self.menubar, tearoff=tk.FALSE)
            self.edit_menu.add_command(accelerator='Ctrl+C',
                                       state=tk.DISABLED,
                                       command=self.copy)
            self.menubar.add_cascade(menu=self.edit_menu)
            if platform == 'win32':
                # Must be added after at least one "real" menu entry
                self.always_ontop = tk.BooleanVar(
                    value=config.getint('always_ontop'))
                self.system_menu = tk.Menu(self.menubar,
                                           name='system',
                                           tearoff=tk.FALSE)
                self.system_menu.add_separator()
                self.system_menu.add_checkbutton(
                    label=_('Always on top'),
                    variable=self.always_ontop,
                    command=self.ontop_changed)  # Appearance setting
                self.menubar.add_cascade(menu=self.system_menu)
            self.w.bind('<Control-c>', self.copy)
            self.w.protocol("WM_DELETE_WINDOW", self.onexit)
            theme.register(
                self.menubar
            )  # menus and children aren't automatically registered
            theme.register(self.file_menu)
            theme.register(self.edit_menu)

            # Alternate title bar and menu for dark theme
            self.theme_menubar = tk.Frame(frame)
            self.theme_menubar.columnconfigure(2, weight=1)
            theme_titlebar = tk.Label(self.theme_menubar,
                                      text=applongname,
                                      image=self.theme_icon,
                                      anchor=tk.W,
                                      compound=tk.LEFT)
            theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW)
            self.drag_offset = None
            theme_titlebar.bind('<Button-1>', self.drag_start)
            theme_titlebar.bind('<B1-Motion>', self.drag_continue)
            theme_titlebar.bind('<ButtonRelease-1>', self.drag_end)
            if platform == 'win32':  # Can't work out how to deiconify on Linux
                theme_minimize = tk.Label(self.theme_menubar,
                                          image=self.theme_minimize)
                theme_minimize.grid(row=0, column=3, padx=2)
                theme.button_bind(theme_minimize,
                                  self.oniconify,
                                  image=self.theme_minimize)
            theme_close = tk.Label(self.theme_menubar, image=self.theme_close)
            theme_close.grid(row=0, column=4, padx=2)
            theme.button_bind(theme_close, self.onexit, image=self.theme_close)
            self.theme_file_menu = tk.Label(self.theme_menubar, anchor=tk.W)
            self.theme_file_menu.grid(row=1, column=0, padx=5, sticky=tk.W)
            theme.button_bind(
                self.theme_file_menu, lambda e: self.file_menu.tk_popup(
                    e.widget.winfo_rootx(),
                    e.widget.winfo_rooty() + e.widget.winfo_height()))
            self.theme_edit_menu = tk.Label(self.theme_menubar, anchor=tk.W)
            self.theme_edit_menu.grid(row=1, column=1, sticky=tk.W)
            theme.button_bind(
                self.theme_edit_menu, lambda e: self.edit_menu.tk_popup(
                    e.widget.winfo_rootx(),
                    e.widget.winfo_rooty() + e.widget.winfo_height()))
            theme.register_highlight(theme_titlebar)
            theme.register(
                self.theme_minimize)  # images aren't automatically registered
            theme.register(self.theme_close)
            theme.register_alternate((self.menubar, self.theme_menubar), {
                'row': 0,
                'columnspan': 2,
                'sticky': tk.NSEW
            })

        self.set_labels()

        # update geometry
        if config.get('geometry'):
            match = re.match('\+([\-\d]+)\+([\-\d]+)', config.get('geometry'))
            if match:
                if platform == 'darwin':
                    if int(
                            match.group(2)
                    ) >= 0:  # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7
                        self.w.geometry(config.get('geometry'))
                elif platform == 'win32':
                    # Check that the titlebar will be at least partly on screen
                    import ctypes
                    from ctypes.wintypes import POINT
                    # https://msdn.microsoft.com/en-us/library/dd145064
                    MONITOR_DEFAULTTONULL = 0
                    if ctypes.windll.user32.MonitorFromPoint(
                            POINT(
                                int(match.group(1)) + 16,
                                int(match.group(2)) + 16),
                            MONITOR_DEFAULTTONULL):
                        self.w.geometry(config.get('geometry'))
                else:
                    self.w.geometry(config.get('geometry'))
        self.w.attributes('-topmost', config.getint('always_ontop') and 1 or 0)
        self.w.resizable(tk.TRUE, tk.FALSE)

        theme.register(frame)
        theme.register_highlight(self.ship)
        theme.register_highlight(self.system)
        theme.register_highlight(self.station)
        theme.apply(self.w)

        self.w.bind("<Map>", self.onmap)  # Special handling for overrideredict
        self.w.bind('<Return>', self.getandsend)
        self.w.bind('<KP_Enter>', self.getandsend)
        self.w.bind_all('<<Invoke>>', self.getandsend)  # Hotkey monitoring
        self.w.bind_all('<<JournalEvent>>',
                        self.journal_event)  # Journal monitoring
        self.w.bind_all('<<Quit>>', self.onexit)  # Updater

        # Load updater after UI creation (for WinSparkle)
        import update
        self.updater = update.Updater(self.w)

        # First run
        if not config.get('username') or not config.get('password'):
            prefs.PreferencesDialog(self.w, self.postprefs)
        else:
            self.login()

        self.ser.write(b'!0Initialising...\n')
        self.ser.flush()
Exemplo n.º 7
0
 def test_configure_background(self):
     image = tkinter.BitmapImage('::img::test', master=self.root)
     self.assertEqual(image['background'], '-background {} {} {} {}')
     image.configure(background='blue')
     self.assertEqual(image['background'], '-background {} {} {} blue')
 def __init__(self, master, **kw):
     self.img = tk.BitmapImage(data=self.XBM_DATA)
     kw.setdefault('relief', tkc.RELIEF_FLAT)
     kw.setdefault('highlightthickness', 0)
     tk.Button.__init__(self, master, image=self.img, **kw)
def create_image(imagepath):
    if os.path.splitext(imagepath)[1] == '.xbm':
        image = tk.BitmapImage(file=imagepath)
    else:
        image = ImageTk.PhotoImage(file=imagepath)
    return image
    def __init__(self, master):

        # Start a protocol handler to handle cAPI registration. Requires main window to exist.
        protocolhandler.start(master)

        self.holdofftime = config.getint('querytime') + companion.holdoff

        self.w = master
        self.w.title(applongname)
        self.w.rowconfigure(0, weight=1)
        self.w.columnconfigure(0, weight=1)

        self.prefsdialog = None

        plug.load_plugins(master)

        if platform != 'darwin':
            if platform == 'win32':
                self.w.wm_iconbitmap(default='EDMarketConnector.ico')
            else:
                self.w.tk.call(
                    'wm', 'iconphoto', self.w, '-default',
                    tk.PhotoImage(
                        file=join(config.respath, 'EDMarketConnector.png')))
            self.theme_icon = tk.PhotoImage(
                data=
                'R0lGODlhFAAQAMZQAAoKCQoKCgsKCQwKCQsLCgwLCg4LCQ4LCg0MCg8MCRAMCRANChINCREOChIOChQPChgQChgRCxwTCyYVCSoXCS0YCTkdCTseCT0fCTsjDU0jB0EnDU8lB1ElB1MnCFIoCFMoCEkrDlkqCFwrCGEuCWIuCGQvCFs0D1w1D2wyCG0yCF82D182EHE0CHM0CHQ1CGQ5EHU2CHc3CHs4CH45CIA6CIE7CJdECIdLEolMEohQE5BQE41SFJBTE5lUE5pVE5RXFKNaFKVbFLVjFbZkFrxnFr9oFsNqFsVrF8RsFshtF89xF9NzGNh1GNl2GP+KG////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////yH5BAEKAH8ALAAAAAAUABAAAAeegAGCgiGDhoeIRDiIjIZGKzmNiAQBQxkRTU6am0tPCJSGShuSAUcLoIIbRYMFra4FAUgQAQCGJz6CDQ67vAFJJBi0hjBBD0w9PMnJOkAiJhaIKEI7HRoc19ceNAolwbWDLD8uAQnl5ga1I9CHEjEBAvDxAoMtFIYCBy+kFDKHAgM3ZtgYSLAGgwkp3pEyBOJCC2ELB31QATGioAoVAwEAOw=='
            )
            self.theme_minimize = tk.BitmapImage(
                data=
                '#define im_width 16\n#define im_height 16\nstatic unsigned char im_bits[] = {\n   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f,\n   0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\n'
            )
            self.theme_close = tk.BitmapImage(
                data=
                '#define im_width 16\n#define im_height 16\nstatic unsigned char im_bits[] = {\n   0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x1c, 0x38, 0x38, 0x1c, 0x70, 0x0e,\n   0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0x70, 0x0e, 0x38, 0x1c,\n   0x1c, 0x38, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x00 };\n'
            )

        frame = tk.Frame(self.w, name=appname.lower())
        frame.grid(sticky=tk.NSEW)
        frame.columnconfigure(1, weight=1)

        self.cmdr_label = tk.Label(frame)
        self.ship_label = tk.Label(frame)
        self.system_label = tk.Label(frame)
        self.station_label = tk.Label(frame)

        self.cmdr_label.grid(row=1, column=0, sticky=tk.W)
        self.ship_label.grid(row=2, column=0, sticky=tk.W)
        self.system_label.grid(row=3, column=0, sticky=tk.W)
        self.station_label.grid(row=4, column=0, sticky=tk.W)

        self.cmdr = tk.Label(frame,
                             compound=tk.RIGHT,
                             anchor=tk.W,
                             name='cmdr')
        self.ship = HyperlinkLabel(frame,
                                   compound=tk.RIGHT,
                                   url=self.shipyard_url,
                                   name='ship')
        self.system = HyperlinkLabel(frame,
                                     compound=tk.RIGHT,
                                     url=self.system_url,
                                     popup_copy=True,
                                     name='system')
        self.station = HyperlinkLabel(frame,
                                      compound=tk.RIGHT,
                                      url=self.station_url,
                                      name='station')

        self.cmdr.grid(row=1, column=1, sticky=tk.EW)
        self.ship.grid(row=2, column=1, sticky=tk.EW)
        self.system.grid(row=3, column=1, sticky=tk.EW)
        self.station.grid(row=4, column=1, sticky=tk.EW)

        for plugin in plug.PLUGINS:
            appitem = plugin.get_app(frame)
            if appitem:
                tk.Frame(frame,
                         highlightthickness=1).grid(columnspan=2,
                                                    sticky=tk.EW)  # separator
                if isinstance(appitem, tuple) and len(appitem) == 2:
                    row = frame.grid_size()[1]
                    appitem[0].grid(row=row, column=0, sticky=tk.W)
                    appitem[1].grid(row=row, column=1, sticky=tk.EW)
                else:
                    appitem.grid(columnspan=2, sticky=tk.EW)

        self.button = ttk.Button(
            frame,
            text=_('Update'),
            width=28,
            default=tk.ACTIVE,
            state=tk.DISABLED)  # Update button in main window
        self.theme_button = tk.Label(frame,
                                     width=platform == 'darwin' and 32 or 28,
                                     state=tk.DISABLED)
        self.status = tk.Label(frame, name='status', anchor=tk.W)

        row = frame.grid_size()[1]
        self.button.grid(row=row, columnspan=2, sticky=tk.NSEW)
        self.theme_button.grid(row=row, columnspan=2, sticky=tk.NSEW)
        theme.register_alternate(
            (self.button, self.theme_button, self.theme_button), {
                'row': row,
                'columnspan': 2,
                'sticky': tk.NSEW
            })
        self.status.grid(columnspan=2, sticky=tk.EW)
        self.button.bind('<Button-1>', self.getandsend)
        theme.button_bind(self.theme_button, self.getandsend)

        for child in frame.winfo_children():
            child.grid_configure(
                padx=5,
                pady=(platform != 'win32' or isinstance(child, tk.Frame)) and 2
                or 0)

        self.menubar = tk.Menu()
        if platform == 'darwin':
            # Can't handle (de)iconify if topmost is set, so suppress iconify button
            # http://wiki.tcl.tk/13428 and p15 of https://developer.apple.com/legacy/library/documentation/Carbon/Conceptual/HandlingWindowsControls/windowscontrols.pdf
            root.call('tk::unsupported::MacWindowStyle', 'style', root,
                      'document', 'closeBox resizable')

            # https://www.tcl.tk/man/tcl/TkCmd/menu.htm
            self.system_menu = tk.Menu(self.menubar, name='apple')
            self.system_menu.add_command(
                command=lambda: self.w.call('tk::mac::standardAboutPanel'))
            self.system_menu.add_command(
                command=lambda: self.updater.checkForUpdates())
            self.menubar.add_cascade(menu=self.system_menu)
            self.file_menu = tk.Menu(self.menubar, name='file')
            self.file_menu.add_command(command=self.save_raw)
            self.menubar.add_cascade(menu=self.file_menu)
            self.edit_menu = tk.Menu(self.menubar, name='edit')
            self.edit_menu.add_command(accelerator='Command-c',
                                       state=tk.DISABLED,
                                       command=self.copy)
            self.menubar.add_cascade(menu=self.edit_menu)
            self.w.bind('<Command-c>', self.copy)
            self.view_menu = tk.Menu(self.menubar, name='view')
            self.view_menu.add_command(command=lambda: stats.StatsDialog(self))
            self.menubar.add_cascade(menu=self.view_menu)
            window_menu = tk.Menu(self.menubar, name='window')
            self.menubar.add_cascade(menu=window_menu)
            self.help_menu = tk.Menu(self.menubar, name='help')
            self.w.createcommand("::tk::mac::ShowHelp", self.help_general)
            self.help_menu.add_command(command=self.help_privacy)
            self.help_menu.add_command(command=self.help_releases)
            self.menubar.add_cascade(menu=self.help_menu)
            self.w['menu'] = self.menubar
            # https://www.tcl.tk/man/tcl/TkCmd/tk_mac.htm
            self.w.call('set', 'tk::mac::useCompatibilityMetrics', '0')
            self.w.createcommand(
                'tkAboutDialog',
                lambda: self.w.call('tk::mac::standardAboutPanel'))
            self.w.createcommand("::tk::mac::Quit", self.onexit)
            self.w.createcommand(
                "::tk::mac::ShowPreferences",
                lambda: prefs.PreferencesDialog(self.w, self.postprefs))
            self.w.createcommand(
                "::tk::mac::ReopenApplication",
                self.w.deiconify)  # click on app in dock = restore
            self.w.protocol("WM_DELETE_WINDOW",
                            self.w.withdraw)  # close button shouldn't quit app
            self.w.resizable(tk.FALSE,
                             tk.FALSE)  # Can't be only resizable on one axis
        else:
            self.file_menu = self.view_menu = tk.Menu(self.menubar,
                                                      tearoff=tk.FALSE)
            self.file_menu.add_command(command=lambda: stats.StatsDialog(self))
            self.file_menu.add_command(command=self.save_raw)
            self.file_menu.add_command(command=lambda: prefs.PreferencesDialog(
                self.w, self.postprefs))
            self.file_menu.add_separator()
            self.file_menu.add_command(command=self.onexit)
            self.menubar.add_cascade(menu=self.file_menu)
            self.edit_menu = tk.Menu(self.menubar, tearoff=tk.FALSE)
            self.edit_menu.add_command(accelerator='Ctrl+C',
                                       state=tk.DISABLED,
                                       command=self.copy)
            self.menubar.add_cascade(menu=self.edit_menu)
            self.help_menu = tk.Menu(self.menubar, tearoff=tk.FALSE)
            self.help_menu.add_command(command=self.help_general)
            self.help_menu.add_command(command=self.help_privacy)
            self.help_menu.add_command(command=self.help_releases)
            self.help_menu.add_command(
                command=lambda: self.updater.checkForUpdates())
            self.menubar.add_cascade(menu=self.help_menu)
            if platform == 'win32':
                # Must be added after at least one "real" menu entry
                self.always_ontop = tk.BooleanVar(
                    value=config.getint('always_ontop'))
                self.system_menu = tk.Menu(self.menubar,
                                           name='system',
                                           tearoff=tk.FALSE)
                self.system_menu.add_separator()
                self.system_menu.add_checkbutton(
                    label=_('Always on top'),
                    variable=self.always_ontop,
                    command=self.ontop_changed)  # Appearance setting
                self.menubar.add_cascade(menu=self.system_menu)
            self.w.bind('<Control-c>', self.copy)
            self.w.protocol("WM_DELETE_WINDOW", self.onexit)
            theme.register(
                self.menubar
            )  # menus and children aren't automatically registered
            theme.register(self.file_menu)
            theme.register(self.edit_menu)
            theme.register(self.help_menu)

            # Alternate title bar and menu for dark theme
            self.theme_menubar = tk.Frame(frame)
            self.theme_menubar.columnconfigure(2, weight=1)
            theme_titlebar = tk.Label(self.theme_menubar,
                                      text=applongname,
                                      image=self.theme_icon,
                                      cursor='fleur',
                                      anchor=tk.W,
                                      compound=tk.LEFT)
            theme_titlebar.grid(columnspan=3, padx=2, sticky=tk.NSEW)
            self.drag_offset = None
            theme_titlebar.bind('<Button-1>', self.drag_start)
            theme_titlebar.bind('<B1-Motion>', self.drag_continue)
            theme_titlebar.bind('<ButtonRelease-1>', self.drag_end)
            theme_minimize = tk.Label(self.theme_menubar,
                                      image=self.theme_minimize)
            theme_minimize.grid(row=0, column=3, padx=2)
            theme.button_bind(theme_minimize,
                              self.oniconify,
                              image=self.theme_minimize)
            theme_close = tk.Label(self.theme_menubar, image=self.theme_close)
            theme_close.grid(row=0, column=4, padx=2)
            theme.button_bind(theme_close, self.onexit, image=self.theme_close)
            self.theme_file_menu = tk.Label(self.theme_menubar, anchor=tk.W)
            self.theme_file_menu.grid(row=1, column=0, padx=5, sticky=tk.W)
            theme.button_bind(
                self.theme_file_menu, lambda e: self.file_menu.tk_popup(
                    e.widget.winfo_rootx(),
                    e.widget.winfo_rooty() + e.widget.winfo_height()))
            self.theme_edit_menu = tk.Label(self.theme_menubar, anchor=tk.W)
            self.theme_edit_menu.grid(row=1, column=1, sticky=tk.W)
            theme.button_bind(
                self.theme_edit_menu, lambda e: self.edit_menu.tk_popup(
                    e.widget.winfo_rootx(),
                    e.widget.winfo_rooty() + e.widget.winfo_height()))
            self.theme_help_menu = tk.Label(self.theme_menubar, anchor=tk.W)
            self.theme_help_menu.grid(row=1, column=2, sticky=tk.W)
            theme.button_bind(
                self.theme_help_menu, lambda e: self.help_menu.tk_popup(
                    e.widget.winfo_rootx(),
                    e.widget.winfo_rooty() + e.widget.winfo_height()))
            tk.Frame(self.theme_menubar,
                     highlightthickness=1).grid(columnspan=5,
                                                padx=5,
                                                sticky=tk.EW)
            theme.register(
                self.theme_minimize)  # images aren't automatically registered
            theme.register(self.theme_close)
            self.blank_menubar = tk.Frame(frame)
            tk.Label(self.blank_menubar).grid()
            tk.Label(self.blank_menubar).grid()
            tk.Frame(self.blank_menubar, height=2).grid()
            theme.register_alternate(
                (self.menubar, self.theme_menubar, self.blank_menubar), {
                    'row': 0,
                    'columnspan': 2,
                    'sticky': tk.NSEW
                })
            self.w.resizable(tk.TRUE, tk.FALSE)

        # update geometry
        if config.get('geometry'):
            match = re.match('\+([\-\d]+)\+([\-\d]+)', config.get('geometry'))
            if match:
                if platform == 'darwin':
                    if int(
                            match.group(2)
                    ) >= 0:  # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7
                        self.w.geometry(config.get('geometry'))
                elif platform == 'win32':
                    # Check that the titlebar will be at least partly on screen
                    import ctypes
                    from ctypes.wintypes import POINT
                    # https://msdn.microsoft.com/en-us/library/dd145064
                    MONITOR_DEFAULTTONULL = 0
                    if ctypes.windll.user32.MonitorFromPoint(
                            POINT(
                                int(match.group(1)) + 16,
                                int(match.group(2)) + 16),
                            MONITOR_DEFAULTTONULL):
                        self.w.geometry(config.get('geometry'))
                else:
                    self.w.geometry(config.get('geometry'))
        self.w.attributes('-topmost', config.getint('always_ontop') and 1 or 0)

        theme.register(frame)
        theme.apply(self.w)

        self.w.bind('<Map>', self.onmap)  # Special handling for overrideredict
        self.w.bind('<Enter>',
                    self.onenter)  # Special handling for transparency
        self.w.bind('<FocusIn>', self.onenter)  #   "
        self.w.bind('<Leave>', self.onleave)  #   "
        self.w.bind('<FocusOut>', self.onleave)  #   "
        self.w.bind('<Return>', self.getandsend)
        self.w.bind('<KP_Enter>', self.getandsend)
        self.w.bind_all('<<Invoke>>', self.getandsend)  # Hotkey monitoring
        self.w.bind_all('<<JournalEvent>>',
                        self.journal_event)  # Journal monitoring
        self.w.bind_all('<<DashboardEvent>>',
                        self.dashboard_event)  # Dashboard monitoring
        self.w.bind_all('<<PluginError>>', self.plugin_error)  # Statusbar
        self.w.bind_all('<<CompanionAuthEvent>>', self.auth)  # cAPI auth
        self.w.bind_all('<<Quit>>', self.onexit)  # Updater

        # Load updater after UI creation (for WinSparkle)
        import update
        self.updater = update.Updater(self.w)
        if not getattr(sys, 'frozen', False):
            self.updater.checkForUpdates(
            )  # Sparkle / WinSparkle does this automatically for packaged apps

        try:
            config.get_password(
                '')  # Prod SecureStorage on Linux to initialise
        except RuntimeError:
            pass

        # Migration from <= 3.30
        for username in config.get('fdev_usernames') or []:
            config.delete_password(username)
        config.delete('fdev_usernames')
        config.delete('username')
        config.delete('password')
        config.delete('logdir')

        self.postprefs(
            False)  # Companion login happens in callback from monitor

        plugins_not_py3_last = config.getint('plugins_not_py3_last') or int(
            time())
        if (plugins_not_py3_last + 86400) < int(time()) and len(
                plug.PLUGINS_not_py3):
            import tkMessageBox
            tkMessageBox.showinfo(
                'Plugins Without Python 3.x Support',
                "One or more of your enabled plugins do not yet have support for Python 3.x.  Please see the list on the 'Plugins' tab of 'File' > 'Settings'.  You should check if there is an updated version available, else alert the developer that they will need to update the code when EDMC moves to Python 3.x"
            )
            config.set('plugins_not_py3_last', int(time()))
Exemplo n.º 11
0
    def __init__(self, master=None, demo=False):

        tzh = int(
            round((datetime.datetime.utcnow() -
                   datetime.datetime.now()).total_seconds() / 3600.0))
        if tzh > 0:
            self.dtz = datetime.datetime(1970, 1, 1, 0, 0,
                                         0) - datetime.datetime(
                                             1970, 1, 1, abs(tzh), 0, 0)
        else:
            self.dtz = datetime.datetime(1970, 1, 1, abs(tzh), 0,
                                         0) - datetime.datetime(
                                             1970, 1, 1, 0, 0, 0)

        ttk.Frame.__init__(self, master)
        self.grid(sticky=_ALL)
        self.top = self.winfo_toplevel()
        self.top.rowconfigure(0, weight=1)
        self.top.columnconfigure(0, weight=1)

        self.demo = demo

        self.uservar = tk.StringVar()
        self.userlvar = tk.StringVar()
        self.tasknamevar = tk.StringVar()

        self.agendavar = tk.Variable()

        self.deadlinevar = tk.StringVar()
        self.leadtimevar = tk.StringVar()
        self.notice_in_days = tk.IntVar()
        self.morningvar = tk.IntVar()
        self.workdayvar = tk.IntVar()
        self.eveningvar = tk.IntVar()
        self.weekdayvar = tk.IntVar()
        self.weekendvar = tk.IntVar()
        self.schedvar = tk.IntVar()
        self.daemonvar = tk.IntVar()

        self.acal_listvar = tk.Variable()
        self.scal_listvar = tk.Variable()

        self.rarrow = tk.BitmapImage(file="rightarrow.xbm")
        self.larrow = tk.BitmapImage(file="leftarrow.xbm")

        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
        self.HeaderFont = tF.Font(family='Arial', size=18)
        self.title = ttk.Label(self,
                               font=self.HeaderFont,
                               text="NagMe Desktop Client\n",
                               justify=tk.CENTER,
                               anchor=tk.CENTER)
        self.title.grid(row=0, column=0, columnspan=2, sticky=_ALL)
        if self.demo:
            self.user = "******"
            self.createWidgets()
        else:
            #try:
            self.user = pickle.load(open(".user", "rb"))
            self.loadUser(self.user)
            self.createWidgets()
Exemplo n.º 12
0
    def __init__(self, master):

        self.holdofftime = config.getint('querytime') + companion.holdoff
        self.session = companion.Session()
        self.edsm = edsm.EDSM()

        self.w = master
        self.w.title(applongname)
        self.w.rowconfigure(0, weight=1)
        self.w.columnconfigure(0, weight=1)

        # Special handling for overrideredict
        self.w.bind("<Map>", self.onmap)

        plug.load_plugins()

        if platform != 'darwin':
            if platform == 'win32':
                self.w.wm_iconbitmap(default='EDMarketConnector.ico')
            else:
                from PIL import Image, ImageTk
                self.w.tk.call(
                    'wm', 'iconphoto', self.w, '-default',
                    ImageTk.PhotoImage(Image.open("EDMarketConnector.png")))
            self.theme_icon = tk.PhotoImage(
                data=
                'R0lGODlhEAAQAMYAAAAAAAEAAAEBAQICAgQEAwYFBAsHBAoIBgwIBAwIBQ0IBA8JBBAJBBAKBRMMBRkPBhoQBykWCSoWCCoXCTsfCzwfCkAhDEIjDD8kC0AlDEEmC0EmDEcoDk4oDU8pDU4qEFMrD1ktDlotD1ouD1g0EWAyEWU0EV03EmA4EWo2EW03EWQ6Emw4EWo9FGo+E3Y8FH5AFH1IFoBJFo1RGo1SGY1SGpBTGZFTGZJTGZhYG6piHa1kHa5kHbBkHr9uIMt0IgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEKAEAALAAAAAAQABAAAAd7gACCg4SFhoeHGCiIhRs5JwMCkpKGGTIFODaaNjc/D4QaMQMAk5MuEIQOO6OFAiscCIQNPQk8NTO4NDofLwayPi0mIMPDLAcqvoIBDiQWkaUCAykKhAsXAoYCHRKEDDAjIyIiIyEEHhHYhAPr7BQlE+mMABXo8oTx9oWBADs='
            )
            self.theme_minimize = tk.BitmapImage(
                data=
                '#define im_width 16\n#define im_height 16\nstatic unsigned char im_bits[] = {\n   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x3f,\n   0xfc, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };\n'
            )
            self.theme_close = tk.BitmapImage(
                data=
                '#define im_width 16\n#define im_height 16\nstatic unsigned char im_bits[] = {\n   0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x1c, 0x38, 0x38, 0x1c, 0x70, 0x0e,\n   0xe0, 0x07, 0xc0, 0x03, 0xc0, 0x03, 0xe0, 0x07, 0x70, 0x0e, 0x38, 0x1c,\n   0x1c, 0x38, 0x0c, 0x30, 0x00, 0x00, 0x00, 0x00 };\n'
            )

        frame = tk.Frame(self.w, name=appname.lower())
        frame.grid(sticky=tk.NSEW)
        frame.columnconfigure(1, weight=1)

        self.cmdr_label = tk.Label(frame)
        self.system_label = tk.Label(frame)
        self.station_label = tk.Label(frame)

        self.cmdr_label.grid(row=1, column=0, sticky=tk.W)
        self.system_label.grid(row=2, column=0, sticky=tk.W)
        self.station_label.grid(row=3, column=0, sticky=tk.W)

        self.cmdr = tk.Label(frame, anchor=tk.W)
        self.system = HyperlinkLabel(frame,
                                     compound=tk.RIGHT,
                                     url=self.system_url,
                                     popup_copy=True)
        self.station = HyperlinkLabel(
            frame,
            url=self.station_url,
            popup_copy=lambda x: x != self.STATION_UNDOCKED)

        self.cmdr.grid(row=1, column=1, sticky=tk.EW)
        self.system.grid(row=2, column=1, sticky=tk.EW)
        self.station.grid(row=3, column=1, sticky=tk.EW)

        for plugname in plug.PLUGINS:
            appitem = plug.get_plugin_app(plugname, frame)
            if appitem:
                appitem.grid(columnspan=2, sticky=tk.W)

        self.button = ttk.Button(
            frame,
            text=_('Update'),
            width=28,
            command=self.getandsend,
            default=tk.ACTIVE,
            state=tk.DISABLED)  # Update button in main window
        self.theme_button = tk.Label(frame,
                                     width=platform == 'darwin' and 32 or 28,
                                     state=tk.DISABLED)
        self.status = tk.Label(frame, name='status', anchor=tk.W)

        row = frame.grid_size()[1]
        self.button.grid(row=row, columnspan=2, sticky=tk.NSEW)
        self.theme_button.grid(row=row, columnspan=2, sticky=tk.NSEW)
        theme.register_alternate((self.button, self.theme_button), {
            'row': row,
            'columnspan': 2,
            'sticky': tk.NSEW
        })
        self.status.grid(columnspan=2, sticky=tk.EW)

        theme.button_bind(self.theme_button, self.getandsend)
        self.w.bind('<Return>', self.getandsend)
        self.w.bind('<KP_Enter>', self.getandsend)

        for child in frame.winfo_children():
            child.grid_configure(padx=5, pady=(platform == 'win32' and 1 or 3))

        self.menubar = tk.Menu()
        if platform == 'darwin':
            # Can't handle (de)iconify if topmost is set, so suppress iconify button
            # http://wiki.tcl.tk/13428 and p15 of https://developer.apple.com/legacy/library/documentation/Carbon/Conceptual/HandlingWindowsControls/windowscontrols.pdf
            root.call('tk::unsupported::MacWindowStyle', 'style', root,
                      'document', 'closeBox horizontalZoom resizable')

            # https://www.tcl.tk/man/tcl/TkCmd/menu.htm
            self.file_menu = tk.Menu(self.menubar, name='apple')
            self.file_menu.add_command(
                command=lambda: self.w.call('tk::mac::standardAboutPanel'))
            self.file_menu.add_command(
                command=lambda: self.updater.checkForUpdates())
            self.menubar.add_cascade(menu=self.file_menu)
            self.edit_menu = tk.Menu(self.menubar, name='edit')
            self.edit_menu.add_command(accelerator='Command-c',
                                       state=tk.DISABLED,
                                       command=self.copy)
            self.menubar.add_cascade(menu=self.edit_menu)
            self.w.bind('<Command-c>', self.copy)
            self.view_menu = tk.Menu(self.menubar, name='view')
            self.view_menu.add_command(
                state=tk.DISABLED,
                command=lambda: stats.StatsDialog(self.w, self.session))
            self.menubar.add_cascade(menu=self.view_menu)
            window_menu = tk.Menu(self.menubar, name='window')
            self.menubar.add_cascade(menu=window_menu)
            self.w['menu'] = self.menubar
            # https://www.tcl.tk/man/tcl/TkCmd/tk_mac.htm
            self.w.call('set', 'tk::mac::useCompatibilityMetrics', '0')
            self.w.createcommand(
                'tkAboutDialog',
                lambda: self.w.call('tk::mac::standardAboutPanel'))
            self.w.createcommand("::tk::mac::Quit", self.onexit)
            self.w.createcommand(
                "::tk::mac::ShowPreferences",
                lambda: prefs.PreferencesDialog(self.w, self.postprefs))
            self.w.createcommand(
                "::tk::mac::ReopenApplication",
                self.w.deiconify)  # click on app in dock = restore
            self.w.protocol("WM_DELETE_WINDOW",
                            self.w.withdraw)  # close button shouldn't quit app
        else:
            self.file_menu = self.view_menu = tk.Menu(self.menubar,
                                                      tearoff=tk.FALSE)
            self.file_menu.add_command(
                state=tk.DISABLED,
                command=lambda: stats.StatsDialog(self.w, self.session))
            self.file_menu.add_command(
                command=lambda: self.updater.checkForUpdates())
            self.file_menu.add_command(command=lambda: prefs.PreferencesDialog(
                self.w, self.postprefs))
            self.file_menu.add_separator()
            self.file_menu.add_command(command=self.onexit)
            self.menubar.add_cascade(menu=self.file_menu)
            self.edit_menu = tk.Menu(self.menubar, tearoff=tk.FALSE)
            self.edit_menu.add_command(accelerator='Ctrl+C',
                                       state=tk.DISABLED,
                                       command=self.copy)
            self.menubar.add_cascade(menu=self.edit_menu)
            if platform == 'win32':
                # Must be added after at least one "real" menu entry
                self.always_ontop = tk.BooleanVar(
                    value=config.getint('always_ontop'))
                system_menu = tk.Menu(self.menubar,
                                      name='system',
                                      tearoff=tk.FALSE)
                system_menu.add_separator()
                system_menu.add_checkbutton(
                    label=_('Always on top'),
                    variable=self.always_ontop,
                    command=self.ontop_changed)  # Appearance setting
                self.menubar.add_cascade(menu=system_menu)  # Gets index 0
            self.w.bind('<Control-c>', self.copy)
            self.w.protocol("WM_DELETE_WINDOW", self.onexit)
            theme.register(
                self.menubar
            )  # menus and children aren't automatically registered
            theme.register(self.file_menu)
            theme.register(self.edit_menu)

            # Alternate title bar and menu for dark theme
            self.theme_menubar = tk.Frame(frame)
            self.theme_menubar.columnconfigure(2, weight=1)
            theme_titlebar = tk.Label(self.theme_menubar,
                                      text=applongname,
                                      image=self.theme_icon,
                                      anchor=tk.W,
                                      compound=tk.LEFT)
            theme_titlebar.grid(columnspan=3, sticky=tk.NSEW)
            self.drag_offset = None
            theme_titlebar.bind('<Button-1>', self.drag_start)
            theme_titlebar.bind('<B1-Motion>', self.drag_continue)
            theme_titlebar.bind('<ButtonRelease-1>', self.drag_end)
            if platform == 'win32':  # Can't work out how to deiconify on Linux
                theme_minimize = tk.Label(self.theme_menubar,
                                          image=self.theme_minimize)
                theme_minimize.grid(row=0, column=3)
                theme.button_bind(theme_minimize,
                                  self.oniconify,
                                  image=self.theme_minimize)
            theme_close = tk.Label(self.theme_menubar, image=self.theme_close)
            theme_close.grid(row=0, column=4)
            theme.button_bind(theme_close, self.onexit, image=self.theme_close)
            self.theme_file_menu = tk.Label(self.theme_menubar, anchor=tk.W)
            self.theme_file_menu.grid(row=1, column=0, padx=5, sticky=tk.W)
            theme.button_bind(
                self.theme_file_menu, lambda e: self.file_menu.tk_popup(
                    e.widget.winfo_rootx(),
                    e.widget.winfo_rooty() + e.widget.winfo_height()))
            self.theme_edit_menu = tk.Label(self.theme_menubar,
                                            anchor=tk.W)  # Menu title
            self.theme_edit_menu.grid(row=1, column=1, sticky=tk.W)
            theme.button_bind(
                self.theme_edit_menu, lambda e: self.edit_menu.tk_popup(
                    e.widget.winfo_rootx(),
                    e.widget.winfo_rooty() + e.widget.winfo_height()))
            theme.register_highlight(theme_titlebar)
            theme.register(
                self.theme_minimize)  # images aren't automatically registered
            theme.register(self.theme_close)
            theme.register_alternate((self.menubar, self.theme_menubar), {
                'row': 0,
                'columnspan': 2,
                'sticky': tk.NSEW
            })

        self.set_labels()

        # update geometry
        if config.get('geometry'):
            match = re.match('\+([\-\d]+)\+([\-\d]+)', config.get('geometry'))
            if match:
                if platform == 'darwin':
                    if int(
                            match.group(2)
                    ) >= 0:  # http://core.tcl.tk/tk/tktview/c84f660833546b1b84e7
                        self.w.geometry(config.get('geometry'))
                elif platform == 'win32':
                    # Check that the titlebar will be at least partly on screen
                    import ctypes
                    from ctypes.wintypes import POINT
                    # https://msdn.microsoft.com/en-us/library/dd145064
                    MONITOR_DEFAULTTONULL = 0
                    if ctypes.windll.user32.MonitorFromPoint(
                            POINT(
                                int(match.group(1)) + 16,
                                int(match.group(2)) + 16),
                            MONITOR_DEFAULTTONULL):

                        self.w.geometry(config.get('geometry'))
                else:
                    self.w.geometry(config.get('geometry'))
        self.w.attributes('-topmost', config.getint('always_ontop') and 1 or 0)
        self.w.resizable(tk.TRUE, tk.FALSE)

        theme.register(frame)
        theme.register_highlight(self.system)
        theme.register_highlight(self.station)
        theme.apply(self.w)

        # Load updater after UI creation (for WinSparkle)
        import update
        self.updater = update.Updater(self.w)
        self.w.bind_all('<<Quit>>', self.onexit)  # user-generated

        # Install hotkey monitoring
        self.w.bind_all('<<Invoke>>', self.getandsend)  # user-generated
        hotkeymgr.register(self.w, config.getint('hotkey_code'),
                           config.getint('hotkey_mods'))

        # Install log monitoring
        monitor.set_callback(self.system_change)
        edproxy.set_callback(self.system_change)
        if (config.getint('output') & config.OUT_LOG_AUTO) and (
                config.getint('output') &
            (config.OUT_LOG_FILE | config.OUT_LOG_EDSM)):
            monitor.enable_logging()
            monitor.start(self.w)
            edproxy.start(self.w)

        # First run
        if not config.get('username') or not config.get('password'):
            prefs.PreferencesDialog(self.w, self.postprefs)
        else:
            self.login()
Exemplo n.º 13
0
    def initView(self):
        self.selected = -1

        self.master.geometry("580x400")

        self.topFrame = Tk.Frame(self.master)
        self.topFrame.pack(side=Tk.TOP, fill='x')

        self.searchBar = Tk.Entry(self.topFrame)
        self.searchBar.pack(side=Tk.LEFT, fill='both', expand='yes')

        self.inventoryButton = Tk.Button(self.topFrame,
                                         text="Inventory",
                                         command=self.viewInventory)
        self.inventoryButton.pack(side=Tk.RIGHT)

        self.searchButton = Tk.Button(self.topFrame,
                                      text="Search",
                                      command=self.viewSearch)
        self.searchButton.pack(side=Tk.RIGHT)

        self.middleFrame = Tk.Frame(self.master)
        self.middleFrame.pack(fill='x', pady=2, padx=1)

        today = date.today()

        self.monthStringVar = Tk.StringVar()
        self.monthCombo = ttk.Combobox(self.middleFrame,
                                       state='readonly',
                                       textvariable=self.monthStringVar,
                                       width=10)
        self.monthCombo.bind("<<ComboboxSelected>>", self.clearComboSelection)
        months = ("January", "Febuary", "March", "April", "May", "June",
                  "July", "August", "September", "October", "November",
                  "December")
        self.monthCombo["values"] = months
        self.monthCombo.current(today.month - 1)
        self.monthCombo.pack(side=Tk.LEFT)

        self.dayStringVar = Tk.StringVar()
        self.dayCombo = ttk.Combobox(self.middleFrame,
                                     state='readonly',
                                     textvariable=self.dayStringVar,
                                     width=10)
        today = date.today()
        daysInMonth = monthrange(today.year, today.month)

        days = []
        for i in range(daysInMonth[1]):
            days.append(str(i + 1))
        self.dayCombo["values"] = days
        self.dayCombo.current(today.day - 1)
        self.dayCombo.pack(side=Tk.LEFT)
        self.dayCombo.bind("<<ComboboxSelected>>", self.clearComboSelection)
        self.yearStringVar = Tk.StringVar()
        self.yearCombo = ttk.Combobox(self.middleFrame,
                                      state='readonly',
                                      textvariable=self.yearStringVar,
                                      width=10)

        thisYear = today.year
        years = [str(thisYear)]
        for i in range(4):
            years.append(str(thisYear - i - 1))
        years = tuple(years)

        self.yearCombo["values"] = years
        self.yearCombo.current(0)
        self.yearCombo.pack(side=Tk.LEFT)

        self.yearCombo.bind("<<ComboboxSelected>>", self.clearComboSelection)
        self.bottomFrame = Tk.Frame(self.master)
        self.bottomFrame.pack(fill="both", expand=1)

        self.listbox = treectrl.ScrolledMultiListbox(self.bottomFrame)
        self.listbox.config(height="20", scrollmode='auto')
        self.listbox.listbox.config(columns=('Name', 'Servings', 'Calories',
                                             'Protein', 'Carbs', 'Fat'))
        self.listbox.listbox.config(selectcmd=self.selectCmd,
                                    selectmode='single')

        #self.listbox.listbox.column_configure(0, width=260)
        self.listbox.pack(side='top', fill='both', expand=1)

        self.editButton = Tk.Button(self.bottomFrame,
                                    text="Edit",
                                    command=self.editCmd)
        self.editButton.pack(side='right')
        self.deleteButton = Tk.Button(self.bottomFrame,
                                      text="Delete",
                                      command=self.deleteCmd)
        self.deleteButton.pack(side='right')

        Tk.Frame(self.bottomFrame).pack(side='right', padx=12)

        self.downImage = Tk.BitmapImage(file="down.xbm")
        self.downButton = Tk.Button(self.bottomFrame,
                                    image=self.downImage,
                                    text="Down",
                                    command=self.downCmd)
        self.downButton.pack(side='right', fill='y')

        self.upImage = Tk.BitmapImage(file="up.xbm")
        self.upButton = Tk.Button(self.bottomFrame,
                                  image=self.upImage,
                                  text="Up",
                                  command=self.upCmd)
        self.upButton.pack(side='right', fill='y')

        self.exportButton = Tk.Button(self.bottomFrame,
                                      text="Export CSV",
                                      command=self.exportCmd)
        self.exportButton.pack(side='left')

        self.statsFrame = Tk.Frame(self.master)
        self.statsFrame.pack(side='top', pady=2, fill='x')

        self.footerFont = tkFont.Font(size=10)
        self.footerBoldFont = tkFont.Font(size=10, weight='bold')

        self.footerPad = 4

        self.caloriesFrame = Tk.Frame(self.statsFrame)
        self.caloriesFrame.pack(side='left', padx=self.footerPad)
        self.caloriesTopFrame = Tk.Frame(self.caloriesFrame)
        self.caloriesTopFrame.pack(side='top', fill='x')
        self.caloriesBottomFrame = Tk.Frame(self.caloriesFrame)
        self.caloriesBottomFrame.pack(side='bottom', fill='x')

        self.caloriesStringVar = Tk.StringVar()
        Tk.Label(self.caloriesTopFrame, text="Calories",
                 font=self.footerFont).pack(side='left')
        self.caloriesLabel = Tk.Label(self.caloriesBottomFrame,
                                      textvariable=self.caloriesStringVar,
                                      font=self.footerBoldFont)
        self.caloriesLabel.pack(side='left')

        self.proteinFrame = Tk.Frame(self.statsFrame)
        self.proteinFrame.pack(side='left', padx=self.footerPad)
        self.proteinTopFrame = Tk.Frame(self.proteinFrame)
        self.proteinTopFrame.pack(side='top', fill='x')
        self.proteinBottomFrame = Tk.Frame(self.proteinFrame)
        self.proteinBottomFrame.pack(side='bottom', fill='x')

        self.proteinStringVar = Tk.StringVar()
        Tk.Label(self.proteinTopFrame, text=" Protein",
                 font=self.footerFont).pack(side='left')
        self.proteinLabel = Tk.Label(self.proteinBottomFrame,
                                     textvariable=self.proteinStringVar,
                                     font=self.footerBoldFont)
        self.proteinLabel.pack(side='left')

        self.carbFrame = Tk.Frame(self.statsFrame)
        self.carbFrame.pack(side='left', padx=self.footerPad)
        self.carbTopFrame = Tk.Frame(self.carbFrame)
        self.carbTopFrame.pack(side='top', fill='x')
        self.carbBottomFrame = Tk.Frame(self.carbFrame)
        self.carbBottomFrame.pack(side='bottom', fill='x')

        self.carbStringVar = Tk.StringVar()
        Tk.Label(self.carbTopFrame, text=" Carb",
                 font=self.footerFont).pack(side='left')
        self.carbLabel = Tk.Label(self.carbBottomFrame,
                                  textvariable=self.carbStringVar,
                                  font=self.footerBoldFont)
        self.carbLabel.pack(side='left')

        self.fatFrame = Tk.Frame(self.statsFrame)
        self.fatFrame.pack(side='left', padx=self.footerPad)
        self.fatTopFrame = Tk.Frame(self.fatFrame)
        self.fatTopFrame.pack(side='top', fill='x')
        self.fatBottomFrame = Tk.Frame(self.fatFrame)
        self.fatBottomFrame.pack(side='bottom', fill='x')

        self.fatStringVar = Tk.StringVar()
        Tk.Label(self.fatTopFrame, text=" Fat",
                 font=self.footerFont).pack(side='left')
        self.fatLabel = Tk.Label(self.fatBottomFrame,
                                 textvariable=self.fatStringVar,
                                 font=self.footerBoldFont)
        self.fatLabel.pack(side='left')
Exemplo n.º 14
0
    def __init__(self, parent):
        global online
        global callsign
        global callsign_temp
        global command_desc
        global command_raw
        global last_command
        global logger
        global parsed_data
        global tx_power

        global serial_port
        global serial_port_options
        global port_list

        global callsign_entry
        global command_listbox
        global connect_button
        global data_textbox
        global qrcode_label

        # Create main Frame
        tk.Frame.__init__(self, parent)
        self.parent = parent
        self.parent.title("Argo 2 Ground Station")

        # Add UI components

        # Menu Bar
        self.menu_bar = tk.Menu(self)
        self.parent.config(menu=self.menu_bar)

        # File Menu
        self.file_menu = tk.Menu(self.menu_bar)
        self.file_menu.add_command(label="Exit", underline=0, command=on_exit)

        # Receiver Menu
        self.capsule_menu = tk.Menu(self.menu_bar)
        self.capsule_menu.add_command(label="Capsule Status",
                                      underline=0,
                                      command=show_status_window)
        self.capsule_menu.add_separator()
        self.capsule_menu.add_command(label="Send Command",
                                      underline=0,
                                      command=send_command)

        # HabHub Menu
        self.tracking_menu = tk.Menu(self.menu_bar)
        self.tracking_menu.add_command(
            label="Google Maps",
            underline=0,
            command=lambda: webbrowser.open("http://google.com/maps/place/" +
                                            parsed_data[3][1].get(
                                            ) + "," + parsed_data[4][1].get()))
        self.tracking_menu.add_command(
            label="HabHub",
            underline=0,
            command=lambda: webbrowser.open("http://tracker.habhub.org/"))
        self.tracking_menu.add_separator()
        self.tracking_menu.add_checkbutton(label="Online",
                                           underline=0,
                                           offvalue=0,
                                           onvalue=1,
                                           variable=online)

        # Help Menu
        self.help_menu = tk.Menu(self.menu_bar)
        self.help_menu.add_command(label="Help",
                                   underline=0,
                                   command=self.show_help)
        self.help_menu.add_command(label="About",
                                   underline=0,
                                   command=self.show_about)

        # Add Menus to Menu Bar
        self.menu_bar.add_cascade(label="File",
                                  underline=0,
                                  menu=self.file_menu)
        self.menu_bar.add_cascade(label="Capsule",
                                  underline=0,
                                  menu=self.capsule_menu)
        self.menu_bar.add_cascade(label="Tracking",
                                  underline=2,
                                  menu=self.tracking_menu)
        self.menu_bar.add_cascade(label="Help",
                                  underline=0,
                                  menu=self.help_menu)

        # Frames
        left_frame = tk.Frame(self.master)

        # Serial Port Label
        tk.Label(left_frame, text="Port:").grid(row=0, column=0)

        # Serial Port OptionMenu - allow user to choose serial port to connect to
        serial_port = tk.StringVar(self.master)
        port_list = ("", "")
        serial_port_options = tk.OptionMenu(left_frame, serial_port,
                                            *list(port_list))
        serial_port_options.config(width=6)
        serial_port_options.bind('<Button-1>', update_serial_list)
        serial_port_options.grid(row=0, column=1, sticky='w', padx=(10, 0))

        # Serial Port Connect Button
        connect_button = tk.Button(left_frame,
                                   text="Connect",
                                   command=connect_serial)
        connect_button.grid(row=1,
                            column=1,
                            columnspan=2,
                            sticky='w',
                            padx=12,
                            pady=(0, 30))

        # Callsign Label
        tk.Label(left_frame, text="Callsign:").grid(row=2,
                                                    column=0,
                                                    sticky='e')

        # Callsign Entry
        callsign_temp = tk.StringVar(self.master)
        callsign_temp.set("PAN1")
        callsign_entry = tk.Entry(left_frame,
                                  width=12,
                                  textvariable=callsign_temp)
        callsign_entry.grid(row=2, column=1)

        # Callsign Set Button
        callsign = tk.StringVar(self.master)
        callsign.set("PAN1")
        callsign_button = tk.Button(left_frame,
                                    text="Set callsign",
                                    command=set_callsign)
        callsign_button.grid(row=3,
                             column=1,
                             columnspan=2,
                             sticky='w',
                             padx=(7, 0))

        # Online Checkbox - allows user to decide whether to send data to HabHub or not
        self.online_checkbutton = tk.Checkbutton(left_frame,
                                                 text="Offline",
                                                 fg="red",
                                                 variable=online)
        self.online_checkbutton.grid(row=4,
                                     column=1,
                                     columnspan=2,
                                     sticky='w',
                                     padx=(5, 0),
                                     pady=(20, 0))

        # Data Text Box - data recieved from capsule
        data_textbox = ScrolledText(self.master, relief='sunken')
        data_textbox.configure(state=tk.DISABLED,
                               width=64,
                               height=16,
                               wrap=tk.NONE)  # Make data uneditable
        data_textbox.grid(row=0,
                          column=2,
                          columnspan=5,
                          padx=(20, 0),
                          pady=(10, 10))

        #data_scrollbar = tk.Scrollbar(self.master, command=data_textbox.yview)
        #data_scrollbar.grid()

        left_frame.columnconfigure(0, pad=10)
        left_frame.rowconfigure(0, pad=10)
        left_frame.rowconfigure(1, pad=10)
        left_frame.rowconfigure(2, pad=10)
        left_frame.rowconfigure(3, pad=10)
        left_frame.grid(row=0, column=0)

        # Command Listbox
        command_listbox = tk.Listbox(self.master)

        for cmd_num in xrange(0, len(GENERAL_COMMANDS)):
            command_listbox.insert(cmd_num, GENERAL_COMMANDS[cmd_num][0])

        command_listbox.bind('<<ListboxSelect>>', on_select_command)
        command_listbox.grid(row=1, column=0, rowspan=4, sticky='n')

        # Command Entry
        command_raw = tk.StringVar()
        command_entry = tk.Entry(self.master,
                                 width=20,
                                 textvariable=command_raw)
        command_entry.grid(row=1,
                           column=2,
                           padx=(20, 0),
                           pady=(3, 0),
                           sticky='nw')

        # Command Description
        command_desc = tk.StringVar()
        command_desc_label = tk.Label(self.master,
                                      textvariable=command_desc,
                                      justify=tk.LEFT)
        command_desc_label.grid(row=2,
                                column=2,
                                columnspan=4,
                                rowspan=2,
                                padx=(20, 0),
                                sticky='nw')

        # Command TX Power
        tk.Label(self.master, text="TX Power:").grid(row=1,
                                                     column=4,
                                                     sticky='ne',
                                                     pady=(3, 0))

        tx_power = tk.StringVar()
        tx_power.set(20)
        command_power_option = ttk.Combobox(self.master,
                                            width=5,
                                            state='readonly',
                                            textvariable=tx_power)
        command_power_option['values'] = list(reversed(range(5, 23 + 1)))
        command_power_option.grid(row=1, column=5, sticky='ne', pady=(3, 0))

        # Command Buttons (Send Command and Last Command)
        last_command = ""
        last_command_button = tk.Button(
            self.master,
            text="Load Last Command",
            command=lambda: command_raw.set(last_command))
        last_command_button.grid(row=1, column=3, sticky='nw')

        send_command_button = tk.Button(self.master,
                                        text="Send Command",
                                        command=send_command)
        send_command_button.grid(row=1, column=6, sticky='ne')

        # Status Button (show Status Window)
        status_button = tk.Button(self.master,
                                  text="Show Status Window",
                                  command=show_status_window)
        status_button.grid(row=4, column=6, sticky='se')

        # QR Code Label
        tk.Label(self.master, text="Google Maps:").grid(row=2,
                                                        column=6,
                                                        sticky='se',
                                                        pady=(0, 0))
        qrcode = pyqrcode.create('No data yet...')

        # Create XBM image
        qr_xbm = qrcode.xbm(scale=2)

        # Create Tkinter Bitmap
        qr_bmp = tk.BitmapImage(data=qr_xbm)

        # Create label with image
        qrcode_label = tk.Label(self.master, image=qr_bmp)

        # Save reference to change image later
        qrcode_label.image = qr_bmp

        qrcode_label.grid(row=3, column=6, sticky='e')

        # Setup serial check in 100 ms (to repeat forever)
        self.after(100, get_serial_data)
    def __init__(self, parent=None, **kw):

        # Define the megawidget options.
        optiondefs = (
            ('value', None, Pmw.INITOPT),
            ('increment', 1, Pmw.INITOPT),
            ('max', None, Pmw.INITOPT),
            ('min', None, Pmw.INITOPT),
            ('rangeerror', None, self._setrangeerror),
            ('width', None, Pmw.INITOPT),
            ('background', None, self._setbg),
            ('callback', None, self._setcallback),
            ('label', None, Pmw.INITOPT),
            ('labelpos', None, Pmw.INITOPT),
        )
        self.defineoptions(kw, optiondefs)

        # Initialise base class (after defining options).
        Pmw.MegaWidget.__init__(self, parent)

        # Create the components.
        interior = self.interior()

        rbase = 0
        cbase = 0  # default to west
        west = 1
        if self['label'] is not None:
            cbase = 1
            if self['labelpos'] is not None:
                #user spec label position
                if self['labelpos'] in 'nN':
                    cbase = 0
                    rbase = 1
                if self['labelpos'] in 'eE':
                    cbase = 0
                    west = 0
            self.label = self.createcomponent('label', (),
                                              None,
                                              Tkinter.Label,
                                              interior,
                                              text=self['label'],
                                              anchor='w')
            if rbase:
                self.label.grid(row=0, column=0, columnspan=2)
            else:
                if west:
                    self.label.grid(row=0, column=0, rowspan=2)
                else:
                    self.label.grid(row=0, column=cbase + 2, rowspan=2)
        # Create the entry component.
        self.entry = self.createcomponent('entry', (),
                                          None,
                                          Tkinter.Entry,
                                          interior,
                                          borderwidth=2,
                                          relief='raised')
        self.entry.grid(row=rbase, column=cbase, rowspan=2)
        wide = self['width']
        if wide is not None:
            self.entry.configure(width=wide)

        # Create the up button.
        self.uparrow = Tkinter.BitmapImage(data=uparrow_data, master=parent)

        self.up = self.createcomponent(
            'up',
            (),
            None,
            Tkinter.Button,
            interior,
            command=self._upCommand,
            image=self.uparrow,
        )
        self.up.grid(row=rbase, column=cbase + 1)
        # Create the down button.
        self.dnarrow = Tkinter.BitmapImage(data=dnarrow_data, master=parent)
        self.down = self.createcomponent(
            'down',
            (),
            None,
            Tkinter.Button,
            interior,
            command=self._downCommand,
            image=self.dnarrow,
        )
        self.down.grid(row=rbase + 1, column=cbase + 1)

        value = self['value']
        if value is not None:
            self.entry.insert(0, value)

        # Check keywords and initialise options.
        self.initialiseoptions()
Exemplo n.º 16
0
    def register(self, widget):
        # Note widget and children for later application of a theme. Note if the widget has explicit fg or bg attributes.
        assert isinstance(widget, tk.Widget) or isinstance(
            widget, tk.BitmapImage), widget
        if not self.defaults:
            # Can't initialise this til window is created       # Windows, MacOS
            self.defaults = {
                'fg':
                tk.Label()['foreground'],  # SystemButtonText, systemButtonText
                'bg': tk.Label()['background'],  # SystemButtonFace, White
                'font': tk.Label()['font'],  # TkDefaultFont
                'bitmapfg': tk.BitmapImage()
                ['foreground'],  # '-foreground {} {} #000000 #000000'
                'bitmapbg':
                tk.BitmapImage()['background'],  # '-background {} {} {} {}'
                'entryfg': tk.Entry()['foreground'],  # SystemWindowText, Black
                'entrybg':
                tk.Entry()['background'],  # SystemWindow, systemWindowBody
                'entryfont': tk.Entry()['font'],  # TkTextFont
                'frame':
                tk.Frame()['background'],  # SystemButtonFace, systemWindowBody
                'menufg': tk.Menu()['foreground'],  # SystemMenuText,
                'menubg': tk.Menu()['background'],  # SystemMenu,
                'menufont': tk.Menu()['font'],  # TkTextFont
            }

        if widget not in self.widgets:
            # No general way to tell whether the user has overridden, so compare against widget-type specific defaults
            attribs = set()
            if isinstance(widget, tk.BitmapImage):
                if widget['foreground'] not in ['', self.defaults['bitmapfg']]:
                    attribs.add('fg')
                if widget['background'] not in ['', self.defaults['bitmapbg']]:
                    attribs.add('bg')
            elif isinstance(widget, tk.Entry) or isinstance(widget, ttk.Entry):
                if widget['foreground'] not in ['', self.defaults['entryfg']]:
                    attribs.add('fg')
                if widget['background'] not in ['', self.defaults['entrybg']]:
                    attribs.add('bg')
                if 'font' in widget.keys() and str(widget['font']) not in [
                        '', self.defaults['entryfont']
                ]:
                    attribs.add('font')
            elif isinstance(widget, tk.Frame) or isinstance(
                    widget, ttk.Frame) or isinstance(widget, tk.Canvas):
                if ('background' in widget.keys() or isinstance(
                        widget, tk.Canvas)) and widget['background'] not in [
                            '', self.defaults['frame']
                        ]:
                    attribs.add('bg')
            elif isinstance(widget, HyperlinkLabel):
                pass  # Hack - HyperlinkLabel changes based on state, so skip
            elif isinstance(widget, tk.Menu):
                if widget['foreground'] not in ['', self.defaults['menufg']]:
                    attribs.add('fg')
                if widget['background'] not in ['', self.defaults['menubg']]:
                    attribs.add('bg')
                if widget['font'] not in ['', self.defaults['menufont']]:
                    attribs.add('font')
            else:  # tk.Button, tk.Label
                if 'foreground' in widget.keys(
                ) and widget['foreground'] not in ['', self.defaults['fg']]:
                    attribs.add('fg')
                if 'background' in widget.keys(
                ) and widget['background'] not in ['', self.defaults['bg']]:
                    attribs.add('bg')
                if 'font' in widget.keys() and widget['font'] not in [
                        '', self.defaults['font']
                ]:
                    attribs.add('font')
            self.widgets[widget] = attribs

        if isinstance(widget, tk.Frame) or isinstance(widget, ttk.Frame):
            for child in widget.winfo_children():
                self.register(child)
Exemplo n.º 17
0
    def go(self, yacaree):
        "Bindings could not be made in a regular __init__()"
        self.root = Tkinter.Tk()

        button_width = 35
        button_height = 4
        text_width = 92
        text_height = 28

        left_frame = Tkinter.Frame(self.root)
        left_frame.pack(side=Tkinter.LEFT)
        logo = Tkinter.BitmapImage(file="yac-v03.xbm")
        logo_frame = Tkinter.Frame(left_frame)
        logo_frame.configure(width=button_width)
        logo_frame.pack(side=Tkinter.TOP)
        slogan_label = Tkinter.Label(
            left_frame,
            text="yet another\nclosure-based association " +
            "rules\nexperimentation environment\n(version " + statics.version +
            ")")
        slogan_label.configure(width=button_width)
        slogan_label.pack(side=Tkinter.TOP)
        logo_label = Tkinter.Label(logo_frame, image=logo)
        namefont = tkFont.Font(family="Helvetica",
                               size=18,
                               slant="italic",
                               weight="bold")
        name = Tkinter.Label(logo_frame,
                             text="yacaree",
                             font=namefont,
                             anchor=Tkinter.SW)
        logo_label.pack(side=Tkinter.LEFT)
        name.pack(side=Tkinter.LEFT)
        process_frame = Tkinter.LabelFrame(left_frame, text="Process")
        process_frame.pack(side=Tkinter.BOTTOM)

        console_frame = Tkinter.LabelFrame(self.root, text="Console")
        console_frame.pack(side=Tkinter.LEFT)
        self.console = Tkinter.Text(console_frame)
        self.console.configure(width=text_width, height=text_height)
        self.console.pack(side=Tkinter.LEFT)
        self.scrollY = Tkinter.Scrollbar(console_frame,
                                         orient=Tkinter.VERTICAL,
                                         command=self.console.yview)
        self.scrollY.pack(side=Tkinter.LEFT, fill=Tkinter.Y)
        self.console.configure(yscrollcommand=self.scrollY.set)
        self.report("This is yacaree, version " + statics.version + ".")

        self.filepick = Tkinter.Button(process_frame)
        self.filepick.configure(text="Choose a dataset file",
                                width=button_width,
                                height=button_height,
                                command=self.choose_datafile)
        self.filepick.pack()

        self.run = Tkinter.Button(process_frame)
        self.run.configure(
            text="Run yacaree for all rules\n(and be patient), or...",
            width=button_width,
            height=button_height,
            state=Tkinter.DISABLED,
            command=yacaree.standard_run_all)
        self.run.pack()

        self.run50 = Tkinter.Button(process_frame)
        self.run50.configure(
            text=
            "...Run yacaree for at most 50 rules\n(but be equally patient)",
            width=button_width,
            height=button_height,
            state=Tkinter.DISABLED,
            command=yacaree.standard_run)
        self.run50.pack()

        self.finish_button = Tkinter.Button(process_frame)
        self.finish_button.configure(text="Finish",
                                     width=button_width,
                                     height=button_height,
                                     command=self.finish)
        self.finish_button.pack()
        if statics.maxrules == 0:
            self.report("Requested all rules as output.")
        if statics.filenamefull:
            self.report("Selected dataset in file " + statics.filenamefull)
            self.run.configure(state=Tkinter.NORMAL)
            if statics.maxrules:
                self.run50.configure(state=Tkinter.NORMAL)
        self.clock_at_report = clock()
        self.root.mainloop()
Exemplo n.º 18
0
    def __init__(self,
                 master,
                 title,
                 width=None,
                 height=None,
                 header_background=None,
                 header_foreground=None,
                 icon_foreground=None,
                 button_activebackground=None,
                 button_activeforeground=None,
                 button_background=None,
                 button_foreground=None,
                 body_background=None,
                 borderwidth=None,
                 maximize_button=True,
                 minimize_button=True,
                 close_button=True,
                 icon=None,
                 center_on_screen=False):
        if header_background is None:
            header_background = self.HEADER_BACKGROUND

        if header_foreground is None:
            header_foreground = self.HEADER_FOREGROUND

        if icon_foreground is None:
            icon_foreground = self.ICON_FOREGROUND

        if button_activebackground is None:
            button_activebackground = self.BUTTON_ACTIVEBACKGROUND

        if button_activeforeground is None:
            button_activeforeground = self.BUTTON_ACTIVEFOREGROUND

        if button_background is None:
            button_background = self.BUTTON_BACKGROUND

        if button_foreground is None:
            button_foreground = self.BUTTON_FOREGROUND

        if body_background is None:
            body_background = self.BODY_BACKGROUND

        if borderwidth is None:
            borderwidth = self.BORDERWIDTH

        Draggable_Window.__init__(self, master)

        self.wm_attributes('-topmost', True)
        self.overrideredirect(True)

        outer_frame = tk.Frame(self,
                               highlightbackground=header_background,
                               highlightcolor=header_background,
                               highlightthickness=borderwidth)
        outer_frame.pack(expand=True, fill=BOTH)

        self._header = tk.Frame(outer_frame,
                                background=header_background,
                                padx=6,
                                pady=6)
        self._header.pack(fill=X)

        if icon is None:
            if isinstance(Metro_Dialog.WINDOW_ICON, basestring):
                data = base64.b64decode(Metro_Dialog.WINDOW_ICON)
                Metro_Dialog.WINDOW_ICON = tk.BitmapImage(data=data)

            icon = Metro_Dialog.WINDOW_ICON

        if isinstance(icon, tk.BitmapImage):
            icon.configure(foreground=icon_foreground)

        if close_button:
            if isinstance(Metro_Dialog.CLOSE_ICON, basestring):
                data = base64.b64decode(Metro_Dialog.CLOSE_ICON)
                Metro_Dialog.CLOSE_ICON = tk.BitmapImage(
                    data=data, foreground=button_foreground)

            self._close_button = Control_Button(
                self._header,
                foreground=button_foreground,
                background=button_background,
                active_background=button_activebackground,
                image=Metro_Dialog.CLOSE_ICON,
                command=self.close)
            self._close_button.pack(side=RIGHT, padx=(1, 0))

        if maximize_button:
            if isinstance(Metro_Dialog.MAXIMIZE_ICON, basestring):
                data = base64.b64decode(Metro_Dialog.MAXIMIZE_ICON)
                Metro_Dialog.MAXIMIZE_ICON = tk.BitmapImage(
                    data=data, foreground=button_foreground)

            self._maximize_button = Control_Button(
                self._header,
                foreground=button_foreground,
                background=button_background,
                active_background=button_activebackground,
                image=Metro_Dialog.MAXIMIZE_ICON,
                command=self.maximize)
            self._maximize_button.pack(side=RIGHT, padx=(1, 0))

        if minimize_button:
            if isinstance(Metro_Dialog.MINIMIZE_ICON, basestring):
                data = base64.b64decode(Metro_Dialog.MINIMIZE_ICON)
                Metro_Dialog.MINIMIZE_ICON = tk.BitmapImage(
                    data=data, foreground=button_foreground)

            self._minimize_button = Control_Button(
                self._header,
                foreground=button_foreground,
                background=button_background,
                active_background=button_activebackground,
                active_foreground=button_activeforeground,
                image=Metro_Dialog.MINIMIZE_ICON,
                command=self.minimize)
            self._minimize_button.pack(side=RIGHT, padx=(1, 0))

        self._borderwidth = borderwidth

        self._icon_label = tk.Label(self._header,
                                    image=icon,
                                    background=header_background)
        self._icon_label.pack(side=LEFT)

        self._title = title
        self._title_label = tk.Label(self._header,
                                     text=title,
                                     foreground=header_foreground,
                                     background=header_background)
        self._title_label.pack(side=LEFT, padx=6)

        self.body = tk.Frame(outer_frame,
                             padx=4,
                             pady=4,
                             background=body_background)
        self.body.pack(expand=True, fill=BOTH)

        self._width = width
        self._height = height

        self._is_maximized = True

        if center_on_screen:
            self.center_on_screen()