本文整理汇总了Python中PyQt5.QtWidgets.QStackedLayout.currentWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedLayout.currentWidget方法的具体用法?Python QStackedLayout.currentWidget怎么用?Python QStackedLayout.currentWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStackedLayout
的用法示例。
在下文中一共展示了QStackedLayout.currentWidget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
class MainWindow(QWidget):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.actionAuswahl = QComboBox()
self.actionAuswahl.addItem("Einen Sportler bearbeiten")
self.actionAuswahl.addItem("Liste aller Sportler anzeigen")
self.actionAuswahl.addItem("Eine Ergebnissliste bearbeiten")
self.actionAuswahl.addItem("Ergebnisse & Urkunden drucken")
self.actionAuswahl.addItem("Ergebnissvorlagen drucken")
self.actionAuswahl.setEditable(False)
self.actionAuswahl.activated.connect(self.setAction)
self.actionSportlerEdit = SportlerEdit()
self.actionSportlerShow = SportlerShow()
self.actionErgebnissListe = ErgebnissListe()
self.actionErgebnisseDrucken = ErgebnisseDrucken()
self.actionErgebnissVorlage = ErgebnissVorlage()
self.actionLayout = QStackedLayout()
self.actionLayout.addWidget(self.actionSportlerEdit)
self.actionLayout.addWidget(self.actionSportlerShow)
self.actionLayout.addWidget(self.actionErgebnissListe)
self.actionLayout.addWidget(self.actionErgebnisseDrucken)
self.actionLayout.addWidget(self.actionErgebnissVorlage)
self.mainLayout = QVBoxLayout()
self.mainLayout.addWidget(self.actionAuswahl)
self.mainLayout.addStretch(0)
self.mainLayout.addLayout(self.actionLayout)
self.mainLayout.addStretch(0)
self.setLayout(self.mainLayout)
self.show()
def setAction(self,index):
self.actionLayout.setCurrentIndex(index)
self.actionLayout.currentWidget().update()
示例2: _MainContainer
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
#.........这里部分代码省略.........
self.current_widget = self.combo_area
ui_tools.install_shortcuts(self, actions.ACTIONS, ide)
def add_status_bar(self, status):
self._vbox.addWidget(status)
@property
def combo_header_size(self):
return self.combo_area.bar.height()
def add_widget(self, widget):
i = self.stack.addWidget(widget)
#if not isinstance(widget, start_page.StartPage):
self.tryMakeImagePreview(i)
def remove_widget(self, widget):
#self.toRemovePreview.emit(self.stack.widget(widget))
self.stack.removeWidget(widget)
def _close_dialog(self, widget):
self.closeDialog.emit(widget)
widget.finished[int].disconnect()#lambda i: self._close_dialog(widget))
def show_dialog(self, widget):
print("\n\nshow_dialog", self.isVisible())
self._opening_dialog = True
widget.finished[int].connect(lambda i: self._close_dialog(widget))
widget.setVisible(True)
self.show_selector()
def show_selector(self):
print("\n\nshow_selector::", self.selector, self.stack.currentWidget())
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)
示例3: StatusBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
#.........这里部分代码省略.........
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):
"""Setter for self.{insert,command,caret}_active.
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:
webview = objreg.get('tabbed-browser', scope='window',
window=self._win_id).currentWidget()
log.statusbar.debug("Setting caret_mode - val {}, selection "
"{}".format(val, webview.selection_enabled))
if val:
if webview.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 _pop_text(self):
"""Display a text in the statusbar and pop it from _text_queue."""
try:
severity, text = self._text_queue.popleft()
except IndexError:
self._set_severity(Severity.normal)
self.txt.set_text(self.txt.Text.temp, '')
self._text_pop_timer.stop()
# If a previous widget was interrupted by an error, restore it.
if self._previous_widget == PreviousWidget.prompt:
self._stack.setCurrentWidget(self.prompt)
elif self._previous_widget == PreviousWidget.command:
self._stack.setCurrentWidget(self.cmd)
elif self._previous_widget == PreviousWidget.none:
示例4: StatusBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
#.........这里部分代码省略.........
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):
"""Setter for self.{insert,command,caret}_active.
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:
示例5: StatusBar
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
#.........这里部分代码省略.........
pass
else:
raise AssertionError("Unknown _previous_widget!")
return
log.statusbar.debug("Displaying {} message: {}".format(
'error' if error else 'text', text))
log.statusbar.debug("Remaining: {}".format(self._text_queue))
self._set_error(error)
self.txt.set_text(self.txt.Text.temp, text)
def _show_cmd_widget(self):
"""Show command widget instead of temporary text."""
self._set_error(False)
self._previous_widget = PreviousWidget.prompt
if self._text_pop_timer.isActive():
self._timer_was_active = True
self._text_pop_timer.stop()
self._stack.setCurrentWidget(self.cmd)
def _hide_cmd_widget(self):
"""Show temporary text instead of command widget."""
log.statusbar.debug("Hiding cmd widget, queue: {}".format(
self._text_queue))
self._previous_widget = PreviousWidget.none
if self._timer_was_active:
# Restart the text pop timer if it was active before hiding.
self._pop_text()
self._text_pop_timer.start()
self._timer_was_active = False
self._stack.setCurrentWidget(self.txt)
def _show_prompt_widget(self):
"""Show prompt widget instead of temporary text."""
if self._stack.currentWidget() is self.prompt:
return
self._set_error(False)
self._set_prompt_active(True)
self._previous_widget = PreviousWidget.prompt
if self._text_pop_timer.isActive():
self._timer_was_active = True
self._text_pop_timer.stop()
self._stack.setCurrentWidget(self.prompt)
def _hide_prompt_widget(self):
"""Show temporary text instead of prompt widget."""
self._set_prompt_active(False)
self._previous_widget = PreviousWidget.none
log.statusbar.debug("Hiding prompt widget, queue: {}".format(
self._text_queue))
if self._timer_was_active:
# Restart the text pop timer if it was active before hiding.
self._pop_text()
self._text_pop_timer.start()
self._timer_was_active = False
self._stack.setCurrentWidget(self.txt)
def _disp_text(self, text, error, immediately=False):
"""Inner logic for disp_error and disp_temp_text.
Args:
text: The message to display.
error: Whether it's an error message (True) or normal text (False)
immediately: If set, message gets displayed immediately instead of
queued.
"""
# FIXME probably using a QTime here would be easier.
示例6: ComboEditor
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
class ComboEditor(QWidget):
# Signals
closeSplit = pyqtSignal('PyQt_PyObject')
splitEditor = pyqtSignal(
'PyQt_PyObject', 'PyQt_PyObject', Qt.Orientation)
allFilesClosed = pyqtSignal()
about_to_close_combo_editor = pyqtSignal()
fileClosed = pyqtSignal("PyQt_PyObject")
def __init__(self, original=False):
super(ComboEditor, self).__init__(None)
self.__original = original
self.__undocked = []
self._symbols_index = []
vbox = QVBoxLayout(self)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.setSpacing(0)
self.bar = ActionBar(main_combo=original)
vbox.addWidget(self.bar)
# Info bar
# self.info_bar = InfoBar(self)
# self.info_bar.setVisible(False)
# vbox.addWidget(self.info_bar)
self.stacked = QStackedLayout()
vbox.addLayout(self.stacked)
self._main_container = IDE.get_service('main_container')
if not self.__original:
self._main_container.fileOpened['QString'].connect(
self._file_opened_by_main)
self.bar.combo_files.showComboSelector.connect(
self._main_container.show_files_handler)
self.bar.combo_files.hideComboSelector.connect(
self._main_container.hide_files_handler)
self.bar.change_current['PyQt_PyObject',
int].connect(self._set_current)
self.bar.splitEditor[bool].connect(self.split_editor)
self.bar.runFile['QString'].connect(self._run_file)
self.bar.closeSplit.connect(lambda: self.closeSplit.emit(self))
self.bar.addToProject['QString'].connect(self._add_to_project)
self.bar.showFileInExplorer['QString'].connect(
self._show_file_in_explorer)
self.bar.goToSymbol[int].connect(self._go_to_symbol)
self.bar.undockEditor.connect(self.undock_editor)
self.bar.reopenTab['QString'].connect(
lambda path: self._main_container.open_file(path))
self.bar.closeImageViewer.connect(self._close_image)
self.bar.code_navigator.previousPressed.connect(self._navigate_code)
self.bar.code_navigator.nextPressed.connect(self._navigate_code)
# self.connect(self.bar, SIGNAL("recentTabsModified()"),
# lambda: self._main_container.recent_files_changed())
# self.connect(self.bar.code_navigator.btnPrevious,
# SIGNAL("clicked()"),
# lambda: self._navigate_code(False))
# self.connect(self.bar.code_navigator.btnNext, SIGNAL("clicked()"),
# lambda: self._navigate_code(True))
def _navigate_code(self, operation, forward=True):
self._main_container.navigate_code_history(operation, forward)
# op = self.bar.code_navigator.operation
# self._main_container.navigate_code_history(val, op)
def current_editor(self):
return self.stacked.currentWidget()
def setFocus(self):
super(ComboEditor, self).setFocus()
self.current_editor().setFocus()
self._editor_with_focus()
def _file_opened_by_main(self, path):
index = self.stacked.currentIndex()
ninjaide = IDE.get_service('ide')
editable = ninjaide.get_or_create_editable(path)
self.add_editor(editable)
self.bar.set_current_by_index(index)
if index == -1:
self.bar.set_current_by_index(0)
def add_image_viewer(self, viewer):
"""Add Image Viewer widget to the UI area"""
self.stacked.addWidget(viewer)
viewer.scaleFactorChanged.connect(
self.bar.image_viewer_controls.update_scale_label)
viewer.imageSizeChanged.connect(
self.bar.image_viewer_controls.update_size_label)
self.bar.add_item(viewer.display_name(), None)
viewer.create_scene()
if not self.bar.isVisible():
self.bar.setVisible(True)
def add_editor(self, neditable, keep_index=False):
"""Add Editor Widget to the UI area."""
if neditable.editor:
#.........这里部分代码省略.........
示例7: ComboEditor
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
class ComboEditor(QDialog):
closeSplit = pyqtSignal(QWidget)#closeSplit
allFilesClosed = pyqtSignal()
splitEditor = pyqtSignal("QWidget*", "QWidget*", bool)
recentTabsModified = pyqtSignal()
aboutToCloseComboEditor = pyqtSignal()
class NAVIGATE:
prev = 0
next = 1
Q_ENUMS(NAVIGATE)
def __init__(self, original=False):
super(ComboEditor, self).__init__(None, Qt.WindowStaysOnTopHint)
self.__original = original
self.__undocked = []
self._symbols_index = []
vbox = QVBoxLayout(self)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.setSpacing(0)
self.bar = ActionBar(main_combo=original)
vbox.addWidget(self.bar)
self.stacked = QStackedLayout()
vbox.addLayout(self.stacked)
self._main_container = IDE.get_service('main_container')
if not self.__original:
self._main_container.fileOpened.connect(self._file_opened_by_main)
self.bar.combo.showComboSelector.connect(self._main_container.change_tab)
self.bar.changeCurrent.connect(self._set_current)
self.bar.editorSplited.connect(self.split_editor)
self.bar.runFile[str].connect(self._run_file)
self.bar.closeFile.connect(lambda: self.closeSplit.emit(self))
self.bar.addToProject[str].connect(self._add_to_project)
self.bar.showFileInExplorer.connect(self._show_file_in_explorer)
self.bar.goToSymbol.connect(self._go_to_symbol)
self.bar.undockEditor.connect(self.undock_editor)
self.bar.reopenTab[str].connect(self._main_container.open_file)
self.bar.recentTabsModified.connect(self._main_container.recent_files_changed)
self.bar.code_navigator.btnPrevious.clicked['bool'].connect(lambda: self._navigate_code(self.NAVIGATE.prev))
self.bar.code_navigator.btnNext.clicked['bool'].connect(lambda: self._navigate_code(self.NAVIGATE.prev))
def _navigate_code(self, val):
op = self.bar.code_navigator.operation
self._main_container.navigate_code_history(val, op)
def currentWidget(self):
return self.stacked.currentWidget()
def setFocus(self):
super(ComboEditor, self).setFocus()
w = self.stacked.currentWidget()
if w:
w.setFocus()
self._editor_with_focus()
def _file_opened_by_main(self, path):
index = self.stacked.currentIndex()
ninjaide = IDE.getInstance()
editable = ninjaide.get_or_create_editable(path)
print("_file_opened_by_main", editable)
self.add_editor(editable)
self.bar.set_current_by_index(index)
if index == -1:
self.bar.set_current_by_index(0)
def add_editor(self, neditable, keep_index=False):
"""Add Editor Widget to the UI area."""
if neditable.editor:
if self.__original:
editor = neditable.editor
else:
editor = self._main_container.create_editor_from_editable(
neditable)
index = self.stacked.currentIndex()
self.stacked.addWidget(editor)
self.bar.add_item(neditable.display_name, neditable)
if keep_index:
self.bar.set_current_by_index(index)
# Editor Signals
editor.cursorPositionChanged[int, int].connect(self._update_cursor_position)
editor.editorFocusObtained.connect(self._editor_with_focus)
editor.currentLineChanged.connect(self._set_current_symbol)
editor.modificationChanged['bool'].connect(self._editor_modified)
neditable.checkersUpdated.connect(self._show_notification_icon)
neditable.fileSaved.connect(self._update_symbols)
neditable.fileSaved.connect(self._update_combo_info)
# Connect file system signals only in the original
neditable.fileClosing.connect(self._close_file)
if self.__original:
neditable.askForSaveFileClosing.connect(self._ask_for_save)
neditable.fileChanged.connect(self._file_has_been_modified)
#.........这里部分代码省略.........
示例8: ProjectTreeColumn
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
#.........这里部分代码省略.........
if project == nproject:
nproject.is_current = True
else:
project.is_current = False
self._projects_area.setCurrentIndex(index + 1)
self.activeProjectChanged.emit()
def close_opened_projects(self):
for project in reversed(self.projects):
self._close_project(project)
def save_project(self):
"""Save all the opened files that belongs to the actual project."""
if self.current_project is not None:
path = self.current_project.path
main_container = IDE.get_service('main_container')
if path and main_container:
main_container.save_project(path)
def create_new_project(self):
wizard = new_project_manager.NewProjectManager(self)
wizard.show()
@property
def current_project(self):
project = None
if self._projects_area.count() > 0 and self.current_tree is not None:
project = self.current_tree.project
return project
@property
def current_tree(self):
tree = None
widget = self._projects_area.currentWidget()
if isinstance(widget, TreeProjectsWidget):
tree = widget
return tree
def set_current_item(self, path):
if self.current_project is not None:
self.current_tree.set_current_item(path)
def save_recent_projects(self, folder):
settings = IDE.data_settings()
recent_project_list = settings.value('recentProjects', {})
# if already exist on the list update the date time
projectProperties = json_manager.read_ninja_project(folder)
name = projectProperties.get('name', '')
description = projectProperties.get('description', '')
if not name:
name = file_manager.get_basename(folder)
if not description:
description = translations.TR_NO_DESCRIPTION
if folder in recent_project_list:
properties = recent_project_list[folder]
properties["lastopen"] = QDateTime.currentDateTime()
properties["name"] = name
properties["description"] = description
recent_project_list[folder] = properties
else:
recent_project_list[folder] = {
"name": name,
"description": description,
示例9: ProjectTreeColumn
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentWidget [as 别名]
#.........这里部分代码省略.........
self._projects_area.setCurrentIndex(index)
ninjaide = IDE.getInstance()
ninjaide.filesystem.close_project(widget.project.path)
widget.deleteLater()
if len(self.projects) > 1:
title = "%s (%s)" % (
translations.TR_TAB_PROJECTS, len(self.projects))
else:
title = translations.TR_TAB_PROJECTS
self.changeTitle.emit(self, title)
def _change_current_project(self, index):
self._projects_area.setCurrentIndex(index)
def close_opened_projects(self):
for project in reversed(self.projects):
self._close_project(project)
def save_project(self):
"""Save all the opened files that belongs to the actual project."""
if self._projects_area.count() > 0:
path = self.current_project.path
main_container = IDE.get_service('main_container')
if path and main_container:
main_container.save_project(path)
def create_new_project(self):
wizard = new_project_manager.NewProjectManager(self)
wizard.show()
@property
def current_project(self):
if self._projects_area.count() > 0:
return self._projects_area.currentWidget().project
@property
def current_tree(self):
obj = self._projects_area.currentWidget()
return obj
def save_recent_projects(self, folder):
settings = IDE.data_settings()
recent_project_list = settings.value('recentProjects', {})
#if already exist on the list update the date time
projectProperties = json_manager.read_ninja_project(folder)
name = projectProperties.get('name', '')
description = projectProperties.get('description', '')
if name == '':
name = file_manager.get_basename(folder)
if description == '':
description = translations.TR_NO_DESCRIPTION
if folder in recent_project_list:
properties = recent_project_list[folder]
properties["lastopen"] = QDateTime.currentDateTime()
properties["name"] = name
properties["description"] = description
recent_project_list[folder] = properties
else:
recent_project_list[folder] = {
"name": name,
"description": description,
"isFavorite": False, "lastopen": QDateTime.currentDateTime()}
#if the length of the project list it's high that 10 then delete