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.configHandler 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()
def toggle_line_number_event(self, event=None): if not self.label: widgets = self.editwin.text, self.editwin.text_frame pady = 0 for widget in widgets: pady += int(str(widget.pack_info()['pady'])) pady += int(str(widget.cget('pady'))) border = 0 for widget in widgets: border += int(str(widget.cget('border'))) self.label = Tkinter.Label( self.editwin.top, ## text='\n'.join(['%d'%(i+1) for i in range(50)]), text='1', anchor=N, justify=RIGHT, font=self.textfont, bg=self.bgcolor, fg=self.fgcolor, width=self.digit, pady=pady, border=border, relief=SUNKEN) self.label.pack(side=LEFT, fill=Y, expand=False, before=self.editwin.text_frame) else: self.label.destroy() self.label = None idleConf.SetOption('extensions', 'LineNumber', 'visible', str(self.label is not None)) idleConf.SaveUserCfgFiles()
def load_idlex_extensions(self, userExt=None): """ Load extensions. Returns number of extensions loaded. """ if userExt is None: userExt = self.IDLEX_EXTENSIONS # get already-saved settings d = idleConf.GetUserCfgDir() usercfgfile = os.path.join(d, 'idlex-config-extensions.cfg') if os.path.isfile(usercfgfile): U = open(usercfgfile).read() else: U = '' count = 0 userConfParser = make_config_parser(U) key_isdefault = idleConf.GetOption('main', 'Keys', 'default', type="bool") for extName in userExt: if self.reload_cfg(extName): count += 1 # transfer already-saved settings, otherwise IDLE forgets them # when idleConf.SaveUserCfgFiles is called from within IDLE. Bug? self.transfer_cfg(extName, userConfParser, keys=not key_isdefault ) # Overwrite defaults with user config idleConf.SaveUserCfgFiles() return count
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 += int(str(widget.pack_info()['padx'])) padx += int(str(widget.cget('padx'))) border = 0 for widget in widgets: border += int(str(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() return
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 int(str(<value>)), 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 += int(str( widget.pack_info()['padx'] )) padx += int(str( widget.cget('padx') )) # Calculate the required border width border = 0 for widget in widgets: border += int(str( 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()
def close(self): # Extension is being unloaded self.runmanager.close() if self.hl_id: self.text.after_cancel(self.hl_id) idleConf.SaveUserCfgFiles() SubCode.SC_INSTANCES.remove(self) try: self.editwin.ColorDelegator = self.ColorDelegatorOrig finally: self.ColorDelegatorOrig = None
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
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
def load_idlex_extensions(self, userExt=None): """ Load extensions. Returns number of extensions loaded. """ if userExt is None: userExt = self.IDLEX_EXTENSIONS # get already-saved settings d = idleConf.GetUserCfgDir() usercfgfile = os.path.join(d, 'idlex-config-extensions.cfg') if os.path.isfile(usercfgfile): U = open(usercfgfile).read() else: U = '' count = 0 userConfParser = make_config_parser(U) key_isdefault = idleConf.GetOption('main', 'Keys', 'default', type="bool") for extName in userExt: # get the default configuration for the individual extension cfg = self.load_extension_cfg(extName) if cfg is None: continue # shove the conf string into a ConfigParse object extConfParser = make_config_parser(cfg) if extConfParser is None: print('\n Unable to parse configuration for %s' % extName) continue # transfer the configuration to IDLE if not self.transfer_cfg(extName, extConfParser, keys=True): print('\n Unable to transfer configuration for %s' % extName) continue count += 1 # transfer already-saved settings, otherwise IDLE forgets them # when idleConf.SaveUserCfgFiles is called from within IDLE. Bug? self.transfer_cfg( extName, userConfParser, keys=not key_isdefault) # Overwrite defaults with user config idleConf.SaveUserCfgFiles() return count
def toggle_pep8check_event(self, event=None): if not self.verticalLabelFrame: # 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 int(str(<value>)), 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 pady = 0 for widget in widgets: padx += int(str(widget.pack_info()['padx'])) padx += int(str(widget.cget('padx'))) pady += int(str(widget.pack_info()['pady'])) pady += int(str(widget.cget('pady'))) # Calculate the required border width border = 0 for widget in widgets: border += int(str(widget.cget('border'))) self.topLabel = Label( self.editwin.top, text="PEP8 Style Check Mode", 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) self.verticalLabelFrame = LabelFrame(self.editwin.top, text="PEP8 Style Check", bg=self.bgcolor, fg=self.fgcolor, width=pady, border=border, relief=SUNKEN) self.configButton = Button(self.topLabel, text="Configure PEP8", command=self.update) self.closePep8Button = Button(self.topLabel, text="Exit PEP8 mode", command=self.toggle_pep8check_event) #configure pep8 controls #packing all pep8 windows and controls self.topLabel.pack(side=TOP, fill=X, expand=False, before=self.editwin.text_frame) self.verticalLabelFrame.pack(side=RIGHT, fill=Y, expand=True) self.closePep8Button.pack(side=RIGHT) self.configButton.pack(side=RIGHT) #self.editwin.top = Tk() #var = IntVar() #self.c = Checkbutton(self.topLabel, text="Expand", variable=var, onvalue = 1, offvalue = 0) #self.c.pack(after=self.editwin.top) self.editwin.setvar('<<toggle-pep8check>>', True) self.update() else: self.verticalLabelFrame.destroy() self.verticalLabelFrame = None self.configButton.destroy() self.configButton = None self.closePep8Button.destroy() self.closePep8Button = None self.topLabel.destroy() self.topLabel = None self.editwin.setvar('<<toggle-pep8check>>', False) idleConf.SetOption("extensions", "PEP8Check", "visible", str(self.verticalLabelFrame is not None)) idleConf.SaveUserCfgFiles()
def close(self): idleConf.SetOption("extensions", "SubCodeToolbar", "visible", '%s' % self.visible) idleConf.SaveUserCfgFiles()
def close(self): idleConf.SaveUserCfgFiles()