Exemple #1
0
    def __init__(self, parent =None, **kwargs):
        """Creates a new instance of PyGlassWidget."""
        PyGlassElement.__init__(self, parent, **kwargs)
        if kwargs.get('verbose', False):
            print('CREATING: %s | PARENTED TO: %s' % (self, parent))
        self.setStyleSheet(self.owner.styleSheetPath)

        self._displayCount  = 0
        self._widgetClasses = kwargs.get('widgets', dict())
        self._widgetParent  = None
        self._currentWidget = None
        self._widgets       = dict()
        self._widgetFlags   = kwargs.get('widgetFlags')
        self._widgetID      = kwargs.get('widgetID')
        self._lastChildWidgetID  = None
        self._lastPeerWidgetID   = None

        widgetFile = kwargs.get('widgetFile', True)

        if widgetFile:
            parts = self.RESOURCE_WIDGET_FILE
            if parts:
                if StringUtils.isStringType(parts):
                    parts = parts.split('/')[-1:]
                elif parts:
                    parts = parts[-1:]
            self._widgetData = UiFileLoader.loadWidgetFile(self, names=parts)
        else:
            self._widgetData = None

        name = kwargs.get('containerWidgetName')
        self._containerWidget = getattr(self, name) if name and hasattr(self, name) else None
Exemple #2
0
    def __init__(self, **kwargs):
        """Creates a new instance of PyGlassWindow."""
        parent                  = ArgsUtils.extract('parent', None, kwargs)
        self._application       = ArgsUtils.extract('pyGlassApp', None, kwargs)
        self._qApplication      = ArgsUtils.extract('qApp', None, kwargs)
        self._isMainWindow      = ArgsUtils.extract('isMainWindow', bool(parent is None), kwargs)
        self._mainWindow        = ArgsUtils.extract('mainWindow', None, kwargs)
        self._appWrappingWidget = None
        self._centerWidget      = None
        self._hasShown          = False
        self._isHighDpi         = OsUtils.isHighDpiScaledScreen()
        self._settings          = ConfigsDict()

        self._appLevelWidgets              = dict()
        self._appLevelWidgetDisplayHistory = []

        self._keyboardCallback = ArgsUtils.extract('keyboardCallback', None, kwargs)

        if not self._mainWindow:
            if self._isMainWindow:
                self._mainWindow = self
            elif self._application:
                self._mainWindow = self._application.mainWindow

        self._dependentWindows = []
        self._currentWidget    = None

        QtGui.QMainWindow.__init__(self, parent, ArgsUtils.extract('flags', 0, kwargs))

        self._instanceUid = TimeUtils.getUidTimecode(
            prefix=self.__class__.__name__,
            suffix=StringUtils.getRandomString(8))

        self._styleSheet = kwargs.get('styleSheet', None)
        if self._styleSheet:
            self.setStyleSheet(self.styleSheetPath)

        if self._keyboardCallback is not None:
            self.setFocusPolicy(QtCore.Qt.StrongFocus)

        if self._isMainWindow:
            self._log                 = Logger(self, printOut=True)
            self._config              = ApplicationConfig(self)
            self._commonConfig        = ApplicationConfig(self, common=True)
            self._resourceFolderParts = PyGlassGuiUtils.getResourceFolderParts(self)

            icon = PyGlassGuiUtils.createIcon(
                kwargs.get('iconsPath', self.getAppResourcePath('icons', isDir=True)) )
            if icon:
                self.setWindowIcon(icon)

        elif self._mainWindow:
            icon = self._mainWindow.windowIcon()
            if icon:
                self.setWindowIcon(icon)

        self._appWrappingWidget = VisibilityElement(self)
        layout = QtGui.QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self._appWrappingWidget.setLayout(layout)

        self._contentWrappingWidget = self.addApplicationLevelWidget('main')
        layout = QtGui.QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self._contentWrappingWidget.setLayout(layout)

        # Loads the ui file if it exists
        externalCentralParent = None
        hasWindowFile = kwargs.get('mainWindowFile', False)
        if hasWindowFile == self:
            UiFileLoader.loadWidgetFile(self)
            externalCentralParent = getattr(self, 'windowContainer')
            if externalCentralParent:
                externalLayout = externalCentralParent.layout()
                if not externalLayout:
                    externalLayout = QtGui.QVBoxLayout()
                    externalLayout.setContentsMargins(0, 0, 0, 0)
                    externalLayout.setSpacing(0)
                    externalCentralParent.setLayout(externalLayout)

        if externalCentralParent:
            self._appWrappingWidget.setParent(externalCentralParent)
            externalLayout.addWidget(self._appWrappingWidget)
        else:
            self.setCentralWidget(self._appWrappingWidget)

        # Sets a non-standard central widget
        centralWidgetName = kwargs.get('centralWidgetName')
        if centralWidgetName and hasattr(self, centralWidgetName):
            self._centerWidget = getattr(self, centralWidgetName)
        elif hasWindowFile and not hasWindowFile == self:
            if not self._centerWidget:
                self._createCentralWidget()
            UiFileLoader.loadWidgetFile(self, target=self._centerWidget)
        elif not hasWindowFile:
            self._centerWidget = None

        if not self._centerWidget and kwargs.get('defaultCenterWidget', True):
            self._createCentralWidget()

        self._lastChildWidgetID  = None
        self._widgetParent  = None
        self._widgets       = None
        self._widgetFlags   = None

        self._widgetClasses = kwargs.get('widgets', dict())
        if self._widgetClasses:
            self._initializeWidgetChildren()

        self.setWindowTitle(kwargs.get('title', self._createTitleFromClass()))
        self.updateStatusBar()
Exemple #3
0
    def __init__(self, **kwargs):
        """Creates a new instance of PyGlassWindow."""
        parent = ArgsUtils.extract('parent', None, kwargs)
        self._application  = ArgsUtils.extract('pyGlassApp', None, kwargs)
        self._qApplication = ArgsUtils.extract('qApp', None, kwargs)
        self._isMainWindow = ArgsUtils.extract('isMainWindow', bool(parent is None), kwargs)
        self._mainWindow   = ArgsUtils.extract('mainWindow', None, kwargs)
        self._centerWidget = None

        self._keyboardCallback = ArgsUtils.extract('keyboardCallback', None, kwargs)

        if not self._mainWindow:
            if self._isMainWindow:
                self._mainWindow = self
            elif self._application:
                self._mainWindow = self._application.mainWindow

        self._dependentWindows = []
        self._currentWidget    = None

        QtGui.QMainWindow.__init__(self, parent, ArgsUtils.extract('flags', 0, kwargs))

        if self._keyboardCallback is not None:
            self.setFocusPolicy(QtCore.Qt.StrongFocus)

        if self._isMainWindow:
            self._log                 = Logger(self, printOut=True)
            self._config              = ApplicationConfig(self)
            self._commonConfig        = ApplicationConfig(self, common=True)
            self._resourceFolderParts = PyGlassGuiUtils.getResourceFolderParts(self)

            icon = PyGlassGuiUtils.createIcon(
                ArgsUtils.get('iconsPath', self.getAppResourcePath('icons', isDir=True), kwargs) )
            if icon:
                self.setWindowIcon(icon)

        elif self._mainWindow:
            icon = self._mainWindow.windowIcon()
            if icon:
                self.setWindowIcon(icon)

        # Loads the ui file if it exists
        hasWindowFile = ArgsUtils.get('mainWindowFile', False, kwargs)
        if hasWindowFile:
            if not self._centerWidget:
                self._createCentralWidget()
            UiFileLoader.loadWidgetFile(self, target=self._centerWidget)

        self._styleSheet = ArgsUtils.get('styleSheet', None, kwargs)
        if self._styleSheet:
            self.setStyleSheet(self.styleSheetPath)

        # Sets a non-standard central widget
        centralWidgetName = ArgsUtils.get('centralWidgetName', None, kwargs)
        if centralWidgetName and hasattr(self, centralWidgetName):
            self._centerWidget = getattr(self, centralWidgetName)
        elif not hasWindowFile:
            self._centerWidget = None
            if ArgsUtils.get('defaultCenterWidget', False, kwargs):
                self._createCentralWidget()

        self._lastWidgetID  = None
        self._widgetParent  = None
        self._widgets       = None
        self._widgetFlags   = None

        self._widgetClasses = ArgsUtils.get('widgets', None, kwargs)
        if self._widgetClasses:
            self._initializeWidgetChildren()
        else:
            self._widgetClasses = dict()

        self.setWindowTitle(ArgsUtils.get('title', self._createTitleFromClass(), kwargs))
        self.updateStatusBar()
Exemple #4
0
 def __init__(self, parent, pathNoExtension, **kwargs):
     """Creates a new instance of UiFileElement."""
     super(UiFileElement, self).__init__(parent=parent, **kwargs)
     self._widgetData = UiFileLoader.loadUiFile(self, pathNoExtension, True)