def __init__(self, *args, **kwargs): self.bit_opt_map = {} self.checkvars = {} self.checkbtns = {} data_frame.DataFrame.__init__(self, *args, **kwargs) self.content = tk.Frame(self, highlightthickness=0) self.display_comment() self.title_label = tk.Label( self.content, text=self.gui_name, width=self.title_size, anchor='w', disabledforeground=self.text_disabled_color, font=self.get_font("default")) if self.gui_name != '': self.title_label.pack(side='left') self.check_canvas = tk.Canvas(self.content, highlightthickness=0) self.check_frame = tk.Frame(self.check_canvas, bd=self.listbox_depth, relief='sunken', highlightthickness=0) self.scrollbar_y = tk.Scrollbar(self.content, orient='vertical', command=self.check_canvas.yview) self.check_canvas.config(yscrollcommand=self.scrollbar_y.set, yscrollincrement=1, xscrollincrement=1) self.check_frame_id = self.check_canvas.create_window( (0, 0), window=self.check_frame, anchor='nw') if e_c.IS_LNX: self.check_frame.bind('<4>', self.mousewheel_scroll_y) self.check_frame.bind('<5>', self.mousewheel_scroll_y) self.check_canvas.bind('<4>', self.mousewheel_scroll_y) self.check_canvas.bind('<5>', self.mousewheel_scroll_y) else: self.check_frame.bind('<MouseWheel>', self.mousewheel_scroll_y) self.check_canvas.bind('<MouseWheel>', self.mousewheel_scroll_y) self.populate() self._initialized = True
def __init__(self, *args, **kwargs): kwargs.update(relief='flat', bd=0, highlightthickness=0, bg=self.default_bg_color) data_frame.DataFrame.__init__(self, *args, **kwargs) # make the widgets self.entry_string = tk.StringVar(self) self.content = tk.Frame(self, relief='flat', bd=0) self.title_label = tk.Label( self.content, text=self.gui_name, justify='left', anchor='w', width=self.title_size, disabledforeground=self.text_disabled_color) self.data_entry = tk.Entry(self.content, textvariable=self.entry_string, justify='left') self.data_entry.bind('<Return>', self.flush) self.data_entry.bind('<FocusOut>', self.flush) self.write_trace(self.entry_string, self.set_modified) if self.gui_name != '': self.title_label.pack(side="left", fill="x") self.sidetip_label = tk.Label(self.content, anchor='w', justify='left') self.populate() self._initialized = True
def __init__(self, *args, **kwargs): field_widget.FieldWidget.__init__(self, *args, **kwargs) if self.f_widget_parent is None: self.pack_padx = self.pack_pady = 0 kwargs.update(relief='flat', bd=0, highlightthickness=0) show_frame = bool(kwargs.pop('show_frame', not self.blocks_start_hidden)) if self.is_empty and self.hide_if_blank: show_frame = False tk.Frame.__init__(self, *args, **e_c.fix_kwargs(**kwargs)) self.show = tk.BooleanVar(self) self.show.set(show_frame) toggle_text = '-' if show_frame else '+' self.title = tk.Frame(self, relief='raised') self.content = tk.Frame(self, relief="sunken") self.show_btn = ttk.Checkbutton( self.title, width=3, text=toggle_text, command=self.toggle_visible, style='ShowButton.TButton') self.title_label = tk.Label( self.title, text=self.gui_name, anchor='w', width=self.title_size, justify='left', font=self.get_font("frame_title")) self.title_label.font_type = "frame_title" self.import_btn = ttk.Button( self.title, width=7, text='Import', command=self.import_node) self.export_btn = ttk.Button( self.title, width=7, text='Export', command=self.export_node) self.show_btn.pack(side="left") self.title_label.pack(side="left", fill="x", expand=True) self.title.pack(fill="x", expand=True) for w in (self.export_btn, self.import_btn): w.pack(side="right", padx=(0, 4), pady=2) self.populate() self._initialized = True
def __init__(self, *args, **kwargs): kwargs.update(relief='flat', bd=0, highlightthickness=0) data_frame.DataFrame.__init__(self, *args, **kwargs) try: sel_index = self.node.get_index() except Exception: sel_index = -1 # make the widgets self.content = tk.Frame(self, relief='flat', bd=0) self.display_comment() self.title_label = tk.Label( self.content, text=self.gui_name, justify='left', anchor='w', width=self.title_size, disabledforeground=self.text_disabled_color) self.sel_menu = ScrollMenu(self.content, f_widget_parent=self, menu_width=self.widget_width, sel_index=sel_index, max_index=self.desc.get('ENTRIES', 0) - 1, disabled=self.disabled, default_text="<INVALID>", option_getter=self.get_options, callback=self.select_option) if self.gui_name != '': self.title_label.pack(side="left", fill="x") self.content.pack(fill="x", expand=True) self.sel_menu.pack(side="left", fill="x") self.populate() self.pose_fields() self._initialized = True
def __init__(self, *args, **kwargs): kwargs.update(relief='flat', bd=0, highlightthickness=0) data_frame.DataFrame.__init__(self, *args, **kwargs) sel_index = -1 if self.node is None else self.node + 1 # make the widgets self.content = tk.Frame(self, relief='flat', bd=0) self.title_label = tk.Label( self.content, text=self.gui_name, justify='left', anchor='w', width=self.title_size, disabledforeground=self.text_disabled_color) self.sel_menu = ScrollMenu(self.content, f_widget_parent=self, menu_width=self.widget_width, sel_index=sel_index, max_index=0, disabled=self.disabled, default_text="<INVALID>", option_getter=self.get_options, callback=self.select_option) self.sel_menu.bind('<FocusIn>', self.flag_sanity_change) self.sel_menu.arrow_button.bind('<FocusIn>', self.flag_sanity_change) self.sel_menu.bind('<Enter>', self.flag_sanity_change) self.sel_menu.arrow_button.bind('<Enter>', self.flag_sanity_change) self.sel_menu.options_volatile = 'DYN_NAME_PATH' in self.desc if self.gui_name != '': self.title_label.pack(side="left", fill="x") self.content.pack(fill="x", expand=True) self.sel_menu.pack(side="left", fill="x") self.populate() self._initialized = True
def pose_fields(self): # there should only be one wid in here, but for # the sake of consistancy we'll loop over them. for wid in self.f_widget_ids: w = self.f_widgets[wid] # by adding a fixed amount of padding, we fix a problem # with difficult to predict padding based on nesting w.pack(fill='x', side='top', expand=True, padx=self.vertical_padx, pady=self.vertical_pady) # if there are no children in the content, we need to # pack in SOMETHING, update the idletasks, and then # destroy that something to resize the content frame if not self.f_widgets: f = tk.Frame(self.content, width=0, height=0, bd=0) f.pack() self.content.update_idletasks() f.destroy() self.content.pack(fill='both', side='top', anchor='nw', expand=True)
def populate(self): '''Destroys and rebuilds this widgets children.''' orient = self.desc.get('ORIENT', 'v')[:1].lower() vertical = True assert orient in ('v', 'h') content = self if getattr(self, 'content', None): content = self.content if self.show_title and content in (None, self): content = tk.Frame(self, relief="sunken", bd=self.frame_depth, bg=self.default_bg_color) self.content = content # clear the f_widget_ids list self.f_widget_ids = [] self.f_widget_ids_map = {} self.f_widget_ids_map_inv = {} # destroy all the child widgets of the content for w in self.f_widgets.values(): w.destroy() node = self.node desc = self.desc picker = self.widget_picker tag_window = self.tag_window self.display_comment(self.content) # if the orientation is horizontal, remake its label if orient == 'h': vertical = False self.title_label = tk.Label(self, anchor='w', justify='left', width=self.title_size, text=self.gui_name, bg=self.default_bg_color, fg=self.text_normal_color) if self.gui_name != '': self.title_label.pack(fill="x", side="left") self.sidetip_label = tk.Label(self, anchor='w', justify='left', bg=self.default_bg_color, fg=self.text_normal_color) for w in (self, self.content): w.tooltip_string = self.desc.get('TOOLTIP') if getattr(self, 'title', None): self.title.tooltip_string = self.tooltip_string if getattr(self, 'title_label', None): self.title_label.tooltip_string = self.tooltip_string field_indices = range(desc['ENTRIES']) # if the node has a steptree node, include its index in the indices if 'STEPTREE' in desc: field_indices = tuple(field_indices) + ('STEPTREE', ) kwargs = dict(parent=node, tag_window=tag_window, f_widget_parent=self, disabled=self.disabled, vert_oriented=vertical) visible_field_count = self.visible_field_count # if only one sub-widget being displayed, dont # display the title of the widget being displayed if self.field_count != visible_field_count and visible_field_count < 2: if 'STEPTREE' not in desc or not self.get_visible( desc['STEPTREE'].get('VISIBLE', True)): # only make the title not shown if the only # visible widget will not be the subtree kwargs.update(show_title=False) kwargs.update(dont_padx_fields=True) if self.dont_padx_fields: kwargs.update(pack_padx=0) elif visible_field_count < 2 and not self.show_title: # Use this widgets x padding amount so that its # singular child appears where this widget would. kwargs.update(use_parent_pack_padx=True) # loop over each field and make its widget sub_node = None for i in field_indices: sub_desc = desc[i] if hasattr(node, "__getitem__"): sub_node = node[i] if hasattr(sub_node, 'desc'): sub_desc = sub_node.desc # if the field shouldnt be visible, dont make its widget if not self.get_visible(sub_desc.get('VISIBLE', True)): continue widget_cls = picker.get_widget(sub_desc) if i == field_indices[-1] and vertical: kwargs.update(pack_pady=0) try: widget = widget_cls(content, node=sub_node, attr_index=i, desc=sub_desc, **kwargs) except Exception: print(format_exc()) widget = data_frame.NullFrame(content, node=sub_node, attr_index=i, desc=sub_desc, **kwargs) wid = id(widget) self.f_widget_ids.append(wid) self.f_widget_ids_map[i] = wid self.f_widget_ids_map_inv[wid] = i self.build_f_widget_cache() # now that the field widgets are created, position them if self.show.get(): self.pose_fields()
def __init__(self, *args, **kwargs): field_widget.FieldWidget.__init__(self, *args, **kwargs) orient = self.desc.get('ORIENT', 'v')[:1].lower() assert orient in ('v', 'h') self.show_title = kwargs.pop( 'show_title', orient == 'v' and self.f_widget_parent is not None) # if only one sub-widget being displayed, dont display the title if not self.show_title or self.visible_field_count < 2: self.show_title = False self.dont_padx_fields = True if self.f_widget_parent is None: self.pack_padx = self.pack_pady = 0 kwargs.update(relief='flat', bd=0, highlightthickness=0) show_frame = True if self.f_widget_parent is not None: show_frame = bool( kwargs.pop('show_frame', not self.blocks_start_hidden)) if self.is_empty and self.hide_if_blank: show_frame = False tk.Frame.__init__(self, *args, **e_c.fix_kwargs(**kwargs)) self.show = tk.BooleanVar(self) # if the orientation is vertical, make a title frame if self.show_title: self.show.set(show_frame) toggle_text = '-' if show_frame else '+' self.title = tk.Frame(self, relief='raised') self.show_btn = ttk.Checkbutton(self.title, width=3, text=toggle_text, command=self.toggle_visible, style='ShowButton.TButton') self.title_label = tk.Label(self.title, text=self.gui_name, anchor='w', width=self.title_size, justify='left', font=self.get_font("frame_title")) self.title_label.font_type = "frame_title" self.import_btn = ttk.Button(self.title, width=7, text='Import', command=self.import_node) self.export_btn = ttk.Button(self.title, width=7, text='Export', command=self.export_node) self.show_btn.pack(side="left") if self.gui_name != '': self.title_label.pack(fill="x", expand=True, side="left") for w in (self.export_btn, self.import_btn): w.pack(side="right", padx=(0, 4), pady=2) self.title.pack(fill="x", expand=True) else: self.show.set(True) self.populate() self._initialized = True
def __init__(self, *args, **kwargs): field_widget.FieldWidget.__init__(self, *args, **kwargs) self.u_node_widgets_by_u_index = {} if self.f_widget_parent is None: self.pack_padx = self.pack_pady = 0 kwargs.update(relief='flat', bd=0, highlightthickness=0, bg=self.default_bg_color) show_frame = bool( kwargs.pop('show_frame', not self.blocks_start_hidden)) if self.is_empty and self.hide_if_blank: show_frame = False tk.Frame.__init__(self, *args, **e_c.fix_kwargs(**kwargs)) self.show = tk.BooleanVar(self) self.show.set(show_frame) max_u_index = len(self.desc['CASE_MAP']) u_index = getattr(self.node, "u_index", None) if u_index is None: u_index = max_u_index toggle_text = '-' if show_frame else '+' self.title = tk.Frame(self, relief='raised') self.show_btn = ttk.Checkbutton(self.title, width=3, text=toggle_text, command=self.toggle_visible, style='ShowButton.TButton') self.title_label = tk.Label(self.title, text=self.gui_name, anchor='w', width=self.title_size, justify='left') self.title_label.font_type = "frame_title" self.sel_menu = ScrollMenu(self.title, f_widget_parent=self, sel_index=u_index, max_index=max_u_index, disabled=self.disabled, callback=self.select_option, option_getter=self.get_options) self.show_btn.pack(side="left") self.title_label.pack(side="left", fill="x", expand=True) self.sel_menu.pack(side="left", fill="x") self.title.pack(fill="x", expand=True) self.content = tk.Frame(self, relief="sunken") # make the default raw bytes union frame self.raw_frame = tk.Frame(self.content, relief="flat", bd=0) self.raw_label = tk.Label(self.raw_frame, text='DataUnion', width=self.title_size, anchor='w', disabledforeground=self.text_disabled_color) self.import_btn = ttk.Button(self.raw_frame, text='Import', command=self.import_node, width=7) self.export_btn = ttk.Button(self.raw_frame, text='Export', command=self.export_node, width=7) self.raw_label.pack(side="left", expand=True, fill='x') for w in (self.export_btn, self.import_btn): w.pack(side="left", padx=(0, 4), pady=2) self.populate() self._initialized = True
def __init__(self, master, *args, **kwargs): BinillaWidget.__init__(self) self.temp_root = kwargs.pop('temp_root', self.temp_root) textures = kwargs.pop('textures', ()) app_root = kwargs.pop('app_root', ()) self.image_canvas_ids = [] self.textures = [] self._image_handlers = {} temp_name = str(int(random.random() * (1 << 32))) self.temp_dir = os.path.join(self.temp_root, temp_name) kwargs.update(relief='flat', bd=self.frame_depth, bg=self.default_bg_color) tk.Frame.__init__(self, master, *args, **kwargs) self.bitmap_index = tk.IntVar(self) self.mipmap_index = tk.IntVar(self) self.depth_index = tk.IntVar(self) self.channel_index = tk.IntVar(self) self.cube_display_index = tk.IntVar(self) self.root_canvas = tk.Canvas(self, highlightthickness=0) self.root_frame = tk.Frame(self.root_canvas, highlightthickness=0) # create the root_canvas and the root_frame within the canvas self.controls_frame0 = tk.Frame(self.root_frame, highlightthickness=0) self.controls_frame1 = tk.Frame(self.root_frame, highlightthickness=0) self.controls_frame2 = tk.Frame(self.root_frame, highlightthickness=0) self.image_root_frame = tk.Frame(self.root_frame, highlightthickness=0) self.image_canvas = tk.Canvas(self.image_root_frame, highlightthickness=0, bg=self.bitmap_canvas_bg_color) self.depth_canvas = tk.Canvas(self.image_canvas, highlightthickness=0, bg=self.bitmap_canvas_bg_color) self.bitmap_menu = ScrollMenu(self.controls_frame0, menu_width=7, variable=self.bitmap_index, can_scroll=True) self.mipmap_menu = ScrollMenu(self.controls_frame1, menu_width=7, variable=self.mipmap_index, can_scroll=True) self.depth_menu = ScrollMenu(self.controls_frame2, menu_width=7, variable=self.depth_index, can_scroll=True) self.channel_menu = ScrollMenu(self.controls_frame0, menu_width=9, variable=self.channel_index, can_scroll=True) self.cube_display_menu = ScrollMenu(self.controls_frame1, menu_width=9, variable=self.cube_display_index, options=("cross", "linear"), can_scroll=True) self.save_button = ttk.Button(self.controls_frame2, width=11, text="Browse", command=self.save_as) self.depth_menu.default_text = self.mipmap_menu.default_text =\ self.bitmap_menu.default_text =\ self.channel_menu.default_text =\ self.cube_display_menu.default_text = "" labels = [] labels.append(tk.Label(self.controls_frame0, text="Bitmap index")) labels.append(tk.Label(self.controls_frame1, text="Mipmap level")) labels.append(tk.Label(self.controls_frame2, text="Depth level")) labels.append(tk.Label(self.controls_frame0, text="Channels")) labels.append(tk.Label(self.controls_frame1, text="Cubemap display")) labels.append(tk.Label(self.controls_frame2, text="Save to file")) for lbl in labels: lbl.config(width=15, anchor='w', bg=self.default_bg_color, fg=self.text_normal_color, disabledforeground=self.text_disabled_color) self.hsb = tk.Scrollbar(self, orient="horizontal", command=self.root_canvas.xview) self.vsb = tk.Scrollbar(self, orient="vertical", command=self.root_canvas.yview) self.root_canvas.config(xscrollcommand=self.hsb.set, xscrollincrement=1, yscrollcommand=self.vsb.set, yscrollincrement=1) for w in [ self.root_frame, self.root_canvas, self.image_canvas, self.controls_frame0, self.controls_frame1, self.controls_frame2 ] + labels: if e_c.IS_LNX: w.bind('<Shift-4>', self.mousewheel_scroll_x) w.bind('<Shift-5>', self.mousewheel_scroll_x) w.bind('<4>', self.mousewheel_scroll_y) w.bind('<5>', self.mousewheel_scroll_y) else: w.bind('<Shift-MouseWheel>', self.mousewheel_scroll_x) w.bind('<MouseWheel>', self.mousewheel_scroll_y) # pack everything # pack in this order so scrollbars aren't shrunk self.root_frame_id = self.root_canvas.create_window( (0, 0), anchor="nw", window=self.root_frame) self.hsb.pack(side='bottom', fill='x', anchor='nw') self.vsb.pack(side='right', fill='y', anchor='nw') self.root_canvas.pack(fill='both', anchor='nw', expand=True) self.controls_frame0.pack(side='top', fill='x', anchor='nw') self.controls_frame1.pack(side='top', fill='x', anchor='nw') self.controls_frame2.pack(side='top', fill='x', anchor='nw') self.image_root_frame.pack(fill='both', anchor='nw', expand=True) self.image_canvas.pack(fill='both', side='right', anchor='nw', expand=True) padx = self.horizontal_padx pady = self.horizontal_pady for lbl in labels[:3]: lbl.pack(side='left', padx=(25, 0), pady=pady) self.bitmap_menu.pack(side='left', padx=padx, pady=pady) self.mipmap_menu.pack(side='left', padx=padx, pady=pady) self.depth_menu.pack(side='left', padx=padx, pady=pady) for lbl in labels[3:]: lbl.pack(side='left', padx=(15, 0), pady=pady) self.save_button.pack(side='left', padx=padx, pady=pady) self.channel_menu.pack(side='left', padx=padx, pady=pady) self.cube_display_menu.pack(side='left', padx=padx, pady=pady) self.change_textures(textures) self.write_trace(self.bitmap_index, self.settings_changed) self.write_trace(self.mipmap_index, self.settings_changed) self.write_trace(self.depth_index, self.settings_changed) self.write_trace(self.cube_display_index, self.settings_changed) self.write_trace(self.channel_index, self.settings_changed) self.apply_style()
def post_toplevel_init(self): self.update_title() try: self.iconbitmap(self.iconbitmap_filepath) except Exception: print("Could not load window icon.") self.creating_label = tk.Label( self, text=("Creating widgets. Please wait...")) self.styling_label = tk.Label(self, text=("Styling widgets. Please wait...")) # create the root_canvas and the root_frame within the canvas self.root_canvas = rc = tk.Canvas(self, highlightthickness=0) self.root_frame = rf = tk.Frame(rc, highlightthickness=0) # create and set the x and y scrollbars for the root_canvas self.root_hsb = tk.Scrollbar(self, orient='horizontal', command=rc.xview) self.root_vsb = tk.Scrollbar(self, orient='vertical', command=rc.yview) rc.config(xscrollcommand=self.root_hsb.set, xscrollincrement=1, yscrollcommand=self.root_vsb.set, yscrollincrement=1) self.root_frame_id = rc.create_window((0, 0), window=rf, anchor='nw') # make it so if this window is selected it changes the # selected_tag attribute of self.app_root to self.tag self.bind('<Button>', self.select_window) self.bind('<FocusIn>', self.select_window) rf.bind('<Configure>', self._resize_canvas) rc.bind('<Configure>', self._resize_frame) # make the window not show up on the start bar if self.app_root: self.transient(self.app_root) # populate the window self.creating_label.pack(fill="both", expand=True) self.populate() # pack da stuff self.root_hsb.pack(side=t_c.BOTTOM, fill='x') self.root_vsb.pack(side=t_c.RIGHT, fill='y') # set the hotkey bindings self.bind_hotkeys() # if this tag doesnt exist at the given filepath, it's new. try: new = not self.tag.filepath.is_file() except Exception: new = True if new: try: self.field_widget.set_edited() except Exception: pass self.creating_label.pack_forget()
def setup_window(self, *args, **kwargs): ConverterBase.setup_window(self, *args, **kwargs) self.include_weather_polyhedra = tk.IntVar(self, 1) self.include_fog_planes = tk.IntVar(self, 1) self.include_portals = tk.IntVar(self, 1) self.include_collision = tk.IntVar(self, 1) self.include_renderable = tk.IntVar(self, 1) self.include_mirrors = tk.IntVar(self, 0) self.include_lightmaps = tk.IntVar(self, 0) self.include_markers = tk.IntVar(self, 1) self.include_lens_flares = tk.IntVar(self, 0) self.fan_portals = tk.IntVar(self, 1) self.fan_weather_polyhedra = tk.IntVar(self, 1) self.fan_fog_planes = tk.IntVar(self, 1) self.fan_mirrors = tk.IntVar(self, 1) self.fan_collision = tk.IntVar(self, 1) self.optimize_portals = tk.IntVar(self, 0) self.optimize_fog_planes = tk.IntVar(self, 0) self.weather_tolerance_string = tk.StringVar( self, str(self.weather_tolerance)) self.weather_tolerance_string.trace( "w", lambda *a, s=self: s.set_weather_tolerance()) # make the frames self.include_frame = tk.LabelFrame(self, text="Geometry/markers to include") self.weather_tolerance_frame = tk.LabelFrame( self, text="Weather polyhedron tolerance") self.topology_frame = tk.LabelFrame(self, text="Topology generation") # Generate the important frame and its contents include_vars = { "Weather polyhedra": self.include_weather_polyhedra, "Fog planes": self.include_fog_planes, "Portals": self.include_portals, "Collidable": self.include_collision, "Renderable": self.include_renderable, "Mirrors": self.include_mirrors, "Lightmaps": self.include_lightmaps, "Markers": self.include_markers, "Lens flares": self.include_lens_flares } self.include_buttons = [] for text in ("Collidable", "Portals", "Renderable", "Weather polyhedra", "Fog planes", "Markers", "Mirrors", "Lens flares", "Lightmaps"): self.include_buttons.append( tk.Checkbutton(self.include_frame, variable=include_vars[text], text=text)) # Generate the topology frame and its contents topology_vars = { "Weather polyhedra": self.fan_weather_polyhedra, "Fog planes": self.fan_fog_planes, "Mirrors": self.fan_mirrors, "Portals": self.fan_portals, "Collision": self.fan_collision } self.topology_frames = [] self.topology_labels = [] self.topology_buttons = [] for text in ("Portals", "Fog planes", "Weather polyhedra", "Mirrors", "Collision"): var = topology_vars[text] f = tk.Frame(self.topology_frame) name_lbl = tk.Label(f, text=text, width=17, anchor="w") fan_cbtn = tk.Checkbutton(f, variable=var, text="Triangle fan") strip_cbtn = tk.Checkbutton(f, variable=var, text="Triangle strip", onvalue=0, offvalue=1) self.topology_frames.append(f) self.topology_labels.append(name_lbl) self.topology_buttons.extend((fan_cbtn, strip_cbtn)) if text == "Portals": self.topology_buttons.append( tk.Checkbutton(f, variable=self.optimize_portals, text="Optimize")) elif text == "Fog planes": self.topology_buttons.append( tk.Checkbutton(f, variable=self.optimize_fog_planes, text="Optimize")) self.weather_tolerance_info = tk.Label( self.weather_tolerance_frame, justify='left', anchor="w", text= ("Due to how weather polyhedrons work, there is no geometry to extract, so it must be generated. \n" "My method for doing this isn't perfect, so sometimes geometry will be missing faces. Adjust this\n" "value to find the sweet spot. NEVER set to 0, and be wary of setting to 0.0001 or higher.\n" "\tNOTE: You will probably need to manually clean up the generated geometry a bit." )) self.weather_tolerance_spinbox = tk.Spinbox( self.weather_tolerance_frame, from_=self.min_weather_tolerance, to=100, width=25, increment=self.weather_tolerance, textvariable=self.weather_tolerance_string, justify="right") self.pack_widgets() self.apply_style()
def populate(self): node = self.node desc = self.desc sub_node = None sub_desc = desc['SUB_STRUCT'] if node and self.sel_index in range(len(node)): sub_node = node[self.sel_index] sub_desc = desc['SUB_STRUCT'] if hasattr(sub_node, 'desc'): sub_desc = sub_node.desc if self.content in (None, self): self.content = tk.Frame(self, relief="sunken", bd=self.frame_depth, bg=self.default_bg_color) self.sel_menu.default_text = sub_desc.get('GUI_NAME', sub_desc.get('NAME', "")) self.sel_menu.update_label() self.disable_unusable_buttons() rebuild = not bool(self.f_widgets) if hasattr(node, '__len__') and len(node) == 0: # disabling existing widgets self.sel_index = -1 self.sel_menu.max_index = -1 if self.f_widgets: self.unload_child_node_data() else: for w in self.f_widgets: if getattr(w, "desc", None) != sub_desc: rebuild = True break if rebuild: # destroy existing widgets and make new ones self.populated = False self.f_widget_ids = [] self.f_widget_ids_map = {} self.f_widget_ids_map_inv = {} # destroy any child widgets of the content for c in list(self.f_widgets.values()): c.destroy() for w in (self, self.content, self.title, self.title_label, self.controls, self.buttons): w.tooltip_string = self.desc.get('TOOLTIP') self.display_comment(self.content) widget_cls = self.widget_picker.get_widget(sub_desc) try: widget = widget_cls(self.content, node=sub_node, parent=node, show_title=False, dont_padx_fields=True, attr_index=self.sel_index, tag_window=self.tag_window, f_widget_parent=self, disabled=self.disabled) except Exception: print(format_exc()) widget = data_frame.NullFrame(self.content, node=sub_node, parent=node, show_title=False, dont_padx_fields=True, attr_index=self.sel_index, tag_window=self.tag_window, f_widget_parent=self, disabled=self.disabled) wid = id(widget) self.f_widget_ids.append(wid) self.f_widget_ids_map[self.sel_index] = wid self.f_widget_ids_map_inv[wid] = self.sel_index self.populated = True self.build_f_widget_cache() # now that the field widgets are created, position them if self.show.get(): self.pose_fields() if self.node is None: self.set_disabled(True) else: self.set_children_disabled(not self.node)
def __init__(self, *args, **kwargs): kwargs.update(relief='flat', bd=0, highlightthickness=0, bg=self.default_bg_color) field_widget.FieldWidget.__init__(self, *args, **kwargs) tk.Frame.__init__(self, *args, **e_c.fix_kwargs(**kwargs)) show_frame = bool( kwargs.pop('show_frame', not self.blocks_start_hidden)) if self.is_empty and self.hide_if_blank: show_frame = False self.show = tk.BooleanVar() self.show.set(show_frame) self.options_sane = False node_len = 0 try: node_len = len(self.node) except Exception: pass self.sel_index = (node_len > 0) - 1 # make the title, element menu, and all the buttons self.controls = tk.Frame(self, relief='raised', bd=self.frame_depth) self.title = title = tk.Frame(self.controls, relief='flat', bd=0) self.buttons = buttons = tk.Frame(self.controls, relief='flat', bd=0) toggle_text = '-' if show_frame else '+' self.title_label = tk.Label( title, text=self.gui_name, justify='left', anchor='w', width=self.title_size, font=self.get_font("frame_title"), disabledforeground=self.text_disabled_color) self.title_label.font_type = "frame_title" self.show_btn = ttk.Checkbutton(title, width=3, text=toggle_text, command=self.toggle_visible, style='ShowButton.TButton') self.sel_menu = ScrollMenu(title, f_widget_parent=self, sel_index=self.sel_index, max_index=node_len - 1, option_getter=self.get_options, callback=self.select_option) self.shift_up_btn = ttk.Button(title, width=7, text='Shift ▲', command=self.shift_entry_up) self.shift_down_btn = ttk.Button(buttons, width=7, text='Shift ▼', command=self.shift_entry_down) self.add_btn = ttk.Button(buttons, width=4, text='Add', command=self.add_entry) self.insert_btn = ttk.Button(buttons, width=6, text='Insert', command=self.insert_entry) self.duplicate_btn = ttk.Button(buttons, width=9, text='Duplicate', command=self.duplicate_entry) self.delete_btn = ttk.Button(buttons, width=6, text='Delete', command=self.delete_entry) self.delete_all_btn = ttk.Button(buttons, width=10, text='Delete all', command=self.delete_all_entries) self.import_btn = ttk.Button(buttons, width=6, text='Import', command=self.import_node) self.export_btn = ttk.Button(buttons, width=6, text='Export', command=self.export_node) # pack the title, menu, and all the buttons for w in (self.shift_down_btn, self.export_btn, self.import_btn, self.delete_all_btn, self.delete_btn, self.duplicate_btn, self.insert_btn, self.add_btn): w.pack(side="right", padx=(0, 4), pady=(2, 2)) self.show_btn.pack(side="left") if self.gui_name != '': self.title_label.pack(side="left", fill="x", expand=True) self.sel_menu.pack(side="left", fill="x", expand=True, padx=(0, 4)) self.shift_up_btn.pack(side="right", padx=(0, 1), pady=(2, 2)) self.title.pack(fill="x", expand=True, padx=0) self.buttons.pack(fill="x", expand=True, padx=0) self.controls.pack(fill="x", expand=True, padx=0) self.populate() self._initialized = True
def __init__(self, app_root, *args, **kwargs): self.app_root = app_root BinillaWidget.__init__(self) tk.Toplevel.__init__(self, app_root, *args, **kwargs) self.list_index_to_window = [] self.title("Tag window manager") self.minsize(width=400, height=250) # make the frames self.windows_frame = tk.Frame(self) self.button_frame = tk.Frame(self) self.ok_frame = tk.Frame(self.button_frame) self.cancel_frame = tk.Frame(self.button_frame) # make the buttons self.ok_button = tk.Button(self.ok_frame, text='OK', width=15, command=self.select) self.cancel_button = tk.Button(self.cancel_frame, text='Cancel', width=15, command=self.destroy) # make the scrollbars and listbox self.scrollbar_y = tk.Scrollbar(self.windows_frame, orient="vertical") self.scrollbar_x = tk.Scrollbar(self, orient="horizontal") self.windows_listbox = tk.Listbox(self.windows_frame, selectmode='single', exportselection=False, highlightthickness=0, xscrollcommand=self.scrollbar_x.set, yscrollcommand=self.scrollbar_y.set) # set up the scrollbars self.scrollbar_x.config(command=self.windows_listbox.xview) self.scrollbar_y.config(command=self.windows_listbox.yview) # set up the keybindings self.windows_listbox.bind('<Return>', self.select) self.scrollbar_x.bind('<Return>', self.select) self.scrollbar_y.bind('<Return>', self.select) self.windows_listbox.bind('<Double-Button-1>', self.select) self.ok_button.bind('<Return>', self.select) self.cancel_button.bind('<Return>', self.destroy) self.bind('<Escape>', self.destroy) # store the windows by title windows_by_title = {} for w in self.app_root.tag_windows.values(): windows_by_title[w.title()] = w # populate the listbox for title in sorted(windows_by_title): self.list_index_to_window.append(windows_by_title[title]) self.windows_listbox.insert('end', title) self.windows_listbox.select_set(0) # pack everything self.ok_button.pack(padx=12, pady=5, side='right') self.cancel_button.pack(padx=12, pady=5, side='left') self.ok_frame.pack(side='left', fill='x', expand=True) self.cancel_frame.pack(side='right', fill='x', expand=True) self.windows_listbox.pack(side='left', fill="both", expand=True) self.scrollbar_y.pack(side='left', fill="y") self.windows_frame.pack(fill="both", expand=True) self.scrollbar_x.pack(fill="x") self.button_frame.pack(fill="x") self.apply_style() self.transient(self.app_root) self.ok_button.focus_set() self.wait_visibility() self.lift() self.grab_set()
def __init__(self, *args, **kwargs): kwargs.update(relief='flat', bd=0, highlightthickness=0, bg=self.default_bg_color) data_frame.DataFrame.__init__(self, *args, **kwargs) # make the widgets self.content = tk.Frame(self, relief='flat', bd=0) self.title_label = tk.Label( self.content, text=self.gui_name, justify='left', anchor='w', disabledforeground=self.text_disabled_color, width=self.title_size) self.data_text = tk.Text( self.content, wrap=tk.NONE, maxundo=self.max_undos, undo=True, height=self.textbox_height, width=self.textbox_width, state=tk.DISABLED if self.disabled else tk.NORMAL) self.sidetip_label = tk.Label(self.content, anchor='w', justify='left') self.hsb = tk.Scrollbar(self.content, orient='horizontal', command=self.data_text.xview) self.vsb = tk.Scrollbar(self.content, orient='vertical', command=self.data_text.yview) self.data_text.config(xscrollcommand=self.hsb.set, yscrollcommand=self.vsb.set) self.hsb.can_scroll = self.children_can_scroll self.vsb.can_scroll = self.children_can_scroll self.data_text.can_scroll = self.children_can_scroll self.hsb.f_widget_parent = self self.vsb.f_widget_parent = self self.data_text.f_widget_parent = self self.data_text.bind('<FocusOut>', self.flush) self.data_text.bind('<Return>', self.set_modified) self.data_text.bind('<Any-KeyPress>', self.set_modified) self.data_text.text_undo = self._text_undo self.data_text.text_redo = self._text_redo self.data_text.bind('<Control-z>', self.disable_undo_redo) self.data_text.bind('<Control-y>', self.disable_undo_redo) if self.gui_name != '': self.title_label.pack(fill="x") self.hsb.pack(side="bottom", fill='x', expand=True) self.vsb.pack(side="right", fill='y') self.data_text.pack(side="right", fill="x", expand=True) self.content.pack(fill="both", expand=True) self.build_replace_map() self.reload() self._initialized = True
def generate_widgets(self): if self._initialized: return pr_version_str = "%s.%s.%s" % version_info[:3] tk_version_str = str(tk.TkVersion) main_frame = tk.Frame(self, borderwidth=0, relief='sunken') buttons_frame = tk.Frame(self) header_frame = tk.Frame(main_frame) py_label_frame = tk.Frame(header_frame, borderwidth=0) app_image_button = None if os.path.isfile(self.appbitmap_filepath): self.app_image = tk.PhotoImage(file=self.appbitmap_filepath) app_image_button = tk.Button(header_frame, text='[picture]', bd=0, image=self.app_image, relief='flat', command=self._pressed, highlightthickness=0) app_name_label = tk.Label(header_frame, text=self.app_name, font=self.get_font("heading")) app_name_label.font_type = "heading" python_ver_label = tk.Label(py_label_frame, text='Python version: %s' % pr_version_str) tk_ver_label = tk.Label(py_label_frame, text='Tk version: %s' % tk_version_str) close_button = tk.Button(buttons_frame, text='Close', width=12, command=self.destroy) modules_frame = tk.Frame(main_frame, borderwidth=0) names = tuple(sorted(self.module_infos)) max_width = 1 if len(names) > 3: max_width = 2 x = y = 0 for name in names: info = self.module_infos[name] proper_name = self.get_proper_module_name(name) accelerated_str = "" if info.get("accelerated", None) is not None: accelerated_str = " - " + ("Fast" if info["accelerated"] else "Slow") module_frame = tk.LabelFrame( modules_frame, text="%s - %s: %s%s" % (info["date"], proper_name, self.get_version_string(name), accelerated_str)) license_button = tk.Button(module_frame, text='License', width=8, command=lambda s=self, n=name: s. display_module_text(n, "license")) readme_button = tk.Button(module_frame, text='Readme', width=8, command=lambda s=self, n=name: s. display_module_text(n, "readme")) browse_button = tk.Button( module_frame, text='Browse', width=8, command=lambda s=self, n=name: s.open_module_location(n)) browse_button.pack(expand=True, fill='both', side='left', padx=6, pady=4) license_button.pack(expand=True, fill='both', side='left', padx=6, pady=4) readme_button.pack(expand=True, fill='both', side='left', padx=6, pady=4) if not info["location"]: browse_button.config(state="disabled") if not info["license"]: license_button.config(state="disabled") if not info["readme"]: readme_button.config(state="disabled") module_frame.grid(row=y, column=x, sticky="news") x += 1 if x == max_width: x = 0 y += 1 app_name_label.pack(padx=10, fill='both') if app_image_button: app_image_button.pack(padx=0, pady=3) py_label_frame.pack(padx=10, pady=0) python_ver_label.pack(padx=10, pady=0, side='left') tk_ver_label.pack(padx=10, pady=0, side='right') close_button.pack(padx=5, pady=5) header_frame.pack(expand=True, fill="both") main_frame.pack(expand=True, fill="both") modules_frame.pack(fill='both') buttons_frame.pack(fill="x") self._initialized = True
def __init__(self, *args, **kwargs): BinillaWidget.__init__(self) sel_index = kwargs.pop('sel_index', -1) disabled = kwargs.pop('disabled', False) options = kwargs.pop('options', None) self.can_scroll = kwargs.pop('can_scroll', self.can_scroll) self.option_getter = kwargs.pop('option_getter', None) self.callback = kwargs.pop('callback', None) self.variable = kwargs.pop('variable', None) self.str_variable = kwargs.pop('str_variable', None) self.max_index = kwargs.pop('max_index', self.max_index) self.max_height = kwargs.pop('max_height', self.max_height) self.f_widget_parent = kwargs.pop('f_widget_parent', None) self.menu_width = kwargs.pop('menu_width', 0) self.options_volatile = kwargs.pop('options_volatile', False) self.default_text = kwargs.pop('default_text', e_c.INVALID_OPTION) if self.max_height is None: self.max_height = self.scroll_menu_max_height kwargs.update(relief='sunken', bd=self.listbox_depth, bg=self.default_bg_color) tk.Frame.__init__(self, *args, **kwargs) if self.variable is None: self.variable = tk.IntVar(self, sel_index) self.write_trace(self.variable, lambda *a: self.update_label()) menu_width = self.menu_width if self.menu_width else self.scroll_menu_width self.sel_label = tk.Label(self, bg=self.enum_normal_color, fg=self.text_normal_color, bd=2, relief='groove', width=max( min(menu_width, self.scroll_menu_max_width), 1)) # the button_frame is to force the button to be a certain size self.button_frame = tk.Frame(self, relief='flat', height=18, width=18, bd=0) self.button_frame.pack_propagate(0) self.arrow_button = tk.Button(self.button_frame, text="▼", width=2) self.arrow_button.font_type = "fixed_small" self.arrow_button.pack() #self.arrow_button = ttk.Button(self.button_frame, text="▼", width=2) #self.arrow_button.grid(row=1, column=1, sticky='news', # ipadx=0, ipady=0, padx=0, pady=0) self.sel_label.pack(side="left", fill="both", expand=True) self.button_frame.pack(side="left", fill="both") # make the option box to populate option_frame_root = self.winfo_toplevel() if hasattr(option_frame_root, "root_frame"): option_frame_root = option_frame_root.root_frame self.option_frame = tk.Frame(option_frame_root, highlightthickness=0, bd=0) self.option_frame.pack_propagate(0) self.option_bar = tk.Scrollbar(self.option_frame, orient="vertical") self.option_box = tk.Listbox( self.option_frame, highlightthickness=0, exportselection=False, bg=self.enum_normal_color, fg=self.text_normal_color, selectbackground=self.enum_highlighted_color, selectforeground=self.text_highlighted_color, yscrollcommand=self.option_bar.set, width=menu_width) self.option_bar.config(command=self.option_box.yview) # make sure the TagWindow knows these widgets are scrollable for w in (self.sel_label, self.button_frame, self.arrow_button, self.option_frame, self.option_bar, self.option_box): w.can_scroll = self.can_scroll w.f_widget_parent = self.f_widget_parent # make bindings so arrow keys can be used to navigate the menu self.button_frame.bind('<Up>', self.decrement_sel) self.button_frame.bind('<Down>', self.increment_sel) self.arrow_button.bind('<Up>', self.decrement_sel) self.arrow_button.bind('<Down>', self.increment_sel) self.option_bar.bind('<Up>', self.decrement_listbox_sel) self.option_bar.bind('<Down>', self.increment_listbox_sel) if e_c.IS_LNX: self.sel_label.bind('<4>', self._mousewheel_scroll) self.sel_label.bind('<5>', self._mousewheel_scroll) self.button_frame.bind('<4>', self._mousewheel_scroll) self.button_frame.bind('<5>', self._mousewheel_scroll) self.arrow_button.bind('<4>', self._mousewheel_scroll) self.arrow_button.bind('<5>', self._mousewheel_scroll) else: self.sel_label.bind('<MouseWheel>', self._mousewheel_scroll) self.button_frame.bind('<MouseWheel>', self._mousewheel_scroll) self.arrow_button.bind('<MouseWheel>', self._mousewheel_scroll) self.sel_label.bind('<Button-1>', self.click_label) self.arrow_button.bind('<ButtonRelease-1>', self.select_option_box) self.arrow_button.bind('<Return>', self.select_option_box) self.arrow_button.bind('<space>', self.select_option_box) self.option_bar.bind('<FocusOut>', self.deselect_option_box) self.option_bar.bind('<Return>', self.select_menu) self.option_bar.bind('<space>', self.select_menu) self.option_box.bind('<<ListboxSelect>>', self.select_menu) self.set_disabled(disabled) if options is not None: self.set_options(options) if self.str_variable is None: self.str_variable = tk.StringVar(self, "")