Example #1
0
    def __init__(self,
            prompt='>>> ',
            continuation='... ',
            parent=None):
        QTextEdit.__init__(self, parent)
        self.shutting_down = False
        self.compiler = CommandCompiler()
        self.buf = self.old_buf = []
        self.history = History([''], dynamic.get('console_history', []))
        self.prompt_frame = None
        self.allow_output = False
        self.prompt_frame_format = QTextFrameFormat()
        self.prompt_frame_format.setBorder(1)
        self.prompt_frame_format.setBorderStyle(QTextFrameFormat.BorderStyle_Solid)
        self.prompt_len = len(prompt)

        self.doc.setMaximumBlockCount(int(prefs['scrollback']))
        self.lexer = PythonLexer(ensurenl=False)
        self.tb_lexer = PythonTracebackLexer()

        self.context_menu = cm = QMenu(self) # {{{
        cm.theme = ThemeMenu(cm)
        # }}}

        self.formatter = Formatter(prompt, continuation, style=prefs['theme'])
        p = QPalette()
        p.setColor(p.Base, QColor(self.formatter.background_color))
        p.setColor(p.Text, QColor(self.formatter.color))
        self.setPalette(p)

        self.key_dispatcher = { # {{{
                Qt.Key_Enter : self.enter_pressed,
                Qt.Key_Return : self.enter_pressed,
                Qt.Key_Up : self.up_pressed,
                Qt.Key_Down : self.down_pressed,
                Qt.Key_Home : self.home_pressed,
                Qt.Key_End : self.end_pressed,
                Qt.Key_Left : self.left_pressed,
                Qt.Key_Right : self.right_pressed,
                Qt.Key_Backspace : self.backspace_pressed,
                Qt.Key_Delete : self.delete_pressed,
        } # }}}

        motd = textwrap.dedent('''\
        # Python {0}
        # {1} {2}
        '''.format(sys.version.splitlines()[0], __appname__,
            __version__))

        sys.excepthook = self.unhandled_exception

        self.controllers = []
        QTimer.singleShot(0, self.launch_controller)


        with EditBlock(self.cursor):
            self.render_block(motd)
Example #2
0
 def set_color(self):
     r, g, b = gprefs['cover_grid_color']
     pal = QPalette()
     col = QColor(r, g, b)
     pal.setColor(pal.Base, col)
     tex = gprefs['cover_grid_texture']
     if tex:
         from calibre.gui2.preferences.texture_chooser import texture_path
         path = texture_path(tex)
         if path:
             pm = QPixmap(path)
             if not pm.isNull():
                 val = pm.scaled(1, 1).toImage().pixel(0, 0)
                 r, g, b = qRed(val), qGreen(val), qBlue(val)
                 pal.setBrush(pal.Base, QBrush(pm))
     dark = (r + g + b)/3.0 < 128
     pal.setColor(pal.Text, QColor(Qt.white if dark else Qt.black))
     self.setPalette(pal)
     self.delegate.highlight_color = pal.color(pal.Text)
    def _initialize_collections(self):
        '''
        Populate the data model with current collection assignments
        Hook click, doubleClick events
        '''
        self._log_location()

        # Set the bg color of the description text fields to the dialog bg color
        if False:
            bgcolor = self.palette().color(QPalette.Background)
            palette = QPalette()
            palette.setColor(QPalette.Base, bgcolor)
            self.calibre_lw.setPalette(palette)
            self.marvin_lw.setPalette(palette)

        if self.calibre_collections is not None:
            for ca in self.calibre_collections:
                item = ListWidgetItem(ca)
                item.setData(Qt.UserRole, ca)
                if RENAMING_ENABLED:
                    item.setFlags(item.flags() | Qt.ItemIsEditable)
                self.calibre_lw.addItem(item)

        for ma in self.marvin_collections:
            item = ListWidgetItem(ma)
            item.setData(Qt.UserRole, ma)
            if RENAMING_ENABLED:
                item.setFlags(item.flags() | Qt.ItemIsEditable)
            self.marvin_lw.addItem(item)

        # Capture click events to clear selections in opposite list
        self.calibre_lw.clicked.connect(self._clear_marvin_selection)
        self.marvin_lw.clicked.connect(self._clear_calibre_selection)

        # Hook double-click events
        if RENAMING_ENABLED:
            self.calibre_lw.doubleClicked.connect(self.rename_calibre_tag)
            self.marvin_lw.doubleClicked.connect(self.rename_marvin_tag)

        # Enable sorting
        if self.calibre_collections is not None:
            self.calibre_lw.setSortingEnabled(True)
        self.marvin_lw.setSortingEnabled(True)
    def _populate_description(self):
        # Set the bg color of the description text fields to the dialog bg color
        bgcolor = self.palette().color(QPalette.Background)
        palette = QPalette()
        palette.setColor(QPalette.Base, bgcolor)
        self.calibre_description.setPalette(palette)
        self.marvin_description.setPalette(palette)

        if 'comments' in self.mismatches:
            self.calibre_description_label.setText(self.YELLOW_BG.format("<b>Description</b>"))
            if self.mismatches['comments']['calibre']:
                self.calibre_description.setText(self.mismatches['comments']['calibre'])

            self.marvin_description_label.setText(self.YELLOW_BG.format("<b>Description</b>"))
            if self.mismatches['comments']['Marvin']:
                self.marvin_description.setText(self.mismatches['comments']['Marvin'])
        else:
            if self.installed_book.comments:
                self.calibre_description.setText(self.installed_book.comments)
                self.marvin_description.setText(self.installed_book.comments)
    def initialize(self, parent, book_id, cid, installed_book, enable_metadata_updates, marvin_db_path):
        '''
        __init__ is called on SizePersistedDialog()
        shared attributes of interest:
            .authors
            .author_sort
            .cover_hash
            .pubdate
            .publisher
            .rating
            .series
            .series_index
            .title
            .title_sort
            .comments
            .tags
            .uuid
        '''
        self.setupUi(self)
        self.book_id = book_id
        self.cid = cid
        self.connected_device = parent.opts.gui.device_manager.device
        self.installed_book = installed_book
        self.marvin_db_path = marvin_db_path
        self.opts = parent.opts
        self.parent = parent
        self.stored_command = None
        self.verbose = parent.verbose
        self.BORDER_LR = 4
        self.BORDER_TB = 8
        self.GREY_FG = '<font style="color:#A0A0A0">{0}</font>'
        self.YELLOW_BG = '<font style="background:#FDFF99">{0}</font>'

        self._log_location(installed_book.title)

        # Subscribe to Marvin driver change events
        self.connected_device.marvin_device_signals.reader_app_status_changed.connect(
            self.marvin_status_changed)

        #self._log("mismatches:\n%s" % repr(installed_book.metadata_mismatches))
        self.mismatches = installed_book.metadata_mismatches

        self._populate_title()
        self._populate_title_sort()
        self._populate_series()
        self._populate_authors()
        self._populate_author_sort()
        self._populate_uuid()
        self._populate_covers()
        self._populate_subjects()
        self._populate_publisher()
        self._populate_pubdate()
        self._populate_rating()
        self._populate_description()

        # ~~~~~~~~ Export to Marvin button ~~~~~~~~
        self.export_to_marvin_button.setIcon(QIcon(os.path.join(self.parent.opts.resources_path,
                                                   'icons',
                                                   'from_calibre.png')))
        self.export_to_marvin_button.clicked.connect(partial(self.store_command, 'export_metadata'))
        self.export_to_marvin_button.setEnabled(enable_metadata_updates)

        # ~~~~~~~~ Import from Marvin button ~~~~~~~~
        self.import_from_marvin_button.setIcon(QIcon(os.path.join(self.parent.opts.resources_path,
                                                     'icons',
                                                     'from_marvin.png')))
        self.import_from_marvin_button.clicked.connect(partial(self.store_command, 'import_metadata'))
        self.import_from_marvin_button.setEnabled(enable_metadata_updates)

        # If no calibre book, or no mismatches, adjust the display accordingly
        if not self.cid:
            #self._log("self.cid: %s" % repr(self.cid))
            #self._log("self.mismatches: %s" % repr(self.mismatches))
            self.calibre_gb.setVisible(False)
            self.import_from_marvin_button.setVisible(False)
            self.setWindowTitle(u'Marvin metadata')
        elif not self.mismatches:
            # Show both panels, but hide the transfer buttons
            self.export_to_marvin_button.setVisible(False)
            self.import_from_marvin_button.setVisible(False)
        else:
            self.setWindowTitle(u'Metadata Summary')

        if False:
            # Set the Marvin QGroupBox to Marvin red
            marvin_red = QColor()
            marvin_red.setRgb(189, 17, 20, alpha=255)
            palette = QPalette()
            palette.setColor(QPalette.Background, marvin_red)
            self.marvin_gb.setPalette(palette)

        # ~~~~~~~~ Add a Close or Cancel button ~~~~~~~~
        self.close_button = QPushButton(QIcon(I('window-close.png')), 'Close')
        if self.mismatches:
            self.close_button.setText('Cancel')
        self.bb.addButton(self.close_button, QDialogButtonBox.RejectRole)

        self.bb.clicked.connect(self.dispatch_button_click)

        # Restore position
        self.resize_dialog()
Example #6
0
    def update (self,warrior):
        self.warrior = warrior
        groupe_name = warrior.groupe().name
        if warrior.masterGroupe() != None : 
            groupe_name = warrior.masterGroupe().name+"/"+groupe_name
         
        kingdom_name = warrior.kingdom().name
        empire_name = warrior.empire().name
        faction_name = warrior.faction().name
        path = os.path.join(Config().instance.path_to_pic(),faction_name,empire_name,kingdom_name,'Picture',groupe_name,warrior.name)
        picture = QPixmap(path+"/portrait.jpg").scaledToWidth(self.picture.width())
   
        self.warrior_name.setText(warrior.name.replace("_"," "))
        self.warrior_name.setObjectName("Warrior_name")
        couleur = warrior.groupe().attribs['color']
        if warrior.masterGroupe() != None : 
            couleur = warrior.masterGroupe().attribs['color']

        self.picture.setPixmap(picture)


        self.progressBar_life.setStyleSheet("  QProgressBar{ background-color: red;}")
        #self.ui.progressBar_life.setAlignment(QtCore.Qt.AlignCenter)
        #self.progressBar_energy.setStyleSheet("  QProgressBar::chunk {     background-color: #05B8CC;width: 20px;}")
        #self.ui.progressBar_MP.setAlignment(QtCore.Qt.AlignCenter)
        try:
            hp_percent = float(self.warrior.attribs['HP'] / self.warrior.attribs['HP_max'])* 100
            mp_percent = float(self.warrior.attribs['MP'] / self.warrior.attribs['MP_max'])* 100
        except (ZeroDivisionError,KeyError) as e :
            hp_percent =0
            mp_percent =0
        self.progressBar_life.setValue(int(hp_percent))
        self.progressBar_energy.setValue(int(mp_percent))
        self.profil_completion.setPixmap(QPixmap(":/icons/128x128/state_"+str(warrior.attribs['complete']+1)).scaledToHeight(32))
        self.profil_completion.setStyleSheet("#"+self.profil_completion.objectName()+"{background-color:transparent;}")

        pal = QPalette(self.rank_text.palette())
        image = QImage(os.path.join(Config().instance.path_to_icons(),"rank")+"/star_"+warrior.groupe().attribs["color"]+".png")
        value = image.pixel(image.width()/2.0,image.height()/2.0)
        pal.setColor(QPalette.WindowText, QColor(value))
        self.rank_text.setPalette(pal)
        self.rank_text.setText(str(warrior.attribs["rank"]))
        #Boutton Faction 
        path = os.path.join(Config().instance.path_to_icons(),"faction","32x32",faction_name)
        self.iconFaction.setIcon(QIcon(path))
        self.iconFaction.setToolTip(warrior.faction().name)
        #Boutton Empire 
        path = os.path.join(Config().instance.path_to_icons(),"empire","32x32",empire_name)
        self.iconEmpire.setIcon(QIcon(path))
        self.iconEmpire.setToolTip(warrior.empire().name)
        self.iconEmpire.clicked.connect(self.onEmpireClicked)
        #Boutton Kingdom
        path = os.path.join(Config().instance.path_to_icons(),"kingdom","32x32",kingdom_name)
        self.iconKingdom.setIcon(QIcon(path))
        self.iconKingdom.setToolTip(self.warrior.kingdom().name)
        self.iconKingdom.clicked.connect(self.onKingdomClicked)
        #Boutton Groupe
        self.iconGroupe.setText(groupe_name.replace("_"," "))
        groupe_color = self.warrior.groupe().attribs['color']
        if self.warrior.masterGroupe() != None : 
            groupe_color = self.warrior.masterGroupe().attribs['color']
        self.iconGroupe.setStyleSheet("#"+self.iconGroupe.objectName()+"{background-image:url(:/textures/"+groupe_color+");}")
        self.iconGroupe.clicked.connect(self.onGroupClicked)
        path = os.path.join(Config().instance.path_to_icons(),"actions",warrior.attribs['status'])
        # Icone d etat
        self.iconState.setPixmap(QPixmap(path).scaledToHeight(64))
Example #7
0
def apply_theme(app):
    app.setStyle('Fusion')

    # Font
    font_database = QFontDatabase()
    font_database.addApplicationFont('source/ui/noto.ttf')
    app.setFont(QFont('Noto Sans CJK TC Regular', weight=QFont.Normal))

    # QSS
    with open('source/ui/style.qss') as stylesheet:
        app.setStyleSheet(stylesheet.read())

    # palette
    new_palette = QPalette()

    # base
    new_palette.setColor(QPalette.WindowText, QColor('#ABAEB0'))
    new_palette.setColor(QPalette.Button, QColor('#262f36'))
    new_palette.setColor(QPalette.Light, QColor('#D5D6D7'))
    new_palette.setColor(QPalette.Midlight, QColor('#05796E'))
    new_palette.setColor(QPalette.Dark, QColor('#1E272E'))
    new_palette.setColor(QPalette.Text, QColor('#ABAEB0'))
    new_palette.setColor(QPalette.BrightText, QColor('#e6e6e6'))
    new_palette.setColor(QPalette.ButtonText, QColor('#ABAEB0'))
    new_palette.setColor(QPalette.Base, QColor('#384047'))
    new_palette.setColor(QPalette.Window, QColor('#2B343B'))
    new_palette.setColor(QPalette.Shadow, QColor('#181F24'))
    new_palette.setColor(QPalette.Highlight, QColor('#07A092'))
    new_palette.setColor(QPalette.HighlightedText, QColor('#e6e6e6'))
    new_palette.setColor(QPalette.Link, QColor('#07A092'))
    new_palette.setColor(QPalette.AlternateBase, QColor('#262f36'))
    new_palette.setColor(QPalette.ToolTipBase, QColor(53, 53, 53))
    new_palette.setColor(QPalette.ToolTipText, QColor('#828588'))

    # disabled
    new_palette.setColor(QPalette.Disabled, QPalette.WindowText,
                         QColor(127, 127, 127))
    new_palette.setColor(QPalette.Disabled, QPalette.Text,
                         QColor(127, 127, 127))
    new_palette.setColor(QPalette.Disabled, QPalette.ButtonText,
                         QColor(127, 127, 127))
    new_palette.setColor(QPalette.Disabled, QPalette.Highlight,
                         QColor(80, 80, 80))
    new_palette.setColor(QPalette.Disabled, QPalette.HighlightedText,
                         QColor(127, 127, 127))
    app.setPalette(new_palette)