Ejemplo n.º 1
0
def altered_idle_config():
    """
    Inject the appropriate font settings into the idle config file.

    Note that this will ignore any specific config files (eg, config-unix.cfg).
    It's very unlikely that students will be using these.

    """
    from idlelib.config import idleConf

    # save originals
    font_name = idleConf.GetOption('main', 'EditorWindow', 'font-name')
    font_size = idleConf.GetOption('main', 'EditorWindow', 'font-size')

    # replace them
    name, size, _ = map(str, FIXED_FONT)
    idleConf.SetOption('main', 'EditorWindow', 'font-name', name)
    idleConf.SetOption('main', 'EditorWindow', 'font-size', size)

    # save the config file
    idleConf.SaveUserCfgFiles()

    yield

    # replace the values
    if font_name is not None:
        idleConf.SetOption('main', 'EditorWindow', 'font-name', font_name)
    if font_size is not None:
        idleConf.SetOption('main', 'EditorWindow', 'font-size', font_size)

    if font_name is not None or font_size is not None:
        idleConf.SaveUserCfgFiles()
Ejemplo n.º 2
0
    def close_pyshell(self):
        global INTERP, DO_PING
        idleConf.SetOption("extensions", "EventLoop", "active",
                           '%s' % self.active)
        idleConf.SetOption("extensions", "EventLoop", "toolkit", self.kit)
        idleConf.SaveUserCfgFiles()

        self.eventloop_enable(False)

        INTERP = None
        DO_PING = False
Ejemplo n.º 3
0
 def toggle_code_context_event(self, event=None):
     if not self.label:
         widgets = self.editwin.text, self.editwin.text_frame
         padx = 0
         for widget in widgets:
             padx += widget.tk.getint(widget.pack_info()['padx'])
             padx += widget.tk.getint(widget.cget('padx'))
         border = 0
         for widget in widgets:
             border += widget.tk.getint(widget.cget('border'))
         self.label = tkinter.Label(self.editwin.top,
                                    text='\n' * (self.context_depth - 1),
                                    anchor=W,
                                    justify=LEFT,
                                    font=self.textfont,
                                    bg=self.bgcolor,
                                    fg=self.fgcolor,
                                    width=1,
                                    padx=padx,
                                    border=border,
                                    relief=SUNKEN)
         self.label.pack(side=TOP,
                         fill=X,
                         expand=False,
                         before=self.editwin.text_frame)
     else:
         self.label.destroy()
         self.label = None
     idleConf.SetOption('extensions', 'CodeContext', 'visible',
                        str(self.label is not None))
     idleConf.SaveUserCfgFiles()
Ejemplo n.º 4
0
 def toggle_code_context_event(self, event=None):
     if not self.label:
         # Calculate the border width and horizontal padding required to
         # align the context with the text in the main Text widget.
         #
         # All values are passed through getint(), since some
         # values may be pixel objects, which can't simply be added to ints.
         widgets = self.editwin.text, self.editwin.text_frame
         # Calculate the required vertical padding
         padx = 0
         for widget in widgets:
             padx += widget.tk.getint(widget.pack_info()['padx'])
             padx += widget.tk.getint(widget.cget('padx'))
         # Calculate the required border width
         border = 0
         for widget in widgets:
             border += widget.tk.getint(widget.cget('border'))
         self.label = tkinter.Label(self.editwin.top,
                                    text="\n" * (self.context_depth - 1),
                                    anchor=W, justify=LEFT,
                                    font=self.textfont,
                                    bg=self.bgcolor, fg=self.fgcolor,
                                    width=1, #don't request more than we get
                                    padx=padx, border=border,
                                    relief=SUNKEN)
         # Pack the label widget before and above the text_frame widget,
         # thus ensuring that it will appear directly above text_frame
         self.label.pack(side=TOP, fill=X, expand=False,
                         before=self.editwin.text_frame)
     else:
         self.label.destroy()
         self.label = None
     idleConf.SetOption("extensions", "CodeContext", "visible",
                        str(self.label is not None))
     idleConf.SaveUserCfgFiles()
Ejemplo n.º 5
0
    def show_toggle(self, ev=None):
        self.visible = not self.visible
        if self.visible:
            self._show_bar()
        else:
            self._hide_bar()

        # save the option
        idleConf.SetOption("extensions", "Horizontal", "visible",
                           '%s' % self.visible)
Ejemplo n.º 6
0
    def terminal_toggle_event(self, event=None):
        self.enabled = not self.enabled
        self.editwin.setvar("<<terminal-toggle>>", not not self.enabled)

        if self.enabled == False:
            self.terminal_mode_exit()
        else:
            self.terminal_mode_init()

        idleConf.SetOption("extensions", "Terminal", "terminal",
                           '%s' % self.enabled)
Ejemplo n.º 7
0
    def set_visible(self, b=True):
        self.visible = b

        if self.visible:
            self.text.after(1, self.font_timer)  # avoid a start-up bug
            self.show()
            # use .after to avoid a start-up error caused by update_idletasks in update_numbers
            self.text.after(1, self.update_numbers)
        else:
            self.hide()

        idleConf.SetOption("extensions", "LineNumbers", "visible",
                           '%s' % self.visible)

        self.editwin.setvar("<<linenumbers-show>>", self.visible)
Ejemplo n.º 8
0
    def toggle(self, ev=None):
        """ Toggle the selected extension's enable status """
        sel = self.get_sel()
        if sel is None: return

        item = self.extensions[sel]
        en = not idleConf.GetOption(
            'extensions', item, 'enable', type='bool', default=True)
        en = int(en)

        idleConf.SetOption('extensions', item, 'enable', '%s' % en)
        idleConf.SaveUserCfgFiles()
        self.repopulate_list()

        self.restart = True
Ejemplo n.º 9
0
 def set_idleconf_option_with_cleanup(self, configType, section, option,
                                      value):
     prev_val = idleConf.GetOption(configType, section, option)
     idleConf.SetOption(configType, section, option, value)
     self.addCleanup(idleConf.SetOption, configType, section, option,
                     prev_val)
Ejemplo n.º 10
0
 def test_reload(self):
     """Test the reload() class-method."""
     self.assertIsInstance(Squeezer.auto_squeeze_min_lines, int)
     idleConf.SetOption('main', 'PyShell', 'auto-squeeze-min-lines', '42')
     Squeezer.reload()
     self.assertEqual(Squeezer.auto_squeeze_min_lines, 42)
Ejemplo n.º 11
0
def set_cfg(cfg, b):
    return idleConf.SetOption("extensions", "TabExtension", cfg, '%s' % b)
Ejemplo n.º 12
0
def set_cfg(cfg, b):
    return idleConf.SetOption("extensions", "DocViewer", cfg, '%s' % b)
Ejemplo n.º 13
0
def set_cfg(cfg, b):
    return idleConf.SetOption("extensions", EXTNAME, cfg, '%s' % b)
Ejemplo n.º 14
0
def set_cfg(cfg, b):
    return idleConf.SetOption("extensions", "SubCode", cfg, '%s' % b)
Ejemplo n.º 15
0
def set_cfg(cfg, b):
    return idleConf.SetOption("extensions", "CythonScript", cfg, '%s' % b)
Ejemplo n.º 16
0
 def close(self):
     idleConf.SetOption("extensions", "SubCodeToolbar",
                          "visible", '%s' % self.visible)
     idleConf.SaveUserCfgFiles()