def __init__(self, master): ttk.Frame.__init__(self, master) assert isinstance(master, EditorNotebook) self.notebook = master # type: EditorNotebook # parent of codeview will be workbench so that it can be maximized self._code_view = CodeView(get_workbench(), propose_remove_line_numbers=True, font="EditorFont") get_workbench().event_generate("EditorTextCreated", editor=self, text_widget=self.get_text_widget()) self._code_view.grid(row=0, column=0, sticky=tk.NSEW, in_=self) self._code_view.home_widget = self # don't forget home self.maximizable_widget = self._code_view self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self._filename = None self._last_known_mtime = None self._asking_about_external_change = False self._code_view.text.bind("<<Modified>>", self._on_text_modified, True) self._code_view.text.bind("<<TextChange>>", self._on_text_change, True) self._code_view.text.bind("<Control-Tab>", self._control_tab, True) get_workbench().bind("DebuggerResponse", self._listen_debugger_progress, True) get_workbench().bind("ToplevelResponse", self._listen_for_toplevel_response, True) self.update_appearance()
def _init_previews(self): ttk.Label(self, text=tr("Preview")).grid(row=20, column=1, sticky="w", pady=(5, 2), columnspan=5) self._preview_codeview = CodeView(self, height=6, font="EditorFont", relief="groove", borderwidth=1, line_numbers=True) self._preview_codeview.set_content( textwrap.dedent(""" def foo(bar): if bar is None: # """ + tr("This is a comment") + """ print('""" + tr("The answer is") + """', 33) """ + tr("unclosed_string") + ''' = "''' + tr("blah, blah") + "\n").strip()) self._preview_codeview.grid(row=21, column=1, columnspan=5, sticky=tk.NSEW) self._shell_preview = tktextext.TextFrame( self, text_class=BaseShellText, height=4, vertical_scrollbar_style=scrollbar_style("Vertical"), horizontal_scrollbar_style=scrollbar_style("Horizontal"), horizontal_scrollbar_class=ui_utils.AutoScrollbar, relief="groove", borderwidth=1, font="EditorFont", ) self._shell_preview.grid(row=31, column=1, columnspan=5, sticky=tk.NSEW, pady=(5, 5)) self._shell_preview.text.set_read_only(True) self._insert_shell_text() ttk.Label( self, text=tr( "NB! Some style elements change only after restarting Thonny!" ), font="BoldTkDefaultFont", ).grid(row=40, column=1, columnspan=5, sticky="w", pady=(5, 0))
def _init_layout_widgets(self, master, frame_info): self.main_frame= ttk.Frame(self) # just a backgroud behind padding of main_pw, without this OS X leaves white border self.main_frame.grid(sticky=tk.NSEW) self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.main_pw = ui_utils.AutomaticPanedWindow(self.main_frame, orient=tk.VERTICAL) self.main_pw.grid(sticky=tk.NSEW, padx=10, pady=10) self.main_frame.rowconfigure(0, weight=1) self.main_frame.columnconfigure(0, weight=1) self._code_book = ttk.Notebook(self.main_pw) self._text_frame = CodeView(self._code_book, first_line_number=frame_info.firstlineno, font=get_workbench().get_font("EditorFont")) self._code_book.add(self._text_frame, text="Source") self.main_pw.add(self._code_book, minsize=100)
def _create_widgets(self): bg = "#ffff99" banner_frame = tk.Frame(self, background=bg) banner_frame.grid(row=0, column=0, sticky="nsew") banner_frame.rowconfigure(0, weight=1) banner_frame.columnconfigure(0, weight=1) banner_text = tk.Label( banner_frame, text=_("These\nare\ninstructions asdfa afs fa sfasdf"), background=bg, justify="left", ) banner_text.grid(column=0, row=0, pady=10, padx=10, sticky="nsew") main_frame = ttk.Frame(self) main_frame.grid(row=1, column=0, sticky=tk.NSEW, padx=15, pady=15) self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.main_command_text = CodeView(main_frame, height=5) self.main_command_text.grid(column=0, row=1, sticky="nsew") # main_command_text["relief"] = "groove" main_frame.rowconfigure(1, weight=1) main_frame.columnconfigure(0, weight=1) button_frame = ttk.Frame(main_frame) button_frame.grid(row=2, column=0, sticky="nsew") run_button = ttk.Button(button_frame, text=_("Save and execute"), command=self._save_exec) run_button.grid(row=0, column=1, sticky="nsew") ok_button = ttk.Button(button_frame, text=_("Save"), command=self._save) ok_button.grid(row=0, column=2, sticky="nsew") cancel_button = ttk.Button(button_frame, text=_("Cancel"), command=self._cancel) cancel_button.grid(row=0, column=3, sticky="nsew") button_frame.columnconfigure(0, weight=1)
def __init__(self, master, filename=None): ttk.Frame.__init__(self, master) assert isinstance(master, EditorNotebook) # parent of codeview will be workbench so that it can be maximized self._code_view = CodeView(get_workbench(), propose_remove_line_numbers=True, font=get_workbench().get_font("EditorFont")) get_workbench().event_generate("EditorTextCreated", editor=self, text_widget=self.get_text_widget()) self._code_view.grid(row=0, column=0, sticky=tk.NSEW, in_=self) self._code_view.home_widget = self # don't forget home self.maximizable_widget = self._code_view self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self._filename = None self.file_encoding = None if filename is not None: self._load_file(filename) self._code_view.text.edit_modified(False) self._code_view.text.bind("<<Modified>>", lambda e: master.update_editor_title(self), True) self._code_view.text.bind("<Control-Tab>", self._control_tab, True) get_workbench().bind("AfterKnownMagicCommand", self._listen_for_execute, True) get_workbench().bind("ToplevelResult", self._listen_for_toplevel_result, True) self.update_appearance()
def __init__(self, master): self._original_family = get_workbench().get_option( "view.editor_font_family") self._original_size = get_workbench().get_option( "view.editor_font_size") self._original_ui_theme = get_workbench().get_option("view.ui_theme") self._original_syntax_theme = get_workbench().get_option( "view.syntax_theme") self._original_io_family = get_workbench().get_option( "view.io_font_family") self._original_io_size = get_workbench().get_option( "view.io_font_size") ConfigurationPage.__init__(self, master) self._family_variable = create_string_var( self._original_family, modification_listener=self._update_appearance) self._size_variable = create_string_var( self._original_size, modification_listener=self._update_appearance) self._ui_theme_variable = create_string_var( self._original_ui_theme, modification_listener=self._update_appearance) self._syntax_theme_variable = create_string_var( self._original_syntax_theme, modification_listener=self._update_appearance) self._io_family_variable = create_string_var( self._original_io_family, modification_listener=self._update_appearance) self._io_size_variable = create_string_var( self._original_io_size, modification_listener=self._update_appearance) ttk.Label(self, text="UI theme").grid(row=1, column=0, sticky="w", pady=(10, 0)) self._ui_theme_combo = ttk.Combobox( self, exportselection=False, textvariable=self._ui_theme_variable, state="readonly", height=15, values=get_workbench().get_usable_ui_theme_names(), ) self._ui_theme_combo.grid(row=2, column=0, sticky="nsew", padx=(0, 10)) ttk.Label(self, text="Syntax theme").grid(row=1, column=1, sticky="w", pady=(10, 0)) self._syntax_theme_combo = ttk.Combobox( self, exportselection=False, textvariable=self._syntax_theme_variable, state="readonly", height=15, values=get_workbench().get_syntax_theme_names(), ) self._syntax_theme_combo.grid(row=2, column=1, sticky="nsew", padx=(0, 10)) ttk.Label(self, text="Editor font").grid(row=1, column=2, sticky="w", pady=(10, 0)) self._family_combo = ttk.Combobox( self, exportselection=False, state="readonly", height=15, textvariable=self._family_variable, values=self._get_families_to_show(), ) self._family_combo.grid(row=2, column=2, sticky=tk.NSEW, padx=(0, 10)) ttk.Label(self, text="Size").grid(row=1, column=3, sticky="w", pady=(10, 0)) self._size_combo = ttk.Combobox( self, width=4, exportselection=False, textvariable=self._size_variable, state="readonly", height=15, values=[str(x) for x in range(3, 73)], ) self._size_combo.grid(row=2, column=3, sticky="nsew") ttk.Label(self, text="Editor preview").grid(row=3, column=0, sticky="w", pady=(10, 0), columnspan=4) self._preview_codeview = CodeView( self, height=6, font="EditorFont", # relief="sunken", # borderwidth=1, ) self._preview_codeview.set_content( textwrap.dedent(""" def foo(bar): if bar is None: # This is a comment print("The answer is", 33) unclosed_string = "blah, blah """).strip()) self._preview_codeview.grid(row=4, column=0, columnspan=4, sticky=tk.NSEW, pady=(0, 5)) ttk.Label(self, text="Shell font").grid(row=5, column=2, sticky="w", pady=(10, 0)) self._family_combo = ttk.Combobox( self, exportselection=False, state="readonly", height=15, textvariable=self._io_family_variable, values=self._get_families_to_show(), ) self._family_combo.grid(row=6, column=2, sticky=tk.NSEW, padx=(0, 10)) ttk.Label(self, text="Size").grid(row=5, column=3, sticky="w", pady=(10, 0)) self._size_combo = ttk.Combobox( self, width=4, exportselection=False, textvariable=self._io_size_variable, state="readonly", height=15, values=[str(x) for x in range(3, 73)], ) self._size_combo.grid(row=6, column=3, sticky="nsew") ttk.Label(self, text="Shell preview").grid(row=7, column=0, sticky="w", pady=(10, 0), columnspan=4) self._shell_preview = tk.Text(self, height=3) self._shell_preview.grid(row=8, column=0, columnspan=4, sticky=tk.NSEW, pady=(0, 5)) self._insert_shell_text() ttk.Label( self, text="NB! Some style elements change only after restarting Thonny" ).grid(row=9, column=0, columnspan=4, sticky="w", pady=(0, 5)) self.columnconfigure(0, weight=1) self.columnconfigure(1, weight=1) self.columnconfigure(2, weight=1) self.columnconfigure(3, weight=1)