本文整理汇总了Python中PyQt5.QtWidgets.QStackedLayout.currentIndex方法的典型用法代码示例。如果您正苦于以下问题:Python QStackedLayout.currentIndex方法的具体用法?Python QStackedLayout.currentIndex怎么用?Python QStackedLayout.currentIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStackedLayout
的用法示例。
在下文中一共展示了QStackedLayout.currentIndex方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _MainContainer
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
#.........这里部分代码省略.........
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)
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():
示例2: AbstractTemplateWidget
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
class AbstractTemplateWidget(QFrame):
"""
TemplateWidget is used in reports and options tab.
So it needs several common methods and common layout.
But behavior is different. it should be defined in children classes.
"""
def __init__(self, main_window, items):
super().__init__()
self.items = items
self.visible_items = []
self.layout = QStackedLayout()
self.menu_layout = QVBoxLayout()
self.templates_layout = QStackedLayout()
self.showEvent = self._get_show_event(main_window)
self.menu_wrapper = QVBoxLayout()
try:
self.ACTION_BTN_ICON
except AttributeError:
self.ACTION_BTN_ICON = ""
self.setLayout(self.layout)
self.layout.addWidget(self._get_static_widgets())
def _get_static_widgets(self):
"""
Create layout that does not depend on content.
"""
hbox = QHBoxLayout()
self.menu_wrapper.addWidget(utils.get_scrollable(self.menu_layout))
hbox.addLayout(self.menu_wrapper, stretch=30)
hbox.addLayout(self.templates_layout, stretch=70)
widget = QWidget()
widget.setLayout(hbox)
widget.setGraphicsEffect(utils.get_shadow())
return widget
def _iterate_items(self):
"""
Filter items if they has no values.
"""
pass
def hideEvent(self, event):
"""
Clear menu and templates.
"""
utils.clear_layout(self.menu_layout)
utils.clear_layout(self.templates_layout)
def _get_show_event(self, main_window):
"""
Update templates list and re-select them.
"""
def show_event(event):
utils.clear_layout(self.menu_layout)
utils.clear_layout(self.templates_layout)
self.visible_items = self._iterate_items()
self._show_menu()
self._show_templates()
if not self.layout.currentIndex():
main_window.communication.action_button_toggle.emit(
bool(self.visible_items), self.ACTION_BTN_ICON, self.action_btn_function
)
return show_event
def _show_menu(self):
"""
Update menu on showEvent.
"""
for i, item in enumerate(self.visible_items):
b = QRadioButton(self._get_button_name(item))
b.setChecked(i == 0)
b.clicked.connect(functools.partial(self.templates_layout.setCurrentIndex, i))
b.setObjectName("menu_button")
self.menu_layout.addWidget(b)
if not self.visible_items:
self.menu_layout.addStretch()
l = QLabel("Чтобы создать отчет\nначните заполнять данные")
l.setAlignment(Qt.AlignCenter)
self.menu_layout.addWidget(l)
self.menu_layout.addStretch()
def _show_templates(self):
"""
Update templates on shoeEvent.
"""
#.........这里部分代码省略.........
示例3: SettingsDialog
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
class SettingsDialog(QWidget):
"A settings dialog"
scroll_speed_changed = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent, flags=Qt.Window)
self.resize(700, 500)
self.show()
self.restore_values()
self.initUI()
def initUI(self):
main_layout = QVBoxLayout()
sub_layout = QHBoxLayout()
# Left Panel
left_panel = QListWidget()
left_panel.setViewMode(left_panel.ListMode)
#left_panel.setIconSize(QSize(40,40))
left_panel.setTextElideMode(Qt.ElideRight)
left_panel.setMaximumWidth(200)
left_panel.itemClicked.connect(self.change)
#web.setText('Web')
self.application = QListWidgetItem()
self.application.setText('Application')
self.web = QListWidgetItem()
self.web.setText('Web')
self.visual = QListWidgetItem()
self.visual.setText('Visual')
self.advanced = QListWidgetItem()
self.advanced.setText('Advanced')
self.about = QListWidgetItem()
self.about.setText('About')
#main.setIcon(QIcon(os.path.join(gui_constants.static_dir, 'plus2.png')))
left_panel.addItem(self.application)
left_panel.addItem(self.web)
left_panel.addItem(self.visual)
left_panel.addItem(self.advanced)
left_panel.addItem(self.about)
left_panel.setMaximumWidth(100)
# right panel
self.right_panel = QStackedLayout()
self.init_right_panel()
# bottom
bottom_layout = QHBoxLayout()
ok_btn = QPushButton('Ok')
ok_btn.clicked.connect(self.accept)
cancel_btn = QPushButton('Cancel')
cancel_btn.clicked.connect(self.close)
info_lbl = QLabel()
info_lbl.setText('<a href="https://github.com/Pewpews/happypanda">'+
'Visit GitHub Repo</a> | Options marked with * requires application restart.')
info_lbl.setTextFormat(Qt.RichText)
info_lbl.setTextInteractionFlags(Qt.TextBrowserInteraction)
info_lbl.setOpenExternalLinks(True)
self.spacer = QWidget()
self.spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
bottom_layout.addWidget(info_lbl, 0, Qt.AlignLeft)
bottom_layout.addWidget(self.spacer)
bottom_layout.addWidget(ok_btn, 0, Qt.AlignRight)
bottom_layout.addWidget(cancel_btn, 0, Qt.AlignRight)
sub_layout.addWidget(left_panel)
sub_layout.addLayout(self.right_panel)
main_layout.addLayout(sub_layout)
main_layout.addLayout(bottom_layout)
self.restore_options()
self.setLayout(main_layout)
self.setWindowTitle('Settings')
def change(self, item):
def curr_index(index):
if index != self.right_panel.currentIndex():
self.right_panel.setCurrentIndex(index)
if item == self.application:
curr_index(self.application_index)
elif item == self.web:
curr_index(self.web_index)
elif item == self.visual:
curr_index(self.visual_index)
elif item == self.advanced:
curr_index(self.advanced_index)
elif item == self.about:
curr_index(self.about_index)
def restore_values(self):
#Web
self.exprops = settings.ExProperties()
# Visual
self.high_quality_thumbs = gui_constants.HIGH_QUALITY_THUMBS
self.popup_width = gui_constants.POPUP_WIDTH
self.popup_height = gui_constants.POPUP_HEIGHT
self.style_sheet = gui_constants.user_stylesheet_path
# Advanced
#.........这里部分代码省略.........
示例4: SettingsDialog
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
class SettingsDialog(QWidget):
"A settings dialog"
scroll_speed_changed = pyqtSignal()
init_gallery_rebuild = pyqtSignal(bool)
init_gallery_eximport = pyqtSignal(object)
def __init__(self, parent=None):
super().__init__(parent, flags=Qt.Window)
self.init_gallery_rebuild.connect(self.accept)
self.parent_widget = parent
self.setAttribute(Qt.WA_DeleteOnClose)
self.resize(700, 500)
self.restore_values()
self.initUI()
self.setWindowTitle('Settings')
self.show()
def initUI(self):
main_layout = QVBoxLayout(self)
sub_layout = QHBoxLayout()
# Left Panel
left_panel = QListWidget()
left_panel.setViewMode(left_panel.ListMode)
#left_panel.setIconSize(QSize(40,40))
left_panel.setTextElideMode(Qt.ElideRight)
left_panel.setMaximumWidth(200)
left_panel.itemClicked.connect(self.change)
#web.setText('Web')
self.application = QListWidgetItem()
self.application.setText('Application')
self.web = QListWidgetItem()
self.web.setText('Web')
self.visual = QListWidgetItem()
self.visual.setText('Visual')
self.advanced = QListWidgetItem()
self.advanced.setText('Advanced')
self.about = QListWidgetItem()
self.about.setText('About')
#main.setIcon(QIcon(os.path.join(app_constants.static_dir, 'plus2.png')))
left_panel.addItem(self.application)
left_panel.addItem(self.web)
left_panel.addItem(self.visual)
left_panel.addItem(self.advanced)
left_panel.addItem(self.about)
left_panel.setMaximumWidth(100)
# right panel
self.right_panel = QStackedLayout()
self.init_right_panel()
# bottom
bottom_layout = QHBoxLayout()
ok_btn = QPushButton('Ok')
ok_btn.clicked.connect(self.accept)
cancel_btn = QPushButton('Cancel')
cancel_btn.clicked.connect(self.close)
info_lbl = QLabel()
info_lbl.setText('<a href="https://github.com/Pewpews/happypanda">'+
'Visit GitHub Repo</a> | Options marked with * requires application restart.')
info_lbl.setTextFormat(Qt.RichText)
info_lbl.setTextInteractionFlags(Qt.TextBrowserInteraction)
info_lbl.setOpenExternalLinks(True)
self.spacer = QWidget()
self.spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
bottom_layout.addWidget(info_lbl, 0, Qt.AlignLeft)
bottom_layout.addWidget(self.spacer)
bottom_layout.addWidget(ok_btn, 0, Qt.AlignRight)
bottom_layout.addWidget(cancel_btn, 0, Qt.AlignRight)
sub_layout.addWidget(left_panel)
sub_layout.addLayout(self.right_panel)
main_layout.addLayout(sub_layout)
main_layout.addLayout(bottom_layout)
self.restore_options()
def change(self, item):
def curr_index(index):
if index != self.right_panel.currentIndex():
self.right_panel.setCurrentIndex(index)
if item == self.application:
curr_index(self.application_index)
elif item == self.web:
curr_index(self.web_index)
elif item == self.visual:
curr_index(self.visual_index)
elif item == self.advanced:
curr_index(self.advanced_index)
elif item == self.about:
curr_index(self.about_index)
def restore_values(self):
#Web
self.exprops = settings.ExProperties()
# Visual
self.high_quality_thumbs = app_constants.HIGH_QUALITY_THUMBS
#.........这里部分代码省略.........
示例5: AppWindow
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
#.........这里部分代码省略.........
gallery_action_random = gallery_menu.addAction("Open random gallery")
gallery_action_random.triggered.connect(self.manga_list_view.open_random_gallery)
self.toolbar.addWidget(gallery_action)
misc_action = QToolButton()
misc_action.setText('Tools ')
misc_action_menu = QMenu()
misc_action.setMenu(misc_action_menu)
misc_action.setPopupMode(QToolButton.InstantPopup)
misc_action.setToolTip("Contains misc. features")
gallery_downloader = QAction("Gallery Downloader", misc_action_menu)
gallery_downloader.triggered.connect(self.download_window.show)
misc_action_menu.addAction(gallery_downloader)
duplicate_check_simple = QAction("Simple Duplicate Finder", misc_action_menu)
duplicate_check_simple.triggered.connect(lambda: self.manga_list_view.duplicate_check())
misc_action_menu.addAction(duplicate_check_simple)
self.toolbar.addWidget(misc_action)
spacer_middle = QWidget() # aligns buttons to the right
spacer_middle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.toolbar.addWidget(spacer_middle)
sort_action = QToolButton()
sort_action.setIcon(QIcon(app_constants.SORT_PATH))
sort_action.setMenu(misc.SortMenu(self.toolbar, self.manga_list_view))
sort_action.setPopupMode(QToolButton.InstantPopup)
self.toolbar.addWidget(sort_action)
self.grid_toggle_g_icon = QIcon(app_constants.GRID_PATH)
self.grid_toggle_l_icon = QIcon(app_constants.LIST_PATH)
self.grid_toggle = QToolButton()
if self.display.currentIndex() == self.m_l_view_index:
self.grid_toggle.setIcon(self.grid_toggle_l_icon)
else:
self.grid_toggle.setIcon(self.grid_toggle_g_icon)
self.grid_toggle.setObjectName('gridtoggle')
self.grid_toggle.clicked.connect(self.toggle_view)
self.toolbar.addWidget(self.grid_toggle)
spacer_mid2 = QWidget()
spacer_mid2.setFixedSize(QSize(5, 1))
self.toolbar.addWidget(spacer_mid2)
def set_search_case(b):
app_constants.GALLERY_SEARCH_CASE = b
settings.set(b, 'Application', 'gallery search case')
settings.save()
def set_search_strict(b):
app_constants.GALLERY_SEARCH_STRICT = b
settings.set(b, 'Application', 'gallery search strict')
settings.save()
self.search_bar = misc.LineEdit()
search_options = self.search_bar.addAction(QIcon(app_constants.SEARCH_OPTIONS_PATH), QLineEdit.TrailingPosition)
search_options_menu = QMenu(self)
search_options.triggered.connect(lambda: search_options_menu.popup(QCursor.pos()))
search_options.setMenu(search_options_menu)
case_search_option = search_options_menu.addAction('Case Sensitive')
case_search_option.setCheckable(True)
case_search_option.setChecked(app_constants.GALLERY_SEARCH_CASE)
case_search_option.toggled.connect(set_search_case)
strict_search_option = search_options_menu.addAction('Match whole terms')
strict_search_option.setCheckable(True)
示例6: AppWindow
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
#.........这里部分代码省略.........
else:
try:
re.compile(case_ins)
except re.error:
return
self.manga_list_view.sort_model.search(case_ins)
def popup(self, index):
if not self.popup_window.isVisible():
m_x = QCursor.pos().x()
m_y = QCursor.pos().y()
d_w = QDesktopWidget().width()
d_h = QDesktopWidget().height()
p_w = gui_constants.POPUP_WIDTH
p_h = gui_constants.POPUP_HEIGHT
index_rect = self.manga_list_view.visualRect(index)
index_point = self.manga_list_view.mapToGlobal(index_rect.topRight())
# adjust so it doesn't go offscreen
if d_w - m_x < p_w and d_h - m_y < p_h: # bottom
self.popup_window.move(m_x - p_w + 5, m_y - p_h)
elif d_w - m_x > p_w and d_h - m_y < p_h:
self.popup_window.move(m_x + 5, m_y - p_h)
elif d_w - m_x < p_w:
self.popup_window.move(m_x - p_w + 5, m_y + 5)
else:
self.popup_window.move(index_point)
self.popup_window.set_gallery(index.data(Qt.UserRole + 1))
self.popup_window.show()
def favourite_display(self):
"Switches to favourite display"
if self.display.currentIndex() == self.m_l_view_index:
self.manga_list_view.sort_model.fav_view()
else:
self.manga_table_view.sort_model.fav_view()
def catalog_display(self):
"Switches to catalog display"
if self.display.currentIndex() == self.m_l_view_index:
self.manga_list_view.sort_model.catalog_view()
else:
self.manga_table_view.sort_model.catalog_view()
def settings(self):
sett = settingsdialog.SettingsDialog(self)
sett.scroll_speed_changed.connect(self.manga_list_view.updateGeometries)
# sett.show()
def init_toolbar(self):
self.toolbar = QToolBar()
self.toolbar.setFixedHeight(25)
self.toolbar.setWindowTitle("Show") # text for the contextmenu
# self.toolbar.setStyleSheet("QToolBar {border:0px}") # make it user defined?
self.toolbar.setMovable(False)
self.toolbar.setFloatable(False)
# self.toolbar.setIconSize(QSize(20,20))
self.toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
spacer_start = QWidget() # aligns the first actions properly
spacer_start.setFixedSize(QSize(10, 1))
self.toolbar.addWidget(spacer_start)
favourite_view_icon = QIcon(gui_constants.STAR_BTN_PATH)
favourite_view_action = QAction(favourite_view_icon, "Favorites", self)
示例7: ComboEditor
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [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:
#.........这里部分代码省略.........
示例8: ComboEditor
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [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)
#.........这里部分代码省略.........
示例9: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
#.........这里部分代码省略.........
for i, frame in enumerate(frames):
if isinstance(frame, DataWidget):
self.data_frame_index = i
if isinstance(frame, UsersWidget):
self.user_frame_index = i
self.frames_layout.addWidget(frame)
self.frames_layout.setCurrentIndex(len(frames) - 1)
def _set_sys_attributes(self):
"""
Set sys attributes like window titile.
Disable OS-specific buttons.
Remove borders.
"""
self.setWindowFlags(Qt.FramelessWindowHint)
self.setWindowTitle('Hospital Helper')
dw = QDesktopWidget()
w = min(1300, dw.geometry().size().width() * 0.75)
self.setFixedSize(w, w * 0.6)
qr = self.frameGeometry()
cp = dw.availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def menu_btn_clicked(self, index):
"""
Callback to switch between main frames.
"""
if self.frames_layout.currentIndex() == index == self.data_frame_index:
self.communication.toggle_select_item.emit()
return
else:
self.communication.set_select_item_visibility.emit(False)
self.frames_layout.setCurrentIndex(index)
def input_changed(self, item):
"""
Change TopFrame label when client name is changed.
Emit signal for TopFrame.
"""
# Well it doesnt look good, but i was never good with UI.
if self.items.index(item) == 0:
text = []
for i, key in enumerate(item.keys()):
if item[key]:
text.append(str(item[key]))
if i == 2:
break
self.communication.input_changed_signal.emit(' '.join(text))
def _set_shortcuts(self):
"""
Set shortcuts for fast items switch on DataWidget.
"""
def _shortcut_callback(key):
if self.frames_layout.currentIndex() != self.data_frame_index:
return
self.communication.shortcut_pressed.emit(key)
示例10: ProjectTreeColumn
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
class ProjectTreeColumn(QDialog):
dockWidget = pyqtSignal("QObject*")
undockWidget = pyqtSignal()
changeTitle = pyqtSignal("QObject*", str)
def __init__(self, parent=None):
super(ProjectTreeColumn, self).__init__(parent,
Qt.WindowStaysOnTopHint)
vbox = QVBoxLayout(self)
vbox.setSizeConstraint(QVBoxLayout.SetDefaultConstraint)
vbox.setContentsMargins(0, 0, 0, 0)
self._buttons = []
self._combo_project = QComboBox()
self._combo_project.setMinimumHeight(30)
self._combo_project.setContextMenuPolicy(Qt.CustomContextMenu)
vbox.addWidget(self._combo_project)
self._projects_area = QStackedLayout()
logger.debug("This is the projects area")
logger.debug(self._projects_area)
vbox.addLayout(self._projects_area)
self.projects = []
self._combo_project.currentIndexChanged[int].connect(self._change_current_project)
self._combo_project.customContextMenuRequested['const QPoint &'].connect(self.context_menu_for_root)
connections = (
{'target': 'main_container',
'signal_name': 'addToProject',#(QString)
'slot': self._add_file_to_project},
{'target': 'main_container',
'signal_name': 'showFileInExplorer',#(QString)
'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.getInstance()
ui_tools.install_shortcuts(self, actions.PROJECTS_TREE_ACTIONS, ide)
ide.goingDown.connect(self.close)
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):
print("open_project_folder", folderName)
if settings.WORKSPACE:
directory = settings.WORKSPACE
else:
directory = os.path.expanduser("~")
if folderName is None:
folderName = QFileDialog.getExistingDirectory(
self, translations.TR_OPEN_PROJECT_DIRECTORY, directory)
logger.debug("Choosing Foldername")
if folderName:
logger.debug("Opening %s" % folderName)
self._open_project_folder(folderName)
def _open_project_folder(self, folderName):
ninjaide = IDE.get_service("ide")
project = NProject(folderName)
qfsm = ninjaide.filesystem.open_project(project)
if qfsm:
self.add_project(project)
self.save_recent_projects(folderName)
main_container = IDE.get_service('main_container')
if main_container:
main_container.show_editor_area()
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 _add_file_to_project(self, path):
"""Add the file for 'path' in the project the user choose here."""
if self._projects_area.count() > 0:
pathProject = [self.current_project]
addToProject = add_to_project.AddToProject(pathProject, self)
addToProject.exec_()
if not addToProject.pathSelected:
return
#.........这里部分代码省略.........
示例11: OptionsWidget
# 需要导入模块: from PyQt5.QtWidgets import QStackedLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QStackedLayout import currentIndex [as 别名]
class OptionsWidget(QWidget):
"""
Widget holds menu with all options.
"""
def __init__(self, main_window, items):
super().__init__()
self.items = items
self.layout = QStackedLayout()
self._switch_user = self._get_switch_user_func(main_window)
self.setLayout(self.layout)
self._hide_action_button = lambda: main_window.communication.action_button_toggle.emit(False, '', None)
self._create_layout(main_window)
def set_current_index(self, index):
self.layout.setCurrentIndex(index)
if not index:
self._hide_action_button()
def showEvent(self, event):
if not self.layout.currentIndex():
self._hide_action_button()
def _get_switch_user_func(self, main_window):
def _switch_user():
main_window.menu_btn_clicked(main_window.user_frame_index)
self.layout.setCurrentIndex(0)
return _switch_user
def _get_template_import_func(self, main_window):
func = self._wrap_template_func(template.Template.import_, main_window)
def _alert_callback(path, value):
if value:
func(path[0])
def _f():
path = QFileDialog.getOpenFileName(main_window, 'Выберите файл', options.DATABASE_DIR)
if path:
main_window.create_alert('Шаблоны с одинаковыми именами будут перезаписаны.'
'\nПродолжить?', functools.partial(_alert_callback, path))
return _f
def _get_template_export_func(self, main_window):
func = self._wrap_template_func(template.Template.export, main_window)
def _f():
path = QFileDialog.getExistingDirectory(main_window, 'Выберите путь', options.DATABASE_DIR)
if path:
return func(path)
return _f
@staticmethod
def _wrap_template_func(func, main_window):
def _f(path):
ok, result = func(path)
if ok:
main_window.show_message('Готово')
else:
main_window.create_alert('Произошла ошибка\n{}'.format(result.get('error')))
return ok, result
return _f
def _create_layout(self, main_window):
wrapper = QHBoxLayout()
self.layout.addWidget(utils.get_scrollable(wrapper))
rows = 8
cols = 3
vboxes = [QVBoxLayout() for _ in range(cols)]
widgets = ((TemplateWidgetInOptions(main_window, self.items, self), 'Шаблоны'),
(UsersAndGroupsWidget(main_window, self), 'Пользователи и группы'),
(self._switch_user, 'Сменить пользователя'),
(self._get_template_export_func(main_window), 'Экспортировать шаблоны'),
(self._get_template_import_func(main_window), 'Импортировать шаблоны'))
for i, widget in enumerate(widgets):
b = QPushButton(widget[1])
if callable(widget[0]):
b.clicked.connect(widget[0])
else:
b.clicked.connect(functools.partial(self.layout.setCurrentIndex, i + 1))
self.layout.addWidget(widget[0])
b.setGraphicsEffect(utils.get_shadow())
vboxes[(i // rows) % cols].addWidget(b)
for each in vboxes:
each.addStretch()
wrapper.addLayout(each, stretch=int(100 / cols))