def __init__(self, *args, **kw): QOMDescriptionSettingsWidget.__init__(self, *args, **kw) self.mw = None self.var_tabs = v = BooleanVar() self.buttons_fr.columnconfigure(2, weight=0) chb = VarCheckbutton(self.buttons_fr, text=_("Use tabs"), variable=v) chb.grid(row=0, column=2, sticky="NEWS") v.trace_variable("w", self.__on_tabs__) # mesh step seleection self.buttons_fr.columnconfigure(3, weight=0) self.buttons_fr.columnconfigure(4, weight=0) self.buttons_fr.columnconfigure(5, weight=0) Separator(self.buttons_fr, orient=VERTICAL).grid(row=0, column=3, sticky="NEWS") l = VarLabel(self.buttons_fr, text=_("Mesh step:")) l.grid(row=0, column=4, sticky="NEWS") self.var_mesh_step = v = StringVar() v.trace_variable("w", self.__on_mesh_step) self.mesh_step_sb = sb = Spinbox(self.buttons_fr, from_=MIN_MESH_STEP, to=MAX_MESH_STEP, textvariable=v, width=len(str(MAX_MESH_STEP))) sb.grid(row=0, column=5, sticky="NEWS") self.var_tabs.set(True)
def gen_bool_widgets(self, master): v = BooleanVar() w = Checkbutton(master, variable = v) w._validate = lambda : True w._set_color = lambda color : w.config(selectcolor = color) w._cast = lambda x : x return v, w
def gen_prop_value_widget(self, prop_type, prop_val): if prop_type == QOMPropertyTypeLink: var = StringVar() keys = [ DeviceSettingsWidget.gen_node_link_text(n) \ for n in [ None ] + list(self.dsw.mach.id2node.values()) ] ret = Combobox(self.dsw.props_lf, textvariable = var, values = keys, state = "readonly" ) if prop_val: current = DeviceSettingsWidget.gen_node_link_text(prop_val) else: current = keys[0] var.set(current) elif prop_type == QOMPropertyTypeBoolean: var = BooleanVar() ret = VarCheckbutton( self.dsw.props_lf, text = StringVar(""), variable = var ) if prop_val is None: current = False else: current = bool(prop_val) var.set(current) else: var = StringVar() ret = HKEntry( self.dsw.props_lf, textvariable = var ) if prop_val: if prop_type == QOMPropertyTypeInteger: current = prop_type.build_val(prop_val) else: current = str(prop_val) else: if prop_type == QOMPropertyTypeInteger: current = "0x0" else: current = "" var.set(current) return ret, var
def __init__(self, bus, *args, **kw): SettingsWidget.__init__(self, bus, *args, **kw) self.bus = bus self.bus_fr = fr = GUIFrame(self) fr.pack(fill=BOTH, expand=False) fr.columnconfigure(0, weight=0) fr.columnconfigure(1, weight=1) fr.rowconfigure(0, weight=0) l = VarLabel(fr, text=_("Parent device")) l.grid(row=0, column=0, sticky="NES") self.var_parent = StringVar() self.cb_parent = Combobox(fr, textvariable=self.var_parent, state="readonly") self.cb_parent.grid(row=0, column=1, sticky="NEWS") self.fields = [] if type(bus) is BusNode: self.fields.extend([(_("C type"), "c_type", str), (_("Casting macro"), "cast", str), (_("Child name"), "child_name", str), (_("Always show index"), "force_index", bool)]) # Common bus type for row, (text, field, _type) in enumerate(self.fields, start=1): if _type is str: l = VarLabel(fr, text=text) v = StringVar() w = HKEntry(fr, textvariable=v) elif _type is bool: l = None v = BooleanVar() w = VarCheckbutton(fr, text=text, variable=v) fr.rowconfigure(row, weight=0) if l is None: w.grid(row=row, column=0, sticky="NEWS", columnspan=2) else: l.grid(row=row, column=0, sticky="NES") w.grid(row=row, column=1, sticky="NEWS") setattr(self, "w_" + field, w) setattr(self, "var_" + field, v)
def __init__(self, qom_desc, *args, **kw): GUIFrame.__init__(self, *args, **kw) self.desc = qom_desc try: self.pht = self.winfo_toplevel().pht except AttributeError: self.pht = None # shapshot mode without PHT if self.pht is not None: self.pht.watch_changed(self.__on_changed__) sf = self.settings_fr = GUIFrame(self) sf.pack(fill = BOTH, expand = False) f = self.qomd_fr = GUIFrame(sf) f.pack(fill = BOTH, expand = False) f.columnconfigure(0, weight = 0) f.columnconfigure(1, weight = 1) have_pciid = False for row, (attr, info) in enumerate(qom_desc.__attribute_info__.items()): f.rowconfigure(row, weight = 0) l = VarLabel(f, text = info["short"]) l.grid(row = row, column = 0, sticky = "NES") try: _input = info["input"] except KeyError: # attribute is read-only v = StringVar() w = HKEntry(f, textvariable = v, state="readonly") else: if _input is str: v = StringVar() w = HKEntry(f, textvariable = v) elif _input is int: v = StringVar() w = HKEntry(f, textvariable = v) def validate(varname, junk, act, entry = w, var = v): validate_int(var, entry = entry) v.trace_variable("w", validate) elif _input is PCIId: have_pciid = True """ Value of PCI Id could be presented either by PCIId object or by a string. So the actual widget/variable pair will be assigned during refresh. """ v = None w = GUIFrame(f) w.grid() w.rowconfigure(0, weight = 1) w.columnconfigure(0, weight = 1) elif _input is bool: v = BooleanVar() w = Checkbutton(f, variable = v) else: raise RuntimeError("Input of QOM template attribute %s of" " type %s is not supported" % (attr, _input.__name__) ) w.grid(row = row, column = 1, sticky = "NEWS") setattr(self, "_var_" + attr, v) setattr(self, "_w_" + attr, w) btf = self.buttons_fr = GUIFrame(self) btf.pack(fill = BOTH, expand = False) btf.rowconfigure(0, weight = 0) btf.columnconfigure(0, weight = 1) btf.columnconfigure(1, weight = 0) bt_apply = VarButton(btf, text = _("Apply"), command = self.__on_apply__ ) bt_apply.grid(row = 0, column = 1, sticky = "NEWS") bt_revert = VarButton(btf, text = _("Refresh"), command = self.__on_refresh__ ) bt_revert.grid(row = 0, column = 0, sticky = "NES") self.after(0, self.__refresh__) self.bind("<Destroy>", self.__on_destroy__, "+") self.__have_pciid = have_pciid if have_pciid: self.qsig_watch("qvc_available", self.__on_qvc_available)
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 sb.right(_("Background tasks: ")) sb.repack(CoStatusView(sb), RIGHT) 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)
def __init__(self, mem, *args, **kw): SettingsWidget.__init__(self, mem, *args, **kw) self.mem = mem self.mem_fr = fr = GUIFrame(self) fr.pack(fill=BOTH, expand=False) fr.columnconfigure(0, weight=0) fr.columnconfigure(1, weight=1) fr.rowconfigure(0, weight=0) row = 0 l = VarLabel(fr, text=_("Region type")) l.grid(row=row, column=0, sticky="NES") memtype2str = { MemoryNode: _("Container"), MemorySASNode: _("SAS"), MemoryAliasNode: _("Alias"), MemoryRAMNode: _("RAM"), MemoryROMNode: _("ROM") } l = VarLabel(fr, text=memtype2str[type(mem)]) l.grid(row=row, column=1, sticky="NEWS") row += 1 if not isinstance(mem, MemorySASNode): l = VarLabel(fr, text=_("Parent region")) l.grid(row=row, column=0, sticky="NES") self.var_parent = StringVar() self.cb_parent = Combobox(fr, textvariable=self.var_parent, state="readonly") self.cb_parent.grid(row=row, column=1, sticky="NEWS") row += 1 self.fields = [(_("Name"), "name", CConst), (_("Size"), "size", CConst), (_("Offset"), "offset", CConst), (_("May overlap"), "may_overlap", bool), (_("Priority"), "priority", CConst)] if type(mem) is MemoryAliasNode: self.fields.extend([(_("Alias offset"), "alias_offset", CConst)]) if isinstance(mem, MemorySASNode): self.fields = [(_("Name"), "name", str)] for text, field, _type in self.fields: if _type is bool: l = None v = BooleanVar() w = VarCheckbutton(fr, text=text, variable=v) else: l = VarLabel(fr, text=text) v = StringVar() w = HKEntry(fr, textvariable=v) fr.rowconfigure(row, weight=0) if l is None: w.grid(row=row, column=0, sticky="NWS", columnspan=2) else: l.grid(row=row, column=0, sticky="NES") l.gi = l.grid_info() w.grid(row=row, column=1, sticky="NEWS") w.gi = w.grid_info() row += 1 if l: setattr(self, "l_" + field, l) setattr(self, "w_" + field, w) setattr(self, "var_" + field, v) self.var_name.trace_variable("w", self.__on_name_var_changed) if type(mem) is MemoryAliasNode: l = VarLabel(fr, text=_("Alias region")) l.grid(row=row, column=0, sticky="NES") self.var_alias_to = StringVar() self.cb_alias_to = Combobox(fr, textvariable=self.var_alias_to, state="readonly") self.cb_alias_to.grid(row=row, column=1, sticky="NEWS") if not isinstance(mem, MemorySASNode): if not mem.parent: self.l_offset.grid_forget() self.w_offset.grid_forget()
) for col in kw["columns"]: self.column(col, stretch = False) tv = TestTV(root) tv.grid(row = 0, column = 0, sticky = "NEWS") from six.moves.tkinter import ( BooleanVar, IntVar, DoubleVar ) sv = StringVar(value = "xxx...") bv = BooleanVar(value = True) iv = IntVar(value = 0) dv = DoubleVar(value = 1.0) tv.insert("", 0, values = [sv, bv, iv, dv]) tv.insert("", 1, values = [bv, iv, dv, sv]) tv.insert("", 2, values = [iv, dv, sv, bv]) tv.insert("", 3, values = [dv, sv, bv, iv]) def update(): s = sv.get() s = s[-1] + s[:-1] sv.set(s) bv.set(not bv.get()) iv.set(iv.get() + 1) dv.set(dv.get() + 0.1)
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__()