All pastes #2048697 Raw Edit

Untitled

public text v1 · immutable
#2048697 ·published 2011-04-20 17:33 UTC
rendered paste body
    #Bug Fix 608108 - More information in  saved dialog box
    def _timeSince(uri):
        if not uri == None:
            path=uri[7:]
            time_mod=datetime.datetime.fromtimestamp(os.path.getmtime(path))
            time_now = datetime.datetime.now()
            tdelta=time_now-time_mod
            if tdelta.days>2:
                time_since= str(tdelta.days) + _(" days ago")
            elif tdelta.seconds>7200:
                time_since=str(tdelta.seconds/3600)+ _(" hours ago")
            elif tdelta.seconds<120:
                time_since=str(tdelta.seconds) + _(" seconds ago")
            else: time_since= str(tdelta.seconds/60) + _(" minutes ") + str(tdelta.seconds%60) + _(" seconds ago ")
            return _(" since ")+ time_since
        else: return ""


    def _projectManagerClosingProjectCb(self, projectManager, project):
        if not project.hasUnsavedModifications():
            return True

        if project.uri:
            save = gtk.STOCK_SAVE
        else:
            save = gtk.STOCK_SAVE_AS

        dialog = gtk.Dialog("",
            self, gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR,
            (_("Close without saving"), gtk.RESPONSE_REJECT,
                    gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                    save, gtk.RESPONSE_YES))
        dialog.set_icon_name("pitivi")
        dialog.set_resizable(False)
        dialog.set_has_separator(False)
        dialog.set_default_response(gtk.RESPONSE_YES)

        primary = gtk.Label()
        primary.set_line_wrap(True)
        primary.set_use_markup(True)
        primary.set_alignment(0, 0.5)

        message = _("Save changes to the current project before closing?")
        primary.set_markup("<span weight=\"bold\">" + message + "</span>")

        secondary = gtk.Label()
        secondary.set_line_wrap(True)
        secondary.set_use_markup(True)
        secondary.set_alignment(0, 0.5)
        secondary.props.label = _("If you don't save, your "
                "changes %s will be lost" % _timeSince(project.uri))
        
        # put the text in a vbox
        vbox = gtk.VBox(False, 12)
        vbox.pack_start(primary, expand=True, fill=True)
        vbox.pack_start(secondary, expand=True, fill=True)
        
        # make the [[image] text] hbox
        image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING,
               gtk.ICON_SIZE_DIALOG)
        hbox = gtk.HBox(False, 12)
        hbox.pack_start(image, expand=False)
        hbox.pack_start(vbox, expand=True, fill=True)
        action_area = dialog.get_action_area()
        # FIXME: find out where this "6" comes from. It's needed to align our
        # hbox with the action area button box
        hbox.set_border_width(6)