本文整理汇总了Python中PyQt4.Qt.QColor类的典型用法代码示例。如果您正苦于以下问题:Python QColor类的具体用法?Python QColor怎么用?Python QColor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QColor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_spinner
def draw_spinner(self, painter, rect):
width = rect.width()
outer_radius = (width-1)*0.5
inner_radius = (width-1)*0.5*0.38
capsule_height = outer_radius - inner_radius
capsule_width = int(capsule_height * (0.23 if width > 32 else 0.35))
capsule_radius = capsule_width//2
painter.save()
painter.setRenderHint(painter.Antialiasing)
for i in xrange(12):
color = QColor(self.color)
color.setAlphaF(1.0 - (i/12.0))
painter.setPen(Qt.NoPen)
painter.setBrush(color)
painter.save()
painter.translate(rect.center())
painter.rotate(self.angle - i*30.0)
painter.drawRoundedRect(-capsule_width*0.5,
-(inner_radius+capsule_height), capsule_width,
capsule_height, capsule_radius, capsule_radius)
painter.restore()
painter.restore()
示例2: load
def load(self):
st, ui = self.settings, self.ui
self.fgcolor = QColor(st.value("color/messages/fg",
self.app.palette().buttonText().color().name()).toString())
self.bgcolor = QColor(st.value("color/messages/bg",
self.app.palette().button().color().name()).toString())
self.old = drug(fgcolor = self.fgcolor, bgcolor = self.bgcolor)
ui.identicaidEdit.setText(st.value("account/identica/id").toString())
ui.twitteridEdit.setText(st.value("account/twitter/id").toString())
b = st.value("icon/isdark",True).toBool()
ui.darkradioButton.setChecked(b)
ui.lightradioButton.setChecked(not b)
ui.fgcolorButton.setStyleSheet("background-color:"+self.fgcolor.name())
ui.bgcolorButton.setStyleSheet("background-color:"+self.bgcolor.name())
示例3: load
def load(self):
st, ui = self.settings, self.ui
self.fgcolor = QColor(st.value("color/messages/fg",
self.app.palette().buttonText().color().name()).toString())
self.bgcolor = QColor(st.value("color/messages/bg",
self.app.palette().button().color().name()).toString())
self.old = drug(fgcolor = self.fgcolor, bgcolor = self.bgcolor)
b = st.value("icon/isdark",True).toBool()
ui.darkradioButton.setChecked(b)
ui.lightradioButton.setChecked(not b)
ui.fgcolorButton.setStyleSheet("background-color:"+self.fgcolor.name())
ui.bgcolorButton.setStyleSheet("background-color:"+self.bgcolor.name())
if self.app.notifier.buttons:
self.app.notifier.resetRadioButtons()
示例4: __init__
def __init__(self, gui):
QWidget.__init__(self, gui)
self.setObjectName('jobs_pointer')
self.setVisible(False)
self.resize(100, 80)
self.animation = QPropertyAnimation(self, "geometry", self)
self.animation.setDuration(750)
self.animation.setLoopCount(2)
self.animation.setEasingCurve(QEasingCurve.Linear)
self.animation.finished.connect(self.hide)
taily, heady = 0, 55
self.arrow_path = QPainterPath(QPointF(40, taily))
self.arrow_path.lineTo(40, heady)
self.arrow_path.lineTo(20, heady)
self.arrow_path.lineTo(50, self.height())
self.arrow_path.lineTo(80, heady)
self.arrow_path.lineTo(60, heady)
self.arrow_path.lineTo(60, taily)
self.arrow_path.closeSubpath()
c = self.palette().color(QPalette.Active, QPalette.WindowText)
self.color = QColor(c)
self.color.setAlpha(100)
self.brush = QBrush(self.color, Qt.SolidPattern)
示例5: fset
def fset(self, val):
val = unicode(val or '')
col = QColor(val)
orig = self._color
if col.isValid():
self._color = val
self.setText(val)
p = QPixmap(self.iconSize())
p.fill(col)
self.setIcon(QIcon(p))
else:
self._color = None
self.setText(self.choose_text)
self.setIcon(QIcon())
if orig != col:
self.color_changed.emit(self._color)
示例6: drawSquare
def drawSquare(self, painter, x, y, shape):
colorTable = [0x000000, 0xCC6666, 0x66CC66, 0x6666CC,
0xCCCC66, 0xCC66CC, 0x66CCCC, 0xDAAA00]
color = QColor(colorTable[shape])
painter.fillRect(x + 1, y + 1, self.squareWidth() - 2,
self.squareHeight() - 2, color)
painter.setPen(color.light())
painter.drawLine(x, y + self.squareHeight() - 1, x, y)
painter.drawLine(x, y, x + self.squareWidth() - 1, y)
painter.setPen(color.dark())
painter.drawLine(x + 1, y + self.squareHeight() - 1,
x + self.squareWidth() - 1, y + self.squareHeight() - 1)
painter.drawLine(x + self.squareWidth() - 1,
y + self.squareHeight() - 1, x + self.squareWidth() - 1, y + 1)
示例7: read_color
def read_color(col):
if QColor.isValidColor(col):
return QBrush(QColor(col))
try:
r, g, b = col[0:2], col[2:4], col[4:6]
r, g, b = int(r, 16), int(g, 16), int(b, 16)
return QBrush(QColor(r, g, b))
except Exception:
pass
示例8: read_color
def read_color(col):
if QColor.isValidColor(col):
return QBrush(QColor(col))
if col.startswith('rgb('):
r, g, b = map(int, (x.strip() for x in col[4:-1].split(',')))
return QBrush(QColor(r, g, b))
try:
r, g, b = col[0:2], col[2:4], col[4:6]
r, g, b = int(r, 16), int(g, 16), int(b, 16)
return QBrush(QColor(r, g, b))
except Exception:
pass
示例9: __init__
def __init__(self, *args, **kwargs):
super(Figure, self).__init__(*args, **kwargs)
# Creation of the Plotting class:
# Then we add it as background of the View:
self._context = QGLWidget(QGLFormat(QGL.NoAccumBuffer))
self.setViewport(self._context)
# create the context for Opengl
self._context.makeCurrent()
# And we set it as scene for the View:
self.scene = OGLWidget()
self.setScene(self.scene)
self.scene.initializeGL()
# Set some properties and palette to have a black background:
color = QColor()
color.black()
self.background_color = color
# unset the context ???
self._context.doneCurrent()
示例10: __init__
def __init__(self, name, color0=QColor("black"), color1=QColor("white"), alpha=(1, 1)):
QObject.__init__(self)
self.name = name
# color is either specified as one argument (which should then be a [3,n] or [4,n] array),
# or as two QColors orstring names.
if isinstance(color0, (list, tuple)):
self._rgb = numpy.array(color0)
if self._rgb.shape[1] != 3 or self._rgb.shape[0] < 2:
raise TypeError("expected [N,3] (N>=2) array as first argument")
else:
if isinstance(color0, str):
color0 = QColor(color0)
if isinstance(color1, str):
color1 = QColor(color1)
self._rgb = numpy.array([[color0.red(), color0.green(), color0.blue()],
[color1.red(), color1.green(), color1.blue()]]) / 255.
self._rgb_arg = numpy.arange(self._rgb.shape[0]) / (self._rgb.shape[0] - 1.0)
# alpha array
self._alpha = numpy.array(alpha).astype(float)
self._alpha_arg = numpy.arange(len(alpha)) / (len(alpha) - 1.0)
# background brush
self._brush = None
示例11: magnify_icons
def magnify_icons(a, b):
a = a.pixmap(16,16)
b = b.pixmap(16,16)
img = [QPixmap(16,16), QPixmap(16,16)]
for i in img:
i.fill(QColor(0, 0, 0, 0))
g = a.toImage()
for n in range(256):
x, y = n%16, n//16
c = QColor(g.pixel(x, y))
s = (c.redF() + c.greenF() + c.blueF()) / 3.0
l = s * 4.2
if l > 1.0: l = 1.0
c.setRgbF(s, s, s, l)
g.setPixel(x, y, c.rgba())
p = QPainter()
p.begin(i)
p.drawImage( QRectF(6, 0, 8, 16), g, QRectF(0, 0, 10, 16))
p.drawPixmap(QRectF(0, 0, 10, 16), b, QRectF(6, 1, 10, 15))
p.end()
a, b = b, a
return tuple(map(QIcon, img))
示例12: Pointer
class Pointer(QWidget):
def __init__(self, gui):
QWidget.__init__(self, gui)
self.setObjectName('jobs_pointer')
self.setVisible(False)
self.resize(100, 80)
self.animation = QPropertyAnimation(self, "geometry", self)
self.animation.setDuration(750)
self.animation.setLoopCount(2)
self.animation.setEasingCurve(QEasingCurve.Linear)
self.animation.finished.connect(self.hide)
taily, heady = 0, 55
self.arrow_path = QPainterPath(QPointF(40, taily))
self.arrow_path.lineTo(40, heady)
self.arrow_path.lineTo(20, heady)
self.arrow_path.lineTo(50, self.height())
self.arrow_path.lineTo(80, heady)
self.arrow_path.lineTo(60, heady)
self.arrow_path.lineTo(60, taily)
self.arrow_path.closeSubpath()
c = self.palette().color(QPalette.Active, QPalette.WindowText)
self.color = QColor(c)
self.color.setAlpha(100)
self.brush = QBrush(self.color, Qt.SolidPattern)
# from PyQt4.Qt import QTimer
# QTimer.singleShot(1000, self.start)
@property
def gui(self):
return self.parent()
def point_at(self, frac):
return (self.path.pointAtPercent(frac).toPoint() -
QPoint(self.rect().center().x(), self.height()))
def rect_at(self, frac):
return QRect(self.point_at(frac), self.size())
def abspos(self, widget):
pos = widget.pos()
parent = widget.parent()
while parent is not self.gui:
pos += parent.pos()
parent = parent.parent()
return pos
def start(self):
if config['disable_animations']:
return
self.setVisible(True)
self.raise_()
end = self.abspos(self.gui.jobs_button)
end = QPointF( end.x() + self.gui.jobs_button.width()/3.0, end.y()+20)
start = QPointF(end.x(), end.y() - 0.5*self.height())
self.path = QPainterPath(QPointF(start))
self.path.lineTo(end)
self.path.closeSubpath()
self.animation.setStartValue(self.rect_at(0.0))
self.animation.setEndValue(self.rect_at(1.0))
self.animation.setDirection(self.animation.Backward)
num_keys = 100
for i in xrange(1, num_keys):
i /= num_keys
self.animation.setKeyValueAt(i, self.rect_at(i))
self.animation.start()
def paintEvent(self, ev):
p = QPainter(self)
p.setRenderHints(p.Antialiasing)
p.setBrush(self.brush)
p.setPen(Qt.NoPen)
p.drawPath(self.arrow_path)
p.end()
示例13: __init__
class Preferencer:
def __init__(self, app):
self.app = app
self.settings = QSettings("blain", "blain")
self.ui = PreferencesDialog(app)
def connect(self):
ui, ft = self.ui, self.app.filters
self.app.window.ui.actionPreferences.triggered.connect(self.show)
#connect preference window
ui.fgcolorButton.clicked.connect(self.change_fgcolor)
ui.bgcolorButton.clicked.connect(self.change_bgcolor)
ui.resetcolorButton.clicked.connect(self.reset_color)
ui.buttonBox.accepted.connect(self.accept)
ui.buttonBox.rejected.connect(self.reject)
ui.buttonBox.button(QDialogButtonBox.Apply).clicked.connect(self.save)
ui.listWidget.currentRowChanged.connect(
ui.stackedWidget.setCurrentIndex)
def setup(self):
self.load()
def show(self, _):
self.app.window.disable()
self.ui.show()
def hide(self):
self.ui.hide()
self.app.window.enable()
def reject(self):
self.hide()
self.load()
def accept(self):
self.hide()
self.save()
def save(self):
app, st, ui = self.app, self.settings, self.ui
st.setValue("icon/isdark", ui.darkradioButton.isChecked())
st.setValue("color/messages/fg", self.fgcolor.name())
st.setValue("color/messages/bg", self.bgcolor.name())
self.app.notifier.saveRadioButtons()
self.app.icons.update_window_icon()
self.app.icons.update_tray()
if self.fgcolor != self.old.fgcolor or self.bgcolor != self.old.bgcolor:
self.old = drug(fgcolor = self.fgcolor, bgcolor = self.bgcolor)
self.app.reader.update_messages_colors()
def load(self):
st, ui = self.settings, self.ui
self.fgcolor = QColor(st.value("color/messages/fg",
self.app.palette().buttonText().color().name()).toString())
self.bgcolor = QColor(st.value("color/messages/bg",
self.app.palette().button().color().name()).toString())
self.old = drug(fgcolor = self.fgcolor, bgcolor = self.bgcolor)
b = st.value("icon/isdark",True).toBool()
ui.darkradioButton.setChecked(b)
ui.lightradioButton.setChecked(not b)
ui.fgcolorButton.setStyleSheet("background-color:"+self.fgcolor.name())
ui.bgcolorButton.setStyleSheet("background-color:"+self.bgcolor.name())
if self.app.notifier.buttons:
self.app.notifier.resetRadioButtons()
def change_fgcolor(self):
self.change_color('fgcolor')
def change_bgcolor(self):
self.change_color('bgcolor')
def change_color(self, color_name):
if not hasattr(self, color_name): return
color = getattr(self, color_name)
color = QColorDialog.getColor(color, self.ui)
setattr(self, color_name, color)
getattr(self.ui, color_name+"Button").setStyleSheet(
"background-color:" + color.name())
def reset_color(self):
app, ui = self.app, self.ui
self.fgcolor = app.palette().buttonText().color()
self.bgcolor = app.palette().button().color()
ui.fgcolorButton.setStyleSheet("background-color:"+self.fgcolor.name())
ui.bgcolorButton.setStyleSheet("background-color:"+self.bgcolor.name())
示例14: __init__
def __init__(self, parent, text, mi=None, fm=None, color_field=None):
QDialog.__init__(self, parent)
Ui_TemplateDialog.__init__(self)
self.setupUi(self)
self.coloring = color_field is not None
if self.coloring:
cols = sorted([k for k in displayable_columns(fm)])
self.colored_field.addItems(cols)
self.colored_field.setCurrentIndex(self.colored_field.findText(color_field))
colors = QColor.colorNames()
colors.sort()
self.color_name.addItems(colors)
else:
self.colored_field.setVisible(False)
self.colored_field_label.setVisible(False)
self.color_chooser_label.setVisible(False)
self.color_name.setVisible(False)
self.color_copy_button.setVisible(False)
if mi:
self.mi = mi
else:
self.mi = Metadata(None, None)
# Remove help icon on title bar
icon = self.windowIcon()
self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint))
self.setWindowIcon(icon)
self.last_text = ''
self.highlighter = TemplateHighlighter(self.textbox.document())
self.textbox.cursorPositionChanged.connect(self.text_cursor_changed)
self.textbox.textChanged.connect(self.textbox_changed)
self.textbox.setTabStopWidth(10)
self.source_code.setTabStopWidth(10)
self.documentation.setReadOnly(True)
self.source_code.setReadOnly(True)
if text is not None:
self.textbox.setPlainText(text)
self.buttonBox.button(QDialogButtonBox.Ok).setText(_('&OK'))
self.buttonBox.button(QDialogButtonBox.Cancel).setText(_('&Cancel'))
self.color_copy_button.clicked.connect(self.color_to_clipboard)
try:
with open(P('template-functions.json'), 'rb') as f:
self.builtin_source_dict = json.load(f, encoding='utf-8')
except:
self.builtin_source_dict = {}
self.funcs = formatter_functions().get_functions()
self.builtins = formatter_functions().get_builtins()
func_names = sorted(self.funcs)
self.function.clear()
self.function.addItem('')
self.function.addItems(func_names)
self.function.setCurrentIndex(0)
self.function.currentIndexChanged[str].connect(self.function_changed)
self.textbox_changed()
self.rule = (None, '')
tt = _('Template language tutorial')
self.template_tutorial.setText(
'<a href="http://manual.calibre-ebook.com/template_lang.html">'
'%s</a>'%tt)
tt = _('Template function reference')
self.template_func_reference.setText(
'<a href="http://manual.calibre-ebook.com/template_ref.html">'
'%s</a>'%tt)
示例15: initialize
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
#.........这里部分代码省略.........