本文整理汇总了Python中PyQt5.QtWidgets.QStackedLayout.setCurrentWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedLayout.setCurrentWidget方法的具体用法?Python QStackedLayout.setCurrentWidget怎么用?Python QStackedLayout.setCurrentWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStackedLayout
的用法示例。
在下文中一共展示了QStackedLayout.setCurrentWidget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MusicPreviewWidget
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.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)
示例2: StatusBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setCurrentWidget [as 别名]
#.........这里部分代码省略.........
self._color_flags.prompt = val
elif mode == usertypes.KeyMode.caret:
tab = self._current_tab()
log.statusbar.debug("Setting caret flag - val {}, selection "
"{}".format(val, tab.caret.selection_enabled))
if val:
if tab.caret.selection_enabled:
self._set_mode_text("{} selection".format(mode.name))
self._color_flags.caret = ColorFlags.CaretMode.selection
else:
self._set_mode_text(mode.name)
self._color_flags.caret = ColorFlags.CaretMode.on
else:
self._color_flags.caret = ColorFlags.CaretMode.off
config.set_register_stylesheet(self, update=False)
def _set_mode_text(self, mode):
"""Set the mode text."""
if mode == 'passthrough':
key_instance = config.key_instance
all_bindings = key_instance.get_reverse_bindings_for('passthrough')
bindings = all_bindings.get('leave-mode')
if bindings:
suffix = ' ({} to leave)'.format(bindings[0])
else:
suffix = ''
else:
suffix = ''
text = "-- {} MODE --{}".format(mode.upper(), suffix)
self.txt.set_text(self.txt.Text.normal, text)
def _show_cmd_widget(self):
"""Show command widget instead of temporary text."""
self._stack.setCurrentWidget(self.cmd)
self.show()
def _hide_cmd_widget(self):
"""Show temporary text instead of command widget."""
log.statusbar.debug("Hiding cmd widget")
self._stack.setCurrentWidget(self.txt)
self.maybe_hide()
@pyqtSlot(str)
def set_text(self, val):
"""Set a normal (persistent) text in the status bar."""
self.txt.set_text(self.txt.Text.normal, val)
@pyqtSlot(usertypes.KeyMode)
def on_mode_entered(self, mode):
"""Mark certain modes in the commandline."""
keyparsers = objreg.get('keyparsers', scope='window',
window=self._win_id)
if keyparsers[mode].passthrough:
self._set_mode_text(mode.name)
if mode in [usertypes.KeyMode.insert,
usertypes.KeyMode.command,
usertypes.KeyMode.caret,
usertypes.KeyMode.prompt,
usertypes.KeyMode.yesno,
usertypes.KeyMode.passthrough]:
self.set_mode_active(mode, True)
@pyqtSlot(usertypes.KeyMode, usertypes.KeyMode)
def on_mode_left(self, old_mode, new_mode):
"""Clear marked mode."""
keyparsers = objreg.get('keyparsers', scope='window',
示例3: StatusBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setCurrentWidget [as 别名]
#.........这里部分代码省略.........
@pyqtProperty(str)
def severity(self):
"""Getter for self.severity, so it can be used as Qt property.
Return:
The severity as a string (!)
"""
if self._severity is None:
return ""
else:
return self._severity.name
def _set_severity(self, severity):
"""Set the severity for the current message.
Re-set the stylesheet after setting the value, so everything gets
updated by Qt properly.
Args:
severity: A Severity member.
"""
if self._severity == severity:
# This gets called a lot (e.g. if the completion selection was
# changed), and setStyleSheet is relatively expensive, so we ignore
# this if there's nothing to change.
return
log.statusbar.debug("Setting severity to {}".format(severity))
self._severity = severity
self.setStyleSheet(style.get_stylesheet(self.STYLESHEET))
if severity != Severity.normal:
# If we got an error while command/prompt was shown, raise the text
# widget.
self._stack.setCurrentWidget(self.txt)
@pyqtProperty(bool)
def prompt_active(self):
"""Getter for self.prompt_active, so it can be used as Qt property."""
return self._prompt_active
def _set_prompt_active(self, val):
"""Setter for self.prompt_active.
Re-set the stylesheet after setting the value, so everything gets
updated by Qt properly.
"""
log.statusbar.debug("Setting prompt_active to {}".format(val))
self._prompt_active = val
self.setStyleSheet(style.get_stylesheet(self.STYLESHEET))
@pyqtProperty(bool)
def command_active(self):
"""Getter for self.command_active, so it can be used as Qt property."""
return self._command_active
@pyqtProperty(bool)
def insert_active(self):
"""Getter for self.insert_active, so it can be used as Qt property."""
return self._insert_active
@pyqtProperty(str)
def caret_mode(self):
"""Getter for self._caret_mode, so it can be used as Qt property."""
return self._caret_mode.name
def set_mode_active(self, mode, val):
示例4: _MainContainer
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setCurrentWidget [as 别名]
#.........这里部分代码省略.........
if self.selector != self.stack.currentWidget():
_dir = self.Successful_Tmp()
if not _dir:
print("failed!")
return
# 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
# path = os.path.join(temp_dir, "screen%s.png" % index)
#ff = QFile(_dir, "screen%s.png" % index)
path = _dir.absolutePath()+"/screen%s.png" % index
pixmap = widget.grab()#widget.rect())
pixmap.save(path)
#path = path.replace("\\", '/')
#print("path::", path, QFileInfo(path).exists())
path = "file:///"+path
if index == current:
self.selector.set_preview(index, path)#QUrl(path)
collected_data.insert(0, (index, path, closable))
else:
collected_data.append((index, path, closable))
self.selector.set_model(collected_data)
print("self.selector.set_model()", collected_data)
self.stack.setCurrentWidget(self.selector)
else:
print("\n\n_selector_Close()")
self._selector_Close()
def Successful_Tmp(self):# CheckTmpDir, StateTmpDir
failed = lambda: not self.tdir or not self.tdir.isValid()
if failed():# not successfully
self.tdir = QTemporaryDir()
if failed():
QMessageBox.critical(self, "Unexpected Failurer", "The application has detected a problem trying to\nCreate or Access a Temporary File!.")
return None
else:
self.tdir.setAutoRemove(True)
d = QDir(self.tdir.path())
if not d.exists("ninja-ide"):
if not d.mkdir("ninja-ide"):
self.tdir = None
d.cd("ninja-ide")
return d
def tryMakeImagePreview(self, index):
return
d = self.Successful_Tmp()
if d:
self.makeImagePreview(d, index)
def makeImagePreview(self, _dir, index):
return
path = _dir.absolutePath()+"/screen%s.png" % index
widget = self.stack.widget(index)
pixmap = widget.grab()#widget.rect()
示例5: StatusBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setCurrentWidget [as 别名]
#.........这里部分代码省略.........
Re-set the stylesheet after setting the value, so everything gets
updated by Qt properly.
"""
if mode == usertypes.KeyMode.insert:
log.statusbar.debug("Setting insert_active to {}".format(val))
self._insert_active = val
if mode == usertypes.KeyMode.command:
log.statusbar.debug("Setting command_active to {}".format(val))
self._command_active = val
elif mode == usertypes.KeyMode.caret:
tab = objreg.get('tabbed-browser', scope='window',
window=self._win_id).currentWidget()
log.statusbar.debug("Setting caret_mode - val {}, selection "
"{}".format(val, tab.caret.selection_enabled))
if val:
if tab.caret.selection_enabled:
self._set_mode_text("{} selection".format(mode.name))
self._caret_mode = CaretMode.selection
else:
self._set_mode_text(mode.name)
self._caret_mode = CaretMode.on
else:
self._caret_mode = CaretMode.off
self.setStyleSheet(style.get_stylesheet(self.STYLESHEET))
def _set_mode_text(self, mode):
"""Set the mode text."""
text = "-- {} MODE --".format(mode.upper())
self.txt.set_text(self.txt.Text.normal, text)
def _show_cmd_widget(self):
"""Show command widget instead of temporary text."""
self._stack.setCurrentWidget(self.cmd)
self.show()
def _hide_cmd_widget(self):
"""Show temporary text instead of command widget."""
log.statusbar.debug("Hiding cmd widget")
self._stack.setCurrentWidget(self.txt)
self.maybe_hide()
def _show_prompt_widget(self):
"""Show prompt widget instead of temporary text."""
if self._stack.currentWidget() is self.prompt:
return
self._set_prompt_active(True)
self._stack.setCurrentWidget(self.prompt)
self.show()
def _hide_prompt_widget(self):
"""Show temporary text instead of prompt widget."""
self._set_prompt_active(False)
log.statusbar.debug("Hiding prompt widget")
self._stack.setCurrentWidget(self.txt)
self.maybe_hide()
@pyqtSlot(str)
def set_text(self, val):
"""Set a normal (persistent) text in the status bar."""
self.txt.set_text(self.txt.Text.normal, val)
@pyqtSlot(usertypes.KeyMode)
def on_mode_entered(self, mode):
"""Mark certain modes in the commandline."""
keyparsers = objreg.get('keyparsers', scope='window',
示例6: StatusBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setCurrentWidget [as 别名]
#.........这里部分代码省略.........
# We add a parent to Progress here because it calls self.show() based
# on some signals, and if that happens before it's added to the layout,
# it will quickly blink up as independent window.
self.prog = progress.Progress(self)
self._hbox.addWidget(self.prog)
def __repr__(self):
return utils.get_repr(self)
@pyqtProperty(bool)
def error(self):
"""Getter for self.error, so it can be used as Qt property."""
# pylint: disable=method-hidden
return self._error
def _set_error(self, val):
"""Setter for self.error, so it can be used as Qt property.
Re-set the stylesheet after setting the value, so everything gets
updated by Qt properly.
"""
if self._error == val:
# This gets called a lot (e.g. if the completion selection was
# changed), and setStyleSheet is relatively expensive, so we ignore
# this if there's nothing to change.
return
log.statusbar.debug("Setting error to {}".format(val))
self._error = val
self.setStyleSheet(style.get_stylesheet(self.STYLESHEET))
if val:
# If we got an error while command/prompt was shown, raise the text
# widget.
self._stack.setCurrentWidget(self.txt)
@pyqtProperty(bool)
def prompt_active(self):
"""Getter for self.prompt_active, so it can be used as Qt property."""
# pylint: disable=method-hidden
return self._prompt_active
def _set_prompt_active(self, val):
"""Setter for self.prompt_active.
Re-set the stylesheet after setting the value, so everything gets
updated by Qt properly.
"""
log.statusbar.debug("Setting prompt_active to {}".format(val))
self._prompt_active = val
self.setStyleSheet(style.get_stylesheet(self.STYLESHEET))
@pyqtProperty(bool)
def insert_active(self):
"""Getter for self.insert_active, so it can be used as Qt property."""
# pylint: disable=method-hidden
return self._insert_active
def _set_insert_active(self, val):
"""Setter for self.insert_active.
Re-set the stylesheet after setting the value, so everything gets
updated by Qt properly.
"""
log.statusbar.debug("Setting insert_active to {}".format(val))
self._insert_active = val
self.setStyleSheet(style.get_stylesheet(self.STYLESHEET))
示例7: _MainContainer
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setCurrentWidget [as 别名]
#.........这里部分代码省略.........
if node is not None:
filename = node[0]
line, col = node[1]
self.open_file(filename, line, col)
def _navigate_bookmarks(self, forward=True):
"""Navigate between the bookmarks"""
current_editor = self.get_current_editor()
current_editor.navigate_bookmarks(forward=forward)
def _set_focus_to_editor(self):
status_bar = IDE.get_service("status_bar")
tools_doock = IDE.get_service("tools_dock")
editor_widget = self.get_current_editor()
if status_bar.isVisible() and tools_doock.isVisible():
status_bar.hide_status_bar()
elif tools_doock.isVisible():
tools_doock._hide()
elif status_bar.isVisible():
status_bar.hide_status_bar()
if editor_widget is not None:
editor_widget.extra_selections.remove("find")
editor_widget.scrollbar().remove_marker("find")
def split_assistance(self):
editor_widget = self.get_current_editor()
if editor_widget is not None:
split_widget = split_orientation.SplitOrientation(self)
split_widget.show()
def show_dialog(self, widget):
self.add_widget(widget)
self.stack.setCurrentWidget(widget)
def show_split(self, orientation_vertical=False):
orientation = Qt.Horizontal
if orientation_vertical:
orientation = Qt.Vertical
self.combo_area.split_editor(orientation)
def show_locator(self):
"""Show the Locator Widget"""
if not self._code_locator.isVisible():
self._code_locator.show()
def _explore_code(self):
"""Update locator metadata for the current projects"""
self._code_locator.explore_code()
def _explore_file_code(self, path):
"""Update locator metadata for the file in path"""
self._code_locator.explore_file_code(path)
def current_editor_changed(self, filename):
"""Notify the new filename of the current editor"""
if filename is None:
filename = translations.TR_NEW_DOCUMENT
self.currentEditorChanged.emit(filename)
def get_current_editor(self):
current_widget = self.combo_area.current_editor()
示例8: ProjectTreeColumn
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setCurrentWidget [as 别名]
class ProjectTreeColumn(QDialog):
# Signalsnproject =
dockWidget = pyqtSignal('PyQt_PyObject')
undockWidget = pyqtSignal()
changeTitle = pyqtSignal('PyQt_PyObject', 'QString')
updateLocator = pyqtSignal()
activeProjectChanged = pyqtSignal()
def __init__(self, parent=None):
super(ProjectTreeColumn, self).__init__(parent)
vbox = QVBoxLayout(self)
vbox.setSizeConstraint(QVBoxLayout.SetDefaultConstraint)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.setSpacing(0)
self._buttons = []
frame = QFrame()
frame.setObjectName("actionbar")
box = QVBoxLayout(frame)
box.setContentsMargins(1, 1, 1, 1)
box.setSpacing(0)
self._combo_project = QComboBox()
self._combo_project.setSizePolicy(
QSizePolicy.Expanding, QSizePolicy.Fixed)
self._combo_project.setSizeAdjustPolicy(
QComboBox.AdjustToMinimumContentsLengthWithIcon)
self._combo_project.setObjectName("combo_projects")
box.addWidget(self._combo_project)
vbox.addWidget(frame)
self._combo_project.setContextMenuPolicy(Qt.CustomContextMenu)
self._projects_area = QStackedLayout()
logger.debug("This is the projects area")
vbox.addLayout(self._projects_area)
# Empty widget
self._empty_proj = QLabel(translations.TR_NO_PROJECTS)
self._empty_proj.setAlignment(Qt.AlignCenter)
self._empty_proj.setAutoFillBackground(True)
self._empty_proj.setBackgroundRole(QPalette.Base)
self._projects_area.addWidget(self._empty_proj)
self._projects_area.setCurrentWidget(self._empty_proj)
self.projects = []
self._combo_project.activated.connect(
self._change_current_project)
self._combo_project.customContextMenuRequested[
'const QPoint&'].connect(self.context_menu_for_root)
connections = (
{
"target": "main_container",
"signal_name": "addToProject",
"slot": self._add_file_to_project
},
{
"target": "main_container",
"signal_name": "showFileInExplorer",
"slot": self._show_file_in_explorer
},
)
IDE.register_service('projects_explorer', self)
IDE.register_signals('projects_explorer', connections)
ExplorerContainer.register_tab(translations.TR_TAB_PROJECTS, self)
# FIXME: Should have a ninja settings object that stores tree state
# FIXME: Or bettter, application data object
# TODO: check this:
# self.connect(ide, SIGNAL("goingDown()"),
# self.tree_projects.shutdown)
# def close_project_signal():
# self.emit(SIGNAL("updateLocator()"))
def install_tab(self):
ide = IDE.get_service('ide')
ui_tools.install_shortcuts(self, actions.PROJECTS_TREE_ACTIONS, ide)
ide.goingDown.connect(self._on_ide_going_down)
def _on_ide_going_down(self):
"""Save some settings before close"""
if self.current_tree is None:
return
ds = IDE.data_settings()
show_filesize = not bool(self.current_tree.isColumnHidden(1))
ds.setValue("projectsExplorer/showFileSize", show_filesize)
def load_session_projects(self, projects):
for project in projects:
if os.path.exists(project):
self._open_project_folder(project)
def open_project_folder(self, folderName=None):
if settings.WORKSPACE:
directory = settings.WORKSPACE
else:
directory = os.path.expanduser("~")
if folderName is None:
#.........这里部分代码省略.........
示例9: __init__
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import setCurrentWidget [as 别名]
def __init__(self, parent=None):
super().__init__()
self.cards = {} # type: Dict[GuiCards, QWidget]
"""
Python's GC will clean up QPropertyAnimations as soon as it leaves the button handler,
therefore they will appear not to work. Use members to store the animations.
see http://stackoverflow.com/a/6953965
"""
self.slide_in_animation = None
self.slide_out_animation = None
self.animation_group = None
self.setObjectName("coffeeFundWindow")
"""
Store the position and size of visible/hidden cards for the animation sequences
"""
self.hidden_geometry = None
self.visible_geometry = None
layout = QStackedLayout()
layout.setStackingMode(QStackedLayout.StackAll)
card_remove = RemoveCard()
self.cards[GuiCards.RemoveCard] = card_remove
layout.addWidget(card_remove)
card_choose_action = ChooseActionCard()
self.cards[GuiCards.ChooseAction] = card_choose_action
layout.addWidget(card_choose_action)
card_account = AccountCard()
self.cards[GuiCards.AccountInfo] = card_account
layout.addWidget(card_account)
# keep this as last initialized card, the last card will be shown on startup!
card_start = StartCard()
self.cards[GuiCards.Start] = card_start
layout.addWidget(card_start)
self.setLayout(layout)
self.setWindowTitle("Kaffeekasse")
layout.setCurrentWidget(card_start)
self.active_card = None
card_choose_action.button_account.clicked.connect(self.signal_account)
card_choose_action.button_coffee.clicked.connect(self.signal_coffee)
card_account.button_back.clicked.connect(self.signal_back)