本文整理汇总了Python中PyQt4.Qt.QPalette类的典型用法代码示例。如果您正苦于以下问题:Python QPalette类的具体用法?Python QPalette怎么用?Python QPalette使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPalette类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getPalette
def getPalette( palette, colorRole, color ):
"""
Assigns a color (based on color role) to palette and returns it.
The color/color role is assigned to all color groups.
@param palette: A palette. If palette is None, we create and return a new
palette.
@type palette: QPalette
@param colorRole: the Qt ColorRole
@type colorRole: Qt.ColorRole
@param color: color
@type color: QColor
@return: Returns the updated palette, or a new palette if none was supplied.
@rtype : QPalette
@see QPalette.setColor()
"""
if palette:
pass # Make sure palette is QPalette.
else:
palette = QPalette()
palette.setColor(colorRole, color)
return palette
示例2: colorframe_bgcolor_setter
def colorframe_bgcolor_setter(color):
#e no convenient/clean way for Formula API to permit but not require this function to receive the formula,
# unless we store it temporarily in env._formula (which we might as well do if this feature is ever needed)
try:
# make sure errors here don't stop the formula from running:
# (Need to protect against certain kinds of erroneous color values? RGBf_to_QColor does it well enough.)
## Qt3 code used: colorframe.setPaletteBackgroundColor(RGBf_to_QColor(color))
qcolor = RGBf_to_QColor(color)
palette = QPalette() # QPalette(qcolor) would have window color set from qcolor, but that doesn't help us here
qcolorrole = QPalette.Window
## http://doc.trolltech.com/4.2/qpalette.html#ColorRole-enum says:
## QPalette.Window 10 A general background color.
palette.setColor(QPalette.Active, qcolorrole, qcolor) # used when window is in fg and has focus
palette.setColor(QPalette.Inactive, qcolorrole, qcolor) # used when window is in bg or does not have focus
palette.setColor(QPalette.Disabled, qcolorrole, qcolor) # used when widget is disabled
colorframe.setPalette(palette)
colorframe.setAutoFillBackground(True)
# [Note: the above scheme was revised again by bruce 070430, for improved appearance
# (now has thin black border around color patch), based on Ninad's change in UserPrefs.py.]
## no longer needed: set color for qcolorrole = QPalette.ColorRole(role) for role in range(14)
## no longer needed: colorframe.setLineWidth(500) # width of outline of frame (at least half max possible size)
except:
print "data for following exception: ",
print "colorframe %r has palette %r" % (colorframe, colorframe.palette())
# fyi: in Qt4, like in Qt3, colorframe is a QFrame
print_compact_traceback( "bug (ignored): exception in formula-setter: " ) #e include formula obj in this msg?
pass
示例3: _getHeaderTitlePalette
def _getHeaderTitlePalette(self):
"""
Return a palette for header title (text) label.
"""
palette = QPalette()
palette.setColor(QPalette.WindowText, pmHeaderTitleColor)
return palette
示例4: __init__
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)
示例5: load_calibre_style
def load_calibre_style(self):
# On OS X QtCurve resets the palette, so we preserve it explicitly
orig_pal = QPalette(self.palette())
path = os.path.join(sys.extensions_location, 'calibre_style.'+(
'pyd' if iswindows else 'so'))
if not self.pi.load_style(path, 'Calibre'):
prints('Failed to load calibre style')
# On OSX, on some machines, colors can be invalid. See https://bugs.launchpad.net/bugs/1014900
for role in (orig_pal.Button, orig_pal.Window):
c = orig_pal.brush(role).color()
if not c.isValid() or not c.toRgb().isValid():
orig_pal.setColor(role, QColor(u'lightgray'))
self.setPalette(orig_pal)
style = self.style()
icon_map = {}
pcache = {}
for k, v in {
'DialogYesButton': u'ok.png',
'DialogNoButton': u'window-close.png',
'DialogCloseButton': u'window-close.png',
'DialogOkButton': u'ok.png',
'DialogCancelButton': u'window-close.png',
'DialogHelpButton': u'help.png',
'DialogOpenButton': u'document_open.png',
'DialogSaveButton': u'save.png',
'DialogApplyButton': u'ok.png',
'DialogDiscardButton': u'trash.png',
'MessageBoxInformation': u'dialog_information.png',
'MessageBoxWarning': u'dialog_warning.png',
'MessageBoxCritical': u'dialog_error.png',
'MessageBoxQuestion': u'dialog_question.png',
'BrowserReload': u'view-refresh.png',
# These two are used to calculate the sizes for the doc widget
# title bar buttons, therefore, they have to exist. The actual
# icon is not used.
'TitleBarCloseButton': u'window-close.png',
'TitleBarNormalButton': u'window-close.png',
'DockWidgetCloseButton': u'window-close.png',
}.iteritems():
if v not in pcache:
p = I(v)
if isinstance(p, bytes):
p = p.decode(filesystem_encoding)
# if not os.path.exists(p): raise ValueError(p)
pcache[v] = p
v = pcache[v]
icon_map[type('')(getattr(style, 'SP_'+k))] = v
style.setProperty(u'calibre_icon_map', icon_map)
self.__icon_map_memory_ = icon_map
示例6: _set_widget_erase_color
def _set_widget_erase_color(self): # revised, bruce 071011
"""
Change this widget's erase color (seen only if it's resized,
and only briefly -- it's independent of OpenGL clearColor) to
self.backgroundColor. This is intended to minimize the visual
effect of widget resizes which temporarily show the erase
color. See comments in this method for caveats about that.
"""
# Note: this was called in GLPane.update_after_new_graphicsMode
# when the graphicsMode could determine the background color,
# but that's no longer true, so it could probably
# just be called at startup and whenever the background color is changed.
# Try that sometime, it might be an optim. For now it continues
# to be called from there. [bruce 071011, still true 080910]
#
# REVIEW: what is self.backgroundColor when we're using the new default
# of "Blue Sky Gradient". For best effect here, what it ought to be
# is the average or central bg color in that gradient. I think it's not,
# which makes me wonder if this bugfix is still needed at all. [bruce 071011]
#
# Note: calling this fixed the bug in which the glpane or its edges
# flickered to black during a main-window resize. [bruce 050408]
#
# Note: limited this to Mac [in caller], since it turns out that bug (which has
# no bug number yet) was Mac-specific, but this change caused a new bug 530
# on Windows. (Not sure about Linux.) See also bug 141 (black during
# mode-change), related but different. [bruce 050413]
#
# Note: for graphicsModes with a translucent surface covering the screen
# (i.e. Build Atoms water surface), it would be better to blend that surface
# color with self.backgroundColor for passing to this method, to approximate
# the effective background color. Alternatively, we could change how those
# graphicsModes set up OpenGL clearcolor, so that their empty space areas
# looked like self.backgroundColor.) [bruce 050615 comment]
bgcolor = self.backgroundColor
r = int(bgcolor[0]*255 + 0.5) # (same formula as in elementSelector.py)
g = int(bgcolor[1]*255 + 0.5)
b = int(bgcolor[2]*255 + 0.5)
pal = QPalette()
pal.setColor(self.backgroundRole(), QColor(r, g, b))
self.setPalette(pal)
# see Qt docs for this and for backgroundRole
return
示例7: setup_inconsistency_checking
def setup_inconsistency_checking(self):
# set-up inconsistency label
inconsistency_palette = QPalette()
inconsistency_palette.setColor(QPalette.WindowText, Qt.red)
self.inconsistencyLabel.setPalette(inconsistency_palette)
self.inconsistencyLabel.setVisible(False)
def action_consistent_table():
self.inconsistencyLabel.setVisible(False)
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True)
def action_inconsistent_table():
# show label, disable OK buttonbox button
self.inconsistencyLabel.setVisible(True)
self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False)
self.check_table_consistency = meta_globals.ConsistencyChecker(
fn_consistent=action_consistent_table,
fn_inconsistent=action_inconsistent_table,
table_2x2=self.raw_data_table)
示例8: _initialize_collections
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)
示例9: _populate_description
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)
示例10: _updateColorFrame
def _updateColorFrame(self):
"""
Updates the color frame with the current color.
"""
colorframe = self.colorFrame
try:
qcolor = self.getQColor()
palette = QPalette() # QPalette(qcolor) would have window color set from qcolor, but that doesn't help us here
qcolorrole = QPalette.Window
## http://doc.trolltech.com/4.2/qpalette.html#ColorRole-enum says:
## QPalette.Window 10 A general background color.
palette.setColor(QPalette.Active, qcolorrole, qcolor) # used when window is in fg and has focus
palette.setColor(QPalette.Inactive, qcolorrole, qcolor) # used when window is in bg or does not have focus
palette.setColor(QPalette.Disabled, qcolorrole, qcolor) # used when widget is disabled
colorframe.setPalette(palette)
colorframe.setAutoFillBackground(True)
except:
print "data for following exception: ",
print "colorframe %r has palette %r" % (colorframe, colorframe.palette())
pass
示例11: set_color
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:
pal.setBrush(pal.Base, QBrush(QPixmap(path)))
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)
示例12: set_color
def set_color(self):
r, g, b = gprefs['cover_grid_color']
pal = QPalette()
col = QColor(r, g, b)
pal.setColor(pal.Base, col)
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)
示例13: set_color
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)
示例14: __init__
def __init__(self, ma_unit, cur_txs, cur_group_str, parent=None):
super(DiagnosticDataForm, self).__init__(parent)
self.setupUi(self)
self.setup_signals_and_slots()
self.ma_unit = ma_unit
self.raw_data_dict = {}
for group in cur_txs:
raw_data = self.ma_unit.get_raw_data_for_group(group)
self.raw_data_dict[group] = raw_data
self.cur_groups = cur_txs
self.group_str = cur_group_str
self.cur_effect = "Sens" # arbitrary
self.entry_widgets = [self.two_by_two_table, self.prevalence_txt_box,
self.low_txt_box, self.high_txt_box,
self.effect_txt_box,]
self.already_showed_change_CI_alert = False
# block all the widgets for a moment
self.block_all_signals(True)
meta_globals.init_ci_spinbox_and_label(self.CI_spinbox, self.ci_label)
self.setup_inconsistency_checking()
self.initialize_backup_structures()
self.setup_clear_button_palettes()
self.setup_table_effect_dict() # gather effect info from ma_unit
self._read_in_table_data_from_MAunit() # populate table items from raw data in ma_unit
self._populate_effect_cmbo_box() # make cmbo box entries for effects
self._update_data_table() # fill in the rest of the data table
self.set_current_effect() # fill in current effect data in line edits
self.enable_back_calculation_btn()
self.enable_txt_box_input()
self.save_form_state()
# unblock
self.block_all_signals(False)
# Color for clear_button_pallette
self.orig_palette = self.clear_Btn.palette()
self.pushme_palette = QPalette()
self.pushme_palette.setColor(QPalette.ButtonText,Qt.red)
self.set_clear_btn_color()
示例15: initialize
def initialize(self, parent, content, book_id, installed_book, marvin_db_path, use_qwv=True):
'''
__init__ is called on SizePersistedDialog()
'''
self.setupUi(self)
self.book_id = book_id
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._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)
# Set the icon
self.setWindowIcon(self.parent.icon)
# Set or hide the header
if content['header']:
self.header.setText(content['header'])
else:
self.header.setVisible(False)
# Set the titles
self.setWindowTitle(content['title'])
self.html_gb.setTitle(content['group_box_title'])
if content['toolTip']:
self.html_gb.setToolTip(content['toolTip'])
# Set the bg color of the content to the dialog bg color
bgcolor = self.palette().color(QPalette.Background)
palette = QPalette()
palette.setColor(QPalette.Base, bgcolor)
#self._log(repr(content['html_content']))
# Initialize the window content
if use_qwv:
# Add a QWebView to layout
self.html_wv = QWebView()
self.html_wv.setHtml(content['html_content'])
self.html_wv.sizeHint = self.wv_sizeHint
self.html_wv.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
self.html_wv.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.html_wv.linkClicked.connect(self.link_clicked)
self.html_gb_vl.addWidget(self.html_wv)
self.html_tb.setVisible(False)
else:
# Initialize the contents of the TextBrowser
self.html_tb.setText(content['html_content'])
#self.html_tb.setPalette(palette)
# Set or hide the footer
if content['footer']:
self.footer.setText(content['footer'])
else:
self.footer.setVisible(False)
# Add Copy to Clipboard button
self.ctc_button = self.bb.addButton('&Copy to clipboard',
self.bb.ActionRole)
self.ctc_button.clicked.connect(self.copy_to_clipboard)
self.ctc_button.setIcon(QIcon(I('edit-copy.png')))
self.ctc_button.setObjectName('copy_to_clipboard_button')
self.ctc_button.setToolTip('<p>Copy plain text to clipboard, <b>Alt/Option-click</b> for HTML</p>')
self.copy_action = QAction(self)
self.addAction(self.copy_action)
self.copy_action.setShortcuts(QKeySequence.Copy)
self.copy_action.triggered.connect(self.copy_to_clipboard)
# Add Refresh button if enabled
if content['refresh']:
self.refresh_method = content['refresh']['method']
self.refresh_button = self.bb.addButton("Refresh '%s'" % content['refresh']['name'],
self.bb.ActionRole)
self.refresh_button.setIcon(QIcon(os.path.join(self.parent.opts.resources_path,
'icons',
'from_marvin.png')))
self.refresh_button.setObjectName('refresh_button')
self.refresh_button.setEnabled(bool(self.installed_book.cid))
# Hook the button events
self.bb.clicked.connect(self.dispatch_button_click)
# Restore position
self.resize_dialog()