Esempio n. 1
0
class ViewLog(QDialog): # {{{

    def __init__(self, title, html, parent=None):
        QDialog.__init__(self, parent)
        self.l = l = QVBoxLayout()
        self.setLayout(l)

        self.tb = QTextBrowser(self)
        self.tb.setHtml('<pre style="font-family: monospace">%s</pre>' % html)
        l.addWidget(self.tb)

        self.bb = QDialogButtonBox(QDialogButtonBox.Ok)
        self.bb.accepted.connect(self.accept)
        self.bb.rejected.connect(self.reject)
        self.copy_button = self.bb.addButton(_('Copy to clipboard'),
                self.bb.ActionRole)
        self.copy_button.setIcon(QIcon(I('edit-copy.png')))
        self.copy_button.clicked.connect(self.copy_to_clipboard)
        l.addWidget(self.bb)
        self.setModal(False)
        self.resize(QSize(700, 500))
        self.setWindowTitle(title)
        self.setWindowIcon(QIcon(I('debug.png')))
        self.show()

    def copy_to_clipboard(self):
        txt = self.tb.toPlainText()
        QApplication.clipboard().setText(txt)
Esempio n. 2
0
    def __init__(self, log, parent=None):
        QDialog.__init__(self, parent)
        self.log = log
        self.l = l = QVBoxLayout()
        self.setLayout(l)

        self.tb = QTextBrowser(self)
        l.addWidget(self.tb)

        self.bb = QDialogButtonBox(QDialogButtonBox.Close)
        l.addWidget(self.bb)
        self.copy_button = self.bb.addButton(_('Copy to clipboard'),
                                             self.bb.ActionRole)
        self.copy_button.clicked.connect(self.copy_to_clipboard)
        self.copy_button.setIcon(QIcon(I('edit-copy.png')))
        self.bb.rejected.connect(self.reject)
        self.bb.accepted.connect(self.accept)

        self.setWindowTitle(_('Download log'))
        self.setWindowIcon(QIcon(I('debug.png')))
        self.resize(QSize(800, 400))

        self.keep_updating = True
        self.last_html = None
        self.finished.connect(self.stop)
        QTimer.singleShot(100, self.update_log)

        self.show()
Esempio n. 3
0
 def __init__(self, movie):
     self.movie = movie
     QDialog.__init__(self, None)
     self.setObjectName("movie_warning")
     self.text_browser = QTextBrowser(self)
     self.text_browser.setObjectName("movie_warning_textbrowser")
     self.text_browser.setMinimumSize(400, 40)
     self.setWindowTitle('Rewind your movie?')
     self.text_browser.setPlainText(  #bruce 080827 revised text
         "You may want to rewind the movie now. The atoms move as the movie "
         "progresses, and saving the part without rewinding will save the "
         "current positions, which is sometimes useful, but will make the "
         "movie invalid, because .dpb files only store deltas relative to "
         "the initial atom positions, and don't store the initial positions "
         "themselves.")
     self.ok_button = QPushButton(self)
     self.ok_button.setObjectName("ok_button")
     self.ok_button.setText("Rewind movie")
     self.cancel_button = QPushButton(self)
     self.cancel_button.setObjectName("cancel_button")
     self.cancel_button.setText(
         "Exit command without rewinding")  #bruce 080827 revised text
     # Note: this is not, in fact, a cancel button --
     # there is no option in the caller to prevent exiting the command.
     # There is also no option to "forward to final position",
     # though for a minimize movie, that might be most useful.
     # [bruce 080827 comment]
     layout = QGridLayout(self)
     layout.addWidget(self.text_browser, 0, 0, 0, 1)
     layout.addWidget(self.ok_button, 1, 0)
     layout.addWidget(self.cancel_button, 1, 1)
     self.connect(self.ok_button, SIGNAL("clicked()"), self.rewindMovie)
     self.connect(self.cancel_button, SIGNAL("clicked()"), self.noThanks)
Esempio n. 4
0
class ViewLog(QDialog):  # {{{
    def __init__(self, title, html, parent=None):
        QDialog.__init__(self, parent)
        self.l = l = QVBoxLayout()
        self.setLayout(l)

        self.tb = QTextBrowser(self)
        self.tb.setHtml('<pre style="font-family: monospace">%s</pre>' % html)
        l.addWidget(self.tb)

        self.bb = QDialogButtonBox(QDialogButtonBox.Ok)
        self.bb.accepted.connect(self.accept)
        self.bb.rejected.connect(self.reject)
        self.copy_button = self.bb.addButton(_('Copy to clipboard'),
                                             self.bb.ActionRole)
        self.copy_button.setIcon(QIcon(I('edit-copy.png')))
        self.copy_button.clicked.connect(self.copy_to_clipboard)
        l.addWidget(self.bb)
        self.setModal(False)
        self.resize(QSize(700, 500))
        self.setWindowTitle(title)
        self.setWindowIcon(QIcon(I('debug.png')))
        self.show()

    def copy_to_clipboard(self):
        txt = self.tb.toPlainText()
        QApplication.clipboard().setText(txt)
Esempio n. 5
0
 def __init__(self, movie):
     self.movie = movie
     QDialog.__init__(self, None)
     self.setObjectName("movie_warning")
     self.text_browser = QTextBrowser(self)
     self.text_browser.setObjectName("movie_warning_textbrowser")
     self.text_browser.setMinimumSize(400, 40)
     self.setWindowTitle('Rewind your movie?')
     self.text_browser.setPlainText(
         "You may want to rewind the movie now. If you save the part without "
         +
         "rewinding the movie, the movie file will become invalid because it "
         +
         "depends upon the initial atom positions. The atoms move as the movie "
         +
         "progresses, and saving the part now will save the final positions, "
         + "which are incorrect for the movie you just watched.")
     self.ok_button = QPushButton(self)
     self.ok_button.setObjectName("ok_button")
     self.ok_button.setText("Rewind movie")
     self.cancel_button = QPushButton(self)
     self.cancel_button.setObjectName("cancel_button")
     self.cancel_button.setText("No thanks")
     layout = QGridLayout(self)
     layout.addWidget(self.text_browser, 0, 0, 0, 1)
     layout.addWidget(self.ok_button, 1, 0)
     layout.addWidget(self.cancel_button, 1, 1)
     self.connect(self.ok_button, SIGNAL("clicked()"), self.rewindMovie)
     self.connect(self.cancel_button, SIGNAL("clicked()"), self.noThanks)
Esempio n. 6
0
    def __init__(self,
                 text,
                 parent=None,
                 clicked_func=None,
                 caption="(caption)"):
        QDialog.__init__(self, parent)

        self.setWindowTitle(caption)
        self.setWindowIcon(QtGui.QIcon("ui/border/MainWindow"))
        self.setObjectName("WikiHelpBrowser")
        TextBrowserLayout = QGridLayout(self)
        TextBrowserLayout.setSpacing(5)
        TextBrowserLayout.setMargin(2)
        self.text_browser = QTextBrowser(self)
        self.text_browser.setOpenExternalLinks(True)
        self.text_browser.setObjectName("text_browser")
        TextBrowserLayout.addWidget(self.text_browser, 0, 0, 1, 0)

        self.text_browser.setMinimumSize(400, 200)
        # make it pale yellow like a post-it note
        self.text_browser.setHtml("<qt bgcolor=\"#FFFF80\">" + text)

        self.close_button = QPushButton(self)
        self.close_button.setObjectName("close_button")
        self.close_button.setText("Close")
        TextBrowserLayout.addWidget(self.close_button, 1, 1)

        spacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                             QSizePolicy.Minimum)
        TextBrowserLayout.addItem(spacer, 1, 0)

        self.resize(QSize(300, 300).expandedTo(self.minimumSizeHint()))

        self.connect(self.close_button, SIGNAL("clicked()"), self.close)
        return
Esempio n. 7
0
    def __init__(self, *args):
        QTextBrowser.__init__(self, *args)

        self.setStyleSheet("background:white;color:black;")

        try:
            self.setText(codecs.open(self.loadFile(), "r", "UTF-8").read())
        except Exception, msg:
            raise GUIError(msg)
Esempio n. 8
0
    def __init__(self, *args):
        QTextBrowser.__init__(self, *args)

        self.setStyleSheet("background:white;color:black;")

        try:
            self.setText(codecs.open(self.loadFile(), "r", "UTF-8").read())
        except Exception, msg:
            raise GUIError(msg)
Esempio n. 9
0
    def __init__(self, win):
        self.xmlfile = os.path.join(_sponsordir, 'sponsors.xml')
        self.win = win

        self.needToAsk = False
        self.downloadSponsors = False
        threading.Thread.__init__(self)

        if not self.refreshWanted():
            return
        if env.prefs[sponsor_permanent_permission_prefs_key]:
            # We have a permanent answer so no need for a dialog
            if env.prefs[sponsor_download_permission_prefs_key]:
                self.downloadSponsors = True
            return

        self.needToAsk = True
        QDialog.__init__(self, None)
        self.setObjectName("Permission")
        self.setModal(True)  #This fixes bug 2296. Mitigates bug 2297
        layout = QGridLayout()
        self.setLayout(layout)
        layout.setMargin(0)
        layout.setSpacing(0)
        layout.setObjectName("PermissionLayout")
        self.text_browser = QTextBrowser(self)
        self.text_browser.setObjectName("text_browser")
        layout.addWidget(self.text_browser, 0, 0, 1, 4)
        self.text_browser.setMinimumSize(400, 80)
        self.setWindowTitle('May we use your network connection?')
        self.setWindowIcon(geticon('ui/border/MainWindow.png'))
        self.text_browser.setPlainText(self.text)
        self.accept_button = QPushButton(self)
        self.accept_button.setObjectName("accept_button")
        self.accept_button.setText("Always OK")
        self.accept_once_button = QPushButton(self)
        self.accept_once_button.setObjectName("accept_once_button")
        self.accept_once_button.setText("OK now")
        self.decline_once_button = QPushButton(self)
        self.decline_once_button.setObjectName("decline_once_button")
        self.decline_once_button.setText("Not now")
        self.decline_always_button = QPushButton(self)
        self.decline_always_button.setObjectName("decline_always_button")
        self.decline_always_button.setText("Never")
        layout.addWidget(self.accept_button, 1, 0)
        layout.addWidget(self.accept_once_button, 1, 1)
        layout.addWidget(self.decline_once_button, 1, 2)
        layout.addWidget(self.decline_always_button, 1, 3)
        self.connect(self.accept_button, SIGNAL("clicked()"),
                     self.acceptAlways)
        self.connect(self.accept_once_button, SIGNAL("clicked()"),
                     self.acceptJustOnce)
        self.connect(self.decline_once_button, SIGNAL("clicked()"),
                     self.declineJustOnce)
        self.connect(self.decline_always_button, SIGNAL("clicked()"),
                     self.declineAlways)
Esempio n. 10
0
 def __init__(self, movie):
     self.movie = movie
     QDialog.__init__(self, None)
     self.setObjectName("movie_warning")
     self.text_browser = QTextBrowser(self)
     self.text_browser.setObjectName("movie_warning_textbrowser")
     self.text_browser.setMinimumSize(400, 40)
     self.setWindowTitle('Rewind your movie?')
     self.text_browser.setPlainText(
         "You may want to rewind the movie now. If you save the part without " +
         "rewinding the movie, the movie file will become invalid because it " +
         "depends upon the initial atom positions. The atoms move as the movie " +
         "progresses, and saving the part now will save the final positions, " +
         "which are incorrect for the movie you just watched.")
     self.ok_button = QPushButton(self)
     self.ok_button.setObjectName("ok_button")
     self.ok_button.setText("Rewind movie")
     self.cancel_button = QPushButton(self)
     self.cancel_button.setObjectName("cancel_button")
     self.cancel_button.setText("No thanks")
     layout = QGridLayout(self)
     layout.addWidget(self.text_browser,0,0,0,1)
     layout.addWidget(self.ok_button,1,0)
     layout.addWidget(self.cancel_button,1,1)
     self.connect(self.ok_button,SIGNAL("clicked()"),self.rewindMovie)
     self.connect(self.cancel_button,SIGNAL("clicked()"),self.noThanks)
Esempio n. 11
0
    def __init__(self, parent=None):
        QSplitter.__init__(self, parent)
        self.setChildrenCollapsible(False)

        self.items = i = QListWidget(self)
        i.setContextMenuPolicy(Qt.CustomContextMenu)
        i.customContextMenuRequested.connect(self.context_menu)
        self.items.setSpacing(3)
        self.items.itemDoubleClicked.connect(self.current_item_activated)
        self.items.currentItemChanged.connect(self.current_item_changed)
        self.items.setSelectionMode(self.items.NoSelection)
        self.delegate = Delegate(self.items)
        self.items.setItemDelegate(self.delegate)
        self.addWidget(i)
        self.help = h = QTextBrowser(self)
        h.anchorClicked.connect(self.link_clicked)
        h.setOpenLinks(False)
        self.addWidget(h)
        self.clear_help(_('Check has not been run'))
        self.setStretchFactor(0, 100)
        self.setStretchFactor(1, 50)

        state = tprefs.get('check-book-splitter-state', None)
        if state is not None:
            self.restoreState(state)
Esempio n. 12
0
    def __init__(self, log, parent=None):
        QDialog.__init__(self, parent)
        self.log = log
        self.l = l = QVBoxLayout()
        self.setLayout(l)

        self.tb = QTextBrowser(self)
        l.addWidget(self.tb)

        self.bb = QDialogButtonBox(QDialogButtonBox.Close)
        l.addWidget(self.bb)
        self.copy_button = self.bb.addButton(_('Copy to clipboard'),
                self.bb.ActionRole)
        self.copy_button.clicked.connect(self.copy_to_clipboard)
        self.copy_button.setIcon(QIcon(I('edit-copy.png')))
        self.bb.rejected.connect(self.reject)
        self.bb.accepted.connect(self.accept)

        self.setWindowTitle(_('Download log'))
        self.setWindowIcon(QIcon(I('debug.png')))
        self.resize(QSize(800, 400))

        self.keep_updating = True
        self.last_html = None
        self.finished.connect(self.stop)
        QTimer.singleShot(100, self.update_log)

        self.show()
Esempio n. 13
0
 def __init__(self, movie):
     self.movie = movie
     QDialog.__init__(self, None)
     self.setObjectName("movie_warning")
     self.text_browser = QTextBrowser(self)
     self.text_browser.setObjectName("movie_warning_textbrowser")
     self.text_browser.setMinimumSize(400, 40)
     self.setWindowTitle('Rewind your movie?')
     self.text_browser.setPlainText( #bruce 080827 revised text
         "You may want to rewind the movie now. The atoms move as the movie "
         "progresses, and saving the part without rewinding will save the "
         "current positions, which is sometimes useful, but will make the "
         "movie invalid, because .dpb files only store deltas relative to "
         "the initial atom positions, and don't store the initial positions "
         "themselves." )
     self.ok_button = QPushButton(self)
     self.ok_button.setObjectName("ok_button")
     self.ok_button.setText("Rewind movie")
     self.cancel_button = QPushButton(self)
     self.cancel_button.setObjectName("cancel_button")
     self.cancel_button.setText("Exit command without rewinding") #bruce 080827 revised text
         # Note: this is not, in fact, a cancel button --
         # there is no option in the caller to prevent exiting the command.
         # There is also no option to "forward to final position",
         # though for a minimize movie, that might be most useful.
         # [bruce 080827 comment]
     layout = QGridLayout(self)
     layout.addWidget(self.text_browser, 0, 0, 0, 1)
     layout.addWidget(self.ok_button, 1, 0)
     layout.addWidget(self.cancel_button, 1, 1)
     self.connect(self.ok_button, SIGNAL("clicked()"), self.rewindMovie)
     self.connect(self.cancel_button, SIGNAL("clicked()"), self.noThanks)
Esempio n. 14
0
    def __init__(self, text, parent=None, clicked_func=None, caption="(caption)", size=None):
        QDialog.__init__(self, parent)

        self.setWindowTitle(caption)
        self.setWindowIcon(QtGui.QIcon("ui/border/MainWindow"))
        self.setObjectName("WikiHelpBrowser")
        TextBrowserLayout = QGridLayout(self)
        TextBrowserLayout.setSpacing(5)
        TextBrowserLayout.setMargin(2)
        self.text_browser = QTextBrowser(self)
        self.text_browser.setOpenExternalLinks(True)
        self.text_browser.setObjectName("text_browser")
        TextBrowserLayout.addWidget(self.text_browser, 0, 0, 1, 0)

        self.text_browser.setMinimumSize(400, 200)
        # make it pale yellow like a post-it note
        self.text_browser.setHtml('<qt bgcolor="#FFFF80">' + text)

        self.close_button = QPushButton(self)
        self.close_button.setObjectName("close_button")
        self.close_button.setText("Close")
        TextBrowserLayout.addWidget(self.close_button, 1, 1)

        spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        TextBrowserLayout.addItem(spacer, 1, 0)

        self.resize(QSize(300, 300).expandedTo(self.minimumSizeHint()))
        if size == 1:
            self.text_browser.setMinimumSize(200, 400)
            self.resize(QSize(300, 550).expandedTo(self.minimumSizeHint()))
        if size == 2:
            self.resize(QSize(650, 250).expandedTo(self.minimumSizeHint()))
        self.connect(self.close_button, SIGNAL("clicked()"), self.close)
        return
Esempio n. 15
0
 def polish(self, action, name):
     self.commit_all_editors_to_container()
     with BusyCursor():
         self.add_savepoint(name)
         try:
             report = tweak_polish(current_container(), {action: True})
         except:
             self.rewind_savepoint()
             raise
         self.apply_container_update_to_gui()
         from calibre.ebooks.markdown import markdown
         report = markdown('# %s\n\n' % self.current_metadata.title +
                           '\n\n'.join(report),
                           output_format='html4')
     d = QDialog(self.gui)
     d.l = QVBoxLayout()
     d.setLayout(d.l)
     d.e = QTextBrowser(d)
     d.l.addWidget(d.e)
     d.e.setHtml(report)
     d.bb = QDialogButtonBox(QDialogButtonBox.Close)
     d.l.addWidget(d.bb)
     d.bb.rejected.connect(d.reject)
     d.bb.accepted.connect(d.accept)
     d.resize(600, 400)
     d.exec_()
Esempio n. 16
0
 def __init__(self, parent, config_name=None, buttons=[], *args):
     """Creates dialog.
     'config_name' is used to get/set default window size from Config object
     'buttons' can be a list of names or (QPixmapWrapper,name[,tooltip]) tuples to provide
     custom buttons at the bottom of the dialog. When a button is clicked, the dialog
     emits SIGNAL("name").
     A "Close" button is always provided, this simply hides the dialog.
     """
     QDialog.__init__(self, parent, *args)
     self.setModal(False)
     lo = QVBoxLayout(self)
     # create viewer
     self.label = QLabel(self)
     self.label.setMargin(5)
     self.label.setWordWrap(True)
     lo.addWidget(self.label)
     self.label.hide()
     self.viewer = QTextBrowser(self)
     lo.addWidget(self.viewer)
     # self.viewer.setReadOnly(True)
     self.viewer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
     QObject.connect(self.viewer, SIGNAL("anchorClicked(const QUrl &)"), self._urlClicked)
     self._source = None
     lo.addSpacing(5)
     # create button bar
     btnfr = QFrame(self)
     btnfr.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
     # btnfr.setMargin(5)
     lo.addWidget(btnfr)
     lo.addSpacing(5)
     btnfr_lo = QHBoxLayout(btnfr)
     btnfr_lo.setMargin(5)
     # add user buttons
     self._user_buttons = {}
     for name in buttons:
         if isinstance(name, str):
             btn = QPushButton(name, btnfr)
         elif isinstance(name, (list, tuple)):
             if len(name) < 3:
                 pixmap, name = name
                 tip = None
             else:
                 pixmap, name, tip = name
             btn = QPushButton(pixmap.icon(), name, btnfr)
             if tip:
                 btn.setToolTip(tip)
         self._user_buttons[name] = btn
         btn._clicked = Kittens.utils.curry(self.emit, SIGNAL(name))
         self.connect(btn, SIGNAL("clicked()"), btn._clicked)
         btnfr_lo.addWidget(btn, 1)
     # add a Close button
     btnfr_lo.addStretch(100)
     closebtn = QPushButton(pixmaps.grey_round_cross.icon(), "Close", btnfr)
     self.connect(closebtn, SIGNAL("clicked()"), self.hide)
     btnfr_lo.addWidget(closebtn, 1)
     # resize selves
     self.config_name = config_name or "html-viewer"
     width = Config.getint('%s-width' % self.config_name, 512)
     height = Config.getint('%s-height' % self.config_name, 512)
     self.resize(QSize(width, height))
Esempio n. 17
0
class LogViewer(QDialog):  # {{{
    def __init__(self, log, parent=None):
        QDialog.__init__(self, parent)
        self.log = log
        self.l = l = QVBoxLayout()
        self.setLayout(l)

        self.tb = QTextBrowser(self)
        l.addWidget(self.tb)

        self.bb = QDialogButtonBox(QDialogButtonBox.Close)
        l.addWidget(self.bb)
        self.copy_button = self.bb.addButton(_('Copy to clipboard'),
                                             self.bb.ActionRole)
        self.copy_button.clicked.connect(self.copy_to_clipboard)
        self.copy_button.setIcon(QIcon(I('edit-copy.png')))
        self.bb.rejected.connect(self.reject)
        self.bb.accepted.connect(self.accept)

        self.setWindowTitle(_('Download log'))
        self.setWindowIcon(QIcon(I('debug.png')))
        self.resize(QSize(800, 400))

        self.keep_updating = True
        self.last_html = None
        self.finished.connect(self.stop)
        QTimer.singleShot(100, self.update_log)

        self.show()

    def copy_to_clipboard(self):
        QApplication.clipboard().setText(''.join(self.log.plain_text))

    def stop(self, *args):
        self.keep_updating = False

    def update_log(self):
        if not self.keep_updating:
            return
        html = self.log.html
        if html != self.last_html:
            self.last_html = html
            self.tb.setHtml('<pre style="font-family:monospace">%s</pre>' %
                            html)
        QTimer.singleShot(1000, self.update_log)
Esempio n. 18
0
class LogViewer(QDialog): # {{{

    def __init__(self, log, parent=None):
        QDialog.__init__(self, parent)
        self.log = log
        self.l = l = QVBoxLayout()
        self.setLayout(l)

        self.tb = QTextBrowser(self)
        l.addWidget(self.tb)

        self.bb = QDialogButtonBox(QDialogButtonBox.Close)
        l.addWidget(self.bb)
        self.copy_button = self.bb.addButton(_('Copy to clipboard'),
                self.bb.ActionRole)
        self.copy_button.clicked.connect(self.copy_to_clipboard)
        self.copy_button.setIcon(QIcon(I('edit-copy.png')))
        self.bb.rejected.connect(self.reject)
        self.bb.accepted.connect(self.accept)

        self.setWindowTitle(_('Download log'))
        self.setWindowIcon(QIcon(I('debug.png')))
        self.resize(QSize(800, 400))

        self.keep_updating = True
        self.last_html = None
        self.finished.connect(self.stop)
        QTimer.singleShot(100, self.update_log)

        self.show()

    def copy_to_clipboard(self):
        QApplication.clipboard().setText(''.join(self.log.plain_text))

    def stop(self, *args):
        self.keep_updating = False

    def update_log(self):
        if not self.keep_updating:
            return
        html = self.log.html
        if html != self.last_html:
            self.last_html = html
            self.tb.setHtml('<pre style="font-family:monospace">%s</pre>'%html)
        QTimer.singleShot(1000, self.update_log)
Esempio n. 19
0
    def __init__(self, win):
        self.xmlfile = os.path.join(_sponsordir, 'sponsors.xml')
        self.win = win

        self.needToAsk = False
        self.downloadSponsors = False
        threading.Thread.__init__(self)

        if not self.refreshWanted():
            return
        if env.prefs[sponsor_permanent_permission_prefs_key]:
            # We have a permanent answer so no need for a dialog
            if env.prefs[sponsor_download_permission_prefs_key]:
                self.downloadSponsors = True
            return

        self.needToAsk = True
        QDialog.__init__(self, None)
        self.setObjectName("Permission")
        self.setModal(True) #This fixes bug 2296. Mitigates bug 2297
        layout = QGridLayout()
        self.setLayout(layout)
        layout.setMargin(0)
        layout.setSpacing(0)
        layout.setObjectName("PermissionLayout")
        self.text_browser = QTextBrowser(self)
        self.text_browser.setObjectName("text_browser")
        layout.addWidget(self.text_browser,0,0,1,4)
        self.text_browser.setMinimumSize(400, 80)
        self.setWindowTitle('May we use your network connection?')
        self.setWindowIcon(geticon('ui/border/MainWindow.png'))
        self.text_browser.setPlainText(self.text)
        self.accept_button = QPushButton(self)
        self.accept_button.setObjectName("accept_button")
        self.accept_button.setText("Always OK")
        self.accept_once_button = QPushButton(self)
        self.accept_once_button.setObjectName("accept_once_button")
        self.accept_once_button.setText("OK now")
        self.decline_once_button = QPushButton(self)
        self.decline_once_button.setObjectName("decline_once_button")
        self.decline_once_button.setText("Not now")
        self.decline_always_button = QPushButton(self)
        self.decline_always_button.setObjectName("decline_always_button")
        self.decline_always_button.setText("Never")
        layout.addWidget(self.accept_button,1,0)
        layout.addWidget(self.accept_once_button,1,1)
        layout.addWidget(self.decline_once_button,1,2)
        layout.addWidget(self.decline_always_button,1,3)
        self.connect(self.accept_button,SIGNAL("clicked()"),self.acceptAlways)
        self.connect(self.accept_once_button,SIGNAL("clicked()"),self.acceptJustOnce)
        self.connect(self.decline_once_button,SIGNAL("clicked()"),self.declineJustOnce)
        self.connect(self.decline_always_button,SIGNAL("clicked()"),self.declineAlways)
Esempio n. 20
0
def show_report(changed, title, report, parent, show_current_diff):
    report = format_report(title, report)
    d = QDialog(parent)
    d.l = QVBoxLayout()
    d.setLayout(d.l)
    d.e = QTextBrowser(d)
    d.l.addWidget(d.e)
    d.e.setHtml(report)
    d.bb = QDialogButtonBox(QDialogButtonBox.Close)
    if changed:
        b = d.b = d.bb.addButton(_('See what &changed'), d.bb.AcceptRole)
        b.setIcon(QIcon(I('diff.png'))), b.setAutoDefault(False)
        b.clicked.connect(partial(show_current_diff, allow_revert=True))
    d.bb.button(d.bb.Close).setDefault(True)
    d.l.addWidget(d.bb)
    d.bb.rejected.connect(d.reject)
    d.bb.accepted.connect(d.accept)
    d.resize(600, 400)
    d.exec_()
Esempio n. 21
0
 def __init__(self, parent, config_name=None, buttons=[], *args):
     """Creates dialog.
     'config_name' is used to get/set default window size from Config object
     'buttons' can be a list of names or (QPixmapWrapper,name[,tooltip]) tuples to provide
     custom buttons at the bottom of the dialog. When a button is clicked, the dialog
     emits SIGNAL("name").
     A "Close" button is always provided, this simply hides the dialog.
     """
     QDialog.__init__(self, parent, *args)
     self.setModal(False)
     lo = QVBoxLayout(self)
     # create viewer
     self.label = QLabel(self)
     self.label.setMargin(5)
     self.label.setWordWrap(True)
     lo.addWidget(self.label)
     self.label.hide()
     self.viewer = QTextBrowser(self)
     lo.addWidget(self.viewer)
     # self.viewer.setReadOnly(True)
     self.viewer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
     QObject.connect(self.viewer, SIGNAL("anchorClicked(const QUrl &)"),
                     self._urlClicked)
     self._source = None
     lo.addSpacing(5)
     # create button bar
     btnfr = QFrame(self)
     btnfr.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
     # btnfr.setMargin(5)
     lo.addWidget(btnfr)
     lo.addSpacing(5)
     btnfr_lo = QHBoxLayout(btnfr)
     btnfr_lo.setMargin(5)
     # add user buttons
     self._user_buttons = {}
     for name in buttons:
         if isinstance(name, str):
             btn = QPushButton(name, btnfr)
         elif isinstance(name, (list, tuple)):
             if len(name) < 3:
                 pixmap, name = name
                 tip = None
             else:
                 pixmap, name, tip = name
             btn = QPushButton(pixmap.icon(), name, btnfr)
             if tip:
                 btn.setToolTip(tip)
         self._user_buttons[name] = btn
         btn._clicked = Kittens.utils.curry(self.emit, SIGNAL(name))
         self.connect(btn, SIGNAL("clicked()"), btn._clicked)
         btnfr_lo.addWidget(btn, 1)
     # add a Close button
     btnfr_lo.addStretch(100)
     closebtn = QPushButton(pixmaps.grey_round_cross.icon(), "Close", btnfr)
     self.connect(closebtn, SIGNAL("clicked()"), self.hide)
     btnfr_lo.addWidget(closebtn, 1)
     # resize selves
     self.config_name = config_name or "html-viewer"
     width = Config.getint('%s-width' % self.config_name, 512)
     height = Config.getint('%s-height' % self.config_name, 512)
     self.resize(QSize(width, height))
Esempio n. 22
0
 def __init__(self, parent):
     QTextBrowser.__init__(self, parent.centralWidget())
     self.view = parent.splitter
     self.setGeometry(self.view.geometry())
     self.setWordWrap(True)
     self.setVisible(False)
Esempio n. 23
0
class PermissionDialog(QDialog, threading.Thread):

    # Politely explain what we're doing as clearly as possible. This will be the
    # user's first experience of the sponsorship system and we want to use the
    # Google axiom of "Don't be evil".
    text = ("We would like to use your network connection to update a list of our " +
            "sponsors. This enables us to recoup some of our development costs " +
            "by putting buttons with sponsor logos on some dialogs. If you click " +
            "on a sponsor logo button, you will get a small window with some " +
            "information about that sponsor. May we do this? Otherwise we'll " +
            "just use buttons with our own Nanorex logo.")

    def __init__(self, win):
        self.xmlfile = os.path.join(_sponsordir, 'sponsors.xml')
        self.win = win

        self.needToAsk = False
        self.downloadSponsors = False
        threading.Thread.__init__(self)

        if not self.refreshWanted():
            return
        if env.prefs[sponsor_permanent_permission_prefs_key]:
            # We have a permanent answer so no need for a dialog
            if env.prefs[sponsor_download_permission_prefs_key]:
                self.downloadSponsors = True
            return

        self.needToAsk = True
        QDialog.__init__(self, None)
        self.setObjectName("Permission")
        self.setModal(True) #This fixes bug 2296. Mitigates bug 2297
        layout = QGridLayout()
        self.setLayout(layout)
        layout.setMargin(0)
        layout.setSpacing(0)
        layout.setObjectName("PermissionLayout")
        self.text_browser = QTextBrowser(self)
        self.text_browser.setObjectName("text_browser")
        layout.addWidget(self.text_browser,0,0,1,4)
        self.text_browser.setMinimumSize(400, 80)
        self.setWindowTitle('May we use your network connection?')
        self.setWindowIcon(geticon('ui/border/MainWindow.png'))
        self.text_browser.setPlainText(self.text)
        self.accept_button = QPushButton(self)
        self.accept_button.setObjectName("accept_button")
        self.accept_button.setText("Always OK")
        self.accept_once_button = QPushButton(self)
        self.accept_once_button.setObjectName("accept_once_button")
        self.accept_once_button.setText("OK now")
        self.decline_once_button = QPushButton(self)
        self.decline_once_button.setObjectName("decline_once_button")
        self.decline_once_button.setText("Not now")
        self.decline_always_button = QPushButton(self)
        self.decline_always_button.setObjectName("decline_always_button")
        self.decline_always_button.setText("Never")
        layout.addWidget(self.accept_button,1,0)
        layout.addWidget(self.accept_once_button,1,1)
        layout.addWidget(self.decline_once_button,1,2)
        layout.addWidget(self.decline_always_button,1,3)
        self.connect(self.accept_button,SIGNAL("clicked()"),self.acceptAlways)
        self.connect(self.accept_once_button,SIGNAL("clicked()"),self.acceptJustOnce)
        self.connect(self.decline_once_button,SIGNAL("clicked()"),self.declineJustOnce)
        self.connect(self.decline_always_button,SIGNAL("clicked()"),self.declineAlways)

    def acceptAlways(self):
        env.prefs[sponsor_download_permission_prefs_key] = True
        env.prefs[sponsor_permanent_permission_prefs_key] = True
        self.downloadSponsors = True
        self.close()

    def acceptJustOnce(self):
        env.prefs[sponsor_permanent_permission_prefs_key] = False
        self.downloadSponsors = True
        self.close()

    def declineAlways(self):
        env.prefs[sponsor_download_permission_prefs_key] = False
        env.prefs[sponsor_permanent_permission_prefs_key] = True
        self.close()

    def declineJustOnce(self):
        env.prefs[sponsor_permanent_permission_prefs_key] = False
        self.close()


    def run(self):
        #
        # Implements superclass's threading.Thread.run() function
        #
        if self.downloadSponsors:
            _download_xml_file(self.xmlfile)
        self.finish()
        env.prefs[sponsor_md5_mismatch_flag_key] = self.md5Mismatch()


    def refreshWanted(self):
        if not os.path.exists(self.xmlfile):
            return True

        if env.prefs[sponsor_md5_mismatch_flag_key]:
            return True

        return False


    def md5Mismatch(self):
        # Check the MD5 hash - if it hasn't changed, then there is
        # no reason to download sponsors.xml.
        try:
            (gotMD5_File, remoteDigest) = \
                _get_remote_file("sponsors.md5", "md5:")
            if gotMD5_File:
                m = md5.new()
                m.update(open(self.xmlfile).read())
                localDigest = "md5:" + base64.encodestring(m.digest())
                remoteDigest = remoteDigest.rstrip()
                localDigest = localDigest.rstrip()
                return (remoteDigest != localDigest)

            else:
                return True
        except:
            return True


    def finish(self):
        _load_sponsor_info(self.xmlfile, self.win)

    pass
Esempio n. 24
0
class PermissionDialog(QDialog, threading.Thread):

    # Politely explain what we're doing as clearly as possible. This will be the
    # user's first experience of the sponsorship system and we want to use the
    # Google axiom of "Don't be evil".
    text = (
        "We would like to use your network connection to update a list of our "
        +
        "sponsors. This enables us to recoup some of our development costs " +
        "by putting buttons with sponsor logos on some dialogs. If you click "
        + "on a sponsor logo button, you will get a small window with some " +
        "information about that sponsor. May we do this? Otherwise we'll " +
        "just use buttons with our own Nanorex logo.")

    def __init__(self, win):
        self.xmlfile = os.path.join(_sponsordir, 'sponsors.xml')
        self.win = win

        self.needToAsk = False
        self.downloadSponsors = False
        threading.Thread.__init__(self)

        if not self.refreshWanted():
            return
        if env.prefs[sponsor_permanent_permission_prefs_key]:
            # We have a permanent answer so no need for a dialog
            if env.prefs[sponsor_download_permission_prefs_key]:
                self.downloadSponsors = True
            return

        self.needToAsk = True
        QDialog.__init__(self, None)
        self.setObjectName("Permission")
        self.setModal(True)  #This fixes bug 2296. Mitigates bug 2297
        layout = QGridLayout()
        self.setLayout(layout)
        layout.setMargin(0)
        layout.setSpacing(0)
        layout.setObjectName("PermissionLayout")
        self.text_browser = QTextBrowser(self)
        self.text_browser.setObjectName("text_browser")
        layout.addWidget(self.text_browser, 0, 0, 1, 4)
        self.text_browser.setMinimumSize(400, 80)
        self.setWindowTitle('May we use your network connection?')
        self.setWindowIcon(geticon('ui/border/MainWindow.png'))
        self.text_browser.setPlainText(self.text)
        self.accept_button = QPushButton(self)
        self.accept_button.setObjectName("accept_button")
        self.accept_button.setText("Always OK")
        self.accept_once_button = QPushButton(self)
        self.accept_once_button.setObjectName("accept_once_button")
        self.accept_once_button.setText("OK now")
        self.decline_once_button = QPushButton(self)
        self.decline_once_button.setObjectName("decline_once_button")
        self.decline_once_button.setText("Not now")
        self.decline_always_button = QPushButton(self)
        self.decline_always_button.setObjectName("decline_always_button")
        self.decline_always_button.setText("Never")
        layout.addWidget(self.accept_button, 1, 0)
        layout.addWidget(self.accept_once_button, 1, 1)
        layout.addWidget(self.decline_once_button, 1, 2)
        layout.addWidget(self.decline_always_button, 1, 3)
        self.connect(self.accept_button, SIGNAL("clicked()"),
                     self.acceptAlways)
        self.connect(self.accept_once_button, SIGNAL("clicked()"),
                     self.acceptJustOnce)
        self.connect(self.decline_once_button, SIGNAL("clicked()"),
                     self.declineJustOnce)
        self.connect(self.decline_always_button, SIGNAL("clicked()"),
                     self.declineAlways)

    def acceptAlways(self):
        env.prefs[sponsor_download_permission_prefs_key] = True
        env.prefs[sponsor_permanent_permission_prefs_key] = True
        self.downloadSponsors = True
        self.close()

    def acceptJustOnce(self):
        env.prefs[sponsor_permanent_permission_prefs_key] = False
        self.downloadSponsors = True
        self.close()

    def declineAlways(self):
        env.prefs[sponsor_download_permission_prefs_key] = False
        env.prefs[sponsor_permanent_permission_prefs_key] = True
        self.close()

    def declineJustOnce(self):
        env.prefs[sponsor_permanent_permission_prefs_key] = False
        self.close()

    def run(self):
        #
        # Implements superclass's threading.Thread.run() function
        #
        if self.downloadSponsors:
            _download_xml_file(self.xmlfile)
        self.finish()
        env.prefs[sponsor_md5_mismatch_flag_key] = self.md5Mismatch()

    def refreshWanted(self):
        if not os.path.exists(self.xmlfile):
            return True

        if env.prefs[sponsor_md5_mismatch_flag_key]:
            return True

        return False

    def md5Mismatch(self):
        # Check the MD5 hash - if it hasn't changed, then there is
        # no reason to download sponsors.xml.
        try:
            (gotMD5_File, remoteDigest) = \
                _get_remote_file("sponsors.md5", "md5:")
            if gotMD5_File:
                m = md5.new()
                m.update(open(self.xmlfile).read())
                localDigest = "md5:" + base64.encodestring(m.digest())
                remoteDigest = remoteDigest.rstrip()
                localDigest = localDigest.rstrip()
                return (remoteDigest != localDigest)

            else:
                return True
        except:
            return True

    def finish(self):
        _load_sponsor_info(self.xmlfile, self.win)

    pass
Esempio n. 25
0
class HTMLViewerDialog(QDialog):
    """This class implements a dialog to view a piece of HTML text."""

    def __init__(self, parent, config_name=None, buttons=[], *args):
        """Creates dialog.
        'config_name' is used to get/set default window size from Config object
        'buttons' can be a list of names or (QPixmapWrapper,name[,tooltip]) tuples to provide
        custom buttons at the bottom of the dialog. When a button is clicked, the dialog
        emits SIGNAL("name").
        A "Close" button is always provided, this simply hides the dialog.
        """
        QDialog.__init__(self, parent, *args)
        self.setModal(False)
        lo = QVBoxLayout(self)
        # create viewer
        self.label = QLabel(self)
        self.label.setMargin(5)
        self.label.setWordWrap(True)
        lo.addWidget(self.label)
        self.label.hide()
        self.viewer = QTextBrowser(self)
        lo.addWidget(self.viewer)
        # self.viewer.setReadOnly(True)
        self.viewer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        QObject.connect(self.viewer, SIGNAL("anchorClicked(const QUrl &)"), self._urlClicked)
        self._source = None
        lo.addSpacing(5)
        # create button bar
        btnfr = QFrame(self)
        btnfr.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        # btnfr.setMargin(5)
        lo.addWidget(btnfr)
        lo.addSpacing(5)
        btnfr_lo = QHBoxLayout(btnfr)
        btnfr_lo.setMargin(5)
        # add user buttons
        self._user_buttons = {}
        for name in buttons:
            if isinstance(name, str):
                btn = QPushButton(name, btnfr)
            elif isinstance(name, (list, tuple)):
                if len(name) < 3:
                    pixmap, name = name
                    tip = None
                else:
                    pixmap, name, tip = name
                btn = QPushButton(pixmap.icon(), name, btnfr)
                if tip:
                    btn.setToolTip(tip)
            self._user_buttons[name] = btn
            btn._clicked = Kittens.utils.curry(self.emit, SIGNAL(name))
            self.connect(btn, SIGNAL("clicked()"), btn._clicked)
            btnfr_lo.addWidget(btn, 1)
        # add a Close button
        btnfr_lo.addStretch(100)
        closebtn = QPushButton(pixmaps.grey_round_cross.icon(), "Close", btnfr)
        self.connect(closebtn, SIGNAL("clicked()"), self.hide)
        btnfr_lo.addWidget(closebtn, 1)
        # resize selves
        self.config_name = config_name or "html-viewer"
        width = Config.getint('%s-width' % self.config_name, 512)
        height = Config.getint('%s-height' % self.config_name, 512)
        self.resize(QSize(width, height))

    def resizeEvent(self, ev):
        QDialog.resizeEvent(self, ev)
        sz = ev.size()
        Config.set('%s-width' % self.config_name, sz.width())
        Config.set('%s-height' % self.config_name, sz.height())

    def setDocument(self, filename, empty=""):
        """Sets the HTML text to be displayed. """
        self._source = QUrl.fromLocalFile(filename)
        if os.path.exists(filename):
            self.viewer.setSource(self._source)
        else:
            self.viewer.setText(empty)

    def _urlClicked(self, url):
        path = str(url.path())
        if path:
            self.emit(SIGNAL("viewPath"), path)
        # to make sure it keeps displaying the same thing
        self.viewer.setSource(self._source)

    def reload(self):
        self.viewer.reload()

    def setLabel(self, label=None):
        if label is None:
            self.label.hide()
        else:
            self.label.setText(label)
            self.label.show()
Esempio n. 26
0
class HTMLViewerDialog(QDialog):
    """This class implements a dialog to view a piece of HTML text."""
    def __init__(self, parent, config_name=None, buttons=[], *args):
        """Creates dialog.
        'config_name' is used to get/set default window size from Config object
        'buttons' can be a list of names or (QPixmapWrapper,name[,tooltip]) tuples to provide
        custom buttons at the bottom of the dialog. When a button is clicked, the dialog
        emits SIGNAL("name").
        A "Close" button is always provided, this simply hides the dialog.
        """
        QDialog.__init__(self, parent, *args)
        self.setModal(False)
        lo = QVBoxLayout(self)
        # create viewer
        self.label = QLabel(self)
        self.label.setMargin(5)
        self.label.setWordWrap(True)
        lo.addWidget(self.label)
        self.label.hide()
        self.viewer = QTextBrowser(self)
        lo.addWidget(self.viewer)
        # self.viewer.setReadOnly(True)
        self.viewer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        QObject.connect(self.viewer, SIGNAL("anchorClicked(const QUrl &)"),
                        self._urlClicked)
        self._source = None
        lo.addSpacing(5)
        # create button bar
        btnfr = QFrame(self)
        btnfr.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        # btnfr.setMargin(5)
        lo.addWidget(btnfr)
        lo.addSpacing(5)
        btnfr_lo = QHBoxLayout(btnfr)
        btnfr_lo.setMargin(5)
        # add user buttons
        self._user_buttons = {}
        for name in buttons:
            if isinstance(name, str):
                btn = QPushButton(name, btnfr)
            elif isinstance(name, (list, tuple)):
                if len(name) < 3:
                    pixmap, name = name
                    tip = None
                else:
                    pixmap, name, tip = name
                btn = QPushButton(pixmap.icon(), name, btnfr)
                if tip:
                    btn.setToolTip(tip)
            self._user_buttons[name] = btn
            btn._clicked = Kittens.utils.curry(self.emit, SIGNAL(name))
            self.connect(btn, SIGNAL("clicked()"), btn._clicked)
            btnfr_lo.addWidget(btn, 1)
        # add a Close button
        btnfr_lo.addStretch(100)
        closebtn = QPushButton(pixmaps.grey_round_cross.icon(), "Close", btnfr)
        self.connect(closebtn, SIGNAL("clicked()"), self.hide)
        btnfr_lo.addWidget(closebtn, 1)
        # resize selves
        self.config_name = config_name or "html-viewer"
        width = Config.getint('%s-width' % self.config_name, 512)
        height = Config.getint('%s-height' % self.config_name, 512)
        self.resize(QSize(width, height))

    def resizeEvent(self, ev):
        QDialog.resizeEvent(self, ev)
        sz = ev.size()
        Config.set('%s-width' % self.config_name, sz.width())
        Config.set('%s-height' % self.config_name, sz.height())

    def setDocument(self, filename, empty=""):
        """Sets the HTML text to be displayed. """
        self._source = QUrl.fromLocalFile(filename)
        if os.path.exists(filename):
            self.viewer.setSource(self._source)
        else:
            self.viewer.setText(empty)

    def _urlClicked(self, url):
        path = str(url.path())
        if path:
            self.emit(SIGNAL("viewPath"), path)
        # to make sure it keeps displaying the same thing
        self.viewer.setSource(self._source)

    def reload(self):
        self.viewer.reload()

    def setLabel(self, label=None):
        if label is None:
            self.label.hide()
        else:
            self.label.setText(label)
            self.label.show()