示例#1
0
 def change_cover_grid_color(self):
     col = QColorDialog.getColor(
         self.cg_bg_widget.bcol, self.gui,
         _('Choose background color for the Cover grid'))
     if col.isValid():
         col = tuple(col.getRgb())[:3]
         self.set_cg_color(col)
         self.changed_signal.emit()
         if self.cg_bg_widget.btex:
             if question_dialog(
                     self, _('Remove background image?'),
                     _('There is currently a background image set, so the color'
                       ' you have chosen will not be visible. Remove the background image?'
                       )):
                 self.set_cg_texture(None)
示例#2
0
文件: text.py 项目: qykth-git/calibre
 def format_text(self, formatting):
     if self.syntax != 'html':
         return
     if formatting.startswith('justify_'):
         return self.smarts.set_text_alignment(
             self,
             formatting.partition('_')[-1])
     color = 'currentColor'
     if formatting in {'color', 'background-color'}:
         color = QColorDialog.getColor(
             QColor(Qt.GlobalColor.black if formatting ==
                    'color' else Qt.GlobalColor.white), self,
             _('Choose color'),
             QColorDialog.ColorDialogOption.ShowAlphaChannel)
         if not color.isValid():
             return
         r, g, b, a = color.getRgb()
         if a == 255:
             color = 'rgb(%d, %d, %d)' % (r, g, b)
         else:
             color = 'rgba(%d, %d, %d, %.2g)' % (r, g, b, a / 255)
     prefix, suffix = {
         'bold': ('<b>', '</b>'),
         'italic': ('<i>', '</i>'),
         'underline': ('<u>', '</u>'),
         'strikethrough': ('<strike>', '</strike>'),
         'superscript': ('<sup>', '</sup>'),
         'subscript': ('<sub>', '</sub>'),
         'color': ('<span style="color: %s">' % color, '</span>'),
         'background-color':
         ('<span style="background-color: %s">' % color, '</span>'),
     }[formatting]
     left, right = self.get_range_inside_tag()
     c = self.textCursor()
     c.setPosition(left)
     c.setPosition(right, QTextCursor.MoveMode.KeepAnchor)
     prev_text = str(c.selectedText()).rstrip('\0')
     c.insertText(prefix + prev_text + suffix)
     if prev_text:
         right = c.position()
         c.setPosition(left)
         c.setPosition(right, QTextCursor.MoveMode.KeepAnchor)
     else:
         c.setPosition(c.position() - len(suffix))
     self.setTextCursor(c)
示例#3
0
 def choose_color(self):
     col = QColorDialog.getColor(
         QColor(self._color or Qt.GlobalColor.white), self,
         _('Choose a color'))
     if col.isValid():
         self.color = unicode_type(col.name())
示例#4
0
 def choose_color(self):
     c = QColorDialog.getColor(self._color, self, _('Choose color'))
     if c.isValid():
         self._color = c
         self.update_display()