本文整理汇总了Python中PyQt4.Qt.QCheckBox.isChecked方法的典型用法代码示例。如果您正苦于以下问题:Python QCheckBox.isChecked方法的具体用法?Python QCheckBox.isChecked怎么用?Python QCheckBox.isChecked使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QCheckBox
的用法示例。
在下文中一共展示了QCheckBox.isChecked方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UpdateNotification
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
class UpdateNotification(QDialog):
def __init__(self, calibre_version, plugin_updates, parent=None):
QDialog.__init__(self, parent)
self.setAttribute(Qt.WA_QuitOnClose, False)
self.resize(400, 250)
self.l = QGridLayout()
self.setLayout(self.l)
self.logo = QLabel()
self.logo.setMaximumWidth(110)
self.logo.setPixmap(QPixmap(I('lt.png')).scaled(100, 100,
Qt.IgnoreAspectRatio, Qt.SmoothTransformation))
ver = calibre_version
if ver.endswith('.0'):
ver = ver[:-2]
self.label = QLabel(('<p>'+
_('New version <b>%(ver)s</b> of %(app)s is available for download. '
'See the <a href="http://calibre-ebook.com/whats-new'
'">new features</a>.'))%dict(
app=__appname__, ver=ver))
self.label.setOpenExternalLinks(True)
self.label.setWordWrap(True)
self.setWindowTitle(_('Update available!'))
self.setWindowIcon(QIcon(I('lt.png')))
self.l.addWidget(self.logo, 0, 0)
self.l.addWidget(self.label, 0, 1)
self.cb = QCheckBox(
_('Show this notification for future updates'), self)
self.l.addWidget(self.cb, 1, 0, 1, -1)
self.cb.setChecked(config.get('new_version_notification'))
self.cb.stateChanged.connect(self.show_future)
self.bb = QDialogButtonBox(self)
b = self.bb.addButton(_('&Get update'), self.bb.AcceptRole)
b.setDefault(True)
b.setIcon(QIcon(I('arrow-down.png')))
if plugin_updates > 0:
b = self.bb.addButton(_('Update &plugins'), self.bb.ActionRole)
b.setIcon(QIcon(I('plugins/plugin_updater.png')))
b.clicked.connect(self.get_plugins, type=Qt.QueuedConnection)
self.bb.addButton(self.bb.Cancel)
self.l.addWidget(self.bb, 2, 0, 1, -1)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
dynamic.set('update to version %s'%calibre_version, False)
def get_plugins(self):
from calibre.gui2.dialogs.plugin_updater import (PluginUpdaterDialog,
FILTER_UPDATE_AVAILABLE)
d = PluginUpdaterDialog(self.parent(),
initial_filter=FILTER_UPDATE_AVAILABLE)
d.exec_()
def show_future(self, *args):
config.set('new_version_notification', bool(self.cb.isChecked()))
def accept(self):
open_url(QUrl(get_download_url()))
QDialog.accept(self)
示例2: do_user_config
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
def do_user_config(self, parent=None):
'''
This method shows a configuration dialog for this plugin. It returns
True if the user clicks OK, False otherwise. The changes are
automatically applied.
'''
from PyQt4.Qt import (QDialog, QDialogButtonBox, QVBoxLayout,
QLabel, Qt, QLineEdit, QCheckBox)
config_dialog = QDialog(parent)
button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
v = QVBoxLayout(config_dialog)
def size_dialog():
config_dialog.resize(config_dialog.sizeHint())
button_box.accepted.connect(config_dialog.accept)
button_box.rejected.connect(config_dialog.reject)
config_dialog.setWindowTitle(_('Customize') + ' ' + self.name)
from calibre.customize.ui import (plugin_customization,
customize_plugin)
help_text = self.customization_help(gui=True)
help_text = QLabel(help_text, config_dialog)
help_text.setWordWrap(True)
help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse
| Qt.LinksAccessibleByKeyboard)
help_text.setOpenExternalLinks(True)
v.addWidget(help_text)
bf = QCheckBox(_('Add linked files in breadth first order'))
bf.setToolTip(_('Normally, when following links in HTML files'
' calibre does it depth first, i.e. if file A links to B and '
' C, but B links to D, the files are added in the order A, B, D, C. '
' With this option, they will instead be added as A, B, C, D'))
sc = plugin_customization(self)
if not sc:
sc = ''
sc = sc.strip()
enc = sc.partition('|')[0]
bfs = sc.partition('|')[-1]
bf.setChecked(bfs == 'bf')
sc = QLineEdit(enc, config_dialog)
v.addWidget(sc)
v.addWidget(bf)
v.addWidget(button_box)
size_dialog()
config_dialog.exec_()
if config_dialog.result() == QDialog.Accepted:
sc = unicode(sc.text()).strip()
if bf.isChecked():
sc += '|bf'
customize_plugin(self, sc)
return config_dialog.result()
示例3: ConfigWidget
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
class ConfigWidget(QWidget):
def __init__(self):
QWidget.__init__(self)
self.l = QGridLayout()
self.setLayout(self.l)
self.newFormatCheckboxLabel = QLabel("Generate new format data (SQLite3)")
self.l.addWidget(self.newFormatCheckboxLabel, 0, 0, 1, 1)
self.newFormatCheckbox = QCheckBox(self)
self.l.addWidget(self.newFormatCheckbox, 0, 1, 1, 1)
self.newFormatCheckbox.setChecked(prefs["newFormat"])
# ARTTBD Maybe should be a native directory picker? Works for now..
self.cacheDirLabel = QLabel("Caching directory (optional, useful if re-running for a given book)")
self.l.addWidget(self.cacheDirLabel, 1, 0, 1, 1)
self.cacheDirEdit = QLineEdit(self)
self.l.addWidget(self.cacheDirEdit, 1, 1, 1, 1)
self.cacheDirEdit.setText(prefs["cacheDir"])
self.autoExpandAliasesLabel = QLabel("Auto-generate aliases from character names")
self.l.addWidget(self.autoExpandAliasesLabel, 2, 0, 1, 1)
self.autoExpandAliasesCheckbox = QCheckBox(self)
self.l.addWidget(self.autoExpandAliasesCheckbox, 2, 1, 1, 1)
self.autoExpandAliasesCheckbox.setChecked(prefs["autoExpandAliases"])
self.logfileLabel = QLabel("Log file (optional)")
self.l.addWidget(self.logfileLabel, 3, 0, 1, 1)
self.logfileEdit = QLineEdit(self)
self.l.addWidget(self.logfileEdit, 3, 1, 1, 1)
self.logfileEdit.setText(prefs["logfile"])
def save_settings(self):
prefs["newFormat"] = self.newFormatCheckbox.isChecked()
prefs["cacheDir"] = unicode(self.cacheDirEdit.text())
prefs["autoExpandAliases"] = self.autoExpandAliasesCheckbox.isChecked()
prefs["logfile"] = unicode(self.logfileEdit.text())
示例4: Choose
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
class Choose(QDialog):
def __init__(self, fmts, parent=None):
QDialog.__init__(self, parent)
self.l = l = QVBoxLayout(self)
self.setLayout(l)
self.setWindowTitle(_('Choose format to edit'))
self.la = la = QLabel(_(
'This book has multiple formats that can be edited. Choose the format you want to edit.'))
l.addWidget(la)
self.rem = QCheckBox(_('Always ask when more than one format is available'))
self.rem.setChecked(True)
l.addWidget(self.rem)
self.bb = bb = QDialogButtonBox(self)
l.addWidget(bb)
bb.accepted.connect(self.accept)
bb.rejected.connect(self.reject)
self.buts = buts = []
for fmt in fmts:
b = bb.addButton(fmt.upper(), bb.AcceptRole)
b.clicked.connect(partial(self.chosen, fmt))
buts.append(b)
self.fmt = None
self.resize(self.sizeHint())
def chosen(self, fmt):
self.fmt = fmt
def accept(self):
from calibre.gui2.tweak_book import tprefs
tprefs['choose_tweak_fmt'] = self.rem.isChecked()
QDialog.accept(self)
示例5: ConfigWidget
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
#.........这里部分代码省略.........
"""
def save_combobox_setting(self, cb, index):
'''
Apply changes immediately
'''
cf = str(getattr(self, cb).currentText())
self._log_location("%s => %s" % (cb, repr(cf)))
if cb == 'annotations_field_comboBox':
field = None
if cf:
field = self.eligible_annotations_fields[cf]
set_cc_mapping('annotations', combobox=cf, field=field)
"""
def save_settings(self):
self._log_location()
# Annotations field
cf = unicode(self.annotations_field_comboBox.currentText())
field = None
if cf:
field = self.eligible_annotations_fields[cf]
set_cc_mapping('annotations', combobox=cf, field=field)
# Collections field
cf = unicode(self.collection_field_comboBox.currentText())
field = None
if cf:
field = self.eligible_collection_fields[cf]
set_cc_mapping('collections', combobox=cf, field=field)
# Date read field
cf = unicode(self.date_read_field_comboBox.currentText())
field = None
if cf:
field = self.eligible_date_read_fields[cf]
set_cc_mapping('date_read', combobox=cf, field=field)
# Locked field
cf = unicode(self.locked_field_comboBox.currentText())
field = None
if cf:
field = self.eligible_locked_fields[cf]
set_cc_mapping('locked', combobox=cf, field=field)
# Progress field
cf = unicode(self.progress_field_comboBox.currentText())
field = None
if cf:
field = self.eligible_progress_fields[cf]
set_cc_mapping('progress', combobox=cf, field=field)
# Read field
cf = unicode(self.read_field_comboBox.currentText())
field = None
if cf:
field = self.eligible_read_fields[cf]
set_cc_mapping('read', combobox=cf, field=field)
# Reading list field
cf = unicode(self.reading_list_field_comboBox.currentText())
field = None
if cf:
field = self.eligible_reading_list_fields[cf]
set_cc_mapping('reading_list', combobox=cf, field=field)
# Word count field
cf = unicode(self.word_count_field_comboBox.currentText())
field = None
if cf:
field = self.eligible_word_count_fields[cf]
set_cc_mapping('word_count', combobox=cf, field=field)
'''
# Save Dropbox settings
self.prefs.set('dropbox_syncing', self.dropbox_syncing_checkbox.isChecked())
self.prefs.set('dropbox_folder', unicode(self.dropbox_location_lineedit.text()))
'''
# Save general settings
self.prefs.set('apply_markers_to_duplicates', self.duplicate_markers_checkbox.isChecked())
self.prefs.set('apply_markers_to_updated', self.updated_markers_checkbox.isChecked())
self.prefs.set('auto_refresh_at_startup', self.auto_refresh_checkbox.isChecked())
self.prefs.set('show_progress_as_percentage', self.reading_progress_checkbox.isChecked())
# Save debug settings
self.prefs.set('debug_plugin', self.debug_plugin_checkbox.isChecked())
self.prefs.set('debug_libimobiledevice', self.debug_libimobiledevice_checkbox.isChecked())
# If restart needed, inform user
if self.restart_required:
do_restart = show_restart_warning('Restart calibre for the changes to be applied.',
parent=self.gui)
if do_restart:
self.gui.quit(restart=True)
def start_inventory(self):
self._log_location()
self.annotated_books_scanner.start()
示例6: ImageControlDialog
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
#.........这里部分代码省略.........
self._line_std.marker.setValue(mean, ypos)
self._line_std.setText(("\u03C3=" + DataValueFormat) % std)
self._line_std.show()
self._histplot.replot()
def _setIntensityLogCyclesLabel(self, value):
self._wlogcycles_label.setText("Log cycles: %4.1f" % value)
def _previewIntensityLogCycles(self, value):
self._setIntensityLogCycles(value, notify_image=False, write_config=False)
self._wlogcycles_timer.start(500)
def _setIntensityLogCycles(self, value=None, notify_image=True, write_config=True):
if value is None:
value = self._wlogcycles.value()
# stop timer if being called to finalize the change in value
if notify_image:
self._wlogcycles_timer.stop()
if not self._updating_imap:
self._setIntensityLogCyclesLabel(value)
self._rc.setIntensityMapLogCycles(value, notify_image=notify_image, write_config=write_config)
self._updateITF()
self._histplot.replot()
def _updateDisplayRange(self, dmin, dmax):
self._rangebox.setData([dmin, dmax], [.9, .9])
self._wrange[0].setText(DataValueFormat % dmin)
self._wrange[1].setText(DataValueFormat % dmax)
self._wrangeleft0.setEnabled(dmin != 0)
self._display_range = dmin, dmax
# if auto-zoom is on, zoom the histogram
# try to be a little clever about this. Zoom only if (a) both limits have changed (so that adjusting one end of the range
# does not cause endless rezooms), or (b) display range is < 1/10 of the histogram range
if self._wautozoom.isChecked() and self._hist is not None:
if (dmax - dmin) / (self._hist_range[1] - self._hist_range[0]) < .1 or (
dmin != self._prev_range[0] and dmax != self._prev_range[1]):
margin = (dmax - dmin) / 8
self._updateHistogram(dmin - margin, dmax + margin)
self._updateITF()
self._histplot.replot()
def _updateIntensityMap(self, imap, index):
self._updating_imap = True
try:
self._cb_item.setIntensityMap(imap)
self._updateITF()
self._histplot.replot()
self._wimap.setCurrentIndex(index)
if isinstance(imap, Colormaps.LogIntensityMap):
self._wlogcycles.setValue(imap.log_cycles)
self._setIntensityLogCyclesLabel(imap.log_cycles)
self._wlogcycles.show()
self._wlogcycles_label.show()
else:
self._wlogcycles.hide()
self._wlogcycles_label.hide()
finally:
self._updating_imap = False
def _updateColorMap(self, cmap):
self._cb_item.setColorMap(cmap)
self._histplot.replot()
try:
index = self._rc.getColormapList().index(cmap)
except:
return
示例7: Report
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
class Report(QDialog): # {{{
def __init__(self, parent):
QDialog.__init__(self, parent)
self.gui = parent
self.setAttribute(Qt.WA_DeleteOnClose, False)
self.setWindowIcon(QIcon(I('polish.png')))
self.reports = []
self.l = l = QGridLayout()
self.setLayout(l)
self.view = v = QTextEdit(self)
v.setReadOnly(True)
l.addWidget(self.view, 0, 0, 1, 2)
self.backup_msg = la = QLabel('')
l.addWidget(la, 1, 0, 1, 2)
la.setVisible(False)
la.setWordWrap(True)
self.ign_msg = _('Ignore remaining %d reports')
self.ign = QCheckBox(self.ign_msg, self)
l.addWidget(self.ign, 2, 0)
bb = self.bb = QDialogButtonBox(QDialogButtonBox.Close)
bb.accepted.connect(self.accept)
bb.rejected.connect(self.reject)
b = self.log_button = bb.addButton(_('View full &log'), bb.ActionRole)
b.clicked.connect(self.view_log)
bb.button(bb.Close).setDefault(True)
l.addWidget(bb, 2, 1)
self.finished.connect(self.show_next, type=Qt.QueuedConnection)
self.resize(QSize(800, 600))
def setup_ign(self):
self.ign.setText(self.ign_msg%len(self.reports))
self.ign.setVisible(bool(self.reports))
self.ign.setChecked(False)
def __call__(self, *args):
self.reports.append(args)
self.setup_ign()
if not self.isVisible():
self.show_next()
def show_report(self, book_title, book_id, fmts, job, report):
from calibre.ebooks.markdown.markdown import markdown
self.current_log = job.details
self.setWindowTitle(_('Polishing of %s')%book_title)
self.view.setText(markdown('# %s\n\n'%book_title + report,
output_format='html4'))
self.bb.button(self.bb.Close).setFocus(Qt.OtherFocusReason)
self.backup_msg.setVisible(bool(fmts))
if fmts:
m = ngettext('The original file has been saved as %s.',
'The original files have been saved as %s.', len(fmts))%(
_(' and ').join('ORIGINAL_'+f for f in fmts)
)
self.backup_msg.setText(m + ' ' + _(
'If you polish again, the polishing will run on the originals.')%(
))
def view_log(self):
self.view.setPlainText(self.current_log)
self.view.verticalScrollBar().setValue(0)
def show_next(self, *args):
if not self.reports:
return
if not self.isVisible():
self.show()
self.show_report(*self.reports.pop(0))
self.setup_ign()
def accept(self):
if self.ign.isChecked():
self.reports = []
if self.reports:
self.show_next()
return
super(Report, self).accept()
def reject(self):
if self.ign.isChecked():
self.reports = []
if self.reports:
self.show_next()
return
super(Report, self).reject()
示例8: ProceedQuestion
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
class ProceedQuestion(QDialog):
ask_question = pyqtSignal(object, object, object)
def __init__(self, parent):
QDialog.__init__(self, parent)
self.setAttribute(Qt.WA_DeleteOnClose, False)
self.setWindowIcon(QIcon(I('dialog_question.png')))
self.questions = []
self._l = l = QGridLayout(self)
self.setLayout(l)
self.icon_label = ic = QLabel(self)
ic.setPixmap(QPixmap(I('dialog_question.png')))
self.msg_label = msg = QLabel('some random filler text')
msg.setWordWrap(True)
ic.setMaximumWidth(110)
ic.setMaximumHeight(100)
ic.setScaledContents(True)
ic.setStyleSheet('QLabel { margin-right: 10px }')
self.bb = QDialogButtonBox()
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
self.log_button = self.bb.addButton(_('View log'), self.bb.ActionRole)
self.log_button.setIcon(QIcon(I('debug.png')))
self.log_button.clicked.connect(self.show_log)
self.copy_button = self.bb.addButton(_('&Copy to clipboard'),
self.bb.ActionRole)
self.copy_button.clicked.connect(self.copy_to_clipboard)
self.action_button = self.bb.addButton('', self.bb.ActionRole)
self.action_button.clicked.connect(self.action_clicked)
self.show_det_msg = _('Show &details')
self.hide_det_msg = _('Hide &details')
self.det_msg_toggle = self.bb.addButton(self.show_det_msg, self.bb.ActionRole)
self.det_msg_toggle.clicked.connect(self.toggle_det_msg)
self.det_msg_toggle.setToolTip(
_('Show detailed information about this error'))
self.det_msg = QPlainTextEdit(self)
self.det_msg.setReadOnly(True)
self.bb.setStandardButtons(self.bb.Yes|self.bb.No)
self.bb.button(self.bb.Yes).setDefault(True)
self.checkbox = QCheckBox('', self)
l.addWidget(ic, 0, 0, 1, 1)
l.addWidget(msg, 0, 1, 1, 1)
l.addWidget(self.checkbox, 1, 0, 1, 2)
l.addWidget(self.det_msg, 2, 0, 1, 2)
l.addWidget(self.bb, 3, 0, 1, 2)
self.ask_question.connect(self.do_ask_question,
type=Qt.QueuedConnection)
def copy_to_clipboard(self, *args):
QApplication.clipboard().setText(
'calibre, version %s\n%s: %s\n\n%s' %
(__version__, unicode(self.windowTitle()),
unicode(self.msg_label.text()),
unicode(self.det_msg.toPlainText())))
self.copy_button.setText(_('Copied'))
def action_clicked(self):
if self.questions:
q = self.questions[0]
self.questions[0] = q._replace(callback=q.action_callback)
self.accept()
def accept(self):
if self.questions:
payload, callback, cancel_callback = self.questions[0][:3]
self.questions = self.questions[1:]
cb = None
if self.checkbox.isVisible():
cb = bool(self.checkbox.isChecked())
self.ask_question.emit(callback, payload, cb)
self.hide()
def reject(self):
if self.questions:
payload, callback, cancel_callback = self.questions[0][:3]
self.questions = self.questions[1:]
cb = None
if self.checkbox.isVisible():
cb = bool(self.checkbox.isChecked())
self.ask_question.emit(cancel_callback, payload, cb)
self.hide()
def do_ask_question(self, callback, payload, checkbox_checked):
if callable(callback):
args = [payload]
if checkbox_checked is not None:
args.append(checkbox_checked)
callback(*args)
self.show_question()
def toggle_det_msg(self, *args):
vis = unicode(self.det_msg_toggle.text()) == self.hide_det_msg
self.det_msg_toggle.setText(self.show_det_msg if vis else
#.........这里部分代码省略.........
示例9: BookInfo
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
#.........这里部分代码省略.........
self.resize(max(int(screen_width/2), 700), screen_height)
saved_layout = gprefs.get('book_info_dialog_layout', None)
if saved_layout is not None:
try:
self.restoreGeometry(saved_layout[0])
self.splitter.restoreState(saved_layout[1])
except Exception:
pass
def link_clicked(self, qurl):
link = unicode(qurl.toString())
self.link_delegate(link)
def done(self, r):
saved_layout = (bytearray(self.saveGeometry()), bytearray(self.splitter.saveState()))
gprefs.set('book_info_dialog_layout', saved_layout)
ret = QDialog.done(self, r)
self.view.selectionModel().currentChanged.disconnect(self.slave)
self.view = self.link_delegate = self.gui = None
self.closed.emit(self)
return ret
def cover_changed(self, data):
if self.current_row is not None:
id_ = self.view.model().id(self.current_row)
self.view.model().db.set_cover(id_, data)
if self.gui.cover_flow:
self.gui.cover_flow.dataChanged()
ci = self.view.currentIndex()
if ci.isValid():
self.view.model().current_changed(ci, ci)
self.cover_pixmap = QPixmap()
self.cover_pixmap.loadFromData(data)
if self.fit_cover.isChecked():
self.resize_cover()
def details_size_hint(self):
return QSize(350, 550)
def toggle_cover_fit(self, state):
gprefs.set('book_info_dialog_fit_cover', self.fit_cover.isChecked())
self.resize_cover()
def cover_view_resized(self, event):
QTimer.singleShot(1, self.resize_cover)
def slave(self, current, previous):
if current.row() != previous.row():
row = current.row()
self.refresh(row)
def move(self, delta=1):
self.view.selectionModel().currentChanged.disconnect(self.slave)
try:
idx = self.view.currentIndex()
if idx.isValid():
m = self.view.model()
ni = m.index(idx.row() + delta, idx.column())
if ni.isValid():
self.view.setCurrentIndex(ni)
self.refresh(ni.row())
if self.view.isVisible():
self.view.scrollTo(ni)
finally:
self.view.selectionModel().currentChanged.connect(self.slave)
示例10: MakeBrickDialog
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
#.........这里部分代码省略.........
for axis in range(1, hdr['NAXIS'] + 1):
if hdr['CTYPE%d' % axis].upper() == 'FREQ':
self.wfreq.setText(str(hdr['CRVAL%d' % axis] / 1e+6))
break
except Exception as err:
busy = None
self.wfile.setFilename('')
if not quiet:
QMessageBox.warning(self, "Error reading FITS",
"Error reading FITS file %s: %s" % (filename, str(err)))
return None
self.wokbtn.setEnabled(True)
# if filename is not in model already, enable the "add to model" control
for src in self.model.sources:
if isinstance(getattr(src, 'shape', None), ModelClasses.FITSImage) \
and os.path.exists(src.shape.filename) and os.path.exists(filename) \
and os.path.samefile(src.shape.filename, filename):
self.wadd.setChecked(True)
self.wadd.setEnabled(False)
self.wadd.setText("image already in sky model")
break
else:
self.wadd.setText("add image to sky model")
return filename
def accept(self):
"""Tries to make a brick, and closes the dialog if successful."""
sources = [src for src in self.model.sources if src.selected and src.typecode == 'pnt']
filename = self.wfile.filename()
if not self._fileSelected(filename):
return
# get PB expression
pbfunc = None
if self.wpb_apply.isChecked():
pbexp = str(self.wpb_exp.text())
try:
pbfunc = eval("lambda r,fq:" + pbexp)
except Exception as err:
QMessageBox.warning(self, "Error parsing PB experssion",
"Error parsing primary beam expression %s: %s" % (pbexp, str(err)))
return
# get frequency
freq = str(self.wfreq.text())
freq = float(freq) * 1e+6 if freq else None
# get pad factor
pad = str(self.wpad.text())
pad = max(float(pad), 1) if pad else 1
# read fits file
busy = BusyIndicator()
try:
input_hdu = pyfits.open(filename)[0]
except Exception as err:
busy = None
QMessageBox.warning(self, "Error reading FITS", "Error reading FITS file %s: %s" % (filename, str(err)))
return
# reset data if asked to
if self.woverwrite.isChecked():
input_hdu.data[...] = 0
# insert sources
Imaging.restoreSources(input_hdu, sources, 0, primary_beam=pbfunc, freq=freq)
# save fits file
try:
# pyfits seems to produce an exception:
# TypeError: formatwarning() takes exactly 4 arguments (5 given)
# when attempting to overwrite a file. As a workaround, remove the file first.
if os.path.exists(filename):
示例11: ConfigWidget
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
#.........这里部分代码省略.........
flesch_reading_column_label = QLabel('&Flesch Reading Ease:', self)
flesch_reading_column_label.setToolTip('Specify the custom column to store a computed Flesch Reading Ease score.\n'
'Leave this blank if you do not want to calculate it')
flesch_reading_col = library_config.get(KEY_FLESCH_READING_CUSTOM_COLUMN, '')
self.flesch_reading_column_combo = CustomColumnComboBox(self, avail_columns, flesch_reading_col)
flesch_reading_column_label.setBuddy(self.flesch_reading_column_combo)
readability_layout.addWidget(flesch_reading_column_label, 1, 0, 1, 1)
readability_layout.addWidget(self.flesch_reading_column_combo, 1, 1, 1, 2)
flesch_grade_column_label = QLabel('Flesch-&Kincaid Grade:', self)
flesch_grade_column_label.setToolTip('Specify the custom column to store a computed Flesch-Kincaid Grade Level score.\n'
'Leave this blank if you do not want to calculate it')
flesch_grade_col = library_config.get(KEY_FLESCH_GRADE_CUSTOM_COLUMN, '')
self.flesch_grade_column_combo = CustomColumnComboBox(self, avail_columns, flesch_grade_col)
flesch_grade_column_label.setBuddy(self.flesch_grade_column_combo)
readability_layout.addWidget(flesch_grade_column_label, 2, 0, 1, 1)
readability_layout.addWidget(self.flesch_grade_column_combo, 2, 1, 1, 2)
gunning_fog_column_label = QLabel('&Gunning Fox Index:', self)
gunning_fog_column_label.setToolTip('Specify the custom column to store a computed Gunning Fog Index score.\n'
'Leave this blank if you do not want to calculate it')
gunning_fog_col = library_config.get(KEY_GUNNING_FOG_CUSTOM_COLUMN, '')
self.gunning_fog_column_combo = CustomColumnComboBox(self, avail_columns, gunning_fog_col)
gunning_fog_column_label.setBuddy(self.gunning_fog_column_combo)
readability_layout.addWidget(gunning_fog_column_label, 3, 0, 1, 1)
readability_layout.addWidget(self.gunning_fog_column_combo, 3, 1, 1, 2)
# --- Other options ---
layout.addSpacing(5)
other_group_box = QGroupBox('Other options:', self)
layout.addWidget(other_group_box)
other_group_box_layout = QGridLayout()
other_group_box.setLayout(other_group_box_layout)
button_default_label = QLabel('&Button default:', self)
button_default_label.setToolTip('If plugin is placed as a toolbar button, choose a default action when clicked on')
self.button_default_combo = KeyValueComboBox(self, BUTTON_DEFAULTS, button_default)
button_default_label.setBuddy(self.button_default_combo)
other_group_box_layout.addWidget(button_default_label, 0, 0, 1, 1)
other_group_box_layout.addWidget(self.button_default_combo, 0, 1, 1, 2)
self.overwrite_checkbox = QCheckBox('Always overwrite an existing word/page count', self)
self.overwrite_checkbox.setToolTip('Uncheck this option if you have manually populated values in\n'
'either of your page/word custom columns, and never want the\n'
'plugin to overwrite it. Acts as a convenience option for users\n'
'who have the toolbar button configured to populate both page\n'
'and word count, but for some books have already assigned values\n'
'into a column and just want the zero/blank column populated.')
self.overwrite_checkbox.setChecked(overwrite_existing)
other_group_box_layout.addWidget(self.overwrite_checkbox, 1, 0, 1, 3)
keyboard_shortcuts_button = QPushButton('Keyboard shortcuts...', self)
keyboard_shortcuts_button.setToolTip(_(
'Edit the keyboard shortcuts associated with this plugin'))
keyboard_shortcuts_button.clicked.connect(self.edit_shortcuts)
view_prefs_button = QPushButton('&View library preferences...', self)
view_prefs_button.setToolTip(_(
'View data stored in the library database for this plugin'))
view_prefs_button.clicked.connect(self.view_prefs)
layout.addWidget(keyboard_shortcuts_button)
layout.addWidget(view_prefs_button)
layout.addStretch(1)
def save_settings(self):
new_prefs = {}
new_prefs[KEY_BUTTON_DEFAULT] = self.button_default_combo.selected_key()
new_prefs[KEY_OVERWRITE_EXISTING] = self.overwrite_checkbox.isChecked()
plugin_prefs[STORE_NAME] = new_prefs
db = self.plugin_action.gui.current_db
library_config = get_library_config(db)
library_config[KEY_PAGES_ALGORITHM] = self.page_algorithm_combo.currentIndex()
library_config[KEY_PAGES_CUSTOM_COLUMN] = self.page_column_combo.get_selected_column()
library_config[KEY_WORDS_CUSTOM_COLUMN] = self.word_column_combo.get_selected_column()
library_config[KEY_FLESCH_READING_CUSTOM_COLUMN] = self.flesch_reading_column_combo.get_selected_column()
library_config[KEY_FLESCH_GRADE_CUSTOM_COLUMN] = self.flesch_grade_column_combo.get_selected_column()
library_config[KEY_GUNNING_FOG_CUSTOM_COLUMN] = self.gunning_fog_column_combo.get_selected_column()
set_library_config(db, library_config)
def get_custom_columns(self):
column_types = ['float','int']
custom_columns = self.plugin_action.gui.library_view.model().custom_columns
available_columns = {}
for key, column in custom_columns.iteritems():
typ = column['datatype']
if typ in column_types:
available_columns[key] = column
return available_columns
def _link_activated(self, url):
open_url(QUrl(url))
def edit_shortcuts(self):
d = KeyboardConfigDialog(self.plugin_action.gui, self.plugin_action.action_spec[0])
if d.exec_() == d.Accepted:
self.plugin_action.gui.keyboard.finalize()
def view_prefs(self):
d = PrefsViewerDialog(self.plugin_action.gui, PREFS_NAMESPACE)
d.exec_()
示例12: JobError
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
#.........这里部分代码省略.........
self.setWindowIcon(self.icon)
self.icon_label = QLabel()
self.icon_label.setPixmap(self.icon.pixmap(68, 68))
self.icon_label.setMaximumSize(QSize(68, 68))
self.msg_label = QLabel('<p> ')
self.msg_label.setStyleSheet('QLabel { margin-top: 1ex; }')
self.msg_label.setWordWrap(True)
self.msg_label.setTextFormat(Qt.RichText)
self.det_msg = QPlainTextEdit(self)
self.det_msg.setVisible(False)
self.bb = QDialogButtonBox(QDialogButtonBox.Close, parent=self)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
self.ctc_button = self.bb.addButton(_('&Copy to clipboard'),
self.bb.ActionRole)
self.ctc_button.clicked.connect(self.copy_to_clipboard)
self.show_det_msg = _('Show &details')
self.hide_det_msg = _('Hide &details')
self.det_msg_toggle = self.bb.addButton(self.show_det_msg, self.bb.ActionRole)
self.det_msg_toggle.clicked.connect(self.toggle_det_msg)
self.det_msg_toggle.setToolTip(
_('Show detailed information about this error'))
self.suppress = QCheckBox(self)
l.addWidget(self.icon_label, 0, 0, 1, 1)
l.addWidget(self.msg_label, 0, 1, 1, 1)
l.addWidget(self.det_msg, 1, 0, 1, 2)
l.addWidget(self.suppress, 2, 0, 1, 2, Qt.AlignLeft|Qt.AlignBottom)
l.addWidget(self.bb, 3, 0, 1, 2, Qt.AlignRight|Qt.AlignBottom)
l.setColumnStretch(1, 100)
self.setModal(False)
self.suppress.setVisible(False)
self.do_resize()
def update_suppress_state(self):
self.suppress.setText(_(
'Hide the remaining %d error messages'%len(self.queue)))
self.suppress.setVisible(len(self.queue) > 3)
self.do_resize()
def copy_to_clipboard(self, *args):
d = QTextDocument()
d.setHtml(self.msg_label.text())
QApplication.clipboard().setText(
u'calibre, version %s (%s, isfrozen: %s)\n%s: %s\n\n%s' %
(__version__, sys.platform, isfrozen,
unicode(self.windowTitle()), unicode(d.toPlainText()),
unicode(self.det_msg.toPlainText())))
if hasattr(self, 'ctc_button'):
self.ctc_button.setText(_('Copied'))
def toggle_det_msg(self, *args):
vis = unicode(self.det_msg_toggle.text()) == self.hide_det_msg
self.det_msg_toggle.setText(self.show_det_msg if vis else
self.hide_det_msg)
self.det_msg.setVisible(not vis)
self.do_resize()
def do_resize(self):
h = self.sizeHint().height()
self.setMinimumHeight(0) # Needed as this gets set if det_msg is shown
# Needed otherwise re-showing the box after showing det_msg causes the box
# to not reduce in height
self.setMaximumHeight(h)
self.resize(QSize(self.WIDTH, h))
def showEvent(self, ev):
ret = QDialog.showEvent(self, ev)
self.bb.button(self.bb.Close).setFocus(Qt.OtherFocusReason)
return ret
def show_error(self, title, msg, det_msg=u''):
self.queue.append((title, msg, det_msg))
self.update_suppress_state()
self.pop()
def pop(self):
if not self.queue or self.isVisible():
return
title, msg, det_msg = self.queue.pop(0)
self.setWindowTitle(title)
self.msg_label.setText(msg)
self.det_msg.setPlainText(det_msg)
self.det_msg.setVisible(False)
self.det_msg_toggle.setText(self.show_det_msg)
self.det_msg_toggle.setVisible(True)
self.suppress.setChecked(False)
self.update_suppress_state()
if not det_msg:
self.det_msg_toggle.setVisible(False)
self.do_resize()
self.show()
def done(self, r):
if self.suppress.isChecked():
self.queue = []
QDialog.done(self, r)
self.do_pop.emit()
示例13: RuleEditor
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
#.........这里部分代码省略.........
self.conditions_widget.layout().setAlignment(Qt.AlignTop)
self.conditions = []
if self.rule_kind == 'color':
for b in (self.column_box, self.color_box):
b.setSizeAdjustPolicy(b.AdjustToMinimumContentsLengthWithIcon)
b.setMinimumContentsLength(15)
for key in sorted(displayable_columns(fm),
key=lambda(k): sort_key(fm[k]['name']) if k != color_row_key else 0):
if key == color_row_key and self.rule_kind != 'color':
continue
name = all_columns_string if key == color_row_key else fm[key]['name']
if name:
self.column_box.addItem(name, key)
self.column_box.setCurrentIndex(0)
if self.rule_kind == 'color':
self.color_box.addItems(QColor.colorNames())
self.color_box.setCurrentIndex(0)
self.update_color_label()
self.color_box.currentIndexChanged.connect(self.update_color_label)
else:
self.rule_icon_files = []
self.filename_button.clicked.connect(self.filename_button_clicked)
self.resize(self.sizeHint())
def multiple_box_clicked(self):
self.update_filename_box()
self.update_icon_filenames_in_box()
def update_filename_box(self):
doing_multiple = self.multiple_icon_cb.isChecked()
model = QStandardItemModel()
self.filename_box.setModel(model)
self.icon_file_names.sort(key=sort_key)
if doing_multiple:
item = QStandardItem(_('Open to see checkboxes'))
else:
item = QStandardItem('')
model.appendRow(item)
for i,filename in enumerate(self.icon_file_names):
item = QStandardItem(filename)
if doing_multiple:
item.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled);
item.setData(Qt.Unchecked, Qt.CheckStateRole)
else:
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable);
icon = QIcon(os.path.join(config_dir, 'cc_icons', filename))
item.setIcon(icon)
model.appendRow(item)
def update_color_label(self):
pal = QApplication.palette()
bg1 = unicode(pal.color(pal.Base).name())
bg2 = unicode(pal.color(pal.AlternateBase).name())
c = unicode(self.color_box.currentText())
self.color_label.setText('''
<span style="color: {c}; background-color: {bg1}"> {st} </span>
<span style="color: {c}; background-color: {bg2}"> {st} </span>
'''.format(c=c, bg1=bg1, bg2=bg2, st=_('Sample Text')))
def filename_button_clicked(self):
示例14: ExportKarmaDialog
# 需要导入模块: from PyQt4.Qt import QCheckBox [as 别名]
# 或者: from PyQt4.Qt.QCheckBox import isChecked [as 别名]
class ExportKarmaDialog(QDialog):
def __init__(self, parent, modal=True, flags=Qt.WindowFlags()):
QDialog.__init__(self, parent, flags)
self.setModal(modal)
self.setWindowTitle("Export Karma annotations")
lo = QVBoxLayout(self)
lo.setMargin(10)
lo.setSpacing(5)
# file selector
self.wfile = FileSelector(self, label="Filename:", dialog_label="Karma annotations filename",
default_suffix="ann", file_types="Karma annotations (*.ann)")
lo.addWidget(self.wfile)
# selected sources checkbox
self.wsel = QCheckBox("selected sources only", self)
lo.addWidget(self.wsel)
# OK/cancel buttons
lo.addSpacing(10)
lo2 = QHBoxLayout()
lo.addLayout(lo2)
lo2.setContentsMargins(0, 0, 0, 0)
lo2.setMargin(5)
self.wokbtn = QPushButton("OK", self)
self.wokbtn.setMinimumWidth(128)
QObject.connect(self.wokbtn, SIGNAL("clicked()"), self.accept)
self.wokbtn.setEnabled(False)
cancelbtn = QPushButton("Cancel", self)
cancelbtn.setMinimumWidth(128)
QObject.connect(cancelbtn, SIGNAL("clicked()"), self.reject)
lo2.addWidget(self.wokbtn)
lo2.addStretch(1)
lo2.addWidget(cancelbtn)
self.setMinimumWidth(384)
# signals
QObject.connect(self.wfile, SIGNAL("valid"), self.wokbtn.setEnabled)
# internal state
self.qerrmsg = QErrorMessage(self)
self._model_filename = None
def setModel(self, model):
self.model = model
# set the default annotations filename, whenever a new model filename is set
filename = self.model.filename()
if filename and filename != self._model_filename:
self._model_filename = filename
self.wfile.setFilename(os.path.splitext(filename)[0] + ".ann")
def accept(self):
"""Tries to export annotations, and closes the dialog if successful."""
try:
filename = self.wfile.filename()
if os.path.exists(filename) and QMessageBox.question(self, "Exporting Karma annotations",
"<P>Overwrite the file %s?</P>" % filename,
QMessageBox.Yes | QMessageBox.No,
QMessageBox.Yes) != QMessageBox.Yes:
return
f = file(self.wfile.filename(), "wt")
f.write('COORD W\nPA STANDARD\nCOLOR GREEN\nFONT hershey12\n')
# source list
if self.wsel.isChecked():
sources = [src for src in self.model.sources if src.selected]
else:
sources = self.model.sources
# calculate basis size for crosses (TODO: replace min_size with something more sensible, as this value is in degrees)
brightnesses = [abs(src.brightness()) for src in sources if src.brightness() != 0]
min_bright = brightnesses and min(brightnesses)
min_size = 0.01
# loop over sources
busy = BusyIndicator()
for src in sources:
ra = src.pos.ra / DEG
dec = src.pos.dec / DEG
# figure out source size
if src.brightness() and min_bright:
ysize = (math.log10(abs(src.brightness())) - math.log10(min_bright) + 1) * min_size
else:
ysize = min_size
xsize = ysize / (math.cos(src.pos.dec) or 1)
# figure out source style
style, label = self.model.getSourcePlotStyle(src)
if style:
f.write('# %s\n' % src.name)
# write symbol for source
f.write('COLOR %s\n' % style.symbol_color)
if style.symbol == "plus":
f.write('CROSS %.12f %.12f %f %f\n' % (ra, dec, xsize, ysize))
elif style.symbol == "cross":
f.write('CROSS %.12f %.12f %f %f 45\n' % (ra, dec, ysize, ysize))
elif style.symbol == "circle":
f.write('CIRCLE %.12f %.12f %f\n' % (ra, dec, ysize))
elif style.symbol == "dot":
f.write('DOT %.12f %.12f\n' % (ra, dec))
elif style.symbol == "square":
f.write('CBOX %.12f %.12f %f %f\n' % (ra, dec, xsize, ysize))
elif style.symbol == "diamond":
f.write('CBOX %.12f %.12f %f %f 45\n' % (ra, dec, xsize, ysize))
# write label
if label:
f.write('FONT hershey%d\n' % (style.label_size * 2))
f.write('COLOR %s\n' % style.label_color)
f.write('TEXT %.12f %.12f %s\n' % (ra, dec, label))
#.........这里部分代码省略.........