コード例 #1
0
ファイル: common.py プロジェクト: xerxes2/gpodder
    def show_message(self, message, title=None, important=False, widget=None):
        if gpodder.ui.diablo:
            import hildon
            if important:
                try:
                    dlg = hildon.Note('information',
                                      (self.main_window, message))
                except TypeError:
                    if title is None:
                        message = message
                    else:
                        message = '%s\n%s' % (title, message)
                    dlg = hildon.hildon_note_new_information(self.main_window, \
                            message)
                dlg.run()
                dlg.destroy()
            else:
                if title is None:
                    title = 'gPodder'
                pango_markup = '<b>%s</b>\n<small>%s</small>' % (title,
                                                                 message)
                try:
                    hildon.hildon_banner_show_information_with_markup(
                        gtk.Label(''), None, pango_markup)
                except TypeError:
                    # We're probably running the Diablo UI on Maemo 5 :)
                    hildon.hildon_banner_show_information(self.main_window, \
                            '', message)
        elif gpodder.ui.fremantle:
            import hildon
            if important:
                if title is None:
                    message = message
                else:
                    message = '%s\n%s' % (title, message)

                dlg = hildon.hildon_note_new_information( \
                        self.get_dialog_parent(), \
                        message)
                dlg.run()
                dlg.destroy()
            else:
                hildon.hildon_banner_show_information(self.get_dialog_parent(), \
                        '', message)
        else:
            # XXX: Dirty hack to get access to the gPodder-specific config object
            config = getattr(self, '_config', getattr(self, 'config', None))

            if important:
                dlg = gtk.MessageDialog(self.main_window, gtk.DIALOG_MODAL,
                                        gtk.MESSAGE_INFO, gtk.BUTTONS_OK)
                if title:
                    dlg.set_title(str(title))
                    dlg.set_markup(
                        '<span weight="bold" size="larger">%s</span>\n\n%s' %
                        (title, message))
                else:
                    dlg.set_markup(
                        '<span weight="bold" size="larger">%s</span>' %
                        (message))
                dlg.run()
                dlg.destroy()
            elif config is not None and config.enable_notifications:
                if pynotify is not None:
                    if title is None:
                        title = 'gPodder'
                    notification = pynotify.Notification(title, message,\
                            gpodder.icon_file)
                    try:
                        notification.show()
                    except:
                        # See http://gpodder.org/bug/966
                        pass
                elif widget and isinstance(widget, gtk.Widget):
                    if not widget.window:
                        widget = self.main_window
                    elif not gpodder.win32:
                        widget = self.main_window
                    notification = NotificationWindow(message,
                                                      title,
                                                      important=False,
                                                      widget=widget)
                    notification.show_timeout()