示例#1
0
 def __init__(self):
     """Creates a new instance of UniqueObject."""
     self._INSTANCE_INDEX += 1
     self._instanceUid = TimeUtils.getUidTimecode(
         prefix=self.__class__.__name__,
         suffix=StringUtils.toUnicode(self._INSTANCE_INDEX) + '-' +
         StringUtils.getRandomString(8))
示例#2
0
    def _handleAddApp(self):
        defaultPath = self.appConfig.get('LAST_APP_PATH', OsUtils.getDocumentsPath())

        path = PyGlassBasicDialogManager.browseForDirectory(
            parent=self,
            caption=StringUtils.dedent("""
                Specify the root path to a PyGlass application, in which a resource folder
                resides"""),
            defaultPath=defaultPath)
        if not path:
            return

        label = PyGlassBasicDialogManager.openTextQuery(
            parent=self,
            header='Enter Application Name',
            message='Specify the name of this application for display within Alembic Migrator',
            defaultText=os.path.basename(path.rstrip(os.sep)) )

        apps = self.appConfig.get('APPLICATIONS', dict())
        appData = {
            'label':label,
            'path':path,
            'databases':dict(),
            'id':TimeUtils.getUidTimecode('App', StringUtils.slugify(label))}
        apps[appData['id']] = appData
        self.appConfig.set('APPLICATIONS', apps)

        self.refresh()
        resultItem = self.appsListWidget.findItems(appData['id'], QtCore.Qt.MatchExactly)
        if resultItem:
            resultItem[0].setSelected(True)
示例#3
0
 def __init__(self):
     """Creates a new instance of UniqueObject."""
     self._INSTANCE_INDEX += 1
     self._instanceUid = TimeUtils.getUidTimecode(
         prefix=self.__class__.__name__,
         suffix=StringUtils.toUnicode(
             self._INSTANCE_INDEX) + '-' + StringUtils.getRandomString(8) )
示例#4
0
 def __init__(self, parent=None, **kwargs):
     """Creates a new instance of VisibilityElement."""
     super(VisibilityElement, self).__init__(parent=parent)
     self._instanceUid = TimeUtils.getUidTimecode(
         prefix=self.__class__.__name__, suffix=StringUtils.getRandomString(8)
     )
     self._visibility = VisibilityManager(target=self)
示例#5
0
    def saveFigure(self, key, path =None, close =True, **kwargs):
        """ Saves the specified figure to a file at teh specified path.

            key :: String
                The key for the figure to be saved. If no such key exists, the method will return
                false.

            path :: String :: None
                The absolute file location to where the figure should be saved. If no path is
                specified the file will be saved as a pdf in this Analyzer's temporary folder.

            close :: Boolean :: True
                If true, the figure will be closed upon successful completion of the save process.

            [kwargs]
                Data to be passed directly to the PyPlot Figure.savefig() method, which can be
                used to further customize how the figure is saved. """

        if not plt or key not in self._plotFigures:
            return False

        if not path:
            path = self.getTempPath('%s-%s.pdf' % (
                key, TimeUtils.getUidTimecode(suffix=StringUtils.getRandomString(16))), isFile=True)

        figure = self._plotFigures[key]

        if 'orientation' not in kwargs:
            kwargs['orientation'] = 'landscape'

        figure.savefig(path, **kwargs)
        if close:
            self.closeFigure(key)
        return path
示例#6
0
    def getTempFilePath(self, name =None, extension =None, *args):
        """ Used to create a temporary file path within this instance's temporary folder.
            Any file on this path will be automatically removed at the end of the analysis
            process.

            [name] :: String :: None
                The desired file name for the desired file within the temporary directory. If no
                name is specified, a name will be created automatically using the current time
                (microsecond) and a 16 digit random code for a very low probability of collisions.

            [extension] :: String :: None
                Specifies the extension to add to this file. The file name is not altered if no
                extension is specified.

            [*args] :: [String] :: []
                A list of relative folder prefixes in which the file should reside. For example,
                if you wish to have a file 'bar' in a folder 'foo' then you would specify 'foo' as
                the single arg to get a file located at 'foo/bar' within the temporary file. No
                directory prefixes will be created within this method. """

        if not name:
            name = TimeUtils.getUidTimecode(suffix=StringUtils.getRandomString(16))
        if extension:
            extension = '.' + extension.strip('.')
            if not name.endswith(extension):
                name += extension

        args = list(args) + [name]
        return FileUtils.makeFilePath(self.tempPath, *args)
示例#7
0
    def _handleAddDatabase(self):
        result = PyGlassBasicDialogManager.openTextQuery(
            parent=self,
            header='Enter Database Name',
            message='Enter the name of the database as it would appear in the Database URL, e.g. '
                    +'"activity" or "employees/artists"')
        if not result:
            return

        data = {
            'id':TimeUtils.getUidTimecode('DATABASE', StringUtils.slugify(result)),
            'label':StringUtils.toText(result).title(),
            'name':result }

        apps = self.appConfig.get('APPLICATIONS')
        app  = apps[self.currentAppID]
        app['databases'][data['id']] = data
        self.appConfig.set('APPLICATIONS', apps)

        self._refreshAppDisplay()
        resultItem = self.databasesListWidget.findItems(result, QtCore.Qt.MatchExactly)
        if resultItem:
            resultItem[0].setSelected(True)
示例#8
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()