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

📄 uibackenddelegate.py

📁 属性sosuo算法
💻 PY
📖 第 1 页 / 共 2 页
字号:
import errnoimport osimport signalimport sysimport timeimport gobjectimport gtkimport threadingimport tracebackimport appimport dialogsfrom gtcache import gettext as _from gtcache import ngettextimport reimport MainFrameimport resourcesimport feedimport utilimport viewsimport indexesimport configimport prefsfrom frontend import *from frontend_implementation.gtk_queue import gtkAsyncMethod################################################################################### 'Delegate' objects for asynchronously asking the user questions       ###################################################################################dialogParent = Nonedef asUTF8(string):    if type(string) == unicode:        return string.encode("utf8", "replace")    else:        return stringinKDE = Nonedef checkKDE():    global inKDE    if inKDE is None:        inKDE = False        try:            if (os.environ["KDE_FULL_SESSION"]):                inKDE = True        except:            pass    return inKDE# Copied from feed.py and modified for edge cases.# URL validitation and normalizationdef validateFeedURL(url):    return re.match(r"^(http|https)://[^/]+/.*", url) is not Nonedef normalizeFeedURL(url):    if url is None:        return url    # Valid URL are returned as-is    if validateFeedURL(url):        return url    originalURL = url        # Check valid schemes with invalid separator    match = re.match(r"^(http|https):/*(.*)$", url)    if match is not None:        url = "%s://%s" % match.group(1,2)    # Replace invalid schemes by http    match = re.match(r"^(([A-Za-z]*):/*)*(.*)$", url)    if match is not None and match.group(2) in ['feed', 'podcast', None]:        url = "http://%s" % match.group(3)    elif match is not None and match.group(1) == 'feeds':        url = "https://%s" % match.group(3)    # Make sure there is a leading / character in the path    match = re.match(r"^(http|https)://[^/]*$", url)    if match is not None:        url = url + "/"    if not validateFeedURL(url):        return None    else:        return urldef EscapeMessagePart(message_part):    if '&' in message_part or '<' in message_part:        message_part = message_part.replace ("&", "&amp;")        message_part = message_part.replace ("<", "&lt;")    return message_partdef BuildDialog (title, message, buttons, default):    flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT    dialog = gtk.Dialog(title, dialogParent, flags, buttons)    dialog.set_default_size(425, -1)    label = gtk.Label()    label.set_line_wrap(True)    label.set_selectable(True)    label.set_markup(message)    label.set_padding (6, 6)    dialog.vbox.add(label)    label.show()    dialog.set_default_response (default)    return dialogdef BuildTextEntryDialog(title, message, buttons, default, prefillCallback, fillWithClipboardURL):    dialog = BuildDialog(title, message, buttons, default)    dialog.entry = gtk.Entry()    dialog.entry.set_activates_default(True)    dialog.vbox.add(dialog.entry)        prefill = None    if fillWithClipboardURL:        global clipboard        global primary        init_clipboard()        prefill = primary.wait_for_text()        prefill = normalizeFeedURL(prefill)        if prefill is None:            prefill = clipboard.wait_for_text()            prefill = normalizeFeedURL(prefill)    if prefill is None and prefillCallback:        prefill = prefillCallback()        if prefill == "":            prefill = None    if prefill:        dialog.entry.set_text(prefill)    dialog.entry.show()    return dialogdef BuildHTTPAuth(summary, message, prefillUser = None, prefillPassword = None):    """Ask the user for HTTP login information for a location, identified    to the user by its URL and the domain string provided by the    server requesting the authorization. Default values can be    provided for prefilling the form. If the user submits    information, it's returned as a (user, password)    tuple. Otherwise, if the user presses Cancel or similar, None    is returned."""    dialog = gtk.Dialog(summary, None, (), (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK))    dialog.set_default_size(425, -1)    table = gtk.Table()    dialog.vbox.add(table)        label = gtk.Label()    label.set_line_wrap(True)    label.set_selectable(True)    label.set_markup(message)    label.set_padding (6, 6)    table.attach (label, 0, 2, 0, 1, gtk.FILL, gtk.FILL)    label = gtk.Label()    label.set_markup(_("Username:"))    label.set_padding (6, 6)    label.set_alignment (1.0, 0.5)    table.attach (label, 0, 1, 1, 2, gtk.FILL, gtk.FILL)    dialog.user = gtk.Entry()    if (prefillUser != None):        dialog.user.set_text(prefillUser)    table.attach (dialog.user, 1, 2, 1, 2, gtk.FILL | gtk.EXPAND, gtk.FILL, 6, 6)    label = gtk.Label()    label.set_markup(_("Password:"))    label.set_padding (6, 6)    label.set_alignment (1.0, 0.5)    table.attach (label, 0, 1, 2, 3, gtk.FILL, gtk.FILL)    dialog.password = gtk.Entry()    dialog.password.set_visibility(False)    dialog.password.set_activates_default(True)    if (prefillPassword != None):        dialog.password.set_text(prefillPassword)    table.attach (dialog.password, 1, 2, 2, 3, gtk.FILL | gtk.EXPAND, gtk.FILL, 6, 6)    table.show_all()    dialog.set_default_response (gtk.RESPONSE_OK)    return dialogdef BuildSearchChannelDialog(dialog):    widgetTree = MainFrame.WidgetTree(resources.path('democracy.glade'), 'dialog-search', 'democracyplayer')    gtkDialog = widgetTree['dialog-search']    gtkDialog.set_data("glade", widgetTree)    channel_id = -1    engine_name = dialog.defaultEngine#    mainWindow = self.mainFrame.widgetTree['main-window']#    gtkDialog.set_transient_for(mainWindow)    if dialog.style == dialog.CHANNEL:        widgetTree["radiobutton-search-channel"].set_active(True)        if dialog.location is not None:            channel_id = dialog.location    elif dialog.style == dialog.ENGINE:        widgetTree["radiobutton-search-engine"].set_active(True)        if dialog.location is not None:            engine_name = str(dialog.location)    elif dialog.style == dialog.URL:        widgetTree["radiobutton-search-url"].set_active(True)        if dialog.location:            widgetTree["entry-search-url"].set_text(dialog.location)    if dialog.term:        widgetTree["entry-search-term"].set_text(dialog.term)    def connect_sensitive (toggle, widget):        toggle = widgetTree[toggle]        widget = widgetTree[widget]        def toggled(*args):            widget.set_sensitive(toggle.get_active())        toggle.connect("toggled", toggled)        toggled()    connect_sensitive ("radiobutton-search-channel", "combobox-search-channel")    connect_sensitive ("radiobutton-search-engine", "combobox-search-engine")    connect_sensitive ("radiobutton-search-url", "entry-search-url")    store = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING)    select_iter = None    for id, title in dialog.channels:        iter = store.append((id, title))        if select_iter is None or channel_id == id:            select_iter = iter    cell = gtk.CellRendererText()    combo = widgetTree["combobox-search-channel"]    combo.pack_start(cell, True)    combo.add_attribute(cell, 'text', 1)    combo.set_model (store)    combo.set_active_iter(select_iter)    store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)    select_iter = None    for name, title in dialog.engines:        iter = store.append((name, title))        if select_iter is None or engine_name == name:            select_iter = iter    cell = gtk.CellRendererText()    combo = widgetTree["combobox-search-engine"]    combo.pack_start(cell, True)    combo.add_attribute(cell, 'text', 1)    combo.set_model (store)    combo.set_active_iter(select_iter)    return gtkDialogonce_dialogs = {}@gtkAsyncMethoddef ShowDialogAsync (title, message, buttons, default = gtk.RESPONSE_CANCEL, once=None, callback=None):    def AsyncDialogResponse(dialog, response):        if callback:            callback (response)        dialog.destroy()

⌨️ 快捷键说明

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