def __init__(self, master, proc, title, long_description=None, autoclose=True): self._proc = proc self.stdout = "" self.stderr = "" self._stdout_thread = None self._stderr_thread = None self.returncode = None self.cancelled = False self._autoclose = autoclose self._event_queue = collections.deque() tk.Toplevel.__init__(self, master) self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) main_frame = ttk.Frame(self) # To get styled background main_frame.grid(sticky="nsew") text_font=tk.font.nametofont("TkFixedFont").copy() #text_font["size"] = int(text_font["size"] * 0.9) text_font["family"] = "Courier" if running_on_mac_os() else "Courier New" text_frame = tktextext.TextFrame(main_frame, read_only=True, horizontal_scrollbar=False, #vertical_scrollbar=False, background=get_main_background(), font=text_font, wrap="word") text_frame.grid(row=0, column=0, sticky=tk.NSEW, padx=15, pady=15) self.text = text_frame.text self.text["width"] = 60 self.text["height"] = 12 if long_description is not None: self.text.direct_insert("1.0", long_description + "\n\n") self.button = ttk.Button(main_frame, text="Cancel", command=self._close) self.button.grid(row=1, column=0, pady=(0,15)) main_frame.rowconfigure(0, weight=1) main_frame.columnconfigure(0, weight=1) self.title(title) if misc_utils.running_on_mac_os(): self.configure(background="systemSheetBackground") #self.resizable(height=tk.FALSE, width=tk.FALSE) self.transient(master) self.grab_set() # to make it active and modal self.text.focus_set() self.bind('<Escape>', self._close_if_done, True) # escape-close only if process has completed self.protocol("WM_DELETE_WINDOW", self._close) center_window(self, master) self._start_listening()
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_log_frame(self): self.log_frame = ttk.Frame(self) self.log_frame.columnconfigure(1, weight=1) self.log_frame.rowconfigure(1, weight=1) fixed_font = tk.font.nametofont("TkFixedFont") font = fixed_font.copy() font.configure(size=round(fixed_font.cget("size") * 0.8)) self.log_text = tktextext.TextFrame( self.log_frame, horizontal_scrollbar=False, wrap="word", borderwidth=1, height=5, width=20, font=font, read_only=True, ) padding = self.get_padding() self.log_text.grid(row=1, column=1, sticky="nsew", padx=padding, pady=(0, padding))
def _create_widgets(self, parent): header_frame = ttk.Frame(parent) header_frame.grid(row=1, column=0, sticky="nsew", padx=15, pady=(15, 0)) header_frame.columnconfigure(0, weight=1) header_frame.rowconfigure(1, weight=1) name_font = tk.font.nametofont("TkDefaultFont").copy() name_font.configure(size=16) self.search_box = ttk.Entry(header_frame) self.search_box.grid(row=1, column=0, sticky="nsew") self.search_box.bind("<Return>", self._on_search, False) self.search_button = ttk.Button( header_frame, text=_("Find package from PyPI"), command=self._on_search, width=25, ) self.search_button.grid(row=1, column=1, sticky="nse", padx=(10, 0)) main_pw = tk.PanedWindow( parent, orient=tk.HORIZONTAL, background=lookup_style_option("TPanedWindow", "background"), sashwidth=15, ) main_pw.grid(row=2, column=0, sticky="nsew", padx=15, pady=15) parent.rowconfigure(2, weight=1) parent.columnconfigure(0, weight=1) listframe = ttk.Frame(main_pw, relief="flat", borderwidth=1) listframe.rowconfigure(0, weight=1) listframe.columnconfigure(0, weight=1) self.listbox = ui_utils.ThemedListbox( listframe, activestyle="dotbox", width=20, height=18, selectborderwidth=0, relief="flat", # highlightthickness=4, # highlightbackground="red", # highlightcolor="green", borderwidth=0, ) self.listbox.insert("end", " <INSTALL>") self.listbox.bind("<<ListboxSelect>>", self._on_listbox_select, True) self.listbox.grid(row=0, column=0, sticky="nsew") list_scrollbar = AutoScrollbar(listframe, orient=tk.VERTICAL, style=scrollbar_style("Vertical")) list_scrollbar.grid(row=0, column=1, sticky="ns") list_scrollbar["command"] = self.listbox.yview self.listbox["yscrollcommand"] = list_scrollbar.set info_frame = ttk.Frame(main_pw) info_frame.columnconfigure(0, weight=1) info_frame.rowconfigure(1, weight=1) main_pw.add(listframe) main_pw.add(info_frame) self.name_label = ttk.Label(info_frame, text="", font=name_font) self.name_label.grid(row=0, column=0, sticky="w", padx=5) info_text_frame = tktextext.TextFrame( info_frame, read_only=True, horizontal_scrollbar=False, background=lookup_style_option("TFrame", "background"), vertical_scrollbar_class=AutoScrollbar, vertical_scrollbar_style=scrollbar_style("Vertical"), horizontal_scrollbar_style=scrollbar_style("Horizontal"), width=60, height=10, ) info_text_frame.configure(borderwidth=0) info_text_frame.grid(row=1, column=0, columnspan=4, sticky="nsew", pady=(0, 10)) self.info_text = info_text_frame.text link_color = lookup_style_option("Url.TLabel", "foreground", "red") self.info_text.tag_configure("url", foreground=link_color, underline=True) self.info_text.tag_bind("url", "<ButtonRelease-1>", self._handle_url_click) self.info_text.tag_bind( "url", "<Enter>", lambda e: self.info_text.config(cursor="hand2")) self.info_text.tag_bind("url", "<Leave>", lambda e: self.info_text.config(cursor="")) self.info_text.tag_configure("install_file", foreground=link_color, underline=True) self.info_text.tag_bind("install_file", "<ButtonRelease-1>", self._handle_install_file_click) self.info_text.tag_bind( "install_file", "<Enter>", lambda e: self.info_text.config(cursor="hand2")) self.info_text.tag_bind("install_file", "<Leave>", lambda e: self.info_text.config(cursor="")) default_font = tk.font.nametofont("TkDefaultFont") self.info_text.configure(font=default_font, wrap="word") bold_font = default_font.copy() # need to explicitly copy size, because Tk 8.6 on certain Ubuntus use bigger font in copies bold_font.configure(weight="bold", size=default_font.cget("size")) self.info_text.tag_configure("caption", font=bold_font) self.info_text.tag_configure("bold", font=bold_font) self.command_frame = ttk.Frame(info_frame) self.command_frame.grid(row=2, column=0, sticky="w") self.install_button = ttk.Button(self.command_frame, text=_(" Upgrade "), command=self._on_click_install) self.install_button.grid(row=0, column=0, sticky="w", padx=0) self.uninstall_button = ttk.Button( self.command_frame, text=_("Uninstall"), command=lambda: self._perform_action("uninstall"), ) self.uninstall_button.grid(row=0, column=1, sticky="w", padx=(5, 0)) self.advanced_button = ttk.Button( self.command_frame, text="...", width=3, command=lambda: self._perform_action("advanced"), ) self.advanced_button.grid(row=0, column=2, sticky="w", padx=(5, 0)) self.close_button = ttk.Button(info_frame, text=_("Close"), command=self._on_close) self.close_button.grid(row=2, column=3, sticky="e")
def __init__(self, master, main_file_path, all_snapshots): super().__init__(master=master) main_frame = ttk.Frame(self) main_frame.grid(row=0, column=0, sticky="nsew") self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.main_file_path = main_file_path self.snapshots = self._select_unsent_snapshots(all_snapshots) self.title("Send feedback for Assistant") padx = 15 intro_label = ttk.Label( main_frame, text="Below are the messages Assistant gave you in response to " + ("using the shell" if self._happened_in_shell() else "testing '" + os.path.basename(main_file_path) + "'") + " since " + self._get_since_str() + ".\n\n" + "In order to improve this feature, Thonny developers would love to know how " + "useful or confusing these messages were. We will only collect version " + "information and the data you enter or approve on this form.", wraplength=550, ) intro_label.grid(row=1, column=0, columnspan=3, sticky="nw", padx=padx, pady=(15, 15)) tree_label = ttk.Label( main_frame, text= "Which messages were helpful (H) or confusing (C)? Click on [ ] to mark!", ) tree_label.grid(row=2, column=0, columnspan=3, sticky="nw", padx=padx, pady=(15, 0)) tree_frame = ui_utils.TreeFrame( main_frame, columns=["helpful", "confusing", "title", "group", "symbol"], displaycolumns=["helpful", "confusing", "title"], height=10, borderwidth=1, relief="groove", ) tree_frame.grid(row=3, column=0, columnspan=3, sticky="nsew", padx=padx) self.tree = tree_frame.tree self.tree.column("helpful", width=30, anchor=tk.CENTER, stretch=False) self.tree.column("confusing", width=30, anchor=tk.CENTER, stretch=False) self.tree.column("title", width=350, anchor=tk.W, stretch=True) self.tree.heading("helpful", text="H", anchor=tk.CENTER) self.tree.heading("confusing", text="C", anchor=tk.CENTER) self.tree.heading("title", text="Group / Message", anchor=tk.W) self.tree["show"] = ("headings", ) self.tree.bind("<1>", self._on_tree_click, True) main_font = tk.font.nametofont("TkDefaultFont") bold_font = main_font.copy() bold_font.configure(weight="bold", size=main_font.cget("size")) self.tree.tag_configure("group", font=bold_font) self.include_thonny_id_var = tk.IntVar(value=1) include_thonny_id_check = ttk.Checkbutton( main_frame, variable=self.include_thonny_id_var, onvalue=1, offvalue=0, text= "Include Thonny's installation time (allows us to group your submissions)", ) include_thonny_id_check.grid(row=4, column=0, columnspan=3, sticky="nw", padx=padx, pady=(5, 0)) self.include_snapshots_var = tk.IntVar(value=1) include_snapshots_check = ttk.Checkbutton( main_frame, variable=self.include_snapshots_var, onvalue=1, offvalue=0, text= "Include snapshots of the code and Assistant responses at each run", ) include_snapshots_check.grid(row=5, column=0, columnspan=3, sticky="nw", padx=padx, pady=(0, 0)) comments_label = ttk.Label(main_frame, text="Any comments? Enhancement ideas?") comments_label.grid(row=6, column=0, columnspan=3, sticky="nw", padx=padx, pady=(15, 0)) self.comments_text_frame = tktextext.TextFrame( main_frame, vertical_scrollbar_style=scrollbar_style("Vertical"), horizontal_scrollbar_style=scrollbar_style("Horizontal"), horizontal_scrollbar_class=ui_utils.AutoScrollbar, wrap="word", font="TkDefaultFont", # cursor="arrow", padx=5, pady=5, height=4, borderwidth=1, relief="groove", ) self.comments_text_frame.grid(row=7, column=0, columnspan=3, sticky="nsew", padx=padx) url_font = tk.font.nametofont("TkDefaultFont").copy() url_font.configure(underline=1, size=url_font.cget("size")) preview_link = ttk.Label( main_frame, text="(Preview the data to be sent)", style="Url.TLabel", cursor="hand2", font=url_font, ) preview_link.bind("<1>", self._preview_submission_data, True) preview_link.grid(row=8, column=0, sticky="nw", padx=15, pady=15) submit_button = ttk.Button(main_frame, text="Submit", width=10, command=self._submit_data) submit_button.grid(row=8, column=0, sticky="ne", padx=0, pady=15) cancel_button = ttk.Button(main_frame, text="Cancel", width=7, command=self._close) cancel_button.grid(row=8, column=1, sticky="ne", padx=(10, 15), pady=15) self.protocol("WM_DELETE_WINDOW", self._close) self.bind("<Escape>", self._close, True) main_frame.columnconfigure(0, weight=1) main_frame.rowconfigure(3, weight=3) main_frame.rowconfigure(6, weight=2) self._empty_box = "[ ]" self._checked_box = "[X]" self._populate_tree()
def __init__(self, master): ConfigurationPage.__init__(self, master) self.add_checkbox("general.single_instance", tr("Allow only single Thonny instance"), row=1, columnspan=2) self.add_checkbox("general.event_logging", tr("Log program usage events"), row=4, columnspan=2) self.add_checkbox( "file.reopen_all_files", tr("Reopen all files from previous session"), row=5, columnspan=2, ) if running_on_linux(): self.add_checkbox( "file.avoid_zenity", tr("Use Tk file dialogs instead of Zenity"), tooltip=tr( "Select if the file dialogs end up behind the main window" ), row=6, columnspan=2, ) self.add_checkbox( "general.disable_notification_sound", tr("Disable notification sound"), row=7, columnspan=2, ) self.add_checkbox( "general.debug_mode", tr("Debug mode (provides more detailed diagnostic logs)"), row=8, columnspan=2, ) # language self._language_name_var = tk.StringVar( value=languages.LANGUAGES_DICT.get( get_workbench().get_option("general.language"), "")) self._language_label = ttk.Label(self, text=tr("Language")) self._language_label.grid(row=10, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0)) self._language_combo = ttk.Combobox( self, width=20, exportselection=False, textvariable=self._language_name_var, state="readonly", height=15, values=list(languages.LANGUAGES_DICT.values()), ) self._language_combo.grid(row=10, column=1, sticky=tk.W, pady=(10, 0)) # Mode ttk.Label(self, text=tr("UI mode")).grid(row=20, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0)) self.add_combobox( "general.ui_mode", ["simple", "regular", "expert"], row=20, column=1, pady=(10, 0), width=10, ) # scaling self._scaling_label = ttk.Label(self, text=tr("UI scaling factor")) self._scaling_label.grid(row=30, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0)) scalings = ["default"] + sorted( {0.5, 0.75, 1.0, 1.25, 1.33, 1.5, 2.0, 2.5, 3.0, 4.0}) self.add_combobox("general.scaling", scalings, row=30, column=1, pady=(10, 0), width=10) self._font_scaling_var = get_workbench().get_variable( "general.font_scaling_mode") self._font_scaling_label = ttk.Label(self, text=tr("Font scaling mode")) self._font_scaling_label.grid(row=40, column=0, sticky=tk.W, padx=(0, 10), pady=(10, 0)) self.add_combobox( "general.font_scaling_mode", ["default", "extra", "automatic"], row=40, column=1, pady=(10, 0), width=10, ) env_label = ttk.Label( self, text=tr("Environment variables (one KEY=VALUE per line)")) env_label.grid(row=90, column=0, sticky=tk.W, pady=(20, 0), columnspan=2) self.env_box = tktextext.TextFrame(self, horizontal_scrollbar=False, height=4, borderwidth=1, undo=True, wrap="none") self.env_box.grid(row=100, column=0, sticky="nsew", pady=(0, 10), columnspan=2) for entry in get_workbench().get_option("general.environment"): self.env_box.text.insert("end", entry + "\n") reopen_label = ttk.Label( self, text=tr("NB! Restart Thonny after changing these options!"), font="BoldTkDefaultFont", ) reopen_label.grid(row=110, column=0, sticky="sw", pady=(20, 0), columnspan=2) self.columnconfigure(1, weight=1) self.rowconfigure(100, weight=1)