def __init__( self, parent: tk.Misc, *, tool_frame: tk.Frame, tool_img: str, menu_bar: tk.Menu, tool_col: int=0, title: str='', resize_x: bool=False, resize_y: bool=False, name: str='', ) -> None: self.visible = tk.BooleanVar(parent, True) self.win_name = name self.allow_snap = False self.can_save = False self.parent = parent self.relX = 0 self.relY = 0 self.can_resize_x = resize_x self.can_resize_y = resize_y super().__init__(parent, name='pane_' + name) self.withdraw() # Hide by default self.tool_button = make_tool_button( frame=tool_frame, img=tool_img, command=self._toggle_win, ) self.tool_button.state(('pressed',)) self.tool_button.grid( row=0, column=tool_col, # Contract the spacing to allow the icons to fit. padx=(2 if utils.MAC else (5, 2)), ) tooltip.add_tooltip( self.tool_button, text=gettext('Hide/Show the "{}" window.').format(title)) menu_bar.add_checkbutton( label=title, variable=self.visible, command=self._set_state_from_menu, ) self.transient(master=parent) self.resizable(resize_x, resize_y) self.title(title) tk_tools.set_window_icon(self) self.protocol("WM_DELETE_WINDOW", self.hide_win) parent.bind('<Configure>', self.follow_main, add=True) self.bind('<Configure>', self.snap_win) self.bind('<FocusIn>', self.enable_snap)
def __init__(self, title: str, text: str): super().__init__(TK_ROOT) self.withdraw() self.title(title) self.transient(master=TK_ROOT) self.resizable(width=True, height=True) self.text = text tk_tools.set_window_icon(self) # Hide when the exit button is pressed, or Escape # on the keyboard. self.protocol("WM_DELETE_WINDOW", self.withdraw) self.bind("<Escape>", self.withdraw) frame = tk.Frame(self, background='white') frame.grid(row=0, column=0, sticky='nsew') self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.textbox = tkRichText(frame, width=80, height=24) self.textbox.configure(background='white', relief='flat') self.textbox.grid(row=0, column=0, sticky='nsew') frame.grid_columnconfigure(0, weight=1) frame.grid_rowconfigure(0, weight=1) scrollbox = tk_tools.HidingScroll( frame, orient='vertical', command=self.textbox.yview, ) scrollbox.grid(row=0, column=1, sticky='ns') self.textbox['yscrollcommand'] = scrollbox.set ttk.Button( frame, text=gettext('Close'), command=self.withdraw, ).grid( row=1, column=0, )
# All the auto-created checkbox variables VARS: Dict[Tuple[str, str], BooleanVar] = {} def reset_all_win() -> None: """Return all windows to their default positions. This is replaced by `UI.reset_panes`. """ pass win = Toplevel(TK_ROOT) win.transient(master=TK_ROOT) tk_tools.set_window_icon(win) win.title(_('BEE2 Options')) win.withdraw() def show() -> None: """Display the option window.""" win.deiconify() contextWin.hide_context() # Ensure this closes utils.center_win(win) def load() -> None: """Load the current settings from config.""" for var in VARS.values(): var.load() # type: ignore
def init(cback: Callable[[dict[str, str]], None]) -> None: """Build the properties window widgets.""" global callback callback = cback win.title("BEE2") win.resizable(False, False) tk_tools.set_window_icon(win) win.protocol("WM_DELETE_WINDOW", exit_win) if utils.MAC: # Switch to use the 'modal' window style on Mac. TK_ROOT.call('::tk::unsupported::MacWindowStyle', 'style', win, 'moveableModal', '') # Stop our init from triggering UI sounds. sound.block_fx() frame = ttk.Frame(win, padding=10) frame.grid(row=0, column=0, sticky='NSEW') frame.rowconfigure(0, weight=1) frame.columnconfigure(0, weight=1) labels['noOptions'] = ttk.Label(frame, text=gettext('No Properties available!')) widgets['saveButton'] = ttk.Button(frame, text=gettext('Close'), command=exit_win) widgets['titleLabel'] = ttk.Label(frame, text='') widgets['titleLabel'].grid(columnspan=9) widgets['div_1'] = ttk.Separator(frame, orient="vertical") widgets['div_2'] = ttk.Separator(frame, orient="vertical") widgets['div_h'] = ttk.Separator(frame, orient="horizontal") for key, (prop_type, prop_name) in PROP_TYPES.items(): # Translate property names from Valve's files. if prop_name.startswith('PORTAL2_'): prop_name = gameMan.translate(prop_name) + ':' labels[key] = ttk.Label(frame, text=prop_name) if prop_type is PropTypes.CHECKBOX: values[key] = tk.IntVar(value=DEFAULTS[key]) out_values[key] = srctools.bool_as_int(DEFAULTS[key]) widgets[key] = ttk.Checkbutton( frame, variable=values[key], command=func_partial(set_check, key), ) widgets[key].bind('<Return>', func_partial( toggle_check, key, values[key], )) elif prop_type is PropTypes.OSCILLATE: values[key] = tk.IntVar(value=DEFAULTS[key]) out_values[key] = srctools.bool_as_int(DEFAULTS[key]) widgets[key] = ttk.Checkbutton( frame, variable=values[key], command=func_partial(save_rail, key), ) elif prop_type is PropTypes.PANEL: frm = ttk.Frame(frame) widgets[key] = frm values[key] = tk.StringVar(value=DEFAULTS[key]) for pos, (angle, disp_angle) in enumerate(PANEL_ANGLES): ttk.Radiobutton( frm, variable=values[key], value=str(angle), text=gameMan.translate(disp_angle), command=func_partial(save_angle, key, angle), ).grid(row=0, column=pos) frm.columnconfigure(pos, weight=1) elif prop_type is PropTypes.GELS: frm = ttk.Frame(frame) widgets[key] = frm values[key] = tk.IntVar(value=DEFAULTS[key]) for pos, text in enumerate(PAINT_OPTS): ttk.Radiobutton( frm, variable=values[key], value=pos, text=gameMan.translate(text), command=func_partial(save_paint, key, pos), ).grid(row=0, column=pos) frm.columnconfigure(pos, weight=1) out_values[key] = str(DEFAULTS[key]) elif prop_type is PropTypes.PISTON: widgets[key] = pist_scale = ttk.Scale( frame, from_=0, to=4, orient="horizontal", command=func_partial(save_pist, key), ) values[key] = DEFAULTS[key] out_values[key] = str(DEFAULTS[key]) if ((key == 'toplevel' and DEFAULTS['startup']) or (key == 'bottomlevel' and not DEFAULTS['startup'])): pist_scale.set( max(DEFAULTS['toplevel'], DEFAULTS['bottomlevel'])) if ((key == 'toplevel' and not DEFAULTS['startup']) or (key == 'bottomlevel' and DEFAULTS['startup'])): pist_scale.set( min(DEFAULTS['toplevel'], DEFAULTS['bottomlevel'])) elif prop_type is PropTypes.TIMER: widgets[key] = ttk.Scale( frame, from_=0, to=30, orient="horizontal", command=func_partial(save_tim, key), ) values[key] = DEFAULTS[key] values['startup'] = DEFAULTS['startup']
def init_widgets(): """Make all the window components.""" win.columnconfigure(0, weight=1) win.transient(master=TK_ROOT) tk_tools.set_window_icon(win) win.protocol("WM_DELETE_WINDOW", quit) win.bind("<Escape>", quit) pane = PanedWindow( win, orient=VERTICAL, sashpad=2, # Padding above/below panes sashwidth=3, # Width of border sashrelief=RAISED, # Raise the border between panes ) UI['pane'] = pane pane.grid(row=1, column=0, sticky='NSEW') win.rowconfigure(1, weight=1) UI['tabs'] = ttk.Notebook(pane) UI['tabs'].enable_traversal() # Add keyboard shortcuts pane.add(UI['tabs']) pane.paneconfigure(UI['tabs'], minsize=50) trans_frame = ttk.Frame(pane) trans_frame.rowconfigure(1, weight=1) trans_frame.columnconfigure(0, weight=1) ttk.Label( trans_frame, text=_('Transcript:'), ).grid( row=0, column=0, sticky=W, ) trans_inner_frame = ttk.Frame(trans_frame, borderwidth=2, relief='sunken') trans_inner_frame.grid(row=1, column=0, sticky='NSEW') trans_inner_frame.rowconfigure(0, weight=1) trans_inner_frame.columnconfigure(0, weight=1) default_bold_font = font.nametofont('TkDefaultFont').copy() default_bold_font['weight'] = 'bold' UI['trans'] = Text( trans_inner_frame, width=10, height=4, wrap='word', relief='flat', state='disabled', font='TkDefaultFont', ) UI['trans_scroll'] = tk_tools.HidingScroll( trans_inner_frame, orient=VERTICAL, command=UI['trans'].yview, ) UI['trans'].tag_config( 'bold', font=default_bold_font, ) UI['trans']['yscrollcommand'] = UI['trans_scroll'].set UI['trans_scroll'].grid(row=0, column=1, sticky='NS') UI['trans'].grid(row=0, column=0, sticky='NSEW') ttk.Button( win, text=_('Save'), command=save, ).grid(row=2, column=0) # Don't allow resizing the transcript box to be smaller than the # original size. trans_frame.update_idletasks() pane.paneconfigure(trans_frame, minsize=trans_frame.winfo_reqheight())