コード例 #1
0
    def initialize(self):

        self.title(TITLE)
        self.config(background=COLOR_BG)

        # HACK: set application icon
        # see http://stackoverflow.com/a/11180300
        icon = open_photoimage(resource_path('resources', 'icon.png'))
        self.tk.call('wm', 'iconphoto', self._w, icon)

        # create application frame
        self.frame = AppFrame(self)
        self.frame.pack(fill=Tkinter.BOTH, expand=1)

        # Specific modifications for Mac OS X systems
        if OS_DARWIN:

            # Add an empty main menu.
            menu = Tkinter.Menu(self)
            try:
                self.config(menu=menu)
            except AttributeError:
                # master is a toplevel window (Python 1.4/Tkinter 1.63)
                self.tk.call(self, 'config', '-menu', menu)

            # Register about dialog.
            self.createcommand('tkAboutDialog', self.show_about_dialog)

        # event on window close
        self.protocol('WM_DELETE_WINDOW', self.shutdown)

        # close window with ESC
        #self.bind('<Escape>', lambda e: self.on_close())

        # set window size
        #self.resizable(False,False)
        #self.resizable(width=False, height=False)
        w = get_configuration_int('gui', 'application-window-width', 500)
        h = get_configuration_int('gui', 'application-window-height', 300)
        self.geometry('%sx%s' % (w, h))
コード例 #2
0
class Application(Tkinter.Tk):
    def __init__(self):
        Tkinter.Tk.__init__(self)
        self.attributes('-alpha', 0.0)
        self.thread = None
        self.threadLock = thread.allocate_lock()
        self.settings = Settings()
        self.initialize()

    def initialize(self):

        self.title(TITLE)
        self.config(background=COLOR_BG)

        # HACK: set application icon
        # see http://stackoverflow.com/a/11180300
        icon = open_photoimage(resource_path('resources', 'icon.png'))
        self.tk.call('wm', 'iconphoto', self._w, icon)

        # create application frame
        self.frame = AppFrame(self)
        self.frame.pack(fill=Tkinter.BOTH, expand=1)

        # Specific modifications for Mac OS X systems
        if OS_DARWIN:

            # Add an empty main menu.
            menu = Tkinter.Menu(self)
            try:
                self.config(menu=menu)
            except AttributeError:
                # master is a toplevel window (Python 1.4/Tkinter 1.63)
                self.tk.call(self, 'config', '-menu', menu)

            # Register about dialog.
            self.createcommand('tkAboutDialog', self.show_about_dialog)

        # event on window close
        self.protocol('WM_DELETE_WINDOW', self.shutdown)

        # close window with ESC
        #self.bind('<Escape>', lambda e: self.on_close())

        # set window size
        #self.resizable(False,False)
        #self.resizable(width=False, height=False)
        w = get_configuration_int('gui', 'application-window-width', 500)
        h = get_configuration_int('gui', 'application-window-height', 300)
        self.geometry('%sx%s' % (w, h))

    def mainloop(self, n=0):
        self.attributes('-alpha', 1.0)
        Tkinter.Tk.mainloop(self, n=n)

    def set_connected(self):
        if self.threadLock.locked(): return
        try:
            self.threadLock.acquire()
            self.frame.set_connected()
        finally:
            self.threadLock.release()

    def set_connecting(self):
        if self.threadLock.locked(): return
        try:
            self.threadLock.acquire()
            self.frame.set_connecting()
        finally:
            self.threadLock.release()

    def set_disconnected(self, show_message=True):
        if self.threadLock.locked(): return
        try:
            self.threadLock.acquire()
            self.frame.set_disconnected(show_message=show_message)
        finally:
            self.threadLock.release()

    def set_error(self, msg=None):
        if self.threadLock.locked(): return
        try:
            self.threadLock.acquire()
            self.frame.set_error(msg=msg)
        finally:
            self.threadLock.release()

    def show_about_dialog(self):
        dlg = AboutDialog(self)
        #self.eval('tk::PlaceWindow %s center' % dlg.winfo_pathname(dlg.winfo_id()))

        x = self.winfo_rootx()
        y = self.winfo_rooty()
        w = get_configuration_int('gui', 'about-window-width', 550)
        h = get_configuration_int('gui', 'about-window-height', 350)
        dlg.geometry('%sx%s+%d+%d' % (w, h, x+25, y+25))

        dlg.grab_set()
        self.wait_window(dlg)

    def show_extended_settings_dialog(self):
        dlg = SettingsDialog(self)
        #self.eval('tk::PlaceWindow %s center' % dlg.winfo_pathname(dlg.winfo_id()))

        x = self.winfo_rootx()
        y = self.winfo_rooty()
        w = get_configuration_int('gui', 'settings-window-width', 550)
        h = get_configuration_int('gui', 'settings-window-height', 350)
        dlg.geometry('%sx%s+%d+%d' % (w, h, x+25, y+25))

        dlg.grab_set()
        self.wait_window(dlg)

    def shutdown(self):
        self.stop_thread()
        self.destroy()

    def start_thread(self):
        self.stop_thread(False)

        # validate hostname
        host = self.settings.get_host()
        if host is None:
            self.set_error(msg=_('The address in invalid.'))
            return

        # validate port number
        port = self.settings.get_port()
        if port is None:
            self.set_error(msg=_('The port number is invalid.'))
            return
        if port < 0 or port > 65535:
            self.set_error(_('The port number is not in the interval from {0} to {1}.').format(1, 65535))
            return

        #print 'connecting to %s:%s' % (host, port)
        self.set_connecting()
        self.thread = VNC(self, self.settings)
        self.thread.start()

    def stop_thread(self, show_message=True):
        if not self.thread is None:
            self.thread.kill()
        self.thread = None
        self.set_disconnected(show_message)