def OnGoto(win, event): line = win.GetCurLine()[0] b = r.search(common.encode_string(line, common.defaultfilesystemencoding)) if b: filename, lineno = b.groups() Globals.mainframe.editctrl.new(filename) wx.CallAfter(Globals.mainframe.document.goto, int(lineno))
def run(win): import wx if win.document.isModified() or win.document.filename == '': d = wx.MessageDialog( win, tr("The file has not been saved, and it would not be run.\nWould you like to save the file?" ), tr("Run"), wx.YES_NO | wx.ICON_QUESTION) answer = d.ShowModal() d.Destroy() if (answer == wx.ID_YES): win.OnFileSave(None) else: return class MOD: pass mod = MOD() mod.dialog = [ ('savefile', 'imagefile', '', 'Saving image filename:', None), ('single', 'filetype', 'png', 'Image file type:', [('Gif', 'gif'), ('Png', 'png'), ('Jpeg', 'jpg')]), ('string', 'args', '', 'Other command line options:', None), ] mod.title = 'Input dot command line' from modules.EasyGuider import EasyCommander from modules.Debug import error from modules import common easy = EasyCommander.EasyCommander(win, mod, cmdoption='') if easy.run(): values = easy.GetValue() import os try: cmd = 'dot -T%s -o%s %s %s' % ( values['filetype'], common.encode_string(values['imagefile'], common.defaultfilesystemencoding), values['args'], win.document.filename) win.createMessageWindow() win.panel.showPage(tr('Message')) win.messagewindow.SetText(cmd) os.system(cmd) except: error.traceback() common.showerror(win, tr("Can't execute [%s]") % cmd) return if os.path.exists(values['imagefile']): from modules import ImageWin try: win = ImageWin.ImageWin(win, values['imagefile']) win.Show() except: common.showerror( win, tr("Can't open image file %s") % values['imagefile'])
def SaveToFile(self,filepath=None): if filepath: self.filepath=filepath fout=None try: fout=open(self.filepath,'w') except: if fout: fout.close() raise SaveMusicListException() fout.write('#EXTM3U\n') for data in self.data: title = common.encode_string(data['Author-Title'], common.defaultfilesystemencoding) path = common.encode_string(data['Path'], common.defaultfilesystemencoding) fout.write(self.template%(data['Time'], title, path)) return True
def OnPythonRun(win, event): interpreter = _get_python_exe(win) if not interpreter: return doc = win.editctrl.getCurDoc() if doc.isModified() or doc.filename == '': if win.pref.python_save_before_run: win.OnFileSave(event) else: d = wx.MessageDialog(win, tr("The script can't run because the document hasn't been saved.\nWould you like to save it?"), tr("Run"), wx.YES_NO | wx.ICON_QUESTION) answer = d.ShowModal() d.Destroy() if answer == wx.ID_YES: win.OnFileSave(event) else: return if win.pref.python_show_args: if not get_python_args(win): return args = doc.args.replace('$path', os.path.dirname(doc.filename)) args = args.replace('$file', doc.filename) ext = os.path.splitext(doc.filename)[1].lower() parameter = Globals.pref.python_default_paramters.get(Globals.pref.default_interpreter, '') interpreter = dict(Globals.pref.python_interpreter).get(Globals.pref.default_interpreter, '') command = u'"%s" %s "%s" %s' % (interpreter, parameter, doc.filename, args) #chanage current path to filename's dirname path = os.path.dirname(doc.filename) os.chdir(common.encode_string(path)) win.RunCommand(command, redirect=win.document.redirect)
def goto_error_line(msgwin, line, lineno): import re r = re.compile("((\w:)?[^:\t\n\r\?\;]+):(\d+)") b = r.search(common.encode_string(line, common.defaultfilesystemencoding)) if b: return True, (b.groups()[0], b.groups()[2])
def getcurrentpath(self): #current path try: self.curpath = common.encode_string(self.ftp.pwd()) except Exception, msg: common.showerror(self, msg) error.traceback() self.curpath = ''
def SaveToFile(self, filepath=None): if filepath: self.filepath = filepath fout = None try: fout = open(self.filepath, 'w') except: if fout: fout.close() raise SaveMusicListException() fout.write('#EXTM3U\n') for data in self.data: title = common.encode_string(data['Author-Title'], common.defaultfilesystemencoding) path = common.encode_string(data['Path'], common.defaultfilesystemencoding) fout.write(self.template % (data['Time'], title, path)) return True
def OnKeyDown(win, event): keycode = event.GetKeyCode() pos = win.GetCurrentPos() if win.pid > -1: if (pos >= win.editpoint) and (keycode == wx.WXK_RETURN): text = win.GetTextRange(win.writeposition, win.GetLength()) l = len(win.CommandArray) if (l < win.MAX_PROMPT_COMMANDS): win.CommandArray.insert(0, text) win.CommandArrayPos = -1 else: win.CommandArray.pop() win.CommandArray.insert(0, text) win.CommandArrayPos = -1 if isinstance(text, types.UnicodeType): text = common.encode_string(text) win.outputstream.write(text + '\n') win.GotoPos(win.GetLength()) win.CmdKeyExecute(wx.stc.STC_CMD_NEWLINE) win.writeposition = win.GetLength() return if keycode == wx.WXK_UP: if (len(win.CommandArray) > 0): if (win.CommandArrayPos + 1) < l: win.GotoPos(win.editpoint) win.SetTargetStart(win.editpoint) win.SetTargetEnd(win.GetLength()) win.CommandArrayPos = win.CommandArrayPos + 1 win.ReplaceTarget(win.CommandArray[win.CommandArrayPos]) else: event.Skip() elif keycode == wx.WXK_DOWN: if len(win.CommandArray) > 0: win.GotoPos(win.editpoint) win.SetTargetStart(win.editpoint) win.SetTargetEnd(win.GetLength()) if (win.CommandArrayPos - 1) > -1: win.CommandArrayPos = win.CommandArrayPos - 1 win.ReplaceTarget(win.CommandArray[win.CommandArrayPos]) else: if (win.CommandArrayPos - 1) > -2: win.CommandArrayPos = win.CommandArrayPos - 1 win.ReplaceTarget("") else: event.Skip() # if ((pos > win.editpoint) and (not keycode == wx.WXK_UP)) or ((not keycode == wx.WXK_BACK) and (not keycode == wx.WXK_LEFT) and (not keycode == wx.WXK_UP) and (not keycode == wx.WXK_DOWN)): # if (pos < win.editpoint): # if (not keycode == wx.WXK_RIGHT): # event.Skip() # else: # event.Skip() event.Skip()
def OnAddDir(self, event): dialog = wx.DirDialog(self.mainframe, "Add Dir\All Media files to Music List", ".", 0, name="Add Dir") path = [] if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() else: return for root, dirs, files in os.walk(path): for file in files: filename = os.path.join(root, file) if self.m3u.isExists(filename): continue if filename[-4:].lower() in [ '.mp3', '.wav', '.mid', '.wma', '.asf' ]: file = common.decode_string( filename, common.defaultfilesystemencoding) record = {} if filename.lower().endswith(".mp3"): from PyMp3Info import MP3FileInfo fi = MP3FileInfo(filename) if fi.parse(): record['Author-Title'] = (fi['author'] and fi['author'] + ' - ' or '') + fi['title'] else: record['Author-Title'] = os.path.split( filename)[-1] else: record['Author-Title'] = os.path.split(filename)[-1] try: from pySonic import FileStream f = FileStream( common.encode_string( filename, common.defaultfilesystemencoding), 0) record['Time'] = str(int(f.Duration)) del f except: dlg = wx.MessageDialog( self, tr('Can\'t add file [%s] or this file isn\'t a media file!' ) % filename, tr('Error'), wx.OK | wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() continue record['Path'] = filename self.m3u.Append(record) self.addrecord(record) self.m3u.SaveToFile(self.defm3u)
def refresh(self, path=''): if not path: path = self.txtPath.GetValue() try: common.setmessage(self.mainframe, tr('Changing the current directory...')) self.ftp.cwd(common.encode_string(path)) self.data = [] self.ftp.retrlines('LIST', self.receivedData) self.curpath = common.decode_string(self.ftp.pwd()) self.txtPath.SetValue(self.curpath) self.loadFile(self.data) except Exception, msg: common.showerror(self, msg) error.traceback() return
def run(win): import wx if win.document.isModified() or win.document.filename == '': d = wx.MessageDialog(win, tr("The file has not been saved, and it would not be run.\nWould you like to save the file?"), tr("Run"), wx.YES_NO | wx.ICON_QUESTION) answer = d.ShowModal() d.Destroy() if (answer == wx.ID_YES): win.OnFileSave(None) else: return class MOD:pass mod = MOD() mod.dialog = [ ('savefile', 'imagefile', '', 'Saving image filename:', None), ('single', 'filetype', 'png', 'Image file type:', [('Gif', 'gif'), ('Png', 'png'), ('Jpeg', 'jpg')]), ('string', 'args', '', 'Other command line options:', None), ] mod.title = 'Input dot command line' from modules.EasyGuider import EasyCommander from modules.Debug import error from modules import common easy = EasyCommander.EasyCommander(win, mod, cmdoption='') if easy.run(): values = easy.GetValue() import os try: cmd = 'dot -T%s -o%s %s %s' % (values['filetype'], common.encode_string(values['imagefile'], common.defaultfilesystemencoding), values['args'], win.document.filename) win.createMessageWindow() win.panel.showPage(tr('Message')) win.messagewindow.SetText(cmd) os.system(cmd) except: error.traceback() common.showerror(win, tr("Can't execute [%s]") % cmd) return if os.path.exists(values['imagefile']): from modules import ImageWin try: win = ImageWin.ImageWin(win, values['imagefile']) win.Show() except: common.showerror(win, tr("Can't open image file %s") % values['imagefile'])
def OnToolRegister(win, event): try: key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '*', _winreg.KEY_ALL_ACCESS) filename = os.path.basename(sys.argv[0]) f, ext = os.path.splitext(filename) if ext == '.exe': command = '"%s" "%%L"' % os.path.normpath(common.uni_work_file(filename)) else: path = os.path.normpath(common.uni_work_file('%s.pyw' % f)) execute = sys.executable.replace('python.exe', 'pythonw.exe') command = '"%s" "%s" "%%L"' % (execute, path) _winreg.SetValue(key, 'shell\\UliPad\\command', _winreg.REG_SZ, common.encode_string(command, common.defaultfilesystemencoding)) common.note(tr('Done')) except: error.traceback() wx.MessageDialog(win, tr('Registering UliPad to the context menu of Windows Explorer failed.'), tr("Error"), wx.OK | wx.ICON_EXCLAMATION).ShowModal()
def OnAdd(self, event): dialog = wx.FileDialog( self.mainframe, "Add Media File To Music List", "", "", "Media files(*.mp3;*.wma;*.asf;*.mid;*.wav)|*.mp3;*.wma;*.asf;*.mid;*.wav", wx.OPEN | wx.MULTIPLE) filenames = [] filename = '' if dialog.ShowModal() == wx.ID_OK: filenames = dialog.GetPaths() dialog.Destroy() record = {} for filename in filenames: if self.m3u.isExists(filename): continue if filename.lower().endswith(".mp3"): from PyMp3Info import MP3FileInfo fi = MP3FileInfo(filename) if fi.parse(): record['Author-Title'] = (fi['author'] and fi['author'] + ' - ' or '') + fi['title'] else: record['Author-Title'] = os.path.split(filename)[-1] else: record['Author-Title'] = os.path.split(filename)[-1] try: from pySonic import FileStream f = FileStream( common.encode_string(filename, common.defaultfilesystemencoding), 0) record['Time'] = str(int(f.Duration)) del f except: error.traceback() dlg = wx.MessageDialog( self, tr('Can\'t add file [%s] or this file isn\'t a media file!' ) % filename, tr('Error'), wx.OK | wx.ICON_ERROR #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION ) dlg.ShowModal() dlg.Destroy() record = {} continue record['Path'] = filename self.m3u.Append(record) self.addrecord(record) self.m3u.SaveToFile(self.defm3u)
def OnAddDir(self,event): dialog = wx.DirDialog(self.mainframe, "Add Dir\All Media files to Music List", ".", 0, name="Add Dir" ) path=[] if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() else: return for root, dirs, files in os.walk(path): for file in files: filename=os.path.join(root,file) if self.m3u.isExists(filename): continue if filename[-4:].lower() in ['.mp3','.wav','.mid','.wma','.asf']: file = common.decode_string(filename, common.defaultfilesystemencoding) record={} if filename.lower().endswith(".mp3"): from PyMp3Info import MP3FileInfo fi = MP3FileInfo(filename) if fi.parse(): record['Author-Title']=(fi['author'] and fi['author']+' - ' or '')+fi['title'] else: record['Author-Title']=os.path.split(filename)[-1] else: record['Author-Title']=os.path.split(filename)[-1] try: from pySonic import FileStream f=FileStream(common.encode_string(filename, common.defaultfilesystemencoding), 0) record['Time']=str(int(f.Duration)) del f except: dlg = wx.MessageDialog(self, tr('Can\'t add file [%s] or this file isn\'t a media file!') % filename, tr('Error'), wx.OK | wx.ICON_ERROR ) dlg.ShowModal() dlg.Destroy() continue record['Path'] = filename self.m3u.Append(record) self.addrecord(record) self.m3u.SaveToFile(self.defm3u)
def OnAdd(self, event): dialog = wx.FileDialog(self.mainframe, "Add Media File To Music List", "", "", "Media files(*.mp3;*.wma;*.asf;*.mid;*.wav)|*.mp3;*.wma;*.asf;*.mid;*.wav", wx.OPEN|wx.MULTIPLE ) filenames=[] filename = '' if dialog.ShowModal() == wx.ID_OK: filenames = dialog.GetPaths() dialog.Destroy() record={} for filename in filenames: if self.m3u.isExists(filename): continue if filename.lower().endswith(".mp3"): from PyMp3Info import MP3FileInfo fi=MP3FileInfo(filename) if fi.parse(): record['Author-Title']=(fi['author'] and fi['author']+' - ' or '')+fi['title'] else: record['Author-Title']=os.path.split(filename)[-1] else: record['Author-Title']=os.path.split(filename)[-1] try: from pySonic import FileStream f=FileStream(common.encode_string(filename, common.defaultfilesystemencoding),0) record['Time']=str(int(f.Duration)) del f except: error.traceback() dlg = wx.MessageDialog(self, tr('Can\'t add file [%s] or this file isn\'t a media file!') % filename, tr('Error'), wx.OK | wx.ICON_ERROR #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION ) dlg.ShowModal() dlg.Destroy() record={} continue record['Path']=filename self.m3u.Append(record) self.addrecord(record) self.m3u.SaveToFile(self.defm3u)
def Check(mainframe, document): message = [] if document.filename: message = check(document.GetText().encode(document.locale) + '\n\n', common.encode_string(document.filename, common.defaultfilesystemencoding)) else: message = check(document.GetText().encode(document.locale) + '\n\n', '<stdin>') if mainframe.pref.auto_py_pep8_check: pep8check(document, message) message.sort() mainframe.createSyntaxCheckWindow() mainframe.syntaxcheckwindow.adddata(message) if message: mainframe.panel.showPage(syntax_pagename) else: mainframe.panel.closePage(syntax_pagename) wx.CallAfter(document.SetFocus)
def Check(mainframe, document): message = [] if document.filename: message = check( document.GetText().encode(document.locale) + '\n\n', common.encode_string(document.filename, common.defaultfilesystemencoding)) else: message = check(document.GetText().encode(document.locale) + '\n\n', '<stdin>') if mainframe.pref.auto_py_pep8_check: pep8check(document, message) message.sort() mainframe.createSyntaxCheckWindow() mainframe.syntaxcheckwindow.adddata(message) if message: mainframe.panel.showPage(syntax_pagename) else: mainframe.panel.closePage(syntax_pagename) wx.CallAfter(document.SetFocus)
def OnLuaRun(win, event): interpreter = _get_lua_exe(win) if not interpreter: return doc = win.editctrl.getCurDoc() if doc.isModified() or doc.filename == '': if win.pref.lua_save_before_run: win.OnFileSave(event) else: d = wx.MessageDialog( win, tr("The script can't run because the document hasn't been saved.\nWould you like to save it?" ), tr("Run"), wx.YES_NO | wx.ICON_QUESTION) answer = d.ShowModal() d.Destroy() if answer == wx.ID_YES: win.OnFileSave(event) else: return if win.pref.lua_show_args: if not get_lua_args(win): return args = doc.args.replace('$path', os.path.dirname(doc.filename)) args = args.replace('$file', doc.filename) ext = os.path.splitext(doc.filename)[1].lower() parameter = Globals.pref.lua_default_paramters.get( Globals.pref.default_lua_interpreter, '') interpreter = dict(Globals.pref.lua_interpreter).get( Globals.pref.default_lua_interpreter, '') command = u'"%s" %s "%s" %s' % (interpreter, parameter, doc.filename, args) #chanage current path to filename's dirname path = os.path.dirname(doc.filename) os.chdir(common.encode_string(path)) win.RunCommand(command, redirect=win.document.redirect)
def OnToolRegister(win, event): try: key = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '*', _winreg.KEY_ALL_ACCESS) filename = os.path.basename(sys.argv[0]) f, ext = os.path.splitext(filename) if ext == '.exe': command = '"%s" "%%L"' % os.path.normpath( common.uni_work_file(filename)) else: path = os.path.normpath(common.uni_work_file('%s.pyw' % f)) execute = sys.executable.replace('python.exe', 'pythonw.exe') command = '"%s" "%s" "%%L"' % (execute, path) _winreg.SetValue( key, 'shell\\UliPad\\command', _winreg.REG_SZ, common.encode_string(command, common.defaultfilesystemencoding)) common.note(tr('Done')) except: error.traceback() wx.MessageDialog( win, tr('Registering UliPad to the context menu of Windows Explorer failed.' ), tr("Error"), wx.OK | wx.ICON_EXCLAMATION).ShowModal()
def goto_error_line(msgwin, line, lineno): import re r = re.compile('((\w:)?[^:\t\n\r\?\;]+):(\d+)') b = r.search(common.encode_string(line, common.defaultfilesystemencoding)) if b: return True, (b.groups()[0], b.groups()[2])
def goto_error_line(msgwin, line, lineno): import re r = re.compile('File\s+"(.*?)",\s+line\s+(\d+)') b = r.search(common.encode_string(line, common.defaultfilesystemencoding)) if b: return True, b.groups()