def __init__(self, *args, **kw): if "text" in kw: self.text_var = kw.pop("text") kw["text"] = self.text_var.get() else: self.text_var = StringVar("") Checkbutton.__init__(self, *args, **kw) self.text_var.trace_variable("w", self.on_var_changed)
def __init__(self, *args, **kw): text = kw.get("text", "") if isinstance(text, variables): kw["text"] = text.get() Checkbutton.__init__(self, *args, **kw) # `StringVar` requires its master to be initialized. if not isinstance(text, variables): text = StringVar(self, text) self.text_var = text text.trace_variable("w", self.on_var_changed)
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 __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_gui(self): """init helper""" window = PanedWindow(self.root, orient="vertical") window.pack(side=TOP, fill=BOTH, expand=True) top_pane = Frame(window) window.add(top_pane) mid_pane = Frame(window) window.add(mid_pane) bottom_pane = Frame(window) window.add(bottom_pane) #setting up frames top_frame = Frame(top_pane) mid_frame = Frame(top_pane) history_frame = Frame(top_pane) radio_frame = Frame(mid_pane) rating_frame = Frame(mid_pane) res_frame = Frame(mid_pane) check_frame = Frame(bottom_pane) msg_frame = Frame(bottom_pane) btn_frame = Frame(bottom_pane) top_frame.pack(side=TOP, fill=X) mid_frame.pack(side=TOP, fill=X) history_frame.pack(side=TOP, fill=BOTH, expand=True) radio_frame.pack(side=TOP, fill=X) rating_frame.pack(side=TOP, fill=X) res_frame.pack(side=TOP, fill=BOTH, expand=True) check_frame.pack(side=TOP, fill=X) msg_frame.pack(side=TOP, fill=BOTH, expand=True) btn_frame.pack(side=TOP, fill=X) # Binding F5 application-wide to run lint self.root.bind('<F5>', self.run_lint) #Message ListBox rightscrollbar = Scrollbar(msg_frame) rightscrollbar.pack(side=RIGHT, fill=Y) bottomscrollbar = Scrollbar(msg_frame, orient=HORIZONTAL) bottomscrollbar.pack(side=BOTTOM, fill=X) self.lb_messages = Listbox( msg_frame, yscrollcommand=rightscrollbar.set, xscrollcommand=bottomscrollbar.set, bg="white") self.lb_messages.bind("<Double-Button-1>", self.show_sourcefile) self.lb_messages.pack(expand=True, fill=BOTH) rightscrollbar.config(command=self.lb_messages.yview) bottomscrollbar.config(command=self.lb_messages.xview) #History ListBoxes rightscrollbar2 = Scrollbar(history_frame) rightscrollbar2.pack(side=RIGHT, fill=Y) bottomscrollbar2 = Scrollbar(history_frame, orient=HORIZONTAL) bottomscrollbar2.pack(side=BOTTOM, fill=X) self.showhistory = Listbox( history_frame, yscrollcommand=rightscrollbar2.set, xscrollcommand=bottomscrollbar2.set, bg="white") self.showhistory.pack(expand=True, fill=BOTH) rightscrollbar2.config(command=self.showhistory.yview) bottomscrollbar2.config(command=self.showhistory.xview) self.showhistory.bind('<Double-Button-1>', self.select_recent_file) self.set_history_window() #status bar self.status = Label(self.root, text="", bd=1, relief=SUNKEN, anchor=W) self.status.pack(side=BOTTOM, fill=X) #labelbl_ratingls lbl_rating_label = Label(rating_frame, text='Rating:') lbl_rating_label.pack(side=LEFT) lbl_rating = Label(rating_frame, textvariable=self.rating) lbl_rating.pack(side=LEFT) Label(mid_frame, text='Recently Used:').pack(side=LEFT) Label(top_frame, text='Module or package').pack(side=LEFT) #file textbox self.txt_module = Entry(top_frame, background='white') self.txt_module.bind('<Return>', self.run_lint) self.txt_module.pack(side=LEFT, expand=True, fill=X) #results box rightscrollbar = Scrollbar(res_frame) rightscrollbar.pack(side=RIGHT, fill=Y) bottomscrollbar = Scrollbar(res_frame, orient=HORIZONTAL) bottomscrollbar.pack(side=BOTTOM, fill=X) self.results = Listbox( res_frame, yscrollcommand=rightscrollbar.set, xscrollcommand=bottomscrollbar.set, bg="white", font="Courier") self.results.pack(expand=True, fill=BOTH, side=BOTTOM) rightscrollbar.config(command=self.results.yview) bottomscrollbar.config(command=self.results.xview) #buttons Button(top_frame, text='Open', command=self.file_open).pack(side=LEFT) Button(top_frame, text='Open Package', command=(lambda: self.file_open(package=True))).pack(side=LEFT) self.btnRun = Button(top_frame, text='Run', command=self.run_lint) self.btnRun.pack(side=LEFT) Button(btn_frame, text='Quit', command=self.quit).pack(side=BOTTOM) #radio buttons self.information_box = IntVar() self.convention_box = IntVar() self.refactor_box = IntVar() self.warning_box = IntVar() self.error_box = IntVar() self.fatal_box = IntVar() i = Checkbutton(check_frame, text="Information", fg=COLORS['(I)'], variable=self.information_box, command=self.refresh_msg_window) c = Checkbutton(check_frame, text="Convention", fg=COLORS['(C)'], variable=self.convention_box, command=self.refresh_msg_window) r = Checkbutton(check_frame, text="Refactor", fg=COLORS['(R)'], variable=self.refactor_box, command=self.refresh_msg_window) w = Checkbutton(check_frame, text="Warning", fg=COLORS['(W)'], variable=self.warning_box, command=self.refresh_msg_window) e = Checkbutton(check_frame, text="Error", fg=COLORS['(E)'], variable=self.error_box, command=self.refresh_msg_window) f = Checkbutton(check_frame, text="Fatal", fg=COLORS['(F)'], variable=self.fatal_box, command=self.refresh_msg_window) i.select() c.select() r.select() w.select() e.select() f.select() i.pack(side=LEFT) c.pack(side=LEFT) r.pack(side=LEFT) w.pack(side=LEFT) e.pack(side=LEFT) f.pack(side=LEFT) #check boxes self.box = StringVar() # XXX should be generated report = Radiobutton( radio_frame, text="Report", variable=self.box, value="Report", command=self.refresh_results_window) raw_met = Radiobutton( radio_frame, text="Raw metrics", variable=self.box, value="Raw metrics", command=self.refresh_results_window) dup = Radiobutton( radio_frame, text="Duplication", variable=self.box, value="Duplication", command=self.refresh_results_window) ext = Radiobutton( radio_frame, text="External dependencies", variable=self.box, value="External dependencies", command=self.refresh_results_window) stat = Radiobutton( radio_frame, text="Statistics by type", variable=self.box, value="Statistics by type", command=self.refresh_results_window) msg_cat = Radiobutton( radio_frame, text="Messages by category", variable=self.box, value="Messages by category", command=self.refresh_results_window) msg = Radiobutton( radio_frame, text="Messages", variable=self.box, value="Messages", command=self.refresh_results_window) source_file = Radiobutton( radio_frame, text="Source File", variable=self.box, value="Source File", command=self.refresh_results_window) report.select() report.grid(column=0, row=0, sticky=W) raw_met.grid(column=1, row=0, sticky=W) dup.grid(column=2, row=0, sticky=W) msg.grid(column=3, row=0, sticky=W) stat.grid(column=0, row=1, sticky=W) msg_cat.grid(column=1, row=1, sticky=W) ext.grid(column=2, row=1, sticky=W) source_file.grid(column=3, row=1, sticky=W) #dictionary for check boxes and associated error term self.msg_type_dict = { 'I': lambda: self.information_box.get() == 1, 'C': lambda: self.convention_box.get() == 1, 'R': lambda: self.refactor_box.get() == 1, 'E': lambda: self.error_box.get() == 1, 'W': lambda: self.warning_box.get() == 1, 'F': lambda: self.fatal_box.get() == 1 } self.txt_module.focus_set()
def init_gui(self): """init helper""" window = PanedWindow(self.root, orient="vertical") window.pack(side=TOP, fill=BOTH, expand=True) top_pane = Frame(window) window.add(top_pane) mid_pane = Frame(window) window.add(mid_pane) bottom_pane = Frame(window) window.add(bottom_pane) #setting up frames top_frame = Frame(top_pane) mid_frame = Frame(top_pane) history_frame = Frame(top_pane) radio_frame = Frame(mid_pane) rating_frame = Frame(mid_pane) res_frame = Frame(mid_pane) check_frame = Frame(bottom_pane) msg_frame = Frame(bottom_pane) btn_frame = Frame(bottom_pane) top_frame.pack(side=TOP, fill=X) mid_frame.pack(side=TOP, fill=X) history_frame.pack(side=TOP, fill=BOTH, expand=True) radio_frame.pack(side=TOP, fill=X) rating_frame.pack(side=TOP, fill=X) res_frame.pack(side=TOP, fill=BOTH, expand=True) check_frame.pack(side=TOP, fill=X) msg_frame.pack(side=TOP, fill=BOTH, expand=True) btn_frame.pack(side=TOP, fill=X) # Binding F5 application-wide to run lint self.root.bind('<F5>', self.run_lint) #Message ListBox rightscrollbar = Scrollbar(msg_frame) rightscrollbar.pack(side=RIGHT, fill=Y) bottomscrollbar = Scrollbar(msg_frame, orient=HORIZONTAL) bottomscrollbar.pack(side=BOTTOM, fill=X) self.lb_messages = Listbox(msg_frame, yscrollcommand=rightscrollbar.set, xscrollcommand=bottomscrollbar.set, bg="white") self.lb_messages.bind("<Double-Button-1>", self.show_sourcefile) self.lb_messages.pack(expand=True, fill=BOTH) rightscrollbar.config(command=self.lb_messages.yview) bottomscrollbar.config(command=self.lb_messages.xview) #History ListBoxes rightscrollbar2 = Scrollbar(history_frame) rightscrollbar2.pack(side=RIGHT, fill=Y) bottomscrollbar2 = Scrollbar(history_frame, orient=HORIZONTAL) bottomscrollbar2.pack(side=BOTTOM, fill=X) self.showhistory = Listbox(history_frame, yscrollcommand=rightscrollbar2.set, xscrollcommand=bottomscrollbar2.set, bg="white") self.showhistory.pack(expand=True, fill=BOTH) rightscrollbar2.config(command=self.showhistory.yview) bottomscrollbar2.config(command=self.showhistory.xview) self.showhistory.bind('<Double-Button-1>', self.select_recent_file) self.set_history_window() #status bar self.status = Label(self.root, text="", bd=1, relief=SUNKEN, anchor=W) self.status.pack(side=BOTTOM, fill=X) #labelbl_ratingls lbl_rating_label = Label(rating_frame, text='Rating:') lbl_rating_label.pack(side=LEFT) lbl_rating = Label(rating_frame, textvariable=self.rating) lbl_rating.pack(side=LEFT) Label(mid_frame, text='Recently Used:').pack(side=LEFT) Label(top_frame, text='Module or package').pack(side=LEFT) #file textbox self.txt_module = Entry(top_frame, background='white') self.txt_module.bind('<Return>', self.run_lint) self.txt_module.pack(side=LEFT, expand=True, fill=X) #results box rightscrollbar = Scrollbar(res_frame) rightscrollbar.pack(side=RIGHT, fill=Y) bottomscrollbar = Scrollbar(res_frame, orient=HORIZONTAL) bottomscrollbar.pack(side=BOTTOM, fill=X) self.results = Listbox(res_frame, yscrollcommand=rightscrollbar.set, xscrollcommand=bottomscrollbar.set, bg="white", font="Courier") self.results.pack(expand=True, fill=BOTH, side=BOTTOM) rightscrollbar.config(command=self.results.yview) bottomscrollbar.config(command=self.results.xview) #buttons Button(top_frame, text='Open', command=self.file_open).pack(side=LEFT) Button(top_frame, text='Open Package', command=(lambda: self.file_open(package=True))).pack(side=LEFT) self.btnRun = Button(top_frame, text='Run', command=self.run_lint) self.btnRun.pack(side=LEFT) Button(btn_frame, text='Quit', command=self.quit).pack(side=BOTTOM) #radio buttons self.information_box = IntVar() self.convention_box = IntVar() self.refactor_box = IntVar() self.warning_box = IntVar() self.error_box = IntVar() self.fatal_box = IntVar() i = Checkbutton(check_frame, text="Information", fg=COLORS['(I)'], variable=self.information_box, command=self.refresh_msg_window) c = Checkbutton(check_frame, text="Convention", fg=COLORS['(C)'], variable=self.convention_box, command=self.refresh_msg_window) r = Checkbutton(check_frame, text="Refactor", fg=COLORS['(R)'], variable=self.refactor_box, command=self.refresh_msg_window) w = Checkbutton(check_frame, text="Warning", fg=COLORS['(W)'], variable=self.warning_box, command=self.refresh_msg_window) e = Checkbutton(check_frame, text="Error", fg=COLORS['(E)'], variable=self.error_box, command=self.refresh_msg_window) f = Checkbutton(check_frame, text="Fatal", fg=COLORS['(F)'], variable=self.fatal_box, command=self.refresh_msg_window) i.select() c.select() r.select() w.select() e.select() f.select() i.pack(side=LEFT) c.pack(side=LEFT) r.pack(side=LEFT) w.pack(side=LEFT) e.pack(side=LEFT) f.pack(side=LEFT) #check boxes self.box = StringVar() # XXX should be generated report = Radiobutton(radio_frame, text="Report", variable=self.box, value="Report", command=self.refresh_results_window) raw_met = Radiobutton(radio_frame, text="Raw metrics", variable=self.box, value="Raw metrics", command=self.refresh_results_window) dup = Radiobutton(radio_frame, text="Duplication", variable=self.box, value="Duplication", command=self.refresh_results_window) ext = Radiobutton(radio_frame, text="External dependencies", variable=self.box, value="External dependencies", command=self.refresh_results_window) stat = Radiobutton(radio_frame, text="Statistics by type", variable=self.box, value="Statistics by type", command=self.refresh_results_window) msg_cat = Radiobutton(radio_frame, text="Messages by category", variable=self.box, value="Messages by category", command=self.refresh_results_window) msg = Radiobutton(radio_frame, text="Messages", variable=self.box, value="Messages", command=self.refresh_results_window) source_file = Radiobutton(radio_frame, text="Source File", variable=self.box, value="Source File", command=self.refresh_results_window) report.select() report.grid(column=0, row=0, sticky=W) raw_met.grid(column=1, row=0, sticky=W) dup.grid(column=2, row=0, sticky=W) msg.grid(column=3, row=0, sticky=W) stat.grid(column=0, row=1, sticky=W) msg_cat.grid(column=1, row=1, sticky=W) ext.grid(column=2, row=1, sticky=W) source_file.grid(column=3, row=1, sticky=W) #dictionary for check boxes and associated error term self.msg_type_dict = { 'I': lambda: self.information_box.get() == 1, 'C': lambda: self.convention_box.get() == 1, 'R': lambda: self.refactor_box.get() == 1, 'E': lambda: self.error_box.get() == 1, 'W': lambda: self.warning_box.get() == 1, 'F': lambda: self.fatal_box.get() == 1 } self.txt_module.focus_set()
def on_var_changed(self, *args): Checkbutton.config(self, text = self.text_var.get())
def __init__(self, root, *args, **kw): GUIDialog.__init__(self, master=root, *args, **kw) self.qom_type_var = root.qom_type_var self.title(_("Device Tree")) self.grid() self.columnconfigure(0, weight=1, minsize=300) self.columnconfigure(2, weight=1, minsize=100) self.rowconfigure(0, weight=1) geom = "+" + str(int(root.winfo_rootx())) \ + "+" + str(int(root.winfo_rooty())) self.geometry(geom) self.focus() self.device_tree = dt = VarTreeview(self, selectmode="browse") dt["columns"] = "Macros" dt.heading("#0", text=_("Devices")) dt.heading("Macros", text=_("Macros")) dt.bind("<ButtonPress-1>", self.on_b1_press_dt) dt.grid(row=0, column=0, sticky="NEWS") add_scrollbars_native(self, dt) column_fr = Frame(self, borderwidth=0) column_fr.grid(row=0, column=2, rowspan=2, sticky="SEWN") column_fr.columnconfigure(0, weight=1) column_fr.rowconfigure(0, weight=1) column_fr.rowconfigure(1, weight=1, minsize=100) fr_at = VarLabelFrame(column_fr, text=_("Architecture filter")) fr_at.grid(row=0, column=0, sticky="SEWN") self.fr_qt = VarLabelFrame(column_fr, text=_("Select QOM type")) self.fr_qt.grid(row=1, column=0, sticky="SEWN") self.add_button = VarButton(column_fr, text=_("Select"), command=self.on_select_qom_type) self.add_button.grid(row=2, column=0, sticky="EW") self.add_button.config(state="disabled") qtype_dt = self.qtype_dt = qvd_get( root.mach.project.build_path, version=root.mach.project.target_version).qvc.device_tree arch_buttons = Frame(fr_at, borderwidth=0) arch_buttons.pack(fill="x") arch_buttons.columnconfigure(0, weight=1, minsize=60) arch_buttons.columnconfigure(1, weight=1, minsize=60) arch_buttons.columnconfigure(2, weight=1, minsize=60) bt_all_arches = VarButton(arch_buttons, text=_("All"), command=self.select_arches) bt_all_arches.grid(row=0, column=0, sticky="EW") bt_none_arches = VarButton(arch_buttons, text=_("None"), command=self.deselect_arches) bt_none_arches.grid(row=0, column=1, sticky="EW") bt_invert_arches = VarButton(arch_buttons, text=_("Invert"), command=self.invert_arches) bt_invert_arches.grid(row=0, column=2, sticky="EW") if not qtype_dt.arches: bt_all_arches.config(state="disabled") bt_none_arches.config(state="disabled") bt_invert_arches.config(state="disabled") arch_selector_outer = Frame(fr_at, borderwidth=0) arch_selector_outer.pack(fill="both", anchor="w") arch_selector, scrolltag = add_scrollbars_with_tags( arch_selector_outer, GUIFrame) ac = self.arches_checkbox = [] for a in sorted(list(qtype_dt.arches)): v = IntVar() c = Checkbutton(arch_selector, text = a, variable = v, command = lambda arch = a, var = v: \ self.on_toggle_arch(arch, var) ) c.pack(expand=1, anchor="w") c.bindtags((scrolltag, ) + c.bindtags()) c.select() ac.append(c) # key: item # value: ItemDesc self.detached_items = {} self.all_items = {} self.disabled_arches = set() self.qom_create_tree("", qtype_dt.children)