def print_window(self, event): confirm = tkMessageBox.askokcancel(title="Print", message="Print to Default Printer", default=tkMessageBox.OK, master=self.editwin) if not confirm: self.editwin.focus_set() return "break" tempfilename = None saved = self.get_saved() if saved: filename = self.filename # shell undo is reset after every prompt, looks saved, probably isn't if not saved or filename is None: (tfd, tempfilename) = tempfile.mkstemp(prefix='MRPYTHON_tmp_') filename = tempfilename os.close(tfd) if not self.writefile(tempfilename): os.unlink(tempfilename) return "break" platform = os.name printPlatform = True if platform == 'posix': #posix platform command = MrPythonConf.GetOption('main', 'General', 'print-command-posix') command = command + " 2>&1" elif platform == 'nt': #win32 platform command = MrPythonConf.GetOption('main', 'General', 'print-command-win') else: #no printing for this platform printPlatform = False if printPlatform: #we can try to print for this platform command = command % shlex.quote(filename) pipe = os.popen(command, "r") # things can get ugly on NT if there is no printer available. output = pipe.read().strip() status = pipe.close() if status: output = "Printing failed (exit status 0x%x)\n" % \ status + output if output: output = "Printing command: %s\n" % repr(command) + output tkMessageBox.showerror("Print status", output, master=self.editwin) else: #no printing for this platform message = "Printing is not enabled for this platform: %s" % platform tkMessageBox.showinfo("Print status", message, master=self.editwin) if tempfilename: os.unlink(tempfilename) return "break"
def set_notabs_indentwidth(self): "Update the indentwidth if changed and not using tabs in this window" # Called from configDialog.py if not self.usetabs: self.indentwidth = MrPythonConf.GetOption('main', 'Indent', 'num-spaces', type='int')
def ResetColorizer(self): "Update the color theme" # Called from self.filename_change_hook and from configDialog.py self._rmcolorizer() self._addcolorizer() theme = MrPythonConf.GetOption('main','Theme','name') normal_colors = MrPythonConf.GetHighlight(theme, 'normal') cursor_color = MrPythonConf.GetHighlight(theme, 'cursor', fgBg='fg') select_colors = MrPythonConf.GetHighlight(theme, 'hilite') self.config( foreground=normal_colors['foreground'], background=normal_colors['background'], insertbackground=cursor_color, selectforeground=select_colors['foreground'], selectbackground=select_colors['background'], )
def LoadTagDefs(self): theme = MrPythonConf.GetOption('main','Theme','name') self.tagdefs = { "COMMENT": MrPythonConf.GetHighlight(theme, "comment"), "KEYWORD": MrPythonConf.GetHighlight(theme, "keyword"), "BUILTIN": MrPythonConf.GetHighlight(theme, "builtin"), "STRING": MrPythonConf.GetHighlight(theme, "string"), "DEFINITION": MrPythonConf.GetHighlight(theme, "definition"), "SYNC": {'background':None,'foreground':None}, "TODO": {'background':None,'foreground':None}, "ERROR": MrPythonConf.GetHighlight(theme, "error"), # The following is used by ReplaceDialog: "hit": MrPythonConf.GetHighlight(theme, "hit"), } if DEBUG: print('tagdefs',self.tagdefs)
def __init__(self, text): '''Initialize data attributes and bind event methods. .text - MrPython wrapper of tk Text widget, with .bell(). .history - source statements, possibly with multiple lines. .prefix - source already entered at prompt; filters history list. .pointer - index into history. .cyclic - wrap around history list (or not). ''' self.text = text self.history = [] self.prefix = None self.pointer = None self.cyclic = MrPythonConf.GetOption("main", "History", "cyclic", 1, "bool") text.bind("<<history-previous>>", self.history_prev) text.bind("<<history-next>>", self.history_next)
def __init__(self, parent, open=False, filename=None): Text.__init__(self,parent) self.scroll = scroll=Scrollbar(self) scroll['command'] = self.yview scroll.pack(side=RIGHT, fill=Y) self['yscrollcommand'] = scroll.set self.list=parent self.recent_files_path = os.path.join(MrPythonConf.GetUserCfgDir(), 'recent-files.lst') self.apply_bindings() try: sys.ps1 except AttributeError: sys.ps1 = '' # usetabs true -> literal tab characters are used by indent and # dedent cmds, possibly mixed with spaces if # indentwidth is not a multiple of tabwidth, # which will cause Tabnanny to nag! # false -> tab characters are converted to spaces by indent # and dedent cmds, and ditto TAB keystrokes # Although use-spaces=0 can be configured manually in config-main.def, # configuration of tabs v. spaces is not supported in the configuration # dialog. MRPYTHON promotes the preferred Python indentation: use spaces! usespaces = MrPythonConf.GetOption('main', 'Indent', 'use-spaces', type='bool') self.usetabs = not usespaces # tabwidth is the display width of a literal tab character. # CAUTION: telling Tk to use anything other than its default # tab setting causes it to use an entirely different tabbing algorithm, # treating tab stops as fixed distances from the left margin. # Nobody expects this, so for now tabwidth should never be changed. self.tabwidth = 8 # must remain 8 until Tk is fixed. # indentwidth is the number of screen characters per indent level. # The recommended Python indentation is four spaces. self.indentwidth = self.tabwidth self.set_notabs_indentwidth() # If context_use_ps1 is true, parsing searches back for a ps1 line; # else searches for a popular (if, def, ...) Python stmt. self.context_use_ps1 = False # When searching backwards for a reliable place to begin parsing, # first start num_context_lines[0] lines back, then # num_context_lines[1] lines back if that didn't work, and so on. # The last value should be huge (larger than the # of lines in a # conceivable file). # Making the initial values larger slows things down more often. self.num_context_lines = 50, 500, 5000000 self.per = per = self.Percolator(self) self.undo = undo = self.UndoDelegator() per.insertfilter(undo) self.undo_block_start = undo.undo_block_start self.undo_block_stop = undo.undo_block_stop undo.set_saved_change_hook(self.saved_change_hook) self.io = io = self.IOBinding(self) io.set_filename_change_hook(self.filename_change_hook) self.color = None # initialized below in self.ResetColorizer self.good_load = False if open: if filename: if os.path.exists(filename) and not os.path.isdir(filename): if io.loadfile(filename): self.good_load = True is_py_src = self.ispythonsource(filename) else: io.set_filename(filename) else: self.good_load = self.io.open(editFile=filename) else: self.good_load=True self.ResetColorizer() self.saved_change_hook() self.askyesno = tkMessageBox.askyesno self.askinteger = tkSimpleDialog.askinteger # specific font self.font = nametofont(self.cget('font')).copy() self.configure(font=self.font)