Example #1
0
 def closeEvent(self, *args, **kwargs):
     self.save_settings()
     # Enable paste of clipboard after termination
     clipboard = QtGui.QApplication.clipboard()
     event = QtCore.QEvent(QtCore.QEvent.Clipboard)
     QtGui.QApplication.sendEvent(clipboard, event)
     return QtGui.QMainWindow.closeEvent(self, *args, **kwargs)
Example #2
0
    def __init__(self, tab_widget):
        QTabWidget.__init__(self)
        self.tab_widget = tab_widget
        self.setTabsClosable(True)
        self.setMovable(True)
        self.insertTab(0, QtGui.QWidget(), "")
        self.new_label = QLabel("*")
        self.tabBar().setTabButton(0, QtGui.QTabBar.RightSide, self.new_label)
        self.currentChanged.connect(self.current_tab_changed)
        QtCore.QObject.connect(self, QtCore.SIGNAL("tabCloseRequested(int)"), self.close_tab)
        QtCore.QObject.connect(self.tabBar(), QtCore.SIGNAL("tabMoved(int,int)"), self.tabMoved)

        self.labels = lambda: [str(self.tabBar().tabText(i)).lower() for i in range(self.count())]
        self.tabBar().setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tabBar().customContextMenuRequested.connect(self.openMenu)
        self.add_tab()
Example #3
0
 def load_setting(self, key, default_value=None):
     settings = QtCore.QSettings(
         "QtGuiApplication",
         "%s_%s" % (self.app_name, self.__class__.__name__))
     setting = settings.value(self.ui_module.__name__ + "/" + key,
                              default_value)
     try:
         setting = setting.toString()
     except:
         pass  #fails in pyside
     return str(setting)
Example #4
0
 def load_settings(self):
     settings = QtCore.QSettings(
         "QtGuiApplication",
         "%s_%s" % (self.app_name, self.__class__.__name__))
     geometry = settings.value(self.ui_module.__name__ + "/geometry")
     try:
         geometry = geometry.toByteArray()
     except:
         pass  # Fails in PySide
     if geometry:
         self.restoreGeometry(geometry)
Example #5
0
    def connect_actions(self, action_receiver=None):
        if not hasattr(self, 'run') and hasattr(self.parent(), 'run'):
            self.run = self.parent().run
        for name, action in [(n, a) for n, a in vars(self.ui).items()
                             if isinstance(a, QtGui.QAction)]:
            if action_receiver is None:
                action_receiver = self
            if hasattr(action_receiver, "_" + name) and hasattr(
                    self, "run") and hasattr(self, 'gui'):
                func = getattr(action_receiver, "_" + name)

                def action_wrapper(f):
                    def wrapper(*args, **kwargs):
                        return self.gui.run(f, *args, **kwargs)

                    return wrapper

                setattr(action_receiver, name, action_wrapper(func))

            if hasattr(action_receiver, name):
                QtCore.QObject.connect(action, QtCore.SIGNAL("triggered()"),
                                       getattr(action_receiver, name))
            elif not hasattr(action_receiver, "_" + name):
                try:
                    source_file = inspect.getsourcefile(self.__class__)
                    class_source = inspect.getsource(self.__class__)
                    func_source = """
    def _%s(self):
        #Auto implemented action handler
        raise NotImplementedError
""" % name

                    with open(source_file, 'r+') as fid:
                        source = fid.read().replace(class_source,
                                                    class_source + func_source)
                        fid.seek(0)
                        fid.write(source)
                    print("Missing method '_%s' appended to class %s" %
                          (name, self.__class__.__name__))
                except:
                    raise Warning(
                        "Action %s not connected. Method with name '%s' not found and autogeneration failed"
                        % (action.text(), name))
Example #6
0
 def save_setting(self, key, value):
     settings = QtCore.QSettings(
         "QtGuiApplication",
         "%s_%s" % (self.app_name, self.__class__.__name__))
     settings.setValue(self.ui_module.__name__ + "/" + key, value)
Example #7
0
 def save_settings(self):
     settings = QtCore.QSettings(
         "QtGuiApplication",
         "%s_%s" % (self.app_name, self.__class__.__name__))
     settings.setValue(self.ui_module.__name__ + "/geometry",
                       self.saveGeometry())