本文整理汇总了Python中PyQt4.QtGui.QStackedLayout.currentWidget方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedLayout.currentWidget方法的具体用法?Python QStackedLayout.currentWidget怎么用?Python QStackedLayout.currentWidget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QStackedLayout
的用法示例。
在下文中一共展示了QStackedLayout.currentWidget方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ComboEditor
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import currentWidget [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: ComboEditor
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import currentWidget [as 别名]
class ComboEditor(QDialog):
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.connect(self._main_container, SIGNAL("fileOpened(QString)"),
self._file_opened_by_main)
self.connect(self.bar, SIGNAL("changeCurrent(PyQt_PyObject, int)"),
self._set_current)
self.connect(self.bar, SIGNAL("splitEditor(bool)"), self.split_editor)
self.connect(self.bar, SIGNAL("runFile(QString)"),
self._run_file)
self.connect(self.bar, SIGNAL("closeSplit()"),
lambda: self.emit(SIGNAL("closeSplit(PyQt_PyObject)"), self))
self.connect(self.bar, SIGNAL("addToProject(QString)"),
self._add_to_project)
self.connect(self.bar, SIGNAL("goToSymbol(int)"),
self._go_to_symbol)
self.connect(self.bar, SIGNAL("undockEditor()"),
self.undock_editor)
self.connect(self.bar, SIGNAL("reopenTab(QString)"),
lambda path: self._main_container.open_file(path))
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, 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()
self.stacked.currentWidget().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)
def add_editor(self, neditable):
"""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)
self.stacked.addWidget(editor)
self.bar.add_item(neditable.display_name, neditable)
# Editor Signals
self.connect(editor, SIGNAL("cursorPositionChanged()"),
self._update_cursor_position)
self.connect(editor, SIGNAL("editorFocusObtained()"),
self._editor_with_focus)
self.connect(editor, SIGNAL("currentLineChanged(int)"),
self._set_current_symbol)
self.connect(editor, SIGNAL("modificationChanged(bool)"),
self._editor_modified)
self.connect(neditable, SIGNAL("checkersUpdated(PyQt_PyObject)"),
self._show_notification_icon)
self.connect(neditable, SIGNAL("fileSaved(PyQt_PyObject)"),
self._update_symbols)
self.connect(neditable, SIGNAL("fileSaved(PyQt_PyObject)"),
self._update_combo_info)
# Connect file system signals only in the original
self.connect(neditable, SIGNAL("fileClosing(PyQt_PyObject)"),
self._close_file)
if self.__original:
self.connect(neditable,
SIGNAL("neverSavedFileClosing(PyQt_PyObject)"),
self._ask_for_save)
self.connect(neditable, SIGNAL("fileChanged(PyQt_PyObject)"),
self._file_has_been_modified)
#.........这里部分代码省略.........
示例3: _MainContainer
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import currentWidget [as 别名]
#.........这里部分代码省略.........
self.add_widget(self.splitter)
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):
self.stack.addWidget(widget)
def remove_widget(self, widget):
self.stack.removeWidget(widget)
def _close_dialog(self, widget):
self.emit(SIGNAL("closeDialog(PyQt_PyObject)"), widget)
self.disconnect(widget, SIGNAL("finished(int)"),
lambda: self._close_dialog(widget))
def show_dialog(self, widget):
self._opening_dialog = True
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.
示例4: ProjectTreeColumn
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import currentWidget [as 别名]
#.........这里部分代码省略.........
self.connect(ptree, SIGNAL("closeProject(PyQt_PyObject)"),
self._close_project)
pmodel = project.model
ptree.setModel(pmodel)
pindex = pmodel.index(pmodel.rootPath())
ptree.setRootIndex(pindex)
self.projects.append(ptree)
current_index = self._projects_area.count()
self._projects_area.setCurrentIndex(current_index - 1)
self._combo_project.setCurrentIndex(current_index - 1)
def _close_project(self, widget):
"""Close the project related to the tree widget."""
index = self._projects_area.currentIndex()
self.projects.remove(widget)
self._projects_area.takeAt(index)
self._combo_project.removeItem(index)
index = self._combo_project.currentIndex()
self._projects_area.setCurrentIndex(index)
ninjaide = IDE.get_service('ide')
ninjaide.filesystem.close_project(widget.project.path)
widget.deleteLater()
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._active_project:
path = self._projects_area.currentWidget().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):
return self._projects_area.currentWidget()
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:
示例5: ComboEditor
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import currentWidget [as 别名]
class ComboEditor(QWidget):
def __init__(self, original=False):
super(ComboEditor, self).__init__()
self.__original = original
self._symbols_index = []
vbox = QVBoxLayout(self)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.setSpacing(0)
self.bar = ActionBar()
vbox.addWidget(self.bar)
self.stacked = QStackedLayout()
vbox.addLayout(self.stacked)
self._main_container = IDE.get_service('main_container')
self.connect(self.bar, SIGNAL("changeCurrent(PyQt_PyObject)"),
self.set_current)
self.connect(self.bar, SIGNAL("runFile(QString)"),
self._run_file)
self.connect(self.bar, SIGNAL("addToProject(QString)"),
self._add_to_project)
self.connect(self.bar, SIGNAL("goToSymbol(int)"),
self._go_to_symbol)
self.connect(self.bar, SIGNAL("reopenTab(QString)"),
lambda path: self._main_container.open_file(path))
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, val):
op = self.bar.code_navigator.operation
self._main_container.navigate_code_history(val, op)
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)
self.connect(neditable.editor, SIGNAL("currentLineChanged(int)"),
self._set_current_symbol)
self.connect(neditable, SIGNAL("checkersUpdated(PyQt_PyObject)"),
self._show_notification_icon)
self.connect(neditable, SIGNAL("fileSaved(PyQt_PyObject)"),
self._update_symbols)
# Connect file system signals only in the original
self.connect(neditable, SIGNAL("fileClosing(PyQt_PyObject)"),
self._close_file)
if self.__original:
self.connect(neditable,
SIGNAL("neverSavedFileClosing(PyQt_PyObject)"),
self._ask_for_save)
# Load Symbols
self._load_symbols(neditable)
def show_combo_file(self):
self.bar.combo.showPopup()
def close_current_file(self):
self.bar.about_to_close_file()
def _close_file(self, neditable):
index = self.bar.close_file(neditable)
layoutItem = self.stacked.takeAt(index)
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)
#.........这里部分代码省略.........
示例6: BarraConversa
# 需要导入模块: from PyQt4.QtGui import QStackedLayout [as 别名]
# 或者: from PyQt4.QtGui.QStackedLayout import currentWidget [as 别名]
class BarraConversa(QWidget):
conversasNaoVisualizadas = pyqtSignal(Usuario, int)
def __init__(self, servico, parent=None):
super().__init__(parent)
self._configurarGui()
self._servico = servico
self._servico.dadosUsuarioAtualizado.connect(self._atualizarUsuario)
self._servico.conversaRecebida.connect(self._receberConversa)
self._servico.informacaoTipoValorRecebida.connect(self._receberSituacao)
def _configurarGui(self):
self._stackedLayout = QStackedLayout(self)
self._stackedLayout.setMargin(0)
self.setLayout(self._stackedLayout)
self._mostrarTelaInicial()
def _setNumConversasNaoVisualizadas(self, barraConversaUsuario, numConversasNaoVisualizadas):
barraConversaUsuario.setNumConversasNaoVisualizadas(numConversasNaoVisualizadas)
self.conversasNaoVisualizadas.emit(barraConversaUsuario.getUsuario(), numConversasNaoVisualizadas)
def _receberConversa(self, de, inf):
usuario = Usuario(nome=NOME_DEFAULT, ip=de)
barraConversaUsuario = self._getOrCreateBarraConversaUsuario(usuario)
barraConversaUsuario.receberTexto(inf)
if self._stackedLayout.currentWidget() != barraConversaUsuario:
numConversasNaoVisualizadasAtual = barraConversaUsuario.getNumConversasNaoVisualizadas() + 1
self._setNumConversasNaoVisualizadas(barraConversaUsuario, numConversasNaoVisualizadasAtual)
def _receberSituacao(self, de, tipo, valor):
if tipo == ServicoClienteMensageiro.INFORMACAO:
usuario = Usuario(nome=NOME_DEFAULT, ip=de)
self._getOrCreateBarraConversaUsuario(usuario).atualizarSituacao(valor['informacao'])
def _atualizarUsuario(self, usuario):
self._getOrCreateBarraConversaUsuario(usuario).setUsuario(usuario)
def _mostrarTelaInicial(self):
lbl = QLabel("<- Selecione o Usuário")
self._stackedLayout.insertWidget(0, lbl)
self._stackedLayout.setCurrentIndex(0)
def _setConversaUsuarioAtual(self, barraConversaUsuario):
ind = self._indexWidgetConversa(barraConversaUsuario.getUsuario())
self._stackedLayout.setCurrentIndex(ind)
def _indexWidgetConversa(self, usuario):
for i in range(1, self._stackedLayout.count()):
if self._stackedLayout.widget(i).getUsuario().getIP() == usuario.getIP():
return i
return -1
def _getOrCreateBarraConversaUsuario(self, usuario):
ind = self._indexWidgetConversa(usuario)
if ind != -1:
return self._stackedLayout.widget(ind)
else:
barraConversaUsuario = BarraConversaUsuario(self._servico, usuario)
self._stackedLayout.addWidget(barraConversaUsuario)
return barraConversaUsuario
def setUsuarioAtual(self, usuario):
"""Altera a conversa visível para a conversa do usuário
e reinicia a contagem de conversas não visualizadas."""
barraConversaUsuario = self._getOrCreateBarraConversaUsuario(usuario)
barraConversaUsuario.setUsuario(usuario)
self._setNumConversasNaoVisualizadas(barraConversaUsuario, 0)
self._setConversaUsuarioAtual(barraConversaUsuario)