Exemple #1
0
    def resumeTask(self, taskId, listener=None):
        task = self.getTask(taskId)
        if task is None:
            raise ZAppFrameworkException(
                _extstr(u"backgroundtaskimpl.FailedToResumeTaskNotFound") %
                taskId)  #$NON-NLS-1$
        if task.isRunning():
            raise ZAppFrameworkException(
                _extstr(u"backgroundtaskimpl.FailedToResumeTaskAlreadyRunning")
                % taskId)  #$NON-NLS-1$
        if task.isComplete():
            raise ZAppFrameworkException(
                _extstr(u"backgroundtaskimpl.FailedToResumeTaskComplete") %
                taskId)  #$NON-NLS-1$
        if not task.isResumable():
            raise ZAppFrameworkException(
                _extstr(u"backgroundtaskimpl.FailedToResumeTaskNotResumable") %
                taskId)  #$NON-NLS-1$
        if listener is not None:
            task.attachListener(listener)
        self._resumeTask(task)

        self.listeners.doCallback(u"onTaskResumed", [task])  #$NON-NLS-1$

        return task
Exemple #2
0
    def generateThumbnail(self, sourceFile, tnParams, destFile=None):
        if destFile is None:
            destFile = self._createDestFile()
        if os.path.exists(destFile):
            os.remove(destFile)
        if not os.path.isfile(sourceFile):
            raise ZAppFrameworkException(
                _extstr(u"imaging.PathDoesNotExistError") %
                sourceFile)  #$NON-NLS-1$

        width = tnParams.width
        height = tnParams.height

        inputFilePath = sourceFile
        outputFilePath = destFile
        try:
            image = Image.open(inputFilePath)
            image = image.convert(u"RGB")  #$NON-NLS-1$
            image.thumbnail((width, height), Image.ANTIALIAS)
            if tnParams.dropShadow:
                bgcolor = (tnParams.backgroundColor[2] << 16) + (
                    tnParams.backgroundColor[1] <<
                    8) + tnParams.backgroundColor[0]
                image = self._addDropShadow(image, background=bgcolor)
            image.save(outputFilePath)
            (rWidth, rHeight) = image.size
            return (outputFilePath, rWidth, rHeight)
        except Exception, e:
            raise ZAppFrameworkException(
                _extstr(u"imaging.ErrorCreatingThumbnailError") % sourceFile,
                e)  #$NON-NLS-1$
Exemple #3
0
 def createSystemProfile(self, type, data):
     c = self.typeRegistry[type]
     if not c:
         raise ZAppFrameworkException(_extstr(u"system.CouldNotCreateSysProfile") % type) #$NON-NLS-1$
     try:
         return c(data)
     except Exception, ex:
         raise ZAppFrameworkException(_extstr(u"system.CouldNotCreateSysProfile") % type, ex) #$NON-NLS-1$
Exemple #4
0
    def removeTask(self, taskId):
        task = self.getTask(taskId)
        if task is None:
            raise ZAppFrameworkException(
                _extstr(u"backgroundtaskimpl.FailedToRemoveDoesNotExist") %
                taskId)  #$NON-NLS-1$
        if task.isRunning():
            raise ZAppFrameworkException(
                _extstr(u"backgroundtaskimpl.FailedToRemoveStillRunning") %
                taskId)  #$NON-NLS-1$
        self.tasks.remove(task)

        self._removeTask(task)

        self.listeners.doCallback(u"onTaskRemoved", [task])  #$NON-NLS-1$
Exemple #5
0
 def getName(self):
     name = self._getExtensionText(u"plg:prefpage/plg:name")  #$NON-NLS-1$
     if not name:
         raise ZAppFrameworkException(
             u"No name was supplied for extension with id '%s'." %
             self.getId())  #$NON-NLS-1$
     return name
Exemple #6
0
 def getName(self):
     name = self._getExtensionText(u"plg:menu-group/plg:name")  #$NON-NLS-1$
     if not name:
         raise ZAppFrameworkException(
             _extstr(u"menudefs.NameMissingInMenuItemError") %
             self.extensionPoint.getId())  #$NON-NLS-1$
     return name
Exemple #7
0
 def getDeserializer(self, namespace):
     if namespace in self.deserializerMap:
         return self.deserializerMap[namespace]
     else:
         raise ZAppFrameworkException(
             _extstr(u"factory.NoTaskDeserializerFound") %
             namespace)  #$NON-NLS-1$
Exemple #8
0
 def getSerializer(self,
                   namespace=IZAppNamespaces.RAVEN_TASK_NAMESPACE_2006_05):
     if namespace in self.serializerMap:
         return self.serializerMap[namespace]
     else:
         raise ZAppFrameworkException(
             _extstr(u"factory.NoTaskSerializerFound") %
             namespace)  #$NON-NLS-1$
Exemple #9
0
 def getCurrentChoice(self):
     if self.multiSelect:
         raise ZAppFrameworkException(
             u"Attempted to get a single choice from an advanced text box configured for multiple selection."
         )  #$NON-NLS-1$
     if self.selectedChoices:
         return self.selectedChoices[0]
     return None
Exemple #10
0
 def getDescription(self):
     desc = self._getExtensionText(
         u"plg:prefpage/plg:description")  #$NON-NLS-1$
     if not desc:
         raise ZAppFrameworkException(
             u"No description was supplied for extension with id '%s'." %
             self.getId())  #$NON-NLS-1$
     return desc
Exemple #11
0
def saveBackgroundTask(task, taskXmlPath):
    try:
        serializer = getBackgroundTaskSerializerFactory().getSerializer()
        dom = serializer.serialize(task)
        dom.save(taskXmlPath, True)
    except Exception, e:
        raise ZAppFrameworkException(
            _extstr(u"backgroundtaskio.FailedToSaveTask") % task.getId(),
            e)  #$NON-NLS-1$
Exemple #12
0
 def selectTab(self, tabId):
     tab = self._getTabById(tabId)
     if tab is None:
         raise ZAppFrameworkException(u"No tab with id '%s' found." %
                                      unicode(tabId))  #$NON-NLS-1$
     if self.selectedTab is not None:
         self.selectedTab.setSelected(False)
     tab.setSelected(True)
     self.selectedTab = tab
     self.refresh()
Exemple #13
0
 def _loadPluginSchemaXML(self):
     schemaPath = self._getPluginSchemaPath()
     try:
         f = open(schemaPath, u"r")  #$NON-NLS-1$
         xml = f.read()
         f.close()
         return xml
     except Exception, e:
         raise ZAppFrameworkException(_extstr(u"plugin.FailedToLoadSchema"),
                                      e)  #$NON-NLS-1$
Exemple #14
0
    def addTab(self, tabName, tabPanel):
        if tabName in self.tabs:
            raise ZAppFrameworkException(u"A tab named '%s' already exists." %
                                         tabName)  #$NON-NLS-1$
        if not tabPanel.GetParent() == self:
            raise ZAppFrameworkException(
                u"The panel's parent must be the Property Book.")  #$NON-NLS-1$

        firstTab = False
        if len(self.tabs) == 0:
            firstTab = True

        self.tabContainer.addTab(tabName, firstTab)
        self.tabPanelSizer.Add(tabPanel, 1, wx.EXPAND)
        self.tabs[tabName] = tabPanel

        if not firstTab:
            tabPanel.Show(False)

        self.Layout()
Exemple #15
0
 def cancelTask(self, taskId, removeFlag=False):
     task = self.getTask(taskId)
     if task is None:
         raise ZAppFrameworkException(
             _extstr(u"backgroundtaskimpl.FailedToCancelDoesNotExist") %
             taskId)  #$NON-NLS-1$
     task.cancel()
     task.detachListener(self)
     self.listeners.doCallback(u"onTaskCancelled", [task])  #$NON-NLS-1$
     if removeFlag:
         self.removeTask(taskId)
Exemple #16
0
def loadBackgroundTask(taskXmlPath):
    try:
        dom = ZDom()
        dom.load(taskXmlPath)

        deserializer = getBackgroundTaskDeserializerFactory().getDeserializer(
            dom.documentElement.getNamespaceUri())
        return deserializer.deserialize(dom)
    except Exception, e:
        raise ZAppFrameworkException(
            _extstr(u"backgroundtaskio.FailedToLoadTask") % taskXmlPath,
            e)  #$NON-NLS-1$
Exemple #17
0
def loadLanguageCodes(xmlFilePath):
    try:
        dom = ZDom()
        dom.load(xmlFilePath)

        deserializer = getI18NDeserializerFactory().getDeserializer(
            dom.documentElement.getNamespaceUri())
        return deserializer.deserialize(dom)
    except Exception, e:
        raise ZAppFrameworkException(
            _extstr(u"i18nserviceio.ErrorLoadingLanguageCodes"),
            e)  #$NON-NLS-1$
Exemple #18
0
 def _selectTab(self, tabId):
     if not tabId in self.tabPanelMap:
         raise ZAppFrameworkException(u"Tab with id '%s' does not exist." %
                                      unicode(tabId))  #$NON-NLS-1$
     self.tabBar.selectTab(tabId)
     tabPanel = self.tabPanelMap[tabId]
     if self.selectedTabId is not None:
         oldTabPanel = self.tabPanelMap[self.selectedTabId]
         oldTabPanel.Show(False)
     self.selectedTabId = tabId
     tabPanel.Show(True)
     self.Layout()
     self.Refresh()
Exemple #19
0
 def _removeTab(self, tabId):
     if not tabId in self.tabPanelMap:
         raise ZAppFrameworkException(u"Tab with id '%s' does not exist." %
                                      unicode(tabId))  #$NON-NLS-1$
     tabPanel = self.tabPanelMap[tabId]
     del self.tabPanelMap[tabId]
     self.sizer.Remove(tabPanel)
     tabPanel.Destroy()
     self.tabBar.removeTab(tabId)
     # If the one being removed was the selected tab, then select a
     # new ('scuse me) tab
     if self.selectedTabId == tabId:
         self.selectedTabId = self._getFirstTabId()
         if self.selectedTabId is not None:
             self.selectTab(self.selectedTabId)
Exemple #20
0
 def _syncPanelList(self):
     lastIndex = 0
     for i in range(0, self.provider.getNumRows()):
         newItem = self.provider.getRowItem(i)
         if i >= len(self.data):
             self._insertItem(i, newItem)
         else:
             (oldItem, oldPanel) = self.data[i] #@UnusedVariable
             if not oldItem == newItem:
                 self._syncPanelItem(i, newItem)
         lastIndex = i + 1
     # Now delete any trailing items
     if lastIndex < len(self.data):
         self._deleteItems(lastIndex, len(self.data))
     self.numRows = self.provider.getNumRows()
     if len(self.data) != self.numRows:
         raise ZAppFrameworkException(u"Sync'd list (%d) != provider's numRows (%d)" % (len(self.data), self.numRows)) #$NON-NLS-1$
Exemple #21
0
 def removeTab(self, tabId):
     u"""removeTab(int) -> None
     Removes the tab with the given tab ID from the
     tab bar.""" #$NON-NLS-1$
     tab = self._getTabById(tabId)
     if tab is None:
         raise ZAppFrameworkException(u"No tab with id '%s' found." %
                                      unicode(tabId))  #$NON-NLS-1$
     self.totalPreferredWidth -= self._getPreferredTabWidth(
         tab.getPreferredWidth())
     self.Unbind(ZEVT_TAB_CLOSED, tab)
     self.Unbind(ZEVT_TAB_SELECTED, tab)
     self._removeTab(tabId)
     self.tabSizer.Remove(tab)
     tab.Destroy()
     if tab == self.selectedTab:
         self.selectedTab = None
     self.refresh()
Exemple #22
0
    def loadPlugins(self, listener=None):
        if not listener:
            listener = IZPluginRegistryListener()
        self.listener = listener
        pluginDirectories = self._getPluginDirectories()
        self.listener.pluginsLoading(len(pluginDirectories))

        # Go through all of the plugin directories and load each plugin.  The end result is a
        # list of ZPlugin objects.
        totalFailed = 0
        pluginMap = {}
        for pluginDirectory in pluginDirectories:
            self.listener.pluginLoading(os.path.basename(pluginDirectory))
            try:
                plugin = ZPlugin(pluginDirectory)
                if pluginMap.has_key(plugin.getId()):
                    # plugin already exists.
                    # Check for new versions of plug-ins as well as duplicate versions
                    prevPlugin = pluginMap[plugin.getId()]
                    v1 = plugin.getVersion()
                    v2 = prevPlugin.getVersion()
                    if v1 > v2:
                        #  new plugin is the latest version
                        pluginMap[plugin.getId()] = plugin
                    elif v1 == v2:
                        # new plugin and old plug have same version id -> duplicate plugin id error
                        raise ZAppFrameworkException(
                            _extstr(u"plugin.DuplicatePluginId") %
                            plugin.getId())  #$NON-NLS-1$
                    elif v1 < v2:
                        # prevPlugin version number is newer. Do nothing (to keep the prevPlugin)
                        pass
                else:
                    pluginMap[plugin.getId()] = plugin
                    self.listener.pluginLoaded(plugin.getId())
            except ZException, ze:
                self.listener.pluginFailed(os.path.basename(pluginDirectory),
                                           ze.getStackTrace())
                totalFailed += 1
            except Exception, e:
                self.listener.pluginFailed(
                    os.path.basename(pluginDirectory),
                    ZException(rootCause=e).getStackTrace())
                totalFailed += 1
Exemple #23
0
    def getInstallDirectory(self):
        if self.installDir:
            return self.installDir

        # We have 3 cracks at figuring out the install-directory.
        # 1) explicit command line param:  --installdir=path/to/install/dir
        # 2) sub-class dependent lookup
        # 3) path relative to srcroot.py module
        path = self._getCmdLineInstallDirectory()
        if not path:
            path = self._getOSDependentInstallDirectory()
        if not path:
            path = self._getSrcRootInstallDirectory()
        if not path:
            raise ZAppFrameworkException(
                u"Could not locate application install directory."
            )  #$NON-NLS-1$

        self.installDir = path
        return self.installDir
Exemple #24
0
    def addTask(self, task):
        task.setId(generate())
        taskLogFilename = os.path.join(self.tasksDirectory,
                                       task.getId() +
                                       u".task.log")  #$NON-NLS-1$
        task.setLogLocation(taskLogFilename)
        self.tasks.append(task)

        self.listeners.doCallback(u"onTaskAdded", [task])  #$NON-NLS-1$
        self._resumeTask(task)

        # Wait until the num work units has been set by the task (but only
        # wait for up to 30 seconds).
        numWaits = 0
        while task.getNumWorkUnits() <= 0 and numWaits < 60:
            time.sleep(0.5)
            numWaits = numWaits + 1
        if task.getNumWorkUnits() <= 0:
            raise ZAppFrameworkException(
                _extstr(u"backgroundtaskimpl.TaskFailedToStartError") %
                task.getName())  #$NON-NLS-1$
Exemple #25
0
 def _parseParamList(self, paramList):
     i = 0
     while i < len(paramList):
         arg = convertToUnicode(paramList[i])
         match = re.match(CMD_LINE_PARAM_PATTERN_ONE, arg)
         if match:
             i = i + self._parsePatternOne(match)
             continue
         match = re.match(CMD_LINE_PARAM_PATTERN_TWO, arg)
         if match:
             i = i + self._parsePatternTwo(match)
             continue
         match = re.match(CMD_LINE_PARAM_PATTERN_THREE, arg)
         if match:
             i = i + self._parsePatternThree(match, paramList[i + 1:])
             continue
         match = re.match(CMD_LINE_PARAM_PATTERN_FOUR, arg)
         if match:
             i = i + self._parsePatternFour(match, paramList[i + 1:])
             continue
         raise ZAppFrameworkException(
             _extstr(u"cmdline.InvalidCmdLineError") % arg)  #$NON-NLS-1$
Exemple #26
0
 def _run(self):
     raise ZAppFrameworkException(
         u"Subclass should implement this!")  #$NON-NLS-1$
Exemple #27
0
 def getContentStream(self):
     if not os.path.isfile(self.contentFilename):
         raise ZAppFrameworkException(u"%s: '%s'." % (_extstr(u"connresp.NoContentFoundError"), self.contentFilename)) #$NON-NLS-1$ #$NON-NLS-2$
     return open(self.contentFilename)
Exemple #28
0
 def __init__(self, message, rootCause = None):
     ZAppFrameworkException.__init__(self, message, rootCause)
Exemple #29
0
 def getCurrentChoices(self):
     if not self.multiSelect:
         raise ZAppFrameworkException(
             u"Attempted to get multiple choices from an advanced text box configured for single selection."
         )  #$NON-NLS-1$
     return self.selectedChoices
Exemple #30
0
 def runDropDownAction(self, toolBarActionContext, position, size):
     raise ZAppFrameworkException(
         u"Drop-down style toolbar items not supported by ZActiveCallbackToolBarNode"
     )  #$NON-NLS-1$
Exemple #31
0
 def runToggleAction(self, toolBarActionContext, depressed):
     raise ZAppFrameworkException(
         u"Toggle style toolbar items not supported by ZActiveCallbackToolBarNode"
     )  #$NON-NLS-1$