Ejemplo n.º 1
0
    def _init_run(self):
        frame_run = ttk.Frame(self.notebook, padding=4)
        self.notebook.add(frame_run, text='Run')

        frame_run.columnconfigure(2, weight=1)
        # --- run
        self.run_console = tk.StringVar(self, CONFIG.get('Run', 'console'))

        self.external_interactive = ttk.Checkbutton(
            frame_run, text='Interact with the Python console after execution')
        self.external_interactive.state([
            '!alternate',
            '!' * (self.run_console.get() == 'external') + 'disabled', '!' *
            (not CONFIG.getboolean('Run', 'external_interactive')) + 'selected'
        ])

        self.external_console = ttk.Entry(frame_run)
        self.external_console.insert(
            0, CONFIG.get('Run', 'external_console', fallback=''))

        ttk.Label(frame_run, text='Execute in:').grid(row=1,
                                                      column=0,
                                                      padx=(4, 8),
                                                      pady=4,
                                                      sticky='w')
        ttk.Radiobutton(frame_run,
                        text='external terminal:',
                        value='external',
                        command=self._run_setting,
                        variable=self.run_console).grid(row=1,
                                                        column=1,
                                                        pady=4,
                                                        sticky='w')
        ttk.Radiobutton(frame_run,
                        text='embedded console',
                        value='console',
                        command=self._run_setting,
                        variable=self.run_console).grid(row=2,
                                                        column=1,
                                                        pady=4,
                                                        sticky='w')

        jqt = ttk.Radiobutton(frame_run,
                              text='Jupyter QtConsole',
                              value='qtconsole',
                              command=self._run_setting,
                              variable=self.run_console)
        jqt.grid(row=3, column=1, pady=4, sticky='w')
        self.external_console.grid(row=1,
                                   column=2,
                                   sticky='ew',
                                   padx=(0, 4),
                                   pady=4)
        self.external_interactive.grid(row=4,
                                       columnspan=3,
                                       padx=4,
                                       pady=4,
                                       sticky='w')

        ttk.Separator(frame_run, orient='horizontal').grid(row=5,
                                                           columnspan=3,
                                                           sticky='ew',
                                                           pady=4)
        # --- run cell
        self.run_cell_in = tk.StringVar(
            self, CONFIG.get('Run', 'cell', fallback="console"))
        ttk.Label(frame_run, text='Execute cells in:').grid(row=6,
                                                            column=0,
                                                            padx=(4, 8),
                                                            pady=4,
                                                            sticky='w')
        ttk.Radiobutton(frame_run,
                        text='embedded console',
                        value='console',
                        variable=self.run_cell_in).grid(row=6,
                                                        column=1,
                                                        pady=4,
                                                        sticky='w')

        jqt2 = ttk.Radiobutton(frame_run,
                               text='Jupyter QtConsole',
                               value='qtconsole',
                               variable=self.run_cell_in)
        jqt2.grid(row=7, column=1, pady=4, sticky='w')

        if not JUPYTER:
            jqt.state(['disabled'])
            jqt2.state(['disabled'])
Ejemplo n.º 2
0
    def _init_general(self):
        frame_general = ttk.Frame(self.notebook, padding=4)
        self.notebook.add(frame_general, text='General')

        # --- theme
        self.theme = tk.StringVar(self, CONFIG.get('General', 'theme'))
        ctheme = ttk.Combobox(frame_general,
                              textvariable=self.theme,
                              state='readonly',
                              values=['dark', 'light'],
                              width=5)
        ttk.Label(frame_general, text='Theme:').grid(row=0,
                                                     column=0,
                                                     sticky='e',
                                                     padx=4,
                                                     pady=8)
        ctheme.grid(row=0, column=1, sticky='w', padx=4, pady=8)

        # --- font
        families = list(font.families())
        families.sort()
        length = max([len(f) for f in families])
        self.family = AutoCompleteCombobox(frame_general,
                                           values=families,
                                           width=length - 1)
        self.family.insert(0, CONFIG.get('General', 'fontfamily'))
        self.size = AutoCompleteCombobox(frame_general,
                                         values=[str(i) for i in range(6, 20)],
                                         allow_other_values=True,
                                         width=3)
        self.size.insert(0, CONFIG.get('General', 'fontsize'))

        ttk.Label(frame_general, text='Font:').grid(row=1,
                                                    column=0,
                                                    sticky='e',
                                                    padx=4,
                                                    pady=8)
        self.family.grid(row=1, column=1, sticky='w', padx=4, pady=8)
        self.size.grid(row=1, column=2, sticky='w', padx=4, pady=8)

        # --- new file template
        frame_template = ttk.Frame(frame_general)
        ttk.Label(frame_template,
                  text='Edit new file template').pack(side='left',
                                                      padx=4,
                                                      pady=8)
        ttk.Button(frame_template,
                   image='img_edit',
                   padding=1,
                   command=self.edit_template).pack(side='left',
                                                    padx=4,
                                                    pady=8)
        frame_template.grid(row=2, columnspan=2, sticky='w')

        # --- confirm quit
        self.confirm_quit = ttk.Checkbutton(
            frame_general, text="Show confirmation dialog before exiting")
        if CONFIG.getboolean("General", "confirm_quit", fallback=False):
            self.confirm_quit.state(('selected', '!alternate'))
        else:
            self.confirm_quit.state(('!selected', '!alternate'))
        self.confirm_quit.grid(row=3, columnspan=2, sticky='w', padx=4, pady=4)
Ejemplo n.º 3
0
    def _init_editor(self):
        frame_editor = ttk.Frame(self.notebook, padding=4)
        self.notebook.add(frame_editor, text='Editor')

        frame_editor.columnconfigure(1, weight=1)

        # --- comments
        self.comment_marker = ttk.Entry(frame_editor, width=3)
        self.comment_marker.insert(
            0, CONFIG.get("Editor", "comment_marker", fallback="~"))
        self.comment_toggle_mode = tk.StringVar(
            self,
            CONFIG.get('Editor',
                       'toggle_comment_mode',
                       fallback='line_by_line'))
        rbtn_frame = ttk.Frame(frame_editor)
        ttk.Radiobutton(rbtn_frame,
                        text='Line by line',
                        variable=self.comment_toggle_mode,
                        value='line_by_line').pack(side='left', padx=4, pady=4)
        ttk.Radiobutton(rbtn_frame,
                        text='Block',
                        variable=self.comment_toggle_mode,
                        value='block').pack(side='left', padx=4, pady=4)

        # --- code checking
        self.code_check = ttk.Checkbutton(frame_editor, text='Check code')
        if CONFIG.getboolean("Editor", "code_check", fallback=True):
            self.code_check.state(('selected', '!alternate'))
        else:
            self.code_check.state(('!selected', '!alternate'))
        self.style_check = ttk.Checkbutton(
            frame_editor, text='Check style - PEP8 guidelines')
        if CONFIG.getboolean("Editor", "style_check", fallback=True):
            self.style_check.state(('selected', '!alternate'))
        else:
            self.style_check.state(('!selected', '!alternate'))

        # --- syntax highlighting
        frame_s_h = ttk.Frame(frame_editor)
        frame_s_h.columnconfigure(1, weight=1)
        styles = list(get_all_styles())
        styles.sort()
        w = len(max(styles, key=lambda x: len(x)))

        self.editor_style = AutoCompleteCombobox(frame_s_h,
                                                 values=styles,
                                                 width=w)
        self.editor_style.insert(0, CONFIG.get('Editor', 'style'))
        mb = CONFIG.get('Editor',
                        'matching_brackets',
                        fallback='#00B100;;bold').split(';')
        self.editor_matching_brackets = FormattingFrame(frame_s_h, *mb)
        umb = CONFIG.get('Editor',
                         'unmatched_bracket',
                         fallback='#FF0000;;bold').split(';')
        self.editor_unmatched_bracket = FormattingFrame(frame_s_h, *umb)

        ttk.Label(frame_s_h, text='Theme:').grid(row=1,
                                                 column=0,
                                                 sticky='e',
                                                 pady=(0, 10))
        self.editor_style.grid(row=1,
                               column=1,
                               sticky='w',
                               padx=8,
                               pady=(0, 10))
        ttk.Label(frame_s_h, text='Matching brackets:').grid(row=2,
                                                             column=0,
                                                             columnspan=2,
                                                             sticky='w')
        self.editor_matching_brackets.grid(row=3,
                                           column=0,
                                           columnspan=2,
                                           sticky='w',
                                           padx=4)
        ttk.Label(frame_s_h, text='Unmatched bracket:').grid(row=4,
                                                             column=0,
                                                             columnspan=2,
                                                             sticky='w',
                                                             pady=(8, 0))
        self.editor_unmatched_bracket.grid(row=5,
                                           column=0,
                                           columnspan=2,
                                           sticky='w',
                                           padx=4)

        # --- placement
        ttk.Label(frame_editor, text='Comment toggle marker:').grid(row=0,
                                                                    column=0,
                                                                    sticky='e',
                                                                    padx=4,
                                                                    pady=4)
        self.comment_marker.grid(row=0, column=1, sticky='w', padx=4, pady=4)
        ttk.Label(frame_editor, text='Comment toggle mode:').grid(row=1,
                                                                  column=0,
                                                                  sticky='e',
                                                                  padx=4,
                                                                  pady=4)
        rbtn_frame.grid(row=1, column=1, sticky='w')
        ttk.Label(frame_editor,
                  text='Code checking (on file saving):').grid(row=2,
                                                               column=0,
                                                               sticky='e',
                                                               padx=4,
                                                               pady=4)
        self.code_check.grid(row=2, column=1, sticky='w', padx=3, pady=4)
        self.style_check.grid(row=3, column=1, sticky='w', padx=3, pady=4)
        ttk.Separator(frame_editor, orient='horizontal').grid(row=4,
                                                              columnspan=2,
                                                              sticky='ew',
                                                              pady=4)
        ttk.Label(frame_editor, text='Syntax Highlighting:').grid(row=5,
                                                                  columnspan=2,
                                                                  sticky='w',
                                                                  pady=4,
                                                                  padx=4)
        frame_s_h.grid(row=6, columnspan=2, sticky='ew', pady=(4, 8), padx=12)
Ejemplo n.º 4
0
    def __init__(self, master=None, histfile=HISTFILE, **kw):
        BaseWidget.__init__(self, master, 'History', **kw)
        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)

        self._search_count = tk.IntVar(self)

        current_session = CONFIG.getboolean('History', 'current_session', fallback=False)
        self._current_session = tk.BooleanVar(self, current_session)
        # --- menu
        self.menu = tk.Menu(self)
        self.menu.add_checkbutton(label='Current session only',
                                  image='img_menu_dummy_cb',
                                  selectimage='img_selected',
                                  indicatoron=False,
                                  compound='left',
                                  command=self._current_session_toggle,
                                  variable=self._current_session)
        self.menu.add_command(label='Find',
                              command=self.find,
                              image='img_menu_dummy',
                              compound='left')

        syh = AutoHideScrollbar(self, orient='vertical')

        self.history = History(self, HISTFILE, current_session,
                               yscrollcommand=syh.set,
                               relief='flat', borderwidth=0, highlightthickness=0)
        syh.configure(command=self.history.yview)

        # --- search bar
        self._highlighted = ''
        self.frame_search = ttk.Frame(self, padding=2)
        self.frame_search.columnconfigure(1, weight=1)
        self.entry_search = ttk.Entry(self.frame_search)
        self.entry_search.bind('<Return>', self.search)
        self.entry_search.bind('<Escape>', lambda e: self.frame_search.grid_remove())
        search_buttons = ttk.Frame(self.frame_search)
        ttk.Button(search_buttons, style='Up.TButton', padding=0,
                   command=lambda: self.search(backwards=True)).pack(side='left', padx=2, pady=4)
        ttk.Button(search_buttons, style='Down.TButton', padding=0,
                   command=self.search).pack(side='left', padx=2, pady=4)
        self.case_sensitive = ttk.Checkbutton(search_buttons, text='aA')
        self.case_sensitive.state(['selected', '!alternate'])
        self.case_sensitive.pack(side='left', padx=2, pady=4)
        self.regexp = ttk.Checkbutton(search_buttons, text='regexp')
        self.regexp.state(['!selected', '!alternate'])
        self.regexp.pack(side='left', padx=2, pady=4)
        self.full_word = ttk.Checkbutton(search_buttons, text='[-]')
        self.full_word.state(['!selected', '!alternate'])
        self.full_word.pack(side='left', padx=2, pady=4)
        self._highlight_btn = ttk.Checkbutton(search_buttons, image='img_highlight',
                                              padding=0, style='toggle.TButton',
                                              command=self.highlight_all)
        self._highlight_btn.pack(side='left', padx=2, pady=4)

        frame_find = ttk.Frame(self.frame_search)
        ttk.Button(frame_find, padding=0,
                   command=lambda: self.frame_search.grid_remove(),
                   style='close.TButton').pack(side='left')
        ttk.Label(frame_find, text='Find:').pack(side='right')
        frame_find.grid(row=1, column=0, padx=2, pady=4, sticky='ew')
        self.entry_search.grid(row=1, column=1, sticky='ew', pady=4, padx=2)
        search_buttons.grid(row=1, column=2, sticky='w')

        self.bind('<Control-f>', self.find)
        self.history.bind('<Control-f>', self.find)

        # --- placement
        syh.grid(row=0, column=1, sticky='ns')
        self.history.grid(row=0, column=0, sticky='nswe')
        self.frame_search.grid(row=1, columnspan=2, sticky='we')
        self.frame_search.grid_remove()

        self.update_style = self.history.update_style