Example #1
0
    def title(self, stringvar = None):
        """ Add the prefix with node ID. """
        if stringvar is None:
            return GUIToplevel.title(self)

        title = FormatVar("(%u) %%s" % self.node.id) % stringvar
        return GUIToplevel.title(self, title)
Example #2
0
    def __init__(self, *a, **kw):
        color_tasks = kw.pop("color_tasks", "red")
        color_callers = kw.pop("color_callers", "orange")
        color_active = kw.pop("color_active", None)
        color_finished = kw.pop("color_finished", "grey")

        Statusbar.__init__(self, *a, **kw)

        # task_manager property backed value
        self._tm = None

        # create widgets
        for group, c in zip(
                TASK_GROUPS,
            (color_tasks, color_callers, color_active, color_finished)):
            v = IntVar(self)
            setattr(self, "_var_" + group, v)

            lb = self.right(FormatVar(value="%u") % v)
            if c is not None:
                lb.config(fg=c)

        # auto bind to task manager
        guitk = self.winfo_toplevel()
        if isinstance(guitk, GUITk):
            self.task_manager = guitk.task_manager
Example #3
0
    def test_auto_reformat(self):
        fmt = FormatVar(value="Text is '%s'")
        text = StringVar(value="[ a text will be here ]")
        res = fmt % text

        self.assertIsInstance(res, StringVar)

        self.assertEqual(res.get(), "Text is '[ a text will be here ]'")

        def on_w(*__):
            val = res.get()
            # print("New value: %s" % val)
            self._cur_val = val

        res.trace_variable("w", on_w)

        text.set("A text")
        self.assertEqual(self._cur_val, "Text is 'A text'")

        fmt.set("'%s' is text.")
        self.assertEqual(self._cur_val, "'A text' is text.")
Example #4
0
    def __init__(self, project=None):
        GUITk.__init__(self, wait_msec=1)

        for signame in ["qvc_dirtied", "qvd_failed", "qvc_available"]:
            s = CoSignal()
            s.attach(self.signal_dispatcher)
            setattr(self, "sig_" + signame, s)

        self.title_suffix = _("Qemu device creator GUI")
        self.title_suffix.trace_variable("w", self.__on_title_suffix_write__)

        self.title_not_saved_asterisk = StringVar()
        self.title_not_saved_asterisk.trace_variable(
            "w", self.__on_title_suffix_write__)
        self.saved_operation = None

        self.var_title = StringVar()
        self.title(self.var_title)

        # Hot keys, accelerators
        self.hk = hotkeys = HotKey(self)
        hotkeys.add_bindings([
            HotKeyBinding(
                self.invert_history_window,
                key_code=43,
                description=_("If editing history window is hidden then \
show it else hide it."),
                symbol="H"),
            HotKeyBinding(self.on_load,
                          key_code=32,
                          description=_("Load project from file."),
                          symbol="O"),
            HotKeyBinding(self.on_new_project,
                          key_code=57,
                          description=_("Create new project."),
                          symbol="N"),
            HotKeyBinding(self.on_add_description,
                          key_code=40,
                          description=_("Add description to the project"),
                          symbol="D"),
            HotKeyBinding(self.on_set_qemu_build_path,
                          key_code=56,
                          description=_("Set Qemu build path for the project"),
                          symbol="B"),
            HotKeyBinding(
                self.on_sel_tgt_qemu_version,
                key_code=28,
                description=_("Select target Qemu version for the project"),
                symbol="T"),
            HotKeyBinding(self.on_generate,
                          key_code=42,
                          description=_("Launch code generation"),
                          symbol="G"),
            HotKeyBinding(self.on_delete,
                          key_code=24,
                          description=_("Shutdown the application."),
                          symbol="Q"),
            HotKeyBinding(self.undo,
                          key_code=52,
                          description=_("Revert previous editing."),
                          symbol="Z"),
            HotKeyBinding(self.redo,
                          key_code=29,
                          description=_("Make reverted editing again."),
                          symbol="Y"),
            HotKeyBinding(self.on_save,
                          key_code=39,
                          description=_("Save project."),
                          symbol="S"),
            HotKeyBinding(self.on_reload,
                          key_code=27,
                          description=_("Reload current project from file."),
                          symbol="R")
        ])

        # see `set_user_settings`
        self._user_settings = None

        # Menu bar
        menubar = VarMenu(self)

        self.filemenu = filemenu = VarMenu(menubar, tearoff=False)
        filemenu.add_command(label=_("Add description"),
                             command=self.on_add_description,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_add_description))
        filemenu.add_command(label=_("Set Qemu build path"),
                             command=self.on_set_qemu_build_path,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_set_qemu_build_path))
        filemenu.add_command(label=_("Select target Qemu version"),
                             command=self.on_sel_tgt_qemu_version,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_sel_tgt_qemu_version))
        filemenu.add_command(label=_("Generate"),
                             command=self.on_generate,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_generate))
        filemenu.add_separator()
        filemenu.add_command(label=_("New project"),
                             command=self.on_new_project,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_new_project)),
        filemenu.add_command(label=_("Save"),
                             command=self.on_save,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_save)),
        filemenu.add_command(label=_("Save project as..."),
                             command=self.on_save_as)
        filemenu.add_command(label=_("Load"),
                             command=self.on_load,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_load)),
        self.reload_idx = filemenu.count
        filemenu.add_command(label=_("Reload"),
                             command=self.on_reload,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_reload)),
        self.recentmenu = recentmenu = VarMenu(filemenu, tearoff=False)
        filemenu.add_cascade(
            label=_("Recent projects"),
            menu=recentmenu,
            state=DISABLED  # a user settings instance is required
        )

        filemenu.add_separator()
        filemenu.add_command(label=_("Quit"),
                             command=self.quit,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_delete))
        menubar.add_cascade(label=_("File"), menu=filemenu)

        self.editmenu = editmenu = VarMenu(menubar, tearoff=False)
        editmenu.add_command(label=_("Undo"),
                             command=self.undo,
                             accelerator=hotkeys.get_keycode_string(self.undo))
        self.undo_idx = editmenu.count - 1

        editmenu.add_command(label=_("Redo"),
                             command=self.redo,
                             accelerator=hotkeys.get_keycode_string(self.redo))
        self.redo_idx = editmenu.count - 1

        editmenu.add_separator()

        editmenu.add_command(label=_("Rebuild Cache"),
                             command=self.rebuild_cache,
                             accelerator=hotkeys.get_keycode_string(
                                 self.rebuild_cache))

        editmenu.add_separator()

        v = self.var_history_window = BooleanVar()
        v.set(False)

        self.__on_var_history_window = v.trace_variable(
            "w", self.__on_var_history_window__)

        editmenu.add_checkbutton(label=_("Editing history window"),
                                 variable=v,
                                 accelerator=hotkeys.get_keycode_string(
                                     self.invert_history_window))

        menubar.add_cascade(label=_("Edit"), menu=editmenu)

        self.optionsmenu = optionsmenu = VarMenu(menubar, tearoff=False)

        v = self.var_schedule_generation = BooleanVar()
        v.set(False)

        self.__on_var_schedule_generation = v.trace_variable(
            "w", self.__on_var_schedule_generation__)

        optionsmenu.add_checkbutton(
            label=_("Schedule generation after cache loading"), variable=v)

        v = self.var_gen_chunk_graphs = BooleanVar()
        v.set(False)

        self.__on_var_gen_chunk_graphs = v.trace_variable(
            "w", self.__on_var_gen_chunk_graphs__)

        optionsmenu.add_checkbutton(label=_("Generate chunk graphs"),
                                    variable=v)

        menubar.add_cascade(label=_("Options"), menu=optionsmenu)

        self.config(menu=menubar)

        # Widget layout
        self.grid()
        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)

        # Status bar
        self.grid_rowconfigure(1, weight=0)
        self.sb = sb = Statusbar(self)
        sb.grid(row=1, column=0, sticky="NEWS")

        # Target Qemu version in the status bar
        self._target_qemu = Variable(None)

        # This complicated scheme is required because the status must also
        # be updated on language change.
        @as_variable(self._target_qemu, _("No target"), _("Target Qemu: %s"))
        def var_target_qemu(target, no_target, target_qemu):
            if target is None:
                return no_target
            else:
                return target_qemu % target

        sb.left(var_target_qemu)

        # QEMU build path displaying
        self.var_qemu_build_path = StringVar()
        sb.left(self.var_qemu_build_path)

        # Task counters in status bar
        self.var_tasks = vt = IntVar()
        self.var_callers = vc = IntVar()
        self.var_active_tasks = vat = IntVar()
        self.var_finished_tasks = vft = IntVar()
        sb.right(_("Background tasks: "))
        sb.right(FormatVar(value="%u") % vt, fg="red")
        sb.right(FormatVar(value="%u") % vc, fg="orange")
        sb.right(FormatVar(value="%u") % vat)
        sb.right(FormatVar(value="%u") % vft, fg="grey")

        self.task_manager.watch_activated(self.__on_task_state_changed)
        self.task_manager.watch_finished(self.__on_task_state_changed)
        self.task_manager.watch_failed(self.__on_task_state_changed)
        self.task_manager.watch_removed(self.__on_task_state_changed)
        self.signal_dispatcher.watch_failed(self.__on_listener_failed)

        self.protocol("WM_DELETE_WINDOW", self.on_delete)

        self.set_project(GUIProject() if project is None else project)

        self.__update_title__()
        self.__check_saved_asterisk__()

        self.qsig_watch("qvc_available", self.__on_qvc_available)
Example #5
0
    def __init__(self, project=None):
        GUITk.__init__(self, wait_msec=1)

        for signame in ["qvc_dirtied", "qvd_failed", "qvc_available"]:
            s = CoSignal()
            s.attach(self.signal_dispatcher)
            setattr(self, "sig_" + signame, s)

        self.title_suffix = _("Qemu device creator GUI")
        self.title_suffix.trace_variable("w", self.__on_title_suffix_write__)

        self.title_not_saved_asterisk = StringVar()
        self.title_not_saved_asterisk.trace_variable(
            "w", self.__on_title_suffix_write__)
        self.saved_operation = None

        self.var_title = StringVar()
        self.title(self.var_title)

        # Hot keys, accelerators
        self.hk = hotkeys = HotKey(self)
        hotkeys.add_bindings([
            HotKeyBinding(
                self.invert_history_window,
                key_code=43,  # H
                description=_("If editing history window is hidden then \
show it else hide it.")),
            HotKeyBinding(
                self.on_load,
                key_code=32,  # O
                description=_("Load project from file.")),
            HotKeyBinding(
                self.on_new_project,
                key_code=57,  # N
                description=_("Create new project.")),
            HotKeyBinding(
                self.on_add_description,
                key_code=40,  # D
                description=_("Add description to the project")),
            HotKeyBinding(
                self.on_set_qemu_build_path,
                key_code=56,  # B
                description=_("Set Qemu build path for the project")),
            HotKeyBinding(
                self.on_generate,
                key_code=42,  # G
                description=_("Launch code generation")),
            HotKeyBinding(
                self.on_delete,
                key_code=24,  # Q
                description=_("Shutdown the application.")),
            HotKeyBinding(
                self.undo,
                key_code=52,  # Z
                description=_("Revert previous editing.")),
            HotKeyBinding(
                self.redo,
                key_code=29,  # Y
                description=_("Make reverted editing again.")),
            HotKeyBinding(
                self.on_save,
                key_code=39,  # S
                description=_("Save project.")),
            HotKeyBinding(
                self.rebuild_cache,
                key_code=27,  # R
                description=_("Rebuild Cache."))
        ])

        hotkeys.add_key_symbols({
            27: "R",
            43: "H",
            32: "O",
            57: "N",
            40: "D",
            56: "B",
            42: "G",
            24: "Q",
            52: "Z",
            29: "Y",
            39: "S"
        })

        # Menu bar
        menubar = VarMenu(self)

        filemenu = VarMenu(menubar, tearoff=False)
        filemenu.add_command(label=_("Add description"),
                             command=self.on_add_description,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_add_description))
        filemenu.add_command(label=_("Set Qemu build path"),
                             command=self.on_set_qemu_build_path,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_set_qemu_build_path))
        filemenu.add_command(label=_("Generate"),
                             command=self.on_generate,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_generate))
        filemenu.add_separator()
        filemenu.add_command(label=_("New project"),
                             command=self.on_new_project,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_new_project)),
        filemenu.add_command(label=_("Save"),
                             command=self.on_save,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_save)),
        filemenu.add_command(label=_("Save project as..."),
                             command=self.on_save_as)
        filemenu.add_command(label=_("Load"),
                             command=self.on_load,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_load)),
        filemenu.add_separator()
        filemenu.add_command(label=_("Quit"),
                             command=self.quit,
                             accelerator=hotkeys.get_keycode_string(
                                 self.on_delete))
        menubar.add_cascade(label=_("File"), menu=filemenu)

        self.editmenu = editmenu = VarMenu(menubar, tearoff=False)
        editmenu.add_command(label=_("Undo"),
                             command=self.undo,
                             accelerator=hotkeys.get_keycode_string(self.undo))
        self.undo_idx = editmenu.count - 1

        editmenu.add_command(label=_("Redo"),
                             command=self.redo,
                             accelerator=hotkeys.get_keycode_string(self.redo))
        self.redo_idx = editmenu.count - 1

        editmenu.add_separator()

        editmenu.add_command(label=_("Rebuild Cache"),
                             command=self.rebuild_cache,
                             accelerator=hotkeys.get_keycode_string(
                                 self.rebuild_cache))

        editmenu.add_separator()

        v = self.var_history_window = BooleanVar()
        v.set(False)

        self.__on_var_history_window = v.trace_variable(
            "w", self.__on_var_history_window__)

        editmenu.add_checkbutton(label=_("Editing history window"),
                                 variable=v,
                                 accelerator=hotkeys.get_keycode_string(
                                     self.invert_history_window))

        menubar.add_cascade(label=_("Edit"), menu=editmenu)

        self.config(menu=menubar)

        # Widget layout
        self.grid()
        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)

        # Status bar
        self.grid_rowconfigure(1, weight=0)
        self.sb = sb = Statusbar(self)
        sb.grid(row=1, column=0, sticky="NEWS")

        # QEMU build path displaying
        self.var_qemu_build_path = StringVar()
        sb.left(self.var_qemu_build_path)

        # Task counters in status bar
        self.var_tasks = vt = IntVar()
        self.var_callers = vc = IntVar()
        self.var_active_tasks = vat = IntVar()
        self.var_finished_tasks = vft = IntVar()
        sb.right(_("Background tasks: "))
        sb.right(FormatVar(value="%u") % vt, fg="red")
        sb.right(FormatVar(value="%u") % vc, fg="orange")
        sb.right(FormatVar(value="%u") % vat)
        sb.right(FormatVar(value="%u") % vft, fg="grey")

        self.task_manager.watch_activated(self.__on_task_state_changed)
        self.task_manager.watch_finished(self.__on_task_state_changed)
        self.task_manager.watch_failed(self.__on_task_state_changed)
        self.task_manager.watch_removed(self.__on_task_state_changed)

        self.protocol("WM_DELETE_WINDOW", self.on_delete)

        self.set_project(GUIProject() if project is None else project)

        self.__update_title__()
        self.__check_saved_asterisk__()