Exemple #1
0
    def init_css(self):
        '''
        # ensure that css files are up to date.we have a css file..
        # otherwise the layout will be awful!
        '''
        CommonSettings.init_css(self)
        for css in ("notes", "details"):
            resource = QtCore.QResource(":css/%s.css"% css)
            if resource.isCompressed():
                data = QtCore.qUncompress(resource.data())
            else:
                data = resource.data()

            default_loc = os.path.join(self.LOCALFOLDER, "%s.css"% css)

            try:
                f = open(default_loc, "r")
                css_data = f.read()
                f.close()
                if css_data == data:
                    LOGGER.debug("%s is current"% default_loc)
                    continue
            except IOError:
                pass

            print "initiating a new css file - %s"% default_loc
            f = open(default_loc, "w")
            f.write(data)
            f.close()
Exemple #2
0
    def init_css(self):
        '''
        create css files if they don't exist
        '''
        default_loc = os.path.join(self.LOCALFOLDER, "proxy.css")

        resource = QtCore.QResource(":css/proxy.css")
        if resource.isCompressed():
            data = QtCore.qUncompress(resource.data())
        else:
            data = resource.data()

        default_loc = os.path.join(self.LOCALFOLDER, "proxy.css")

        try:
            f = open(default_loc, "r")
            css_data = f.read()
            f.close()
            if css_data == data:
                LOGGER.debug("%s is current" % default_loc)
                return
        except IOError:
            pass

        print "initiating a new css file - %s" % default_loc
        f = open(default_loc, "w")
        f.write(data)
        f.close()
Exemple #3
0
def reset(i=None):
    if i is None:
        r = range(len(templates))
    else:
        r = [i]
    for t in r:
        log.debug('reset %i', t)
        tstr = unicode(QtCore.QResource(templates[t][2]).data(), 'utf8')
        startup.CFG.setValue(templates[t][3], tstr)
Exemple #4
0
    def __init__(self, parent=None):

        QtGui.QDialog.__init__(self, parent)
        self.setupUi(self)

        # connections to slots
        self.connect(self.pushButtonAdd, QtCore.SIGNAL('clicked()'), self.slotAdd)
        self.connect(self.pushButtonRemove, QtCore.SIGNAL('clicked()'), self.slotRemove)
        self.connect(self.pushButtonApply, QtCore.SIGNAL('clicked()'), self.slotApply)
        self.connect(self.pushButtonAddLibrary, QtCore.SIGNAL('clicked()'), self.slotAddLibrary)
        self.connect(self.pushButtonRemoveLibrary, QtCore.SIGNAL('clicked()'), self.slotRemoveLibrary)
        self.connect(self.toolButtonLibrary, QtCore.SIGNAL('clicked()'), self.slotCallLibraryBrowser)
        self.connect(self.treeWidgetNodes,  QtCore.SIGNAL('itemSelectionChanged()'),  self.slotNodeSelectionChanged)
        self.connect(self.treeWidgetSymbols,  QtCore.SIGNAL('itemSelectionChanged()'),  self.slotSymbolSelectionChanged)
        self.connect(self.treeWidgetNodes,  QtCore.SIGNAL('itemActivated(QTreeWidgetItem *, int)'), self.slotNodeSelected)
        self.connect(self.treeWidgetSymbols,  QtCore.SIGNAL('itemActivated(QTreeWidgetItem *, int)'), self.slotLibrarySelected)

        # populate node type list
        for type in SYMBOL_TYPES.values():
            self.comboBoxNodeType.addItem(translate("nodesDock", type))

        # load current nodes
        self.treeWidgetNodes.clear()
        for symbol in SYMBOLS:
            if not symbol['translated']:
                item = QtGui.QTreeWidgetItem(self.treeWidgetNodes)
                item.setText(0, symbol['name'])
                item.setIcon(0,  QtGui.QIcon(symbol['normal_svg_file']))
                item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(translate("nodesDock", SYMBOL_TYPES[symbol['object']])))

        # load built-in symbols
        self.treeWidgetSymbols.clear()
        internal_symbols = QtGui.QTreeWidgetItem()
        internal_symbols.setText(0, 'Built-in symbols')
        internal_symbols.setIcon(0,  QtGui.QIcon(':/icons/package.svg'))
        internal_symbols.setFlags(QtCore.Qt.ItemIsEnabled)
        self.treeWidgetSymbols.addTopLevelItem(internal_symbols)
        self.treeWidgetSymbols.expandItem(internal_symbols)
        symbol_resources = QtCore.QResource(":/symbols")
        for symbol in symbol_resources.children():
            symbol = str(symbol)
            if symbol.endswith('.normal.svg'):
                name = symbol[:-11]
                item = QtGui.QTreeWidgetItem(internal_symbols)
                item.setText(0, name)
                item.setIcon(0,  QtGui.QIcon(':/symbols/' + symbol))
                item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(':/symbols/' + symbol))

        # load libraries
        for (library_name, conf) in globals.GApp.libraries.iteritems():
            self.addLibrarySymbols(library_name, conf.path)

        self.pushButtonAdd.setEnabled(False)
        self.pushButtonRemove.setEnabled(False)
Exemple #5
0
    def __init__(self, items):

        QtGui.QDialog.__init__(self)
        self.setupUi(self)
        self.items = items

        symbol_resources = QtCore.QResource(":/symbols")
        for symbol in symbol_resources.children():
            symbol = str(symbol)
            if symbol.endswith('.normal.svg'):
                name = symbol[:-11]
                item = QtGui.QTreeWidgetItem()
                item.setText(0, name)
                item.setIcon(0, QtGui.QIcon(':/symbols/' + symbol))
                self.treeWidgetSymbols.addTopLevelItem(item)
Exemple #6
0
    def addLibrarySymbols(self, library_name, path):
        """ Add library symbols in the list
        """

        library = QtGui.QTreeWidgetItem()
        library.setText(0, library_name)
        library.setIcon(0,  QtGui.QIcon(':/icons/package.svg'))
        library.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(path))
        self.treeWidgetSymbols.addTopLevelItem(library)
        resources = QtCore.QResource(":/" + library_name)
        for symbol in resources.children():
            item = QtGui.QTreeWidgetItem(library)
            item.setText(0, symbol)
            item.setIcon(0, QtGui.QIcon(':/' + library_name + '/' + symbol))
            item.setData(0, QtCore.Qt.UserRole, QtCore.QVariant(':/' + library_name + '/' + symbol))
Exemple #7
0
def main(**kwargs):
    """Start the QT mainloop and open the main window."""
    if os.environ.get('TESTABILITY', False) and \
            '-testability' not in sys.argv:
        sys.argv.append('-testability')
    app = QtGui.QApplication(sys.argv)

    source.main(app)

    data = []
    for qss_name in (PLATFORM_QSS, ":/stylesheet.qss"):
        qss = QtCore.QResource(qss_name)
        data.append(compat.text_type(qss.data()))
    app.setStyleSheet('\n'.join(data))

    # Fix the string that contains unicode chars.
    for key in kwargs:
        value = kwargs[key]
        if isinstance(value, compat.binary_type):
            kwargs[key] = value.decode('utf-8')

    close_callback = lambda: source.main_quit(app)
    ui = UbuntuSSOClientGUI(close_callback=close_callback, **kwargs)
    style = QtGui.QStyle.alignedRect(QtCore.Qt.LeftToRight,
                                     QtCore.Qt.AlignCenter, ui.size(),
                                     app.desktop().availableGeometry())
    ui.setGeometry(style)

    app = QtGui.QApplication.instance()
    app.setWindowIcon(QtGui.QIcon.fromTheme("ubuntuone"))

    ui.show()
    if sys.platform == 'darwin':
        ui.raise_()

    source.main_start(app)
Exemple #8
0
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        WindowStateReader.__init__(self)
        WindowStateWriter.__init__(self)
        self._db = BookDbLayer()

        self.userConfigDir = QtCore.QDir.homePath() + QtCore.QDir.separator() + \
                             '.pyhomelib'
        if not QtCore.QFileInfo(self.userConfigDir).isDir():
            QtCore.QDir.home().mkdir('.pyhomelib')
        self.uiSettingsFile = self.userConfigDir + QtCore.QDir.separator() + \
                              'ui.xml'
        self.programSettings = MySettings(self.userConfigDir +
                                          QtCore.QDir.separator() +
                                          'pyhomelib.conf')

        if len(sys.argv) < 2:
            dbname = self.userConfigDir + QtCore.QDir.separator() + \
                     'default.sqlite'
        else:
            dbname = QtCore.QString.fromUtf8(sys.argv[1])

        genreModel = GenreTreeModelReader('genres.xml')

        info = QtCore.QFileInfo(dbname)
        if info.exists() and info.size() > 0:
            self._db.open(dbname)
        else:
            QtGui.QMessageBox.information(
                self, self.tr("Information"),
                QtCore.QString(
                    self.tr("Database doesn't exists, recreating: %1")).arg(
                        dbname))
            self._db.create(dbname, 'Default', '', genreModel.list(),
                            [self.tr('Favorites')])

        try:
            import sqlite3ext
            handle = db().driver().handle()
            sqlite3ext.load_icu(handle.data().ascobject())
        except ImportError:
            pass

        self.setupUi(self)
        QtGui.qApp.setStyleSheet(
            QtCore.QResource(":resources/pyhomelib.css").data())
        self.appTitle = self.windowTitle()
        self.prependToTitle(self._db.getDbProperty('name').toString())
        self.actionRuLetterA.setText(u"А")
        self.actionRuLetterB.setText(u"Б")
        self.actionRuLetterV.setText(u"В")
        self.actionRuLetterG.setText(u"Г")
        self.actionRuLetterD.setText(u"Д")
        self.actionRuLetterE.setText(u"Е")
        self.actionRuLetterYo.setText(u"Ё")
        self.actionRuLetterZh.setText(u"Ж")
        self.actionRuLetterZ.setText(u"З")
        self.actionRuLetterI.setText(u"И")
        self.actionRuLetterY.setText(u"Й")
        self.actionRuLetterK.setText(u"К")
        self.actionRuLetterL.setText(u"Л")
        self.actionRuLetterM.setText(u"М")
        self.actionRuLetterN.setText(u"Н")
        self.actionRuLetterO.setText(u"О")
        self.actionRuLetterP.setText(u"П")
        self.actionRuLetterR.setText(u"Р")
        self.actionRuLetterS.setText(u"С")
        self.actionRuLetterT.setText(u"Т")
        self.actionRuLetterU.setText(u"У")
        self.actionRuLetterF.setText(u"Ф")
        self.actionRuLetterH.setText(u"Х")
        self.actionRuLetterTs.setText(u"Ц")
        self.actionRuLetterCh.setText(u"Ч")
        self.actionRuLetterSh.setText(u"Ш")
        self.actionRuLetterSch.setText(u"Щ")
        self.actionRuLetterYy.setText(u"Ы")
        self.actionRuLetterEe.setText(u"Э")
        self.actionRuLetterYu.setText(u"Ю")
        self.actionRuLetterYa.setText(u"Я")

        self.lettersGroup = QtGui.QActionGroup(self)
        for a in self.findChildren(QtGui.QAction):
            if a.objectName().startsWith('actionRuLetter') or \
               a.objectName().startsWith('actionEnLetter'):
                self.lettersGroup.addAction(a)

        self.authorsModel = SqlQueryModel(self, self._db,
                                          "authorid, lastname, firstname",
                                          "libauthorname", None,
                                          "lastname, firstname")
        self.authorsView.setModel(self.authorsModel)
        self.setTableAuthorsModelQuery()
        self.authorsView.hideColumn(0)
        for index, name in enumerate(
            [self.tr("authorid"),
             self.tr("Last name"),
             self.tr("First name")]):
            self.authorsView.model().setHeaderData(index, QtCore.Qt.Horizontal,
                                                   name)

        self.sequencesModel = SqlQueryModel(self, self._db, "seqid, seqname",
                                            "libseqname", None, "seqname")
        self.sequencesView.setModel(self.sequencesModel)
        self.sequencesModel.select()
        self.sequencesView.hideColumn(0)
        for index, name in enumerate([self.tr("seqid"), self.tr("Sequence")]):
            self.sequencesView.model().setHeaderData(index,
                                                     QtCore.Qt.Horizontal,
                                                     name)

        self.genresTree.setModel(genreModel)
        self.genresTree.hideColumn(1)

        self.bookSearchModel = SqlQueryModel(
            self, self._db,
            "b.bookid, firstname, lastname, title, seqname, genredesc, lang, year",
            "libbook b LEFT JOIN libsequence s ON b.bookid = s.bookid LEFT JOIN libseqname sn ON s.seqid = sn.seqid LEFT JOIN libauthor a ON b.bookid = a.bookid LEFT JOIN libauthorname an ON a.authorid = an.authorid LEFT JOIN libgenre g ON b.bookid = g.bookid LEFT JOIN libgenrelist gl ON g.genreid = gl.genreid",
            "b.bookid = 0", None, "1")
        self.bookSearchView.setModel(self.bookSearchModel)
        self.bookSearchModel.select()
        self.bookSearchView.hideColumn(0)
        for index, name in enumerate([
                self.tr("bookid"),
                self.tr("First name"),
                self.tr("Last name"),
                self.tr("Book Title"),
                self.tr("Sequence"),
                self.tr("Genre"),
                self.tr("Lang"),
                self.tr("Year")
        ]):
            self.bookSearchModel.setHeaderData(index, QtCore.Qt.Horizontal,
                                               name)

        self.groupsModel = SqlQueryModel(self, self._db, "groupid, groupname",
                                         "libgrouplist", None, "groupname")
        self.groupsView.setModel(self.groupsModel)
        self.groupsModel.select()
        self.groupsView.hideColumn(0)
        for index, name in enumerate([self.tr("groupid"), self.tr("Group")]):
            self.groupsView.model().setHeaderData(index, QtCore.Qt.Horizontal,
                                                  name)

        self.booksByAuthorModel = SqlQueryModel(
            self, self._db, "bookid, title, seqname, genredesc, lang, year",
            "libauthor a INNER JOIN libbook b USING(bookid) LEFT JOIN libseqname s ON b.seqid = s.seqid LEFT JOIN libgenrelist g ON b.genreid = g.genreid",
            "a.authorid = ?")
        self.booksByAuthorView.setModel(self.booksByAuthorModel)
        self.booksByAuthorModel.addBindValue(0)
        self.booksByAuthorModel.select()
        self.booksByAuthorView.hideColumn(0)
        for index, name in enumerate([
                self.tr("bookid"),
                self.tr("Book Title"),
                self.tr("Sequence"),
                self.tr("Genre"),
                self.tr("Lang"),
                self.tr("Year")
        ]):
            self.booksByAuthorModel.setHeaderData(index, QtCore.Qt.Horizontal,
                                                  name)

        self.booksBySeqModel = SqlQueryModel(
            self, self._db,
            "bookid, firstname, lastname, title, genredesc, lang, year",
            "libsequence s INNER JOIN libbook b USING(bookid) LEFT JOIN libauthorname a ON b.authorid = a.authorid LEFT JOIN libgenrelist g ON b.genreid = g.genreid",
            "s.seqid = ?")
        self.booksBySeqView.setModel(self.booksBySeqModel)
        self.booksBySeqModel.addBindValue(0)
        self.booksBySeqModel.select()
        self.booksBySeqView.hideColumn(0)
        for index, name in enumerate([
                self.tr("bookid"),
                self.tr("First name"),
                self.tr("Last name"),
                self.tr("Book Title"),
                self.tr("Genre"),
                self.tr("Lang"),
                self.tr("Year")
        ]):
            self.booksBySeqModel.setHeaderData(index, QtCore.Qt.Horizontal,
                                               name)

        self.booksByGenreModel = SqlQueryModel(
            self, self._db,
            "bookid, firstname, lastname, title, seqname, lang, year",
            "libgenre g INNER JOIN libbook b USING(bookid) LEFT JOIN libauthorname a ON b.authorid = a.authorid LEFT JOIN libseqname s ON b.seqid = s.seqid",
            "g.genreid = ?")
        self.booksByGenreView.setModel(self.booksByGenreModel)
        self.booksByGenreModel.addBindValue(0)
        self.booksByGenreModel.select()
        self.booksByGenreView.hideColumn(0)
        for index, name in enumerate([
                self.tr("bookid"),
                self.tr("First name"),
                self.tr("Last name"),
                self.tr("Book Title"),
                self.tr("Sequence"),
                self.tr("Lang"),
                self.tr("Year")
        ]):
            self.booksByGenreModel.setHeaderData(index, QtCore.Qt.Horizontal,
                                                 name)

        self.booksByGroupModel = SqlQueryModel(
            self, self._db,
            "b.bookid, firstname, lastname, title, seqname, genredesc, lang, year",
            "libgroup g INNER JOIN libbook b USING(bookid) LEFT JOIN libseqname s ON b.seqid = s.seqid LEFT JOIN libauthorname a ON b.authorid = a.authorid LEFT JOIN libgenrelist gl ON b.genreid = gl.genreid",
            "g.groupid = ?")
        self.booksByGroupView.setModel(self.booksByGroupModel)
        self.booksByGroupModel.addBindValue(0)
        self.booksByGroupModel.select()
        self.booksByGroupView.hideColumn(0)
        for index, name in enumerate([
                self.tr("bookid"),
                self.tr("First name"),
                self.tr("Last name"),
                self.tr("Book Title"),
                self.tr("Sequence"),
                self.tr("Genre"),
                self.tr("Lang"),
                self.tr("Year")
        ]):
            self.booksByGroupModel.setHeaderData(index, QtCore.Qt.Horizontal,
                                                 name)

        self.readStateFrom(self.uiSettingsFile)
        self.actionRussianAlphabet.setChecked(
            self.ruLettersToolbar.isVisibleTo(self))
        self.actionEnglishAlphabet.setChecked(
            self.enLettersToolbar.isVisibleTo(self))

        if not self.programSettings.getRowHeight():
            self.programSettings.writeRowHeight(
                self.authorsView.verticalHeader().defaultSectionSize())
        else:
            self.setRowHeight(self.programSettings.getRowHeight())

        for key in ('/', 'Ctrl+F'):
            QtGui.QShortcut(key, self).activated.connect(
                self.on_quickFindShortcut_activated)

        self.parserThread = FB2BookParserThread()
        self.parserThread.bookParsed.connect(self.bookParsed)
        self.parserThread.start()
Exemple #9
0
    def _setupThemesUI(self, displaySettings):
        # Themes

        children = QtCore.QResource(':/themes').children()
        children.sort()

        currentIndex = None
        index = 0
        for theme in children:
            themeName = str(theme.replace(QtCore.QRegExp('\.css$'), ''))
            self._themeField.addItem(
                themeName.replace('_', ' ').title(), themeName)
            if themeName == displaySettings["theme"]:
                currentIndex = index
            index += 1

        if currentIndex is not None:
            self._themeField.setCurrentIndex(currentIndex)

        # Theme sizes

        currentIndex = None
        index = 0
        for size in [x for x in range(50, 160, 10)]:
            self._themeSizeField.addItem("{n}%".format(n=size), size)
            if size == int(displaySettings["size"]):
                currentIndex = index
            index += 1

        if currentIndex is not None:
            self._themeSizeField.setCurrentIndex(currentIndex)

        # Load preview content

        messages = [
            MessageRenderer.MESSAGES['join'].format(user='******',
                                                    room='Snakefire'),
            MessageRenderer.MESSAGES['message_self'].format(
                time='3:33 pm', user='******', message='Hey everyone!'),
            MessageRenderer.MESSAGES['message_self'].format(
                time='3:33 pm',
                user='******',
                message='How are you all doing?'),
            MessageRenderer.MESSAGES['alert'].format(
                time='3:34 pm',
                user='******',
                message='Hi John Doe! Nice to see you here'),
            MessageRenderer.MESSAGES['tweet'].format(
                url_user='******',
                user='******',
                url='#',
                message='Hello world from twitter :)'),
            MessageRenderer.MESSAGES['message_self'].format(
                time='3:35 pm',
                user='******',
                message='Look at this method:'),
            MessageRenderer.MESSAGES['paste'].format(
                message='def hello(self):<br />  print "Hello World"'),
            MessageRenderer.MESSAGES['topic'].format(
                user='******', topic='Testing Snakefire, and loving it'),
            MessageRenderer.MESSAGES['message'].format(
                time='3:36 pm',
                user='******',
                message='Looks good. Now look at this upload:'),
            MessageRenderer.MESSAGES['message'].format(
                time='3:36 pm',
                user='******',
                message=MessageRenderer.MESSAGES['upload'].format(
                    url='#', name='my_upload.tar.gz'))
        ]

        image = QtGui.QImage(":/icons/snakefire.png")
        buffer = QtCore.QBuffer()
        if buffer.open(QtCore.QIODevice.WriteOnly) and image.save(
                buffer, 'PNG'):
            messages.extend([
                MessageRenderer.MESSAGES['message_self'].format(
                    time='3:38 pm',
                    user='******',
                    message='Look at this image:'),
                MessageRenderer.MESSAGES['message_self'].format(
                    time='3:38 pm',
                    user='******',
                    message=MessageRenderer.MESSAGES['image'].format(
                        url='#',
                        type='image/png',
                        data=buffer.data().toBase64().data(),
                        name='image.png',
                        url_md5='',
                        js='',
                        attribs=''))
            ])

        messages.extend([
            MessageRenderer.MESSAGES['leave'].format(user='******',
                                                     room='Snakefire'),
            MessageRenderer.MESSAGES['message_self'].format(
                time='3:37 pm',
                user='******',
                message='I guess I am all alone now :('),
        ])

        self._themePreview.page().mainFrame().setHtml("\n".join(messages))
        self._themePreview.show()
        self._themeSelected()
        self._themeSizeSelected()

        self.connect(self._themeField,
                     QtCore.SIGNAL("currentIndexChanged(const QString&)"),
                     self._themeSelected)
        self.connect(self._themeSizeField,
                     QtCore.SIGNAL("currentIndexChanged(const QString&)"),
                     self._themeSizeSelected)