当前位置: 首页>>代码示例>>Python>>正文


Python QSplitter.restoreState方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QSplitter.restoreState方法的典型用法代码示例。如果您正苦于以下问题:Python QSplitter.restoreState方法的具体用法?Python QSplitter.restoreState怎么用?Python QSplitter.restoreState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QSplitter的用法示例。


在下文中一共展示了QSplitter.restoreState方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import restoreState [as 别名]

#.........这里部分代码省略.........
    # nothing. Just a splitter with, on the left, a tabset for editviews, and
    # on the right, a scrollbar containing a tabset for panels. (Qt Designer
    # note: it is not possible to build this structure with the Designer. It
    # will not let you put the scroll area into the splitter.)
    #
    # TODO: create a custom QTabWidget using a custom QTabBar to implement
    # drag-out-of-tabset behavior, and use those here.
    def _uic(self):
        # Create the tabset that displays editviews
        self.editview_tabset = QTabWidget()
        self.editview_tabset.setMovable(True) # let user move tabs around
        self.editview_tabset.currentChanged.connect(self._editview_change)
        # Create the tabset that displays find, notes, help &etc.
        self.panel_tabset = QTabWidget()
        self.panel_tabset.setMovable(True)
        # Create the splitter that contains the above two parts.
        self.splitter = QSplitter(Qt.Horizontal, self)
        self.splitter.setChildrenCollapsible(False)
        # Give just a little margin to the left of the editor
        self.splitter.setContentsMargins(8,0,0,0)
        self.splitter.addWidget(self.editview_tabset)
        self.splitter.addWidget(self.panel_tabset)
        # Set that splitter as the main window's central (and only) widget
        self.setCentralWidget(self.splitter)
        # Populate the panel tabset with empty widgets just so there will
        # be tabs that _swap can reference.
        for key in self.panel_dict.keys():
            widj = QWidget()
            self.panel_tabset.addTab(widj,key)
            self.panel_dict[key] = widj
        # Size and position ourself based on saved settings.
        self.move(self.settings.value("mainwindow/position", QPoint(50,50)))
        self.resize(self.settings.value("mainwindow/size", C.STARTUP_DEFAULT_SIZE))
        self.splitter.restoreState(
           self.settings.value("mainwindow/splitter",C.STARTUP_DEFAULT_SPLITTER) )
        # Store a reference to the application menubar. In Mac OS this
        # is a parentless menubar; other platforms it is the default.
        if C.PLATFORM_IS_MAC :
            self.menu_bar = QMenuBar() # parentless menu bar for Mac OS
        else :
            self.menu_bar = self.menuBar # refer to the default one
        set_menu_bar(self.menu_bar)
        # Create the File menu, located in our menu_bar.
        self.file_menu = self.menu_bar.addMenu(_TR('Menu name', '&File'))
        # Populate the File menu with actions.
        #  File:New -> _new()
        work = self.file_menu.addAction( _TR('File menu command','&New') )
        work.setShortcut(QKeySequence.New)
        work.setToolTip( _TR('File:New tooltip','Create a new, empty document') )
        work.triggered.connect(self._new)
        #  File:Open -> _file_open()
        work = self.file_menu.addAction( _TR('File menu command','&Open') )
        work.setShortcut(QKeySequence.Open)
        work.setToolTip( _TR('File:Open tooltip','Open an existing book') )
        work.triggered.connect(self._file_open)
        #  File:Save -> _file_save()
        work = self.file_menu.addAction( _TR('File menu command', '&Save') )
        work.setShortcut(QKeySequence.Save)
        work.setToolTip( _TR('File:Save tooltip','Save the active book') )
        work.triggered.connect(self._save)
        #  Save As -> _file_save_as()
        work = self.file_menu.addAction( _TR('File menu command', 'Save &As') )
        work.setShortcut(QKeySequence.SaveAs)
        work.setToolTip( _TR('File:Save As tooltip','Save the active book under a new name') )
        work.triggered.connect(self._save_as)
        #  Close -> _close()
开发者ID:B-Rich,项目名称:PPQT2,代码行数:70,代码来源:mainwindow.py

示例2: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import restoreState [as 别名]

#.........这里部分代码省略.........
        self.addAction(quit_action)
        
        self.vertical_splitter = QSplitter(Qt.Vertical, self)
        self.setCentralWidget(self.vertical_splitter)
        self.load_central_widget()
        
        self.file_menu = self.menuBar().addMenu(self.tr('&File'))
        self.file_menu.addAction(quit_action)
        self.file_menu.addSeparator()
        
        self.module_menu = self.menuBar().addMenu(self.tr('&Modules'))
        self.module_menu.addAction(reload_modules_action)
        self.module_menu.addSeparator()
        
        Alter.invoke_all('main_window_init', self)
        
        #restore main window state
        size = ModuleManager.core['settings'].Settings.value(
            self.KEY_WINDOW_SIZE, QSize(600, 400))
        maximized = ModuleManager.core['settings'].Settings.value(
            self.KEY_WINDOW_MAXIMIZED, False)
        position = ModuleManager.core['settings'].Settings.value(
            self.KEY_WINDOW_POSITION, QPoint(0,0))
        if maximized == 'true':
            self.showMaximized()
        else:
            self.resize(size)
            self.move(position)
    
    def closeEvent(self, event):
        self.on_quit()
    
    def save_state(self):
        ModuleManager.core['settings'].Settings.set_value(
            self.KEY_WINDOW_SIZE, self.size())
        ModuleManager.core['settings'].Settings.set_value(
            self.KEY_WINDOW_MAXIMIZED, self.isMaximized())
        ModuleManager.core['settings'].Settings.set_value(
            self.KEY_WINDOW_POSITION, self.pos())
        ModuleManager.core['settings'].Settings.set_value(
            self.KEY_H_SPLITTER_STATE, self.horizontal_splitter.saveState())
    
    def on_quit(self):
        self.save_state()
        self.close()
    
    def load_central_widget(self):
        self.populate_central_widget()
        self.connect_widgets()
    
    def populate_central_widget(self):
        self.vertical_widgets = collections.OrderedDict()
        
        self.horizontal_splitter = QSplitter(
            Qt.Horizontal, self.vertical_splitter)
        self.horizontal_widgets = collections.OrderedDict()
        self.vertical_widgets["horizontal_splitter"] = self.horizontal_splitter
        
        Alter.invoke_all(
            'main_window_add_vertical_widget',
            self.vertical_widgets,
            self
        )
        for widget in self.vertical_widgets.values():
            self.vertical_splitter.addWidget(widget)
        
        Alter.invoke_all(
            'main_window_add_horizontal_widget',
            self.horizontal_widgets,
            self.vertical_splitter
        )
        for widget in self.horizontal_widgets.values():
            self.horizontal_splitter.addWidget(widget)
        
        #restore horizontal splitter state
        state = ModuleManager.core['settings'].Settings.value(
            self.KEY_H_SPLITTER_STATE,
            None
        )
        if state:
            self.horizontal_splitter.restoreState(state)
    
    def connect_widgets(self):
        Alter.invoke_all(
            'main_window_connect_widgets', 
            self.vertical_widgets, 
            self.horizontal_widgets
        )
    
    def reload_central_widget(self):
        self.save_state()
        for index in range(self.vertical_splitter.count()):
            widget = self.vertical_splitter.widget(index)
            widget.hide()
            widget.setParent(None)
            del widget
        Alter.clear()
        ModuleManager.reload_all_modules('core')
        ModuleManager.reload_all_modules('custom')
        self.load_central_widget()
开发者ID:FlorianPerrot,项目名称:Mojuru,代码行数:104,代码来源:main_window.py

示例3: SubTabWidget

# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import restoreState [as 别名]

#.........这里部分代码省略.........
        splitterLayout = QVBoxLayout(splitterHandle)
        splitterLayout.setSpacing(0)
        splitterLayout.setContentsMargins(0, 0, 0, 0)

        line = QFrame(splitterHandle)
        line.setFrameShape(QFrame.HLine)
        line.setFrameShadow(QFrame.Sunken)
        splitterLayout.addWidget(line)
        splitterHandle.setLayout(splitterLayout)

    def _createTabName(self, name, cleanState):
        if cleanState is True:
            return name
        else:
            return "%s +" % name

    def _cleanStateForFileChanged(self, filePath, cleanState):
        page = self.tabByPath(filePath)
        if page is not None:
            for i in range(self.tabBar.count()):
                if self.tabBar.tabText(i)[:len(page.name)] == page.name:
                    self.tabBar.setTabText(i, self._createTabName(page.name, cleanState))
                    return

    def saveWidgetState(self, settings):
        settings.setState(self.splitter, self.splitter.saveState())
        settings.setHidden(self._toolbox, self._toolbox.isHidden())

    def restoreWidgetState(self, settings):
        self.showPanel(not settings.getHidden(self._toolbox))

        splitterState = settings.getState(self.splitter)
        if not splitterState.isEmpty():
            self.splitter.restoreState(settings.getState(self.splitter))

    @pyqtSlot(str, bool)
    def openTab(self, filePath, background=False):
        if self._subtitleData.fileExists(filePath):
            tabIndex = self.__addTab(filePath)
            if background is False:
                self.showTab(tabIndex)
        else:
            log.error(_("SubtitleEditor not created for %s!" % filePath))

    @pyqtSlot(str)
    def removeFile(self, filePath):
        tab = self.tabByPath(filePath)
        command = RemoveFile(filePath)
        if tab is not None:
            index = self.pages.indexOf(tab)
            if self.closeTab(index):
                self._subtitleData.execute(command)
        else:
            self._subtitleData.execute(command)


    @pyqtSlot(int)
    def closeTab(self, index):
        tab = self.tab(index)
        if tab.canClose():
            widgetToRemove = self.pages.widget(index)
            self.tabBar.removeTab(index)
            self.pages.removeWidget(widgetToRemove)
            widgetToRemove.deleteLater()
            return True
        return False
开发者ID:mgoral,项目名称:subconvert,代码行数:70,代码来源:SubtitleWindow.py

示例4: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import restoreState [as 别名]

#.........这里部分代码省略.........
        
        
        #----------------------------------------------------
        #
        #    Window
        #
        self.setWindowTitle(self.PROGRAM_NAME)
        Settings = QSettings('kicad-tools', 'Schematic Component Manager')
        #print(Settings.allKeys())
        if Settings.contains('geometry'):
            self.restoreGeometry( Settings.value('geometry') )
        else:
            self.setGeometry(100, 100, 1024, 768)

        if Settings.contains('cmptable'):
            w0, w1 = Settings.value('cmptable')
            self.CmpTable.setColumnWidth( 0, int(w0) )
            self.CmpTable.setColumnWidth( 1, int(w1) )
            
        if Settings.contains('selector'):
            w0, w1 = Settings.value('selector')
            self.Selector.setColumnWidth( 0, int(w0) )
            self.Selector.setColumnWidth( 1, int(w1) )
                        
        if Settings.contains('inspector'):
            w0, w1 = Settings.value('inspector')
            self.Inspector.setColumnWidth( 0, int(w0) )
            self.Inspector.setColumnWidth( 1, int(w1) )
            self.FieldInspector.setColumnWidth( 0, int(w0) )
            self.FieldInspector.setColumnWidth( 1, int(w1) )
            #self.Inspector.setColumnWidth( 2, int(w2) )
            
        if Settings.contains('splitter'):
            self.Splitter.restoreState( Settings.value('splitter') )
            
        if Settings.contains('inssplitter'):
            self.InspectorSplit.restoreState( Settings.value('inssplitter') )
            
        #----------------------------------------------------
        #
        #    Process command line arguments
        #
        if len(sys.argv) > 1:
            fname = sys.argv[1]
            if os.path.exists(fname):
                self.CmpTable.load_file(fname)
            else:
                print('E: input file "' + fname + '"does not exist')
            
        self.show()
    #---------------------------------------------------------------------------
    def closeEvent(self, event):
        Settings = QSettings('kicad-tools', 'Schematic Component Manager')
        Settings.setValue( 'geometry', self.saveGeometry() )
        Settings.setValue( 'cmptable',  [self.CmpTable.columnWidth(0), self.CmpTable.columnWidth(1)] )
        Settings.setValue( 'selector',  [self.Selector.columnWidth(0), self.Selector.columnWidth(1)] )
        Settings.setValue( 'inspector', [self.Inspector.columnWidth(0), self.Inspector.columnWidth(1)] )
        Settings.setValue( 'splitter', self.Splitter.saveState() )
        Settings.setValue( 'inssplitter', self.InspectorSplit.saveState() )
        QWidget.closeEvent(self, event)
    #---------------------------------------------------------------------------
    def open_file(self):
        #filename = QFileDialog.getOpenFileName(self, 'Open schematic file', '/opt/cad/kicad', 'KiCad Schematic Files (*.sch)')
        dialog = QFileDialog(self)
        dialog.setFileMode(QFileDialog.ExistingFile)
        dialog.setNameFilter('KiCad Schematic Files (*.sch)')
开发者ID:harryzhurov,项目名称:kicad-tools,代码行数:70,代码来源:scmgr.py

示例5: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import restoreState [as 别名]
class MainWindow(QWidget):
    def __init__(self, appConfig, projectorControl, parent=None):

        self.PHOTO_DELTAS_FILE_NAME = "//MACALLAN/Photos/Photo Info/Deltas/PhotoDeltas.txt"
        QWidget.__init__(self, parent)
        self._projectorControl = projectorControl
        # File used for delta changes to photos
        self.photoDeltas = PhotoDeltas(self.PHOTO_DELTAS_FILE_NAME)
        # Frameless window
        self.setWindowFlags(Qt.FramelessWindowHint)
        # Background to black
        self.setAutoFillBackground(True)
        palette = QPalette()
        palette.setColor(QPalette.Background, Qt.black)
        self.setPalette(palette)
        # Clock
        self.clock = AnimatedClock()
        # Calendar
        self.calendar = AnimatedCalendar(calUpdateSecs=600, calServerUrl=appConfig["calServerUrl"])
        # Image
        # self.photos = AnimatedPhotos("//macallan/photos/PhotosMain/", ["jpg"], maxCols=3, maxRows=4, borders=[0,0,0,0], xBetweenPics=5, yBetweenPics=5, animationSpeed=1.0, picChangeMs=5000)
        self.photos = StaticPhotos("//macallan/photos/PhotosMain/", ["jpg"], self.photoDeltas, picChangeMs=5000)
        #self.photos = CaptionedPhotos("//macallan/photos/PhotosMain/", ["jpg"], picChangeMs=5000)

        # Toolbar
        self.windowToolbar = WindowToolbar(self.close, self)

        # Left pane of page
        self.leftPane = QSplitter(Qt.Vertical)
        self.leftPane.addWidget(self.clock)
        self.leftPane.addWidget(self.calendar)
        # Right pane of page
        self.rightPane = QSplitter(Qt.Vertical)
        self.rightPane.addWidget(self.windowToolbar)
        self.rightPane.addWidget(self.photos)
        # Splitter between left and right panes
        self.horzSplitter = QSplitter(Qt.Horizontal)
        self.horzSplitter.addWidget(self.leftPane)
        self.horzSplitter.addWidget(self.rightPane)
        self.layout = QHBoxLayout(self)
        self.layout.addWidget(self.horzSplitter)
        self.setLayout(self.layout)

        # Remember the locations of the splitter bars to restore next time the program is run
        settings = QSettings("PhotoCalendar")
        settings.beginGroup("MainWindow")
        position = settings.value("Position", QVariant(QPoint(0, 0)))
        self.move(position)
        size = settings.value("Size", QVariant(QSize(1920, 1200)))
        self.resize(size)
        if settings.value("HorzSplitter") is not None:
            self.horzSplitter.restoreState(settings.value("HorzSplitter"))
            #print("Restoring horz", settings.value("HorzSplitter"))
        if settings.value("LeftPaneSplitter") is not None:
            self.leftPane.restoreState(settings.value("LeftPaneSplitter"))
            #print("Restoring left pane", settings.value("LeftPaneSplitter"))
        if settings.value("RightPaneSplitter") is not None:
            self.rightPane.restoreState(settings.value("RightPaneSplitter"))
            #print("Restoring right pane", settings.value("RightPaneSplitter"))
        settings.endGroup()

        # Start rotating photos
        self.photos.start()

        # # Grid layout
        # layout = QGridLayout()
        # # layout.setContentsMargins(0,0,0,0)
        # layout.setSpacing(0)
        # layout.addWidget(self.clock, 0, 0)
        # layout.addWidget(self.calendar, 1, 0)
        # layout.addWidget(self.photos, 0, 1, 2, 1)
        # layout.setColumnStretch(0, 1)
        # layout.setColumnStretch(1, 2.5)
        # self.setLayout(layout)

        # Start photo animation
        self.photos.start()

    def closeEvent(self, event):
        print("Main window close event")
        # Save layout settings
        settings = QSettings("PhotoCalendar")
        settings.beginGroup("MainWindow")
        curSize = self.size()
        settings.setValue("Size", QVariant(curSize))
        curPos = self.pos()
        settings.setValue("Position", QVariant(curPos))
        #settings.setValue("MainWindow/State", QVariant(self.saveState()))
        horzSplitterState = self.horzSplitter.saveState()
        #print("HorzSplitter save", horzSplitterState)
        settings.setValue("HorzSplitter", QVariant(horzSplitterState))
        leftPaneSplitterState = self.leftPane.saveState()
        settings.setValue("LeftPaneSplitter", QVariant(leftPaneSplitterState))
        #print("LeftPaneSplitter save", leftPaneSplitterState)
        rightPaneSplitterState = self.rightPane.saveState()
        settings.setValue("RightPaneSplitter", QVariant(rightPaneSplitterState))
        #print("RightPaneSplitter save", leftPaneSplitterState)
        settings.endGroup()
        # Stop the sub-elements
        self.calendar.stop()
#.........这里部分代码省略.........
开发者ID:robdobsn,项目名称:KitchenProjectorCalPhotoApp,代码行数:103,代码来源:MainWindow.py

示例6: MainForm

# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import restoreState [as 别名]

#.........这里部分代码省略.........
      self.filterBox.textChanged.connect(self.refresh)
      self.filterLayout.addWidget(self.filterBox)
      
      self.sizeGrip = QSizeGrip(self)
      self.sizeGrip.setMinimumSize(QSize(25, 25))
      self.filterLayout.addWidget(self.sizeGrip, 0, Qt.AlignRight | Qt.AlignTop)
      
      self.buttonListLayout.addLayout(self.filterLayout)
      
      # Top buttons and labels
      self.backButton = QPushButton('Favorites')
      self.backButton.setMinimumHeight(35)
      self.backButton.clicked.connect(self.backClicked)
      self.buttonLayout.addWidget(self.backButton, 1)
      
      self.currentLabel = QLabel()
      self.currentLabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
      self.buttonLayout.addWidget(self.currentLabel, 1)
      
      self.buttonListLayout.addLayout(self.buttonLayout, 0)
      
      # Menu item display
      self.listSplitter = QSplitter()
      self.buttonListLayout.addWidget(self.listSplitter, 1)
      
      self.leftList = ListWidget(self.clearListMouseOver)
      self.listSplitter.addWidget(self.leftList)
      
      self.rightList = ListWidget(self.clearListMouseOver)
      self.listSplitter.addWidget(self.rightList)
      
      # Has to be done after adding widgets to the splitter or the size will get reset again
      if 'splitterState' in self.settings:
         self.listSplitter.restoreState(self.settings['splitterState'])
      
   def setMargins(self, layout, margin = 0):
      layout.setSpacing(margin)
      layout.setContentsMargins(margin, margin, margin, margin)
      
      
   def createMenu(self, widget):
      addFavoriteAction = QAction('Add to Favorites', self)
      addFavoriteAction.triggered.connect(self.addFavoriteClicked)
      widget.insertAction(None, addFavoriteAction)
      addAction = QAction("New...", self)
      addAction.triggered.connect(self.newClicked)
      widget.insertAction(None, addAction)
      editAction = QAction("Edit...", self)
      editAction.triggered.connect(self.editClicked)
      widget.insertAction(None, editAction)
      deleteAction = QAction("Delete", self)
      deleteAction.triggered.connect(self.deleteClicked)
      widget.insertAction(None, deleteAction)
      
      
   def hideOrClose(self):
      if self.settings['quit']:
         self.close()
      else:
         self.hide()
         
   def closeEvent(self, event):
      self.saveSettings()
      
   def hideEvent(self, event):
      self.releaseMouse()
开发者ID:cybertron,项目名称:nemu,代码行数:70,代码来源:MainForm.py

示例7: MainWindow

# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import restoreState [as 别名]

#.........这里部分代码省略.........
            self.KEY_WINDOW_SIZE, self.size())
        ModuleManager.core['settings'].Settings.set_value(
            self.KEY_WINDOW_MAXIMIZED, self.isMaximized())
        ModuleManager.core['settings'].Settings.set_value(
            self.KEY_WINDOW_POSITION, self.pos())
        ModuleManager.core['settings'].Settings.set_value(
            self.KEY_H_SPLITTER_STATE, self.horizontal_splitter.saveState())
    
    def on_quit(self):
        self.save_state()
        self.close()
    
    def load_central_widget(self):
        self.populate_central_widget()
        self.connect_widgets()
    
    def populate_central_widget(self):
        self.vertical_widgets = collections.OrderedDict()
        
        self.horizontal_splitter = QSplitter(
            Qt.Horizontal, self.vertical_splitter)
        self.horizontal_widgets = collections.OrderedDict()
        self.vertical_widgets["horizontal_splitter"] = self.horizontal_splitter
        
        Alter.invoke_all(
            'main_window_add_vertical_widget',
            self.vertical_widgets,
            self
        )
        for widget in self.vertical_widgets.values():
            self.vertical_splitter.addWidget(widget)
        
        Alter.invoke_all(
            'main_window_add_horizontal_widget',
            self.horizontal_widgets,
            self.vertical_splitter
        )
        for widget in self.horizontal_widgets.values():
            self.horizontal_splitter.addWidget(widget)
        
        #restore horizontal splitter state
        state = ModuleManager.core['settings'].Settings.value(
            self.KEY_H_SPLITTER_STATE,
            None
        )
        if state:
            self.horizontal_splitter.restoreState(state)
    
    def connect_widgets(self):
        Alter.invoke_all(
            'main_window_connect_widgets', 
            self.vertical_widgets, 
            self.horizontal_widgets
        )
    
    def reload_central_widget(self):
        self.save_state()
        for index in range(self.vertical_splitter.count()):
            widget = self.vertical_splitter.widget(index)
            widget.hide()
            widget.setParent(None)
            del widget
        Alter.clear()
        ModuleManager.reload_all_modules('core')
        ModuleManager.reload_all_modules('custom')
        self.load_central_widget()
    
    def add_action(self, name, callback, **kwargs):
        """
        Ajoute une action au context menu et au widget lui même.
        Créer une fonction à la volé pour fournir des arguments aux fonctions
        de rappel.
        """
        action = QAction(name, self)
        if 'icon' in kwargs:
            action.setIcon(kwargs['icon'])
        if 'shortcut' in kwargs:
            action.setShortcut(kwargs['shortcut'])
        action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        action.triggered.connect(self.__wrapper(callback, **kwargs))
        self.addAction(action)
        if 'menu' in kwargs:
            kwargs['menu'].addAction(action)

    def add_separator(self, menu):
        """Simple abstraction of self.context_menu.addSeparator()"""
        menu.addSeparator()
    
    def __wrapper(self, callback, **kwargs):
        def __new_function():
            """
            __new_function représente la forme de tous les callbacks connecté
            à une action pour pouvoir utiliser les raccourcis en même temps que
            le menu contextuel.
            """
            args = [
                kwargs['instance'] if 'instance' in kwargs else self
            ]
            callback(*args)
        return __new_function
开发者ID:lheido,项目名称:Mojuru,代码行数:104,代码来源:main_window.py

示例8: DatabaseContainer

# 需要导入模块: from PyQt5.QtWidgets import QSplitter [as 别名]
# 或者: from PyQt5.QtWidgets.QSplitter import restoreState [as 别名]

#.........这里部分代码省略.........
    def __on_data_table_changed(self, row, col, data):
        current_relation = self.lateral_widget.current_text()
        # Relation to be update
        rela = self.table_widget.relations.get(current_relation)
        # Clear old content
        rela.clear()
        current_table = self.table_widget.stacked.currentWidget()
        model = current_table.model()
        for i in range(model.rowCount()):
            reg = []
            for j in range(model.columnCount()):
                if row == i and col == j:
                    reg.append(data)
                else:
                    reg.append(model.item(i, j).text())
            # Insert new content
            rela.insert(reg)
        # Update relation
        self.table_widget.relations[current_relation] = rela

    def new_query(self, filename):
        editor_tab_at = self.query_container.is_open(filename)
        if editor_tab_at != -1:
            self.query_container.set_focus_editor_tab(editor_tab_at)
        else:
            query_widget = query_container.QueryWidget()
            # Create object file
            ffile = pfile.File(filename)
            editor = query_widget.get_editor()
            editor.pfile = ffile
            if not filename:
                ffile.filename = 'untitled_{n}.pqf'.format(n=self.__nquery)
            else:
                content = ffile.read()
                editor.setPlainText(content)
            self.query_container.add_tab(query_widget, ffile.display_name)
            self.__nquery += 1

    def save_query(self, editor):
        if not editor:
            editor = self.query_container.currentWidget().get_editor()
        if editor.is_new:
            return self.save_query_as(editor)
        # Get content of editor
        content = editor.toPlainText()
        try:
            editor.pfile.save(content=content)
        except Exception as reason:
            QMessageBox.critical(self, "Error",
                                 self.tr("The file couldn't be saved!"
                                         "\n\n{}".format(reason)))
            return False
        editor.saved()
        return editor.pfile.filename

    def save_query_as(self, editor=None):
        filename = QFileDialog.getSaveFileName(self, self.tr("Save File"),
                                               editor.name,
                                               "Pireal query files(*.pqf)")
        filename = filename[0]
        if not filename:
            return
        # Get the content
        content = editor.toPlainText()
        # Write the file
        editor.pfile.save(content=content, new_fname=filename)
        editor.saved()

    def execute_queries(self):
        self.query_container.execute_queries()

    def execute_selection(self):
        editor = self.query_container.currentWidget().get_editor()
        text_cursor = editor.textCursor()
        if text_cursor.hasSelection():
            query = text_cursor.selectedText()
            self.query_container.execute_queries(query)

    def showEvent(self, event):
        QSplitter.showEvent(self, event)
        qsettings = QSettings(settings.SETTINGS_PATH, QSettings.IniFormat)
        hsizes = qsettings.value('hsplitter_sizes', None)
        if hsizes is not None:
            self._hsplitter.restoreState(hsizes)
        else:
            self._hsplitter.setSizes([1, self._hsplitter.width() / 3])
        vsizes = qsettings.value('vsplitter_sizes', None)
        if vsizes is not None:
            self.restoreState(vsizes)
        else:
            self.setSizes([self.height() / 3, self.height() / 3])

    def save_sizes(self):
        """ Save sizes of Splitters """

        qsettings = QSettings(settings.SETTINGS_PATH, QSettings.IniFormat)
        qsettings.setValue('hsplitter_sizes',
                           self._hsplitter.saveState())
        qsettings.setValue('vsplitter_sizes',
                           self.saveState())
开发者ID:centaurialpha,项目名称:pireal,代码行数:104,代码来源:database_container.py


注:本文中的PyQt5.QtWidgets.QSplitter.restoreState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。