本文整理汇总了Python中qtpy.QtWidgets.QStackedWidget.setCurrentWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedWidget.setCurrentWidget方法的具体用法?Python QStackedWidget.setCurrentWidget怎么用?Python QStackedWidget.setCurrentWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QStackedWidget
的用法示例。
在下文中一共展示了QStackedWidget.setCurrentWidget方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: VariableExplorer
# 需要导入模块: from qtpy.QtWidgets import QStackedWidget [as 别名]
# 或者: from qtpy.QtWidgets.QStackedWidget import setCurrentWidget [as 别名]
class VariableExplorer(QWidget, SpyderPluginMixin):
"""
Variable Explorer Plugin
"""
CONF_SECTION = 'variable_explorer'
CONFIGWIDGET_CLASS = VariableExplorerConfigPage
sig_option_changed = Signal(str, object)
def __init__(self, parent):
QWidget.__init__(self, parent)
SpyderPluginMixin.__init__(self, parent)
# Widgets
self.stack = QStackedWidget(self)
self.shellwidgets = {}
# Layout
layout = QVBoxLayout()
layout.addWidget(self.stack)
self.setLayout(layout)
# Initialize plugin
self.initialize_plugin()
@staticmethod
def get_settings():
"""
Return Variable Explorer settings dictionary
(i.e. namespace browser settings according to Spyder's configuration file)
"""
settings = {}
# CONF.load_from_ini() # necessary only when called from another process
for name in REMOTE_SETTINGS:
settings[name] = CONF.get(VariableExplorer.CONF_SECTION, name)
return settings
# ----- Stack accesors ----------------------------------------------------
def set_current_widget(self, nsb):
self.stack.setCurrentWidget(nsb)
def current_widget(self):
return self.stack.currentWidget()
def count(self):
return self.stack.count()
def remove_widget(self, nsb):
self.stack.removeWidget(nsb)
def add_widget(self, nsb):
self.stack.addWidget(nsb)
# ----- Public API --------------------------------------------------------
def add_shellwidget(self, shellwidget):
shellwidget_id = id(shellwidget)
# Add shell only once: this method may be called two times in a row
# by the External console plugin (dev. convenience)
from spyder.widgets.externalshell import systemshell
if isinstance(shellwidget, systemshell.ExternalSystemShell):
return
if shellwidget_id not in self.shellwidgets:
nsb = NamespaceBrowser(self)
nsb.set_shellwidget(shellwidget)
nsb.setup(**VariableExplorer.get_settings())
nsb.sig_option_changed.connect(self.sig_option_changed.emit)
self.add_widget(nsb)
self.shellwidgets[shellwidget_id] = nsb
self.set_shellwidget_from_id(shellwidget_id)
return nsb
def remove_shellwidget(self, shellwidget_id):
# If shellwidget_id is not in self.shellwidgets, it simply means
# that shell was not a Python-based console (it was a terminal)
if shellwidget_id in self.shellwidgets:
nsb = self.shellwidgets.pop(shellwidget_id)
self.remove_widget(nsb)
nsb.close()
def set_shellwidget_from_id(self, shellwidget_id):
if shellwidget_id in self.shellwidgets:
nsb = self.shellwidgets[shellwidget_id]
self.set_current_widget(nsb)
if self.isvisible:
nsb.visibility_changed(True)
def import_data(self, fname):
"""Import data in current namespace"""
if self.count():
nsb = self.current_widget()
nsb.refresh_table()
nsb.import_data(filenames=fname)
if self.dockwidget and not self.ismaximized:
self.dockwidget.setVisible(True)
self.dockwidget.raise_()
#------ SpyderPluginMixin API ---------------------------------------------
def visibility_changed(self, enable):
"""DockWidget visibility has changed"""
SpyderPluginMixin.visibility_changed(self, enable)
for nsb in list(self.shellwidgets.values()):
#.........这里部分代码省略.........
示例2: Plots
# 需要导入模块: from qtpy.QtWidgets import QStackedWidget [as 别名]
# 或者: from qtpy.QtWidgets.QStackedWidget import setCurrentWidget [as 别名]
class Plots(SpyderPluginWidget):
"""Plots plugin."""
CONF_SECTION = 'plots'
CONFIGWIDGET_CLASS = PlotsConfigPage
DISABLE_ACTIONS_WHEN_HIDDEN = False
sig_option_changed = Signal(str, object)
def __init__(self, parent):
SpyderPluginWidget.__init__(self, parent)
# Widgets
self.stack = QStackedWidget(self)
self.shellwidgets = {}
# Layout
layout = QGridLayout(self)
layout.addWidget(self.stack)
# Initialize plugin
self.initialize_plugin()
def get_settings(self):
"""Retrieve all Plots configuration settings."""
return {name: self.get_option(name) for name in
['mute_inline_plotting', 'show_plot_outline']}
# ---- Stack accesors
def set_current_widget(self, fig_browser):
"""
Set the currently visible fig_browser in the stack widget, refresh the
actions of the cog menu button and move it to the layout of the new
fig_browser.
"""
self.stack.setCurrentWidget(fig_browser)
# We update the actions of the options button (cog menu) and
# we move it to the layout of the current widget.
self.refresh_actions()
fig_browser.setup_options_button()
def current_widget(self):
return self.stack.currentWidget()
def count(self):
return self.stack.count()
def remove_widget(self, fig_browser):
self.stack.removeWidget(fig_browser)
def add_widget(self, fig_browser):
self.stack.addWidget(fig_browser)
# ---- Public API
def add_shellwidget(self, shellwidget):
"""
Register shell with figure explorer.
This function opens a new FigureBrowser for browsing the figures
in the shell.
"""
shellwidget_id = id(shellwidget)
if shellwidget_id not in self.shellwidgets:
self.options_button.setVisible(True)
fig_browser = FigureBrowser(
self, options_button=self.options_button,
background_color=MAIN_BG_COLOR)
fig_browser.set_shellwidget(shellwidget)
fig_browser.setup(**self.get_settings())
fig_browser.sig_option_changed.connect(
self.sig_option_changed.emit)
fig_browser.thumbnails_sb.redirect_stdio.connect(
self.main.redirect_internalshell_stdio)
self.add_widget(fig_browser)
self.shellwidgets[shellwidget_id] = fig_browser
self.set_shellwidget_from_id(shellwidget_id)
return fig_browser
def remove_shellwidget(self, shellwidget_id):
# If shellwidget_id is not in self.shellwidgets, it simply means
# that shell was not a Python-based console (it was a terminal)
if shellwidget_id in self.shellwidgets:
fig_browser = self.shellwidgets.pop(shellwidget_id)
self.remove_widget(fig_browser)
fig_browser.close()
def set_shellwidget_from_id(self, shellwidget_id):
if shellwidget_id in self.shellwidgets:
fig_browser = self.shellwidgets[shellwidget_id]
self.set_current_widget(fig_browser)
# ---- SpyderPluginWidget API
def get_plugin_title(self):
"""Return widget title"""
return _('Plots')
def get_plugin_icon(self):
"""Return plugin icon"""
return ima.icon('hist')
def get_focus_widget(self):
#.........这里部分代码省略.........
示例3: VariableExplorer
# 需要导入模块: from qtpy.QtWidgets import QStackedWidget [as 别名]
# 或者: from qtpy.QtWidgets.QStackedWidget import setCurrentWidget [as 别名]
class VariableExplorer(SpyderPluginWidget):
"""Variable Explorer plugin."""
CONF_SECTION = 'variable_explorer'
CONFIGWIDGET_CLASS = VariableExplorerConfigPage
DISABLE_ACTIONS_WHEN_HIDDEN = False
INITIAL_FREE_MEMORY_TIME_TRIGGER = 60 * 1000 # ms
SECONDARY_FREE_MEMORY_TIME_TRIGGER = 180 * 1000 # ms
sig_option_changed = Signal(str, object)
def __init__(self, parent):
SpyderPluginWidget.__init__(self, parent)
# Widgets
self.stack = QStackedWidget(self)
self.shellwidgets = {}
# Layout
layout = QVBoxLayout()
layout.addWidget(self.stack)
self.setLayout(layout)
# Initialize plugin
self.initialize_plugin()
def get_settings(self):
"""
Retrieve all Variable Explorer configuration settings.
Specifically, return the settings in CONF_SECTION with keys in
REMOTE_SETTINGS, and the setting 'dataframe_format'.
Returns:
dict: settings
"""
settings = {}
for name in REMOTE_SETTINGS:
settings[name] = self.get_option(name)
# dataframe_format is stored without percent sign in config
# to avoid interference with ConfigParser's interpolation
name = 'dataframe_format'
settings[name] = '%{0}'.format(self.get_option(name))
return settings
@Slot(str, object)
def change_option(self, option_name, new_value):
"""
Change a config option.
This function is called if sig_option_changed is received. If the
option changed is the dataframe format, then the leading '%' character
is stripped (because it can't be stored in the user config). Then,
the signal is emitted again, so that the new value is saved in the
user config.
"""
if option_name == 'dataframe_format':
assert new_value.startswith('%')
new_value = new_value[1:]
self.sig_option_changed.emit(option_name, new_value)
@Slot()
def free_memory(self):
"""Free memory signal."""
self.main.free_memory()
QTimer.singleShot(self.INITIAL_FREE_MEMORY_TIME_TRIGGER,
lambda: self.main.free_memory())
QTimer.singleShot(self.SECONDARY_FREE_MEMORY_TIME_TRIGGER,
lambda: self.main.free_memory())
# ----- Stack accesors ----------------------------------------------------
def set_current_widget(self, nsb):
self.stack.setCurrentWidget(nsb)
# We update the actions of the options button (cog menu) and we move
# it to the layout of the current widget.
self.refresh_actions()
nsb.setup_options_button()
def current_widget(self):
return self.stack.currentWidget()
def count(self):
return self.stack.count()
def remove_widget(self, nsb):
self.stack.removeWidget(nsb)
def add_widget(self, nsb):
self.stack.addWidget(nsb)
# ----- Public API --------------------------------------------------------
def add_shellwidget(self, shellwidget):
"""
Register shell with variable explorer.
This function opens a new NamespaceBrowser for browsing the variables
in the shell.
"""
shellwidget_id = id(shellwidget)
#.........这里部分代码省略.........