示例#1
0
def usage():
    print _("Usage: %s <options> ...") % sys.argv[0]
    print
    print _("The following options are understood:")

    opt_list = []

    for r in opt_table:
        opt = "--" + r[1]
        if r[0]:
            opt = "-" + r[0] + ", " + opt
        if r[2]:
            opt = opt + "=<" + r[2] + ">"

        opt_list.append([opt + "  ", r[3]])

    # By appending [0,0], we insure that this will work even if
    # opt_list is empty (which it never should be)
    max_len = apply(max, map(lambda x: len(x[0]), opt_list) + [0, 0])

    for opt, desc_str in opt_list:

        if 79 - max_len > 10:
            desc = rcd_util.linebreak(desc_str, 79 - max_len)
        else:
            desc = [desc_str]

        desc_first = desc.pop(0)
        print string.ljust(opt, max_len) + desc_first
        for d in desc:
            print " " * max_len + d
示例#2
0
def usage():
    print _("Usage: %s <options> ...") % sys.argv[0]
    print
    print _("The following options are understood:")

    opt_list = []

    for r in opt_table:
        opt = "--" + r[1]
        if r[0]:
            opt = "-" + r[0] + ", " + opt
        if r[2]:
            opt = opt + "=<" + r[2] + ">"

        opt_list.append([opt + "  ", r[3]])

    # By appending [0,0], we insure that this will work even if
    # opt_list is empty (which it never should be)
    max_len = apply(max, map(lambda x:len(x[0]), opt_list) + [0,0])

    for opt, desc_str in opt_list:

        if 79 - max_len > 10:
            desc = rcd_util.linebreak(desc_str, 79 - max_len)
        else:
            desc = [desc_str]

        desc_first = desc.pop(0)
        print string.ljust(opt, max_len) + desc_first
        for d in desc:
            print " " * max_len + d
示例#3
0
def news_item_get_title(item):
    summary = re.sub("\s+", " ", item["summary"])

    # Break the news item up to make it easier to read.
    # FIXME: It would be nice to actually wrap the text in
    # some sort of intelligent way.
    lines = rcd_util.linebreak(summary, 72)
    summary = string.join(lines, "\n")

    return "<b>" + item["title"] + "</b>\n<i>" + item["time_str"] + "</i>\n" + summary
示例#4
0
def news_item_get_title(item):
    summary = re.sub("\s+", " ", item["summary"])

    # Break the news item up to make it easier to read.
    # FIXME: It would be nice to actually wrap the text in
    # some sort of intelligent way.
    lines = rcd_util.linebreak(summary, 72)
    summary = string.join(lines, "\n")

    return "<b>" + item["title"] + "</b>\n<i>" + item[
        "time_str"] + "</i>\n" + summary
示例#5
0
def ok_to_quit(main_app_window):

    ins = red_pendingops.pending_install_count()
    rem = red_pendingops.pending_remove_count()

    if ins == 0 and rem == 0:
        return 1

    msgs = []
    if ins > 0:
        msgs.append("%d pending install%s" % (ins, (ins > 1 and "s") or ""))
    if rem > 0:
        msgs.append("%d pending removal%s" % (rem, (rem > 1 and "s") or ""))

    if (ins == 1 and rem == 0) or (ins == 0 and rem == 1):
        word = "is"
    else:
        word = "are"
    count_msg  = "There %s currently %s.  If you quit now, all pending " \
                 "operations will be lost." % (word, string.join(msgs, " and "))

    msg_lines = rcd_util.linebreak(count_msg, 40)
    msg_lines.append(_("Are you sure you want to quit?"))

    msgbox = gtk.VBox(0, 0)
    msgbox.pack_start(gtk.HBox(0, 0), 0, 0, 4)  # shim
    for line in msg_lines:
        label = gtk.Label(line)
        label.set_alignment(0, 0.5)
        msgbox.pack_start(label, 1, 0, 1)
    msgbox.pack_start(gtk.HBox(0, 0), 0, 0, 4)  # shim

    img = gtk.Image()
    img.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)

    main_box = gtk.HBox(0, 0)

    main_box.pack_start(gtk.HBox(0, 0), 0, 0, 4)  # shim
    main_box.pack_start(img, 0, 0, 5)
    main_box.pack_start(msgbox, 1, 1, 5)
    main_box.pack_start(gtk.HBox(0, 0), 0, 0, 4)  # shim
    main_box.show_all()

    dialog = gtk.Dialog("", parent=main_app_window)
    dialog.add_button(gtk.STOCK_CANCEL, 0)
    dialog.add_button(gtk.STOCK_QUIT, 1)
    dialog.vbox.add(main_box)

    dialog.show()
    retval = dialog.run()
    dialog.destroy()

    return retval
示例#6
0
    def build_verified_ok_page(self):
        page = self.page

        box = gtk.HBox(0, 0)
        box.pack_start(gtk.Label(""), expand=1, fill=1)

        img = red_pixbuf.get_widget("verify")
        box.pack_start(img, expand=0, fill=1, padding=4)

        msg1 = "<span size=\"large\"><b>%s</b></span>" \
               % _("System Verified")

        msg2 = _("All package dependencies are satisfied, and no corrective actions are required.")

        msg = msg1+"\n"+string.join(rcd_util.linebreak(msg2, width=30), "\n")

        label = gtk.Label("")
        label.set_markup(msg)
        box.pack_start(label, expand=0, fill=1, padding=4)

        box.pack_start(gtk.Label(""), expand=1, fill=1)

        frame = gtk.Frame(None)
        frame.add(box)

        bg = gtk.EventBox()
        style = bg.get_style().copy()
        color = bg.get_colormap().alloc_color("white")
        style.bg[gtk.STATE_NORMAL] = color
        bg.set_style(style)

        bg.add(frame)

        page.pack_start(bg, expand=1, fill=1)

        buttons = gtk.HButtonBox()
        buttons.set_layout(gtk.BUTTONBOX_END)
        button = gtk.Button(gtk.STOCK_OK)
        button.set_use_stock(1)
        buttons.add(button)

        page.pack_end(buttons, 0, 0, 0)

        button.set_flags(gtk.CAN_DEFAULT)
        button.grab_default()

        button.connect("clicked", lambda x:self.pop())
            
        page.show_all()
示例#7
0
    def __init__(self,
                 image=None,
                 pixbuf=None,
                 pixbuf_name=None,
                 text=None,
                 formatted_text=None):

        gtk.EventBox.__init__(self)

        if pixbuf_name:
            assert not pixbuf and not image
            image = red_pixbuf.get_widget(pixbuf_name)

        if pixbuf:
            assert not pixbuf_name and not image
            image = gtk.Image()
            image.set_from_pixbuf(pixbuf)

        if text:
            assert not formatted_text
            formatted_text = "<span size=\"large\"><b>%s</b></span>" % text
            formatted_text = string.join(
                rcd_util.linebreak(formatted_text, width=70), "\n")

        box = gtk.HBox(0, 0)
        box.pack_start(gtk.Label(""), expand=1, fill=1)

        if image:
            box.pack_start(image, expand=0, fill=1, padding=4)

        label = gtk.Label("")
        if formatted_text:
            label.set_markup(formatted_text)
        box.pack_start(label, expand=0, fill=1, padding=4)

        box.pack_start(gtk.Label(""), expand=1, fill=1)

        frame = gtk.Frame(None)
        frame.add(box)

        self.add(frame)

        style = self.get_style().copy()
        color = self.get_colormap().alloc_color("white")
        style.bg[gtk.STATE_NORMAL] = color
        self.set_style(style)

        self.show_all()
        self.hide()
示例#8
0
    def set_label(self, msg):
        if msg:
            lines = rcd_util.linebreak(msg, WRAP_LABEL_LEN)
        else:
            lines = []

        # Try to set the scrollbox to a reasonable size, neither too big
        # or too small. (We always want at least 3 lines of text to avoid
        # "jumpyness".)
        n = max(3, min(len(lines), 8))
        self.__scrolled.set_size_request(-1, n * self.__line_height + 2)

        msg = string.join(lines, "\n")
        self.step_label.set_text(msg)
        self.position_window()  # keep window centered
示例#9
0
    def set_label(self, msg):
        if msg:
            lines = rcd_util.linebreak(msg, WRAP_LABEL_LEN)
        else:
            lines = []

        # Try to set the scrollbox to a reasonable size, neither too big
        # or too small. (We always want at least 3 lines of text to avoid
        # "jumpyness".)
        n = max(3, min(len(lines), 8))
        self.__scrolled.set_size_request(-1, n*self.__line_height+2)

        msg = string.join(lines, "\n")
        self.step_label.set_text(msg)
        self.position_window() # keep window centered
示例#10
0
    def __init__(self, image=None, pixbuf=None, pixbuf_name=None, text=None, formatted_text=None):

        gtk.EventBox.__init__(self)

        if pixbuf_name:
            assert not pixbuf and not image
            image = red_pixbuf.get_widget(pixbuf_name)

        if pixbuf:
            assert not pixbuf_name and not image
            image = gtk.Image()
            image.set_from_pixbuf(pixbuf)

        if text:
            assert not formatted_text
            formatted_text = '<span size="large"><b>%s</b></span>' % text
            formatted_text = string.join(rcd_util.linebreak(formatted_text, width=70), "\n")

        box = gtk.HBox(0, 0)
        box.pack_start(gtk.Label(""), expand=1, fill=1)

        if image:
            box.pack_start(image, expand=0, fill=1, padding=4)

        label = gtk.Label("")
        if formatted_text:
            label.set_markup(formatted_text)
        box.pack_start(label, expand=0, fill=1, padding=4)

        box.pack_start(gtk.Label(""), expand=1, fill=1)

        frame = gtk.Frame(None)
        frame.add(box)

        self.add(frame)

        style = self.get_style().copy()
        color = self.get_colormap().alloc_color("white")
        style.bg[gtk.STATE_NORMAL] = color
        self.set_style(style)

        self.show_all()
        self.hide()
示例#11
0
    def build(self):
        self.array = red_packagearray.UpdatedPackages()
        self.connect_array(self.array)

        self.__built = 0

        def updates_changed_cb(array, comp):
            if not self.__built:
                return
            if array.len() == 0:
                comp.__have_updates.hide()
                comp.__no_updates.show()
                self.unselect_all()
            else:
                comp.__have_updates.show()
                comp.__no_updates.hide()

        self.array.connect_after("changed", updates_changed_cb, self)

        page = gtk.VBox(0, 6)

        ### Update All button

        box = gtk.HButtonBox()
        box.set_layout(gtk.BUTTONBOX_START)
        page.pack_start(box, 0, 0)

        def sensitize_update_all(this, button):
            sensitive = 0
            if not this.array.len() == 0:
                sensitive = 1
            button.set_sensitive(sensitive)

        update_all = gtk.Button(_("_Update All"))
        self.array.connect_after("changed",
                                 lambda x, y, z: sensitize_update_all(y, z),
                                 self, update_all)
        update_all.connect("clicked", lambda x, y: y.update_all(), self)
        box.add(update_all)
        box.show_all()

        ### Main

        view = red_packageview.PackageView(self.array)
        self.connect_view(view)
        self.view = view

        view.append_action_column()
        col = view.append_importance_column()
        view.append_channel_column(optionally_show_channel_name=1)
        view.append_name_column()
        view.append_version_column(column_title=_("New Version"))
        view.append_current_version_column()

        view.sort_by(red_packagearray.COLUMN_IMPORTANCE)

        scrolled = gtk.ScrolledWindow()
        scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scrolled.set_shadow_type(gtk.SHADOW_IN)
        scrolled.add(view)
        scrolled.show_all()
        scrolled.hide()

        self.__have_updates = scrolled

        msg1 = "<span size=\"large\"><b>%s</b></span>" \
               % _("The system is up-to-date.")
        msg2 = _(
            "There are no software updates available in any subscribed catalogs."
        )
        msg = msg1 + "\n" + string.join(rcd_util.linebreak(msg2, width=30),
                                        "\n")

        self.__no_updates = red_emptypage.EmptyPage(pixbuf_name="verify",
                                                    formatted_text=msg)

        self.__built = 1

        page.pack_start(self.__have_updates, expand=1, fill=1)
        page.pack_start(self.__no_updates, expand=1, fill=1)

        # Show a blank updates list by default until we get a changed
        # signal, even if we don't have any updates, to reduce flicker
        # at startup in the case where we do actually have updates.
        self.__have_updates.show()
        self.__no_updates.hide()

        return page
示例#12
0
                   CellRendererPref,
                   gobject.SIGNAL_RUN_LAST,
                   gobject.TYPE_NONE,
                   (gobject.TYPE_PYOBJECT, gobject.TYPE_STRING))

COLUMNS = (
    ("PREF",
     lambda x:x,
     gobject.TYPE_PYOBJECT),
    
    ("NAME",
     lambda x:x["name"],
     gobject.TYPE_STRING),
    
    ("DESCRIPTION",
     lambda x:string.join(rcd_util.linebreak(x["description"], 50), "\n"),
     gobject.TYPE_STRING),
    
    ("CATEGORY",
     lambda x:x["category"],
     gobject.TYPE_STRING),
    
    ("VALUE",
     lambda x:x["value"],
     gobject.TYPE_PYOBJECT)
)

for i in range(len(COLUMNS)):
    name = COLUMNS[i][0]
    exec("COLUMN_%s = %d" % (name, i))
示例#13
0
    def build(self):
        self.array = red_packagearray.UpdatedPackages()
        self.connect_array(self.array)

        self.__built = 0

        def updates_changed_cb(array, comp):
            if not self.__built:
                return
            if array.len() == 0:
                comp.__have_updates.hide()
                comp.__no_updates.show()
                self.unselect_all()
            else:
                comp.__have_updates.show()
                comp.__no_updates.hide()
        self.array.connect_after("changed", updates_changed_cb, self)

        page = gtk.VBox(0, 6)

        ### Update All button

        box = gtk.HButtonBox()
        box.set_layout(gtk.BUTTONBOX_START)
        page.pack_start(box, 0, 0)

        def sensitize_update_all(this, button):
            sensitive = 0
            if not this.array.len() == 0:
                sensitive = 1
            button.set_sensitive(sensitive)

        update_all = gtk.Button(_("_Update All"))
        self.array.connect_after("changed", lambda x,y,z: sensitize_update_all(y,z),
                                 self, update_all)
        update_all.connect("clicked", lambda x,y: y.update_all(), self)
        box.add(update_all)
        box.show_all()

        ### Main

        view = red_packageview.PackageView(self.array)
        self.connect_view(view)
        self.view = view

        view.append_action_column()
        col = view.append_importance_column()
        view.append_channel_column(optionally_show_channel_name=1)
        view.append_name_column()
        view.append_version_column(column_title=_("New Version"))
        view.append_current_version_column()

        view.sort_by(red_packagearray.COLUMN_IMPORTANCE)

        scrolled = gtk.ScrolledWindow()
        scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scrolled.set_shadow_type(gtk.SHADOW_IN)
        scrolled.add(view)
        scrolled.show_all()
        scrolled.hide()

        self.__have_updates = scrolled

        msg1 = "<span size=\"large\"><b>%s</b></span>" \
               % _("The system is up-to-date.")
        msg2 = _("There are no software updates available in any subscribed catalogs.")
        msg = msg1+"\n"+string.join(rcd_util.linebreak(msg2, width=30), "\n")

        self.__no_updates = red_emptypage.EmptyPage(pixbuf_name="verify",
                                                    formatted_text=msg)

        self.__built = 1

        page.pack_start(self.__have_updates, expand=1, fill=1)
        page.pack_start(self.__no_updates, expand=1, fill=1)

        # Show a blank updates list by default until we get a changed
        # signal, even if we don't have any updates, to reduce flicker
        # at startup in the case where we do actually have updates.
        self.__have_updates.show()
        self.__no_updates.hide()

        return page