Esempio n. 1
0
def update_gui(window, event, values):
    """Wrapper method that calls the various update_gui methods.
    """
    KcautoControls.update_gui(window, event, values)
    GuiTabButtonsLayout.update_gui(window, event, values)
    Config.update_gui(window, event, values)
    RuntimeLogger.update_gui(window, event, values)
    ClickPlotter.update_gui(window, event, values)
    Settings.update_gui(window, event, values)
    About.update_gui(window, event, values)
    # for tkinter-level modifications
    LayoutBase.update_widgets(window)
Esempio n. 2
0
    def __init__(self, window):
        self.rm_client = RemarkableClient()

        # Define app settings
        font_size = 38
        row_height = 30
        window_width = 750
        window_height = 650

        # Subscribe to events
        self.rm_client.listen_sign_in_event(self)

        # Window settings
        window.title("RemaPy Explorer")

        # Try to start remapy always on the first screen and in the middle.
        # We assume a resolution width of 1920... if 1920 is too large use
        # the real resolution
        x = min(window.winfo_screenwidth(), 1920) / 2 - (window_width / 2)
        y = (window.winfo_screenheight() / 2) - (window_height / 2)
        window.geometry("%dx%d+%d+%d" % (window_width, window_height, x, y))

        # Create different tabs on notebook
        self.notebook = ttk.Notebook(window)
        self.notebook.pack(expand=1, fill="both")

        frame = ttk.Frame(self.notebook)
        self.file_explorer = FileExplorer(frame,
                                          window,
                                          font_size=font_size,
                                          row_height=row_height)
        self.notebook.add(frame, text="File Explorer")

        frame = ttk.Frame(self.notebook)
        self.notebook.add(frame, text="Backup", state="hidden")

        frame = ttk.Frame(self.notebook)
        self.notebook.add(frame, text="Zotero", state="hidden")

        frame = ttk.Frame(self.notebook)
        self.notebook.add(frame, text="Mirror", state="hidden")

        frame = ttk.Frame(self.notebook)
        self.notebook.add(frame, text="SSH", state="hidden")

        frame = ttk.Frame(self.notebook)
        self.settings = Settings(frame, font_size)
        self.notebook.add(frame, text="Settings")

        frame = ttk.Frame(self.notebook)
        self.about = About(frame)
        self.notebook.add(frame, text="About")

        # Try to sign in to the rm cloud without a onetime code i.e. we
        # assume that the user token is already available. If it is not
        # possible we get a signal to disable "My remarkable" and settings
        # are shown...
        self.rm_client.sign_in()
Esempio n. 3
0
 def __init__(self):
     pygame.init()
     self.settings = Settings()
     self.screen = pygame.display.set_mode((self.settings.screen_width,
                                            self.settings.screen_height))  # type: Surface
     pygame.display.set_caption("PyCheckers")
     self.board = Board()
     self.selected_tile = None
     self.red_ai = Ai(self.board, Color.RED, 4)
     self.black_ai = Ai(self.board, Color.BLACK, 4)
     self.first = True
     self.num_AIs = 0
Esempio n. 4
0
File: main.py Progetto: rmln/dtknv
 def __init__(self, master=None):
     tk.Frame.__init__(self, master, height=270, width=500)
     # Settings
     self.main_settings = Settings()
     self.set = self.main_settings
     self.lng = self.set.language
     self.master.title(self.lng['label_about_name'] + ' ' + \
                           version.__version__)
     self.pack(padx=0, pady=0, fill=tk.BOTH, expand=0)
     self.pack_propagate(0)
     self.master.windows_opened = []
     # Conversion class
     self.tocyr = ToCyr()
     # Commands for interfaces
     self.master.main_settings = self.main_settings
     self.master.lng = self.lng
     self.master.show_exceptions = self.show_exceptions
     self.master.show_options = self.show_options
     self.master.show_filesdir = self.show_filesdir
     self.master.show_plaintext = self.show_plaintext
     self.master.show_newversion = self.show_newversion
     self.master.show_aboutwindow = self.show_aboutwindow
     self.master.convert = self.convert
     self.master.update_gui = self.update_gui
     self.master.kill_program = self.kill_program
     # Status bar
     self.create_statusbar()
     # Create and attach the menu
     self.menu = Dmenu(master)
     self.master.config(menu=self.menu.main)
     # This is called in window_exceptions.py to
     # recreate exceptions menu:
     self.master.recreate_excetions_menu = self.menu.create_exceptions_menu
     # Plain text / file conversion frames
     self.window_plaintext = PlainText(self)
     self.window_plaintext.window.forget()
     self.window_filesdir = FilesDir(self)
     # Shortcuts
     self.bind_all("<F2>", self.show_exceptions)
     self.bind_all("<F3>", self.show_options)
     self.bind_all("<F7>", self.show_filesdir)
     self.bind_all("<F8>", self.show_plaintext)
     # Select default mode
     #self.show_plaintext()
     self.show_filesdir()
Esempio n. 5
0
def gui_main():
    """Primary method for composing and initializing the kcauto GUI.
    """
    Log.log_success("Starting kcauto GUI.")

    layout = [
        GuiTabButtonsLayout.get_layout(),
        [
            Config.get_layout(),
            RuntimeLogger.get_layout(),
            ClickPlotter.get_layout(),
            Settings.get_layout(),
            About.get_layout(),
        ],
        ConfigControls.get_layout(),
        KcautoControls.get_layout(),
    ]

    # initialize window
    window = sg.Window('kcauto',
                       layout,
                       use_default_focus=False,
                       element_padding=(0, 0),
                       margins=(3, 7),
                       debugger_enabled=False,
                       finalize=True)

    # initialize misc values
    secondary_event = None
    kcauto_proc = None
    kcauto_proc_poll = None
    proc_reader = None
    gui_queue = queue.Queue()
    timeout = None

    # load default config and refresh UI
    event, values = window.read(timeout=100)
    init_cfg_path = window['cfg_path'].Get()
    cfg_load(window, event, values, init_cfg_path)
    event, values = window.read(timeout=100)
    update_gui(window, event, values)

    while True:
        # primary loop
        event, values = window.read(timeout=timeout)

        if event != '__TIMEOUT__':
            # print(event)
            pass

        if event in (
                None,
                'Cancel',
        ):
            break

        if event == 'save':
            ConfigControls.save_cfg(values['cfg_path'], window, values)

        if event == 'save_cfg_path':
            new_cfg = values['save_cfg_path']
            if new_cfg:
                window['cfg_path'].Update(new_cfg)
                ConfigControls.update_cfg_filename(window, new_cfg)
                ConfigControls.save_cfg(new_cfg, window, values)

        if event == 'load_cfg_path':
            new_cfg = values['load_cfg_path']
            if new_cfg:
                cfg_load(window, event, values, new_cfg)
                secondary_event = 'load'
                event, values = window.read(timeout=100)

        if event == 'run_chrome':
            if values['gui.chrome_path'] and values['general.chrome_dev_port']:
                chrome_cmd_list = [
                    values['gui.chrome_path'], '--remote-debugging-port=' +
                    str(values['general.chrome_dev_port'])
                ]
                Log.log_msg(f"Running chrome: {' '.join(chrome_cmd_list)}")
                subprocess.run(chrome_cmd_list)

        if event == 'run_kcauto':
            timeout = 150
            # automatically switch to log tab
            GuiTabButtonsLayout.switch_to_tab(window, 'log')

            # generate run command for kcauto
            run_cmd_list = values['gui.python_command'].split(' ')
            run_cmd_list.extend(
                ['kcauto', '--cli', '--cfg-path', window['cfg_path'].Get()])
            if not values['gui.track_clicks']:
                run_cmd_list.append('--no-click-track')
            if values['gui.debug_output']:
                run_cmd_list.append('--debug-output')

            # run kcauto
            Log.log_msg(f"Running kcauto: {' '.join(run_cmd_list)}")
            kcauto_proc = RuntimeLogger.run_command(run_cmd_list)
            proc_reader = threading.Thread(target=RuntimeLogger.output_reader,
                                           args=(kcauto_proc, gui_queue))
            proc_reader.start()
            window['run_kcauto'].Update(disabled=True)
            window['stop_kcauto'].Update(
                disabled=False, button_color=LayoutBase.COLORS_ALERT_BUTTON)
            window.TKroot.bind('<Escape>',
                               lambda e, w=window, k=kcauto_proc, p=
                               proc_reader: esc_bind(e, w, k, p))

        if kcauto_proc and proc_reader:
            # process messages from kcauto to logger
            kcauto_proc_poll = (RuntimeLogger.process_queue(
                window, kcauto_proc, gui_queue))

        if event == 'stop_kcauto' or kcauto_proc_poll is not None:
            RuntimeLogger.terminate(window, kcauto_proc, proc_reader)
            window['run_kcauto'].Update(disabled=False)
            window['stop_kcauto'].Update(
                disabled=True,
                button_color=LayoutBase.COLORS_ALERT_BUTTON_DISABLED)
            kcauto_proc_poll = None
            timeout = None

        update_gui(window, event, values)

        if secondary_event == 'load':
            window['scheduler.rules'].Update(window['scheduler.rules'].Values)
            secondary_event = None

    RuntimeLogger.terminate(window, kcauto_proc, proc_reader)
    window.close()
    Log.log_success("Shutting down kcauto GUI.")
Esempio n. 6
0
    def __init__(self, window_title: str = None, theme: str = "dark"):
        """
        Constructor for the GUI

        :param window_title: (optional) Title in the upper bar of the window.
        :param theme: (optional) dark or light (default dark).
        """

        #  --- L A Y O U T ---
        # M A I N   W I N D O W
        self.window = tk.Tk()
        # Configuration:
        self.theme = theme
        self.active_color = "#ad7fa8"
        self.bg_default = None
        self.fg_default = None
        self.window_config(window_title)

        # W I D G E T S
        # --- Frames:
        self.frm_image = ttk.Frame(master=self.window, style="Booklet.TFrame")
        self.frm_notebook = ttk.Frame(master=self.window,
                                      style="Booklet.TFrame")
        self.frm_settings = ttk.Frame(master=self.frm_notebook,
                                      style="Booklet.TFrame")
        self.frm_colormap = ttk.Frame(master=self.frm_notebook,
                                      style="Booklet.TFrame")

        # --- Labels:
        # self.lbl_date = None

        # IMAGE
        header_image_dark = tk.PhotoImage(
            file=join_path(STORE, "Fibonacci-dark.png")).subsample(2, 2)
        header_image_light = tk.PhotoImage(
            file=join_path(STORE, "Fibonacci-light.png")).subsample(2, 2)
        self.img_head_light = ttk.Label(self.frm_image,
                                        image=header_image_light,
                                        style="Title.TLabel")
        self.img_head_dark = ttk.Label(self.frm_image,
                                       image=header_image_dark,
                                       style="Title.TLabel")

        # TITLE
        self.lbl_title = ttk.Label(self.window,
                                   text='Booklet Machine',
                                   style="Title.TLabel")

        # NOTEBOOK
        self.ntb_instance = ttk.Notebook(self.frm_notebook,
                                         style="NB.TNotebook")

        self.frm_browse = BrowseIO()
        self.ntb_instance.add(self.frm_browse, text="Home")

        self.frm_settings = Settings(self.window_config)
        self.ntb_instance.add(self.frm_settings, text="Settings")

        # P A K S
        self.frm_image.pack(fill=tk.BOTH, expand=True)  # Packed in Window
        self.update_image()
        self.lbl_title.pack(fill=tk.BOTH, expand=True, padx=10,
                            pady=10)  # Packed in window

        self.frm_notebook.pack(fill=tk.BOTH, expand=True)  # Packed in window
        self.ntb_instance.pack(fill=tk.BOTH, expand=True, padx=10,
                               pady=10)  # Packed in Notebook

        # M A I N - L O O P
        self.main_loop()