⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uibackenddelegate.py

📁 属性sosuo算法
💻 PY
📖 第 1 页 / 共 2 页
字号:
    def AsyncDialogDestroy (dialog):        try:            del once_dialogs[once]        except:            pass    if once is not None and once_dialogs.has_key (once):        return    dialog = BuildDialog (title, message, buttons, default)    dialog.connect("response", AsyncDialogResponse)    dialog.connect("destroy", AsyncDialogDestroy)    dialog.show()    if once is not None:        once_dialogs[once] = dialog_stock = { dialogs.BUTTON_OK.text : gtk.STOCK_OK,           dialogs.BUTTON_CANCEL.text : gtk.STOCK_CANCEL,           dialogs.BUTTON_YES.text : gtk.STOCK_YES,           dialogs.BUTTON_NO.text : gtk.STOCK_NO,           dialogs.BUTTON_QUIT.text : gtk.STOCK_QUIT}@gtkAsyncMethoddef ShowHTTPAuthDialogAsync(title, description, prefillUser, prefillPassword,        callback):    gtkDialog = BuildHTTPAuth (title, description, prefillUser,            prefillPassword)    gtkDialog.connect("response", callback)    gtkDialog.show()@gtkAsyncMethoddef ShowSearchChannelDialogAsync(dialog, callback):    gtkDialog = BuildSearchChannelDialog (dialog)    gtkDialog.connect("response", callback)    gtkDialog.show()@gtkAsyncMethoddef ShowTextEntryDialogAsync(title, description, buttons, default, prefillCallback, fillWithClipboardURL, callback):    gtkDialog = BuildTextEntryDialog (title, description, buttons, default, prefillCallback, fillWithClipboardURL)    gtkDialog.connect("response", callback)    gtkDialog.show()def pidIsRunning(pid):    if pid is None:        return False    try:        os.kill(pid, 0)        return True    except OSError, err:        return err.errno == errno.EPERMclipboard = Noneprimary = Nonedef init_clipboard ():    global clipboard    global primary    if clipboard is None:        clipboard = gtk.Clipboard(selection="CLIPBOARD")    if primary is None:        primary = gtk.Clipboard(selection="PRIMARY")class UIBackendDelegate:    def performStartupTasks(self, terminationCallback):        import startup        startup.performStartupTasks(terminationCallback)            def openExternalURL(self, url):        # We could use Python's webbrowser.open() here, but        # unfortunately, it doesn't have the same semantics under UNIX        # as under other OSes. Sometimes it blocks, sometimes it doesn't.        if (checkKDE()):            os.spawnlp (os.P_NOWAIT, "kfmclient", "kfmclient", "exec", url)        else:            os.spawnlp (os.P_NOWAIT, "gnome-open", "gnome-open", url)    def revealFile(self, filename):        if not os.path.isdir(filename):            filename = os.path.dirname(filename)        if (checkKDE()):            os.spawnlp (os.P_NOWAIT, "kfmclient", "kfmclient", "exec", "file://" + filename)        else:            os.spawnlp (os.P_NOWAIT, "nautilus", "nautilus", "file://" + filename)    def notifyDownloadCompleted(self, item):        pass    def notifyDownloadFailed(self, item):        pass    def updateAvailableItemsCountFeedback(self, count):        # Inform the user in a way or another that newly available items are        # available        pass    def notifyUnkownErrorOccurence(self, when, log = ''):        summary = _("Unknown Runtime Error")        message = _("An unknown error has occurred %s.") % (EscapeMessagePart(when),)        buttons = (gtk.STOCK_CLOSE, gtk.RESPONSE_OK)        ShowDialogAsync (summary, message, buttons, once="UnknownError")        return True    def makeButtonTuple (self, dialog):        """Given a dialog object, make a tuple of button/id pairs to pass to        the gtk.Dialog constructor.        """        buttons = []        i = 0        for button in dialog.buttons:            if _stock.has_key(button.text):                buttons [0:0] = (_stock[button.text], i)            else:                buttons [0:0] = (asUTF8 (button.text), i)            i = i + 1        return tuple(buttons)    def runDialog (self, dialog):        if isinstance(dialog, dialogs.ChoiceDialog) or isinstance(dialog, dialogs.MessageBoxDialog) or isinstance(dialog, dialogs.ThreeChoiceDialog):            def Callback (response):                if response == gtk.RESPONSE_DELETE_EVENT:                    dialog.runCallback (None)                elif response >= 0 and response < len(dialog.buttons):                    dialog.runCallback (dialog.buttons [response])                else:                    dialog.runCallback (None)                ShowDialogAsync (EscapeMessagePart(dialog.title), EscapeMessagePart(dialog.description), self.makeButtonTuple(dialog), default=0, callback = Callback)        elif isinstance(dialog, dialogs.HTTPAuthDialog):            def AsyncDialogResponse(gtkDialog, response):                retval = None                if (response == gtk.RESPONSE_OK):                    dialog.runCallback(dialogs.BUTTON_OK, gtkDialog.user.get_text().decode('utf8', 'replace'), gtkDialog.password.get_text().decode('utf8', 'replace'))                else:                    dialog.runCallback(None)                gtkDialog.destroy()            ShowHTTPAuthDialogAsync(EscapeMessagePart(dialog.title),                    EscapeMessagePart(dialog.description), dialog.prefillUser,                    dialog.prefillPassword, callback=AsyncDialogResponse)        elif isinstance(dialog, dialogs.TextEntryDialog):            def AsyncDialogResponse(gtkDialog, response):                retval = None                if response == gtk.RESPONSE_DELETE_EVENT:                    dialog.runCallback (None)                elif response >= 0 and response < len(dialog.buttons):                    dialog.runCallback (dialog.buttons [response], gtkDialog.entry.get_text().decode('utf8', 'replace'))                else:                    dialog.runCallback (None)                gtkDialog.destroy()            ShowTextEntryDialogAsync (EscapeMessagePart(dialog.title), EscapeMessagePart(dialog.description), self.makeButtonTuple(dialog), default=0,                                      prefillCallback=dialog.prefillCallback, fillWithClipboardURL=dialog.fillWithClipboardURL,                                      callback = AsyncDialogResponse)        elif isinstance(dialog, dialogs.SearchChannelDialog):            def AsyncDialogResponse(gtkDialog, response):                retval = None                widgetTree = gtkDialog.get_data("glade")                dialog.term = widgetTree["entry-search-term"].get_text()                if widgetTree["radiobutton-search-channel"].get_active():                    dialog.style = dialog.CHANNEL                    iter = widgetTree["combobox-search-channel"].get_active_iter()                    if iter is None:                        dialog.location = None                    else:                        (dialog.location,) = widgetTree["combobox-search-channel"].get_model().get(iter, 0)                elif widgetTree["radiobutton-search-engine"].get_active():                    dialog.style = dialog.ENGINE                    iter = widgetTree["combobox-search-engine"].get_active_iter()                    if iter is None:                        dialog.location = None                    else:                        (dialog.location,) = widgetTree["combobox-search-engine"].get_model().get(iter, 0)                elif widgetTree["radiobutton-search-url"].get_active():                    dialog.style = dialog.URL                    dialog.location = widgetTree["entry-search-url"].get_text()                if (response == gtk.RESPONSE_OK):                    dialog.runCallback(dialogs.BUTTON_CREATE_CHANNEL)                elif (response == gtk.RESPONSE_CANCEL):                    dialog.runCallback(dialogs.BUTTON_CANCEL)                else:                    dialog.runCallback(None)                gtkDialog.destroy()            ShowSearchChannelDialogAsync(dialog, callback=AsyncDialogResponse)        else:            dialog.runCallback (None)    @gtkAsyncMethod    def showContextMenu(self, menuItems):        menu = gtk.Menu()        for item in menuItems:            if item.label:                gtkitem = gtk.MenuItem(item.label)                if item.callback is not None:                    gtkitem.connect("activate",                             lambda foo, item=item: item.activate())                else:                    gtkitem.set_sensitive(False)            else:                gtkitem = gtk.SeparatorMenuItem()            menu.append(gtkitem)            gtkitem.show()        menu.show()        gobject.timeout_add(100, lambda: menu.popup(None, None, None,            gtk.gdk.RIGHTBUTTON, 0))    @gtkAsyncMethod    def copyTextToClipboard(self, text):        global clipboard        global primary        init_clipboard()        clipboard.set_text(text)        primary.set_text(text)    def killDownloadDaemon(self, oldpid):        if oldpid is None:            return        if pidIsRunning(oldpid):            try:                os.kill(oldpid, signal.SIGTERM)                for i in xrange(100):                    time.sleep(.01)                    if not pidIsRunning(oldpid):                        return                os.kill(oldpid, signal.SIGKILL)            except:                print "error killing download daemon"                traceback.print_exc()    def launchDownloadDaemon(self, oldpid, env):        # Use UNIX style kill        if oldpid is not None and pidIsRunning(oldpid):            self.killDownloadDaemon(oldpid)        environ = os.environ.copy()        import democracy        democracyPath = os.path.dirname(democracy.__file__)        dlDaemonPath = os.path.join(democracyPath, 'dl_daemon')        privatePath = os.path.join(dlDaemonPath, 'private')        pythonPath = environ.get('PYTHONPATH', '').split(':')        pythonPath[0:0] = [privatePath, democracyPath]        environ['PYTHONPATH'] = ':'.join(pythonPath)        environ.update(env)        # run the Democracy_Downloader script        script = os.path.join(dlDaemonPath,  'Democracy_Downloader.py')        os.spawnlpe(os.P_NOWAIT, "python2.4", "python2.4", script, environ)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -