def OnDjangoFunc(win, event): _id = event.GetId() try: if hasattr(win, "IDPM_DJANGO_STARTAPP") and _id == win.IDPM_DJANGO_STARTAPP: OnDjangoStartApp(win) elif hasattr(win, "IDPM_DJANGO_INSTALLAPP") and _id == win.IDPM_DJANGO_INSTALLAPP: d = Casing.Casing(OnDjangoInstallApp, win) v = Casing.new_obj() v.count = 0 # d.onprocess(onprocess, v=v, timestep=0.1) # d.onsuccess(onsuccess) # d.onexception(onsuccess) d.start_thread() elif hasattr(win, "IDPM_DJANGO_INSTALLSYSAPP_ADMIN") and _id == win.IDPM_DJANGO_INSTALLSYSAPP_ADMIN: d = Casing.Casing(OnDjangoInstallConApp, win, "admin") v = Casing.new_obj() # d.onprocess(onprocess, v=v, timestep=0.1) # d.onsuccess(onsuccess) # d.onexception(onsuccess) d.start_thread() elif hasattr(win, "IDPM_DJANGO_RUNSERVER") and _id == win.IDPM_DJANGO_RUNSERVER: OnDjangoRunServer(win) elif hasattr(win, "IDPM_DJANGO_RUNSHELL") and _id == win.IDPM_DJANGO_RUNSHELL: OnDjangoRunShell(win) elif hasattr(win, "IDPM_DJANGO_DOT") and _id == win.IDPM_DJANGO_DOT: OnCreateDot(win) except: error.traceback() common.showerror(win, tr("There is some wrong as executing the menu."))
def openfile(self, filename='', encoding='', delay=None, *args, **kwargs): rssid = filename[6:] rssid = int(rssid) d = Casing.Casing(self.load_from_db, rssid) d += Casing.Casing(self.datas.set_guids, self.guids) d += Casing.Casing(self.datas.load, self.getdata) d += Casing.Casing(self.show_unread, rssid) d.start_thread() self.filename = filename self.locale = encoding self.opened = True
def get_casting(self, item): text = Casing.new_obj() text.text = '' node = self.sharewin.get_node(item) rssid = node['data']['id'] feedurl = str(node['data']['url']) d = Casing.Casing(self.get_feed, feedurl=feedurl, text=text) d += Casing.Casing(self.parse_content, rssid=rssid, text=text) d += Casing.Casing(self.update_feed_read, item=item) d.onexception(self.on_exception, item) d.onprocess(self.on_process, item=item) d.onsuccess(self.on_success, item) self.casings[item] = d return d
def start_client(host, port, bindobj): client = ConCurrentClient(host, port) client.bindobject(bindobj) from modules import Casing d = Casing.Casing(asyncore.loop, 1) d.start_thread() return client
def fresh_feed(self, item): d = self.casings.get(item, None) if d and d.isactive(): return d = self.get_casting(item) d += Casing.Casing(self.update_content, item=item) d.start_sync_thread()
def start_server(host, port, bindobj): server = ConCurrentServer(host, port) server.bindobject(bindobj) from modules import Casing d = Casing.Casing(asyncore.loop, 1) d.start_thread() return server
def run(host=HOST, port=PORT): global server server = DDEServer(host, port) from modules import Casing d = Casing.Casing(asyncore.loop, 1) d.start_thread() return server
def fresh_category(self, item): node = self.sharewin.get_node(item) cate_id = node['data']['id'] mc = Casing.MultiCasing() for i in self.cate_items[cate_id]: d = self.get_casting(self.feeds[i]) mc.append(d) mc.start_sync_thread()
def after_addpath(dirwin, item): from modules import common import SvnSupport as vc def walk(dirwin, item): # svn_lock.acquire() # try: if dirwin.isFile(item): path = dirwin.get_node_filename(item) entries = vc.get_entries(path) filename = dirwin.tree.GetItemText(item) f = entries.get(filename, '') img_index = dirwin.get_file_image(filename) new_img_index = get_fix_imgindex(img_index, f) old_img_index = dirwin.tree.GetItemImage(item) if new_img_index != old_img_index: set_image(dirwin.tree, item, new_img_index, wx.TreeItemIcon_Normal) return else: if dirwin.tree.GetChildrenCount( item) == 0 and not dirwin.tree.IsExpanded(item): return path = common.getCurrentDir(dirwin.get_node_filename(item)) entries = vc.get_entries(path) node, cookie = dirwin.tree.GetFirstChild(item) while dirwin.is_ok(node): filename = dirwin.tree.GetItemText(node) f = entries.get(filename, '') if dirwin.isFile(node): img_index = dirwin.get_file_image(filename) new_img_index = get_fix_imgindex(img_index, f) old_img_index = dirwin.tree.GetItemImage(node) if new_img_index != old_img_index: set_image(dirwin.tree, node, new_img_index, wx.TreeItemIcon_Normal) else: img_index = (dirwin.close_image, dirwin.open_image) new_img_index = (get_fix_imgindex(dirwin.close_image, f), get_fix_imgindex(dirwin.open_image, f)) old_img_index = dirwin.tree.GetItemImage(node) if old_img_index not in new_img_index: set_image(dirwin.tree, node, new_img_index[1], wx.TreeItemIcon_Expanded) set_image(dirwin.tree, node, new_img_index[0], wx.TreeItemIcon_Normal) if dirwin.tree.GetChildrenCount(node) > 0: walk(dirwin, node) node, cookie = dirwin.tree.GetNextChild(item, cookie) # finally: # svn_lock.release() from modules import Casing d = Casing.Casing(walk, dirwin, item) d.start_thread()
def OnPylint(win, event): """ Get the filename of the current document. Save it if necessary. Chdir to the Project Home directory and run PyLint. The --files-output=y option directs the output to the files pylint_filename.txt and pylint_global.txt in the Project Home directory. """ try: from pylint import lint except: common.showerror( win, tr("Import pylint error! Maybe you haven't installed it.\nPlease install it first." )) return doc = win.editctrl.getCurDoc() pyfile = doc.filename if doc.isModified() or pyfile == '': dialog = wx.MessageDialog( win, tr("The file has not been saved.\n\ Would you like to save the file and then re-run PyLint ?"), "PyLint", wx.YES_NO | wx.ICON_QUESTION) answer = dialog.ShowModal() if answer == wx.ID_YES: win.OnFileSave(event) return else: return from Report import Report # projecthome = common.getProjectHome(pyfile) # os.chdir(common.encode_string(projecthome)) # args = ["--files-output=y", pyfile] win.createPylintSyntaxCheckWindow() if win.pylintsyntaxcheckwindow: win.pylintsyntaxcheckwindow.list.DeleteAllItems() def f(): try: common.setmessage(win, 'Pylint syntax checking...') try: lint.Run([pyfile], Report(win.pylintsyntaxcheckwindow.list)) except: error.track() finally: common.setmessage(win, '') common.note(tr('Pylint syntax checking finished!')) d = Casing.Casing(f) d.start_thread()
def pipe_command(cmd, callback): from modules import Casing def _run(cmd): try: sin, sout, serr = os.popen3(cmd) if callback: wx.CallAfter(callback, sout.read() + serr.read()) except: error.traceback() d = Casing.Casing(_run, cmd) d.start_thread()
def startup(self, item): sharewin = self.parent RssDb.init(Globals.rss_dbfile) categories = RssDb.Category.select() sharewin.tree.Freeze() for i in categories: data = { 'type': 'rss', 'level': 'category', 'caption': i.title, 'data': { 'save': False, 'id': i.id } } root = sharewin.addnode(item, data=data) self.add_category_ids(i.id, root) for f in RssDb.Feed.select(RssDb.Feed.c.category_id == i.id, order_by=[RssDb.Feed.c.title]): number = RssDb.Data.un_read_count(f.id) if number: caption = u"(%d)%s" % (number, f.title) else: caption = f.title data = { 'type': 'rss', 'level': 'feed', 'caption': caption, 'data': { 'url': f.link, 'homeurl': f.homelink, 'save': False, 'id': f.id } } obj = sharewin.addnode(root, data=data) self.add_feed_ids(i.id, f.id, obj) if number: sharewin.tree.SetItemBold(obj, True) sharewin.tree.Expand(root) sharewin.tree.Thaw() if categories: wx.CallAfter(sharewin.tree.Expand, item) if Globals.mainframe.pref.rss_start: mc = Casing.MultiCasing() for item in self.feeds.values(): d = self.get_casting(item) mc.append(d) mc.start_sync_thread()
def OnDjangoFunc(win, event): _id = event.GetId() try: if hasattr(win, 'IDPM_DJANGO_STARTAPP') and _id == win.IDPM_DJANGO_STARTAPP: OnDjangoStartApp(win) elif hasattr(win, 'IDPM_DJANGO_INSTALLAPP' ) and _id == win.IDPM_DJANGO_INSTALLAPP: d = Casing.Casing(OnDjangoInstallApp, win) v = Casing.new_obj() v.count = 0 # d.onprocess(onprocess, v=v, timestep=0.1) # d.onsuccess(onsuccess) # d.onexception(onsuccess) d.start_thread() elif hasattr(win, 'IDPM_DJANGO_INSTALLSYSAPP_ADMIN' ) and _id == win.IDPM_DJANGO_INSTALLSYSAPP_ADMIN: d = Casing.Casing(OnDjangoInstallConApp, win, 'admin') v = Casing.new_obj() # d.onprocess(onprocess, v=v, timestep=0.1) # d.onsuccess(onsuccess) # d.onexception(onsuccess) d.start_thread() elif hasattr( win, 'IDPM_DJANGO_RUNSERVER') and _id == win.IDPM_DJANGO_RUNSERVER: OnDjangoRunServer(win) elif hasattr( win, 'IDPM_DJANGO_RUNSHELL') and _id == win.IDPM_DJANGO_RUNSHELL: OnDjangoRunShell(win) elif hasattr(win, 'IDPM_DJANGO_DOT') and _id == win.IDPM_DJANGO_DOT: OnCreateDot(win) except: error.traceback() common.showerror(win, tr("There is some wrong as executing the menu."))
def on_modified(win): from par.md import parseHtml for pagename, panelname, notebook, page in Globals.mainframe.panel.getPages(): if is_mdhtmlview(page, win) and not page.isStop() and not page.rendering: page.rendering = True from modules import Casing def f(): try: text = parseHtml(win.GetText().encode('utf-8'), template=md_html_template) page.refresh(text) finally: page.rendering = False d = Casing.Casing(f) d.start_thread() break
def on_modified(win): for pagename, panelname, notebook, page in Globals.mainframe.panel.getPages( ): if is_resthtmlview(page, win) and not page.isStop() and not page.rendering: page.rendering = True from modules import Casing def f(): try: text = html_fragment(win.GetText().encode('utf-8'), win.filename) page.refresh(text) finally: page.rendering = False d = Casing.Casing(f) d.start_thread() break
def wrap_run(func, callback=None, begin_msg=tr('Processing...'), end_msg='', finish_msg='Finished!', result=None): def f(): common.setmessage(begin_msg) try: try: func() if callback: callback() except Exception, e: error.traceback() common.showerror(str(e)) finally: if result: wx.CallAfter(result.finish) common.setmessage(end_msg) Casing.Casing(f).start_thread()
def git_after_addpath(dirwin, item): from modules import common from modules import Casing from Git import Git def walk(dirwin, item, dir, files): if files is None: files = {} for flag, filename in repo.status_files(): files[filename] = flag dir = os.path.normpath(dir).replace('\\', '/') if dir == '.': dir = '' if dirwin.isFile(item): path = dirwin.get_node_filename(item) filename = os.path.join(dir, dirwin.tree.GetItemText(item)).replace( '\\', '/') f = files.get(filename, ' ') img_index = dirwin.get_file_image(filename) new_img_index = git_get_fix_imgindex(img_index, f) old_img_index = dirwin.tree.GetItemImage(item) if new_img_index != old_img_index: git_set_image(dirwin.tree, item, new_img_index, wx.TreeItemIcon_Normal) return else: if dirwin.tree.GetChildrenCount( item) == 0 and not dirwin.tree.IsExpanded(item): return path = common.getCurrentDir(dirwin.get_node_filename(item)) node, cookie = dirwin.tree.GetFirstChild(item) while dirwin.is_ok(node): filename = os.path.join(dir, dirwin.tree.GetItemText(node)).replace( '\\', '/') if not dirwin.isFile(node): filename = filename + '/' f = files.get(filename, ' ') if dirwin.isFile(node): img_index = dirwin.get_file_image(filename) new_img_index = git_get_fix_imgindex(img_index, f) old_img_index = dirwin.tree.GetItemImage(node) if new_img_index != old_img_index: git_set_image(dirwin.tree, node, new_img_index, wx.TreeItemIcon_Normal) else: img_index = (dirwin.close_image, dirwin.open_image) new_img_index = (git_get_fix_imgindex(dirwin.close_image, f), git_get_fix_imgindex(dirwin.open_image, f)) old_img_index = dirwin.tree.GetItemImage(node) if old_img_index not in new_img_index: git_set_image(dirwin.tree, node, new_img_index[1], wx.TreeItemIcon_Expanded) git_set_image(dirwin.tree, node, new_img_index[0], wx.TreeItemIcon_Normal) if dirwin.tree.GetChildrenCount(node) > 0: walk(dirwin, node, os.path.join(dir, filename), files) node, cookie = dirwin.tree.GetNextChild(item, cookie) path = common.getCurrentDir(dirwin.get_node_filename(item)) repo_path = detect_git(path) if repo_path: repo = Git(path) d = Casing.Casing(walk, dirwin, item, os.path.relpath(path, repo_path), None) d.start_thread()
proxy = None try: server = ServerProxy("http://ulipad.appspot.com/XMLRPC", transport=UrllibTransport(proxy)) version = server.version() def _f(): if version > Version.version: dlg = UpdateDialog(Globals.mainframe, version) dlg.ShowModal() dlg.Destroy() else: if force: common.showmessage(tr("There is no newer version.")) wx.CallAfter(_f) except Exception, e: if force: wx.CallAfter(common.showerror, e) if not force: d = Casing.Casing(f) d.start_thread() else: f() def OnHelpCheckUpdate(win, event): check_update(True) Mixin.setMixin('mainframe', 'OnHelpCheckUpdate', OnHelpCheckUpdate) def on_show(win): if not Globals.pref.check_update: return wx.FutureCall(1000, check_update) Mixin.setPlugin('mainframe', 'show', on_show)
def OnFindButtonClick(self, e): if self.stopping: #already stopping return elif self.running: #running, we want to try to stop self.stopping = 1 self.status.SetValue(tr("Stopping...please wait.")) self.btnRun.SetLabel(tr("Start Search")) return if self.starting: #previously was waiting to start due to an #external yield, abort waiting and cancel #search self.starting = 0 self.status.SetValue(tr("Search cancelled.")) self.btnRun.SetLabel(tr("Start Search")) return #try to start self.starting = 1 self.btnRun.SetLabel(tr("Stop Search")) #am currently the topmost call, so will continue. self.starting = 0 self.running = 1 def getlist(c): cc = c.GetCount() e = [c.GetString(i) for i in xrange(cc)] a = c.GetValue() if a: if a in e: e.remove(a) e = [a] + e e = e[:10] if len(e) > cc: c.Append(e[-1]) for i in xrange(len(e)): c.SetString(i, e[i]) c.SetSelection(0) return e self.pref.searchinfile_searchlist = getlist(self.search) self.pref.searchinfile_dirlist = getlist(self.sdirs) self.pref.searchinfile_extlist = getlist(self.extns) self.pref.searchinfile_case = self.cs.IsChecked() self.pref.searchinfile_subdir = self.ss.IsChecked() self.pref.searchinfile_regular = self.re.IsChecked() self.pref.searchinfile_onlyfilename = self.onlyfilename.IsChecked() self.pref.save() search = self.search.GetValue() paths = self.sdirs.GetValue().split(';') extns = self.extns.GetValue().split(';') or ['*.*'] case = self.cs.IsChecked() subd = self.ss.IsChecked() sfunct = self.searchST if self.re.IsChecked(): sfunct = self.searchRE if case: search = re.compile(search) else: search = re.compile(search, re.IGNORECASE) results = self.results results.Clear() def _find(): def file_iterator(path, subdirs, extns): try: lst = os.listdir(path) except: return d = [] for file in lst: a = common.uni_join_path(path, file) if os.path.isfile(a): for extn in extns: if fnmatch.fnmatch(file, str(extn)): yield a break elif subdirs and os.path.isdir(a): d.append(a) if not subdirs: return for p in d: for f in file_iterator(p, subdirs, extns): yield f filecount = 0 filefcount = 0 foundcount = 0 ss = tr("Found %i instances in %i files out of %i files checked.") for path in paths: if not self.running: break for filename in file_iterator(path, subd, extns): filecount += 1 if not self.stopping: r = sfunct(filename, search, case) if r: try: for a in r: wx.CallAfter(results.Append, a) if self.onlyfilename.IsChecked(): break except: #for platforms with limited sized #wx.ListBox controls pass filefcount += 1 foundcount += len(r) - 1 wx.CallAfter(self.status.SetValue, (ss % (foundcount, filefcount, filecount)) + tr('...searching...')) else: break if self.stopping: self.stopping = 0 ex = tr('...cancelled.') #was stopped by a button press else: self.running = 0 ex = tr('...done.') wx.CallAfter(self.btnRun.SetLabel, tr("Start Search")) wx.CallAfter(self.status.SetValue, (ss % (foundcount, filefcount, filecount)) + ex) self.stopping = 0 self.running = 0 self.starting = 0 if self.running: from modules import Casing d = Casing.Casing(_find) d.start_thread()