本文整理汇总了Python中PyQt4.QtGui.QStackedLayout.setCurrentWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedLayout.setCurrentWidget方法的具体用法?Python QStackedLayout.setCurrentWidget怎么用?Python QStackedLayout.setCurrentWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QStackedLayout
的用法示例。
在下文中一共展示了QStackedLayout.setCurrentWidget方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ComboEditor
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import setCurrentWidget [as 别名]
class ComboEditor(QWidget):
def __init__(self, original=False):
super(ComboEditor, self).__init__()
self.__original = original
vbox = QVBoxLayout(self)
vbox.setContentsMargins(0, 0, 0, 0)
self.bar = ActionBar()
self.connect(self.bar, SIGNAL("changeCurrent(PyQt_PyObject)"),
self.set_current)
vbox.addWidget(self.bar)
self.stacked = QStackedLayout()
vbox.addLayout(self.stacked)
def currentWidget(self):
return self.stacked.currentWidget()
def add_editor(self, neditable):
"""Add Editor Widget to the UI area."""
if neditable.editor:
self.stacked.addWidget(neditable.editor)
self.bar.add_item(neditable.display_name, neditable)
# Editor Signals
self.connect(neditable.editor, SIGNAL("cursorPositionChanged()"),
self._update_cursor_position)
# Connect file system signals only in the original
if self.__original:
pass
def set_current(self, neditable):
self.stacked.setCurrentWidget(neditable.editor)
self._update_cursor_position(ignore_sender=True)
neditable.editor.setFocus()
def widget(self, index):
return self.stacked.widget(index)
def count(self):
"""Return the number of editors opened."""
return self.stacked.count()
def _update_cursor_position(self, ignore_sender=False):
obj = self.sender()
editor = self.stacked.currentWidget()
# Check if it's current to avoid signals from other splits.
if ignore_sender or editor == obj:
line = editor.textCursor().blockNumber() + 1
col = editor.textCursor().columnNumber()
self.bar.update_line_col(line, col)
示例2: CSVImportDialog
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import setCurrentWidget [as 别名]
class CSVImportDialog(QDialog):
def __init__(self, parent=None, **kwargs):
super(CSVImportDialog, self).__init__(parent, **kwargs)
self.setLayout(QVBoxLayout())
self._options = None
self._path = None
self.__update_pending = False
self._optionswidget = CSVOptionsWidget()
self._optionswidget.format_changed.connect(self._invalidate_preview)
self._stack = QStackedLayout()
self._stack.setContentsMargins(0, 0, 0, 0)
prev_box = QGroupBox("Preview")
prev_box.setLayout(self._stack)
self._preview = QTableView(tabKeyNavigation=False)
self._preview_error = QLabel()
self._stack.addWidget(self._preview)
self._stack.addWidget(self._preview_error)
buttons = QDialogButtonBox(
orientation=Qt.Horizontal,
standardButtons=(QDialogButtonBox.Ok | QDialogButtonBox.Cancel |
QDialogButtonBox.Reset)
)
buttons.accepted.connect(self.accept)
buttons.rejected.connect(self.reject)
def on_clicked(button):
if buttons.buttonRole(button) == QDialogButtonBox.ResetRole:
self.reset()
buttons.clicked.connect(on_clicked)
self.layout().addWidget(self._optionswidget)
self.layout().addWidget(prev_box)
self.layout().addWidget(buttons)
def set_options(self, options):
self._options = options
self._optionswidget.set_dialect(options.dialect)
self._optionswidget.set_header_format(options.header_format)
self._optionswidget.set_missing_values(options.missing_values or "")
self._invalidate_preview()
def options(self):
missing_values = self._optionswidget.missing_values()
return CSV(self._optionswidget.dialect(),
header_format=self._optionswidget.header_format(),
missing_values=missing_values)
def set_path(self, path):
"""Set the preview path."""
if self._path != path:
self._path = path
self._invalidate_preview()
def path(self):
"""Return the preview path"""
return self._path
def reset(self):
"""Reset the options to their default values."""
self.set_options(self._options)
def _invalidate_preview(self):
if not self.__update_pending:
self.__update_pending = True
QApplication.postEvent(self, QEvent(QEvent.User))
def customEvent(self, event):
if self.__update_pending:
self.__update_pending = False
self._update_preview()
def _update_preview(self):
if not self._path:
return
head = itertools.islice(open(self._path, "rU"), 20)
head = StringIO("".join(head))
try:
data = load_csv(head, **self.options()._asdict())
except csv.Error as err:
self._preview_error.setText(
"Cannot load data preview:\n {!s}".format(err)
)
self._stack.setCurrentWidget(self._preview_error)
except (Orange.data.io.CSVFormatError,
Orange.data.io.VariableDefinitionError) as err:
self._preview_error.setText(
"Data formating error:\n {!s}".format(err)
)
self._stack.setCurrentWidget(self._preview_error)
except Exception as err:
self._preview_error.setText(
"Cannot load data preview:\n {!s}".format(err)
)
self._stack.setCurrentWidget(self._preview_error)
#.........这里部分代码省略.........
示例3: _MainContainer
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import setCurrentWidget [as 别名]
#.........这里部分代码省略.........
self.connect(widget, SIGNAL("finished(int)"),
lambda: self._close_dialog(widget))
self.setVisible(True)
self.stack.addWidget(widget)
self.show_selector()
def show_selector(self):
if self.selector != self.stack.currentWidget():
temp_dir = os.path.join(QDir.tempPath(), "ninja-ide")
if not os.path.exists(temp_dir):
os.mkdir(temp_dir)
collected_data = []
current = self.stack.currentIndex()
for index in range(self.stack.count()):
widget = self.stack.widget(index)
if widget == self.selector:
continue
closable = True
if widget == self.splitter:
closable = False
pixmap = QPixmap.grabWidget(widget, widget.rect())
path = os.path.join(temp_dir, "screen%s.png" % index)
pixmap.save(path)
if index == current:
self.selector.set_preview(index, path)
collected_data.insert(0, (index, path, closable))
else:
collected_data.append((index, path, closable))
self.selector.set_model(collected_data)
else:
self.selector.close_selector()
def _selector_ready(self):
self.stack.setCurrentWidget(self.selector)
self.selector.start_animation()
def _selector_animation_completed(self):
if self._opening_dialog:
# We choose the last one with -2, -1 (for last one) +
# -1 for the hidden selector widget which is in the stacked too.
self.selector.open_item(self.stack.count() - 2)
self._opening_dialog = False
def _change_current_stack(self, index):
self.stack.setCurrentIndex(index)
def _remove_item_from_stack(self, index):
widget = self.stack.takeAt(index)
del widget
def show_editor_area(self):
self.stack.setCurrentWidget(self.splitter)
def _files_closed(self):
if settings.SHOW_START_PAGE:
self.show_start_page()
def change_visibility(self):
"""Show/Hide the Main Container area."""
if self.isVisible():
self.hide()
else:
self.show()
def expand_symbol_combo(self):
self.stack.setCurrentWidget(self.splitter)
示例4: MusicPreviewWidget
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import setCurrentWidget [as 别名]
class MusicPreviewWidget(QWidget):
def __init__(self, parent=None):
super(MusicPreviewWidget, self).__init__(parent)
self._lastbuildtime = 10.0
self._running = None
self._current = None
self._chooserLabel = QLabel()
self._chooser = QComboBox(self, activated=self.selectDocument)
self._log = log.Log()
self._view = popplerview.View()
self._progress = widgets.progressbar.TimedProgressBar()
self._stack = QStackedLayout()
self._top = QWidget()
layout = QVBoxLayout()
self.setLayout(layout)
layout.addWidget(self._top)
layout.addLayout(self._stack)
layout.addWidget(self._progress)
top = QHBoxLayout()
top.setContentsMargins(0, 0, 0, 0)
top.setSpacing(2)
self._top.setLayout(top)
top.addWidget(self._chooserLabel)
top.addWidget(self._chooser)
top.addStretch(1)
self._stack.addWidget(self._log)
self._stack.addWidget(self._view)
self._top.hide()
app.aboutToQuit.connect(self.cleanup)
app.translateUI(self)
def translateUI(self):
self._chooserLabel.setText(_("Document:"))
def preview(self, text, title=None):
"""Runs LilyPond on the given text and shows the resulting PDF."""
j = self._running = MusicPreviewJob(text, title)
j.done.connect(self._done)
self._log.clear()
self._log.connectJob(j)
j.start()
self._progress.start(self._lastbuildtime)
def _done(self, success):
self._progress.stop(False)
pdfs = self._running.resultfiles()
self.setDocuments(pdfs)
if not pdfs:
self._stack.setCurrentWidget(self._log)
return
self._lastbuildtime = self._running.elapsed_time()
self._stack.setCurrentWidget(self._view)
if self._current:
self._current.cleanup()
self._current = self._running # keep the tempdir
self._running = None
def setDocuments(self, pdfs):
"""Loads the given PDF path names in the UI."""
self._documents = [popplertools.Document(name) for name in pdfs]
self._chooser.clear()
self._chooser.addItems([d.name() for d in self._documents])
self._top.setVisible(len(self._documents) > 1)
if pdfs:
self._chooser.setCurrentIndex(0)
self.selectDocument(0)
else:
self._view.clear()
def selectDocument(self, index):
doc = self._documents[index].document()
if doc:
self._view.load(doc)
def cleanup(self):
if self._running:
self._running.abort()
self._running.cleanup()
self._running = None
if self._current:
self._current.cleanup()
self._current = None
self._stack.setCurrentWidget(self._log)
self._top.hide()
self._view.clear()
def print_(self):
"""Prints the currently displayed document."""
if self._documents:
doc = self._documents[self._chooser.currentIndex()]
import popplerprint
popplerprint.printDocument(doc, self)
示例5: InstallWizard
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import setCurrentWidget [as 别名]
class InstallWizard(QDialog):
def __init__(self, config, network, storage, app):
QDialog.__init__(self)
self.app = app
self.config = config
self.network = network
self.storage = storage
self.setMinimumSize(575, 400)
self.setMaximumSize(575, 400)
self.setWindowTitle('Electrum-VCN' + ' - ' + _('Install Wizard'))
self.connect(self, QtCore.SIGNAL('accept'), self.accept)
self.stack = QStackedLayout()
self.setLayout(self.stack)
def set_layout(self, layout):
w = QWidget()
w.setLayout(layout)
self.stack.addWidget(w)
self.stack.setCurrentWidget(w)
self.show()
def restore_or_create(self):
vbox = QVBoxLayout()
main_label = QLabel(_("Electrum-VCN could not find an existing wallet."))
vbox.addWidget(main_label)
grid = QGridLayout()
grid.setSpacing(5)
gb1 = QGroupBox(_("What do you want to do?"))
vbox.addWidget(gb1)
vbox1 = QVBoxLayout()
gb1.setLayout(vbox1)
b1 = QRadioButton(gb1)
b1.setText(_("Create new wallet"))
b1.setChecked(True)
b2 = QRadioButton(gb1)
b2.setText(_("Restore a wallet or import keys"))
group1 = QButtonGroup()
group1.addButton(b1)
group1.addButton(b2)
vbox1.addWidget(b1)
vbox1.addWidget(b2)
gb2 = QGroupBox(_("Wallet type:"))
vbox.addWidget(gb2)
vbox2 = QVBoxLayout()
gb2.setLayout(vbox2)
group2 = QButtonGroup()
self.wallet_types = [
('standard', _("Standard wallet")),
('twofactor', _("Wallet with two-factor authentication")),
('multisig', _("Multi-signature wallet")),
('hardware', _("Hardware wallet")),
]
for i, (wtype, name) in enumerate(self.wallet_types):
if not filter(lambda x: x[0] == wtype, electrum.wallet.wallet_types):
continue
button = QRadioButton(gb2)
button.setText(name)
vbox2.addWidget(button)
group2.addButton(button)
group2.setId(button, i)
if i == 0:
button.setChecked(True)
vbox.addStretch(1)
self.set_layout(vbox)
vbox.addLayout(Buttons(CancelButton(self), OkButton(self, _('Next'))))
self.show()
self.raise_()
if not self.exec_():
return None, None
action = 'create' if b1.isChecked() else 'restore'
wallet_type = self.wallet_types[group2.checkedId()][0]
return action, wallet_type
def verify_seed(self, seed, sid, func=None):
r = self.enter_seed_dialog(MSG_VERIFY_SEED, sid, func)
if not r:
return
if prepare_seed(r) != prepare_seed(seed):
QMessageBox.warning(None, _('Error'), _('Incorrect seed'), _('OK'))
return False
else:
return True
def get_seed_text(self, seed_e):
#.........这里部分代码省略.........
示例6: ComboEditor
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import setCurrentWidget [as 别名]
#.........这里部分代码省略.........
neditable.editor.completer.cc.unload_module()
self._add_to_last_opened(neditable.file_path)
layoutItem.widget().deleteLater()
def _add_to_last_opened(self, path):
if path not in settings.LAST_OPENED_FILES:
settings.LAST_OPENED_FILES.append(path)
if len(settings.LAST_OPENED_FILES) > settings.MAX_REMEMBER_TABS:
self.__lastOpened = self.__lastOpened[1:]
self.emit(SIGNAL("recentTabsModified()"))
def _ask_for_save(self, neditable):
val = QMessageBox.No
fileName = neditable.file_path
val = QMessageBox.question(
self, (self.tr('The file %s was not saved') %
fileName),
self.tr("Do you want to save before closing?"),
QMessageBox.Yes | QMessageBox.No |
QMessageBox.Cancel)
if val == QMessageBox.No:
neditable.nfile.close(force_close=True)
elif val == QMessageBox.Yes:
self._main_container.save_file(neditable.editor)
neditable.nfile.close()
def _run_file(self, path):
self._main_container.run_file(path)
def _add_to_project(self, path):
self._main_container._add_to_project(path)
def set_current(self, neditable):
if neditable:
self.stacked.setCurrentWidget(neditable.editor)
self._update_cursor_position(ignore_sender=True)
neditable.editor.setFocus()
self._main_container.current_editor_changed(
neditable.file_path)
def widget(self, index):
return self.stacked.widget(index)
def count(self):
"""Return the number of editors opened."""
return self.stacked.count()
def _update_cursor_position(self, ignore_sender=False):
obj = self.sender()
editor = self.stacked.currentWidget()
# Check if it's current to avoid signals from other splits.
if ignore_sender or editor == obj:
line = editor.textCursor().blockNumber() + 1
col = editor.textCursor().columnNumber()
self.bar.update_line_col(line, col)
def _set_current_symbol(self, line, ignore_sender=False):
obj = self.sender()
editor = self.stacked.currentWidget()
# Check if it's current to avoid signals from other splits.
if ignore_sender or editor == obj:
index = bisect.bisect(self._symbols_index, line)
if self._symbols_index[index] > line:
index -= 1
self.bar.set_current_symbol(index)
def _go_to_symbol(self, index):
line = self._symbols_index[index]
editor = self.stacked.currentWidget()
editor.go_to_line(line)
def _update_symbols(self, neditable):
editor = self.stacked.currentWidget()
# Check if it's current to avoid signals from other splits.
if editor == neditable.editor:
self._load_symbols(neditable)
def _load_symbols(self, neditable):
symbols_handler = settings.get_symbols_handler('py')
source = neditable.editor.toPlainText()
source = source.encode(neditable.editor.encoding)
symbols = symbols_handler.get_symbols_simplified(source)
self._symbols_index = sorted(symbols.keys())
symbols = sorted(list(symbols.items()), key=lambda x: x[0])
self.bar.add_symbols(symbols)
line = neditable.editor.textCursor().blockNumber()
self._set_current_symbol(line, True)
def _show_notification_icon(self, neditable):
checkers = neditable.sorted_checkers
icon = QIcon()
for items in checkers:
checker, color, _ = items
if checker.checks:
if isinstance(checker.checker_icon, int):
icon = self.style().standardIcon(checker.checker_icon)
elif isinstance(checker.checker_icon, str):
icon = QIcon(checker.checker_icon)
break
self.bar.update_item_icon(neditable, icon)