diff options
author | Xisco Fauli <anistenis@gmail.com> | 2012-10-16 23:39:14 +0200 |
---|---|---|
committer | Xisco Fauli <anistenis@gmail.com> | 2012-10-16 23:40:40 +0200 |
commit | 09f2d543df57ba049a9968292576f6315a51888d (patch) | |
tree | 2ee7b90107baa7a20434e3cb2b7f74b6549b775e /wizards | |
parent | pyletter: get rid of import * (diff) | |
download | core-09f2d543df57ba049a9968292576f6315a51888d.tar.gz core-09f2d543df57ba049a9968292576f6315a51888d.zip |
pywizards: cleanup common code
Change-Id: I6e64ec407326b5759664ace286eb67b2c6cd3b04
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/com/sun/star/wizards/common/Configuration.py | 175 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/common/Desktop.py | 37 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/common/Resource.py | 7 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/common/SystemDialog.py | 22 |
4 files changed, 7 insertions, 234 deletions
diff --git a/wizards/com/sun/star/wizards/common/Configuration.py b/wizards/com/sun/star/wizards/common/Configuration.py index 1b6db1f9c886..69e150c8f7be 100644 --- a/wizards/com/sun/star/wizards/common/Configuration.py +++ b/wizards/com/sun/star/wizards/common/Configuration.py @@ -20,21 +20,8 @@ import traceback from .PropertyNames import PropertyNames from .Helper import Helper -''' -This class gives access to the OO configuration api. -It contains 4 get and 4 set convenience methods for getting and settings -properties in the configuration. <br/> -For the get methods, two parameters must be given: name and parent, where -name is the name of the property, parent is a HierarchyElement -(::com::sun::star::configuration::HierarchyElement)<br/> -The get and set methods support hieryrchical property names like -"options/gridX". <br/> -NOTE: not yet supported, but sometime later, -If you will ommit the "parent" parameter, then the "name" parameter must be -in hierarchy form from the root of the registry. -''' - class Configuration(object): + '''This class gives access to the OO configuration api.''' @classmethod def getConfigurationRoot(self, xmsf, sPath, updateable): @@ -59,163 +46,3 @@ class Configuration(object): sView = "com.sun.star.configuration.ConfigurationAccess" return oConfigProvider.createInstanceWithArguments(sView, tuple(args)) - - @classmethod - def getProductName(self, xMSF): - try: - oProdNameAccess = self.getConfigurationRoot(xMSF, - "org.openoffice.Setup/Product", False) - ProductName = Helper.getUnoObjectbyName(oProdNameAccess, "ooName") - return ProductName - except Exception: - traceback.print_exc() - return None - - @classmethod - def getOfficeLocaleString(self, xMSF): - sLocale = "" - try: - aLocLocale = Locale.Locale() - oMasterKey = self.getConfigurationRoot(xMSF, - "org.openoffice.Setup/L10N/", False) - sLocale = (String) - Helper.getUnoObjectbyName(oMasterKey, "ooLocale") - except Exception, exception: - traceback.print_exc() - - return sLocale - - @classmethod - def getOfficeLocale(self, xMSF): - aLocLocale = Locale.Locale() - sLocale = getOfficeLocaleString(xMSF) - sLocaleList = JavaTools.ArrayoutofString(sLocale, "-") - aLocLocale.Language = sLocaleList[0] - if sLocaleList.length > 1: - aLocLocale.Country = sLocaleList[1] - - return aLocLocale - - @classmethod - def removeNode(self, configView, name, xmsf=None): - commitChanges = False - if xmsf is not None: - configView = self.getConfigurationRoot(xmsf, path, True) - commit = True - - if configView.hasByName(name): - configView.removeByName(name) - - if commitChanges: - configView.commitChanges() - - @classmethod - def updateConfiguration(self, xmsf, path, name, node, param): - view = self.getConfigurationRoot(xmsf, path, True) - addConfigNode(path, name) - node.writeConfiguration(view, param) - view.commitChanges() - - @classmethod - def getNodeDisplayNames(self, _xNameAccessNode): - snames = None - return getNodeChildNames(_xNameAccessNode, - PropertyNames.PROPERTY_NAME) - - @classmethod - def getNodeChildNames(self, xNameAccessNode, _schildname): - snames = None - try: - snames = xNameAccessNode.getElementNames() - sdisplaynames = range(snames.length) - i = 0 - while i < snames.length: - oContent = Helper.getUnoPropertyValue( - xNameAccessNode.getByName(snames[i]), _schildname) - if not AnyConverter.isVoid(oContent): - sdisplaynames[i] = (String) - Helper.getUnoPropertyValue(xNameAccessNode.getByName( - snames[i]), _schildname) - else: - sdisplaynames[i] = snames[i] - - i += 1 - return sdisplaynames - except Exception, e: - traceback.print_exc() - return snames - - @classmethod - def getChildNodebyIndex(self, _xNameAccess, _index): - try: - snames = _xNameAccess.getElementNames() - oNode = _xNameAccess.getByName(snames[_index]) - return oNode - except Exception, e: - traceback.print_exc() - return None - - @classmethod - def getChildNodebyName(self, _xNameAccessNode, _SubNodeName): - try: - if _xNameAccessNode.hasByName(_SubNodeName): - return _xNameAccessNode.getByName(_SubNodeName) - - except Exception, e: - traceback.print_exc() - - return None - - @classmethod - def getChildNodebyDisplayName(self, _xNameAccessNode, _displayname): - snames = None - return getChildNodebyDisplayName(_xNameAccessNode, _displayname, - PropertyNames.PROPERTY_NAME) - - @classmethod - def getChildNodebyDisplayName(self, _xNameAccessNode, _displayname, - _nodename): - - snames = None - try: - snames = _xNameAccessNode.getElementNames() - sdisplaynames = range(snames.length) - i = 0 - while i < snames.length: - curdisplayname = Helper.getUnoPropertyValue( - _xNameAccessNode.getByName(snames[i]), _nodename) - if curdisplayname.equals(_displayname): - return _xNameAccessNode.getByName(snames[i]) - - i += 1 - except Exception, e: - traceback.print_exc() - - return None - - @classmethod - def getChildNodebyDisplayName(self, _xMSF, _aLocale, _xNameAccessNode, - _displayname, _nodename, _nmaxcharcount): - - snames = None - try: - snames = _xNameAccessNode.getElementNames() - sdisplaynames = range(snames.length) - i = 0 - while i < snames.length: - curdisplayname = Helper.getUnoPropertyValue( - _xNameAccessNode.getByName(snames[i]), _nodename) - if (_nmaxcharcount > 0) and (_nmaxcharcount < \ - curdisplayname.length()): - curdisplayname = curdisplayname.substring(0, - _nmaxcharcount) - - curdisplayname = Desktop.removeSpecialCharacters(_xMSF, - _aLocale, curdisplayname) - if curdisplayname.equals(_displayname): - return _xNameAccessNode.getByName(snames[i]) - - i += 1 - except Exception, e: - traceback.print_exc() - return None diff --git a/wizards/com/sun/star/wizards/common/Desktop.py b/wizards/com/sun/star/wizards/common/Desktop.py index 914be171e04b..1876bfd716b9 100644 --- a/wizards/com/sun/star/wizards/common/Desktop.py +++ b/wizards/com/sun/star/wizards/common/Desktop.py @@ -17,7 +17,6 @@ # import uno import traceback -from .NoValidPathException import NoValidPathException from com.sun.star.frame.FrameSearchFlag import ALL, PARENT from com.sun.star.util import URL @@ -130,39 +129,3 @@ class Desktop(object): def getUniqueName(self, xElementContainer, sElementName): sIncSuffix = self.getIncrementSuffix(xElementContainer, sElementName) return sElementName + sIncSuffix - -class OfficePathRetriever: - - def OfficePathRetriever(self, xMSF): - try: - TemplatePath = FileAccess.getOfficePath(xMSF, - "Template", "share", "/wizard") - UserTemplatePath = FileAccess.getOfficePath(xMSF, - "Template", "user", "") - BitmapPath = FileAccess.combinePaths(xMSF, TemplatePath, - "/../wizard/bitmap") - WorkPath = FileAccess.getOfficePath(xMSF, - "Work", "", "") - except NoValidPathException, nopathexception: - pass - - @classmethod - def getTemplatePath(self, _xMSF): - sTemplatePath = "" - try: - sTemplatePath = FileAccess.getOfficePath(_xMSF, - "Template", "share", "/wizard") - except NoValidPathException, nopathexception: - pass - return sTemplatePath - - @classmethod - def getBitmapPath(self, _xMSF): - sBitmapPath = "" - try: - sBitmapPath = FileAccess.combinePaths(_xMSF, - getTemplatePath(_xMSF), "/../wizard/bitmap") - except NoValidPathException, nopathexception: - pass - - return sBitmapPath diff --git a/wizards/com/sun/star/wizards/common/Resource.py b/wizards/com/sun/star/wizards/common/Resource.py index 2e5b1424672f..fc607ea3a826 100644 --- a/wizards/com/sun/star/wizards/common/Resource.py +++ b/wizards/com/sun/star/wizards/common/Resource.py @@ -17,7 +17,6 @@ # import traceback from .Configuration import Configuration -from .SystemDialog import SystemDialog from com.sun.star.awt.VclWindowPeerAttribute import OK @@ -63,9 +62,7 @@ class Resource(object): @classmethod def showCommonResourceError(self, xMSF): - ProductName = Configuration.getProductName(xMSF) + from .SystemDialog import SystemDialog sError = "The files required could not be found.\n" + \ - "Please start the %PRODUCTNAME Setup and choose 'Repair'." - sError = sError.replace("%PRODUCTNAME", ProductName) + "Please start the LibreOffice Setup and choose 'Repair'." SystemDialog.showMessageBox(xMSF, "ErrorBox", OK, sError) - diff --git a/wizards/com/sun/star/wizards/common/SystemDialog.py b/wizards/com/sun/star/wizards/common/SystemDialog.py index c0b76736b7ab..6030d572099b 100644 --- a/wizards/com/sun/star/wizards/common/SystemDialog.py +++ b/wizards/com/sun/star/wizards/common/SystemDialog.py @@ -16,7 +16,6 @@ # the License at http://www.apache.org/licenses/LICENSE-2.0 . # import traceback -from .Configuration import Configuration from .Desktop import Desktop from .Helper import Helper @@ -141,25 +140,12 @@ class SystemDialog(object): traceback.print_exc() ''' - converts the name returned from getFilterUIName_(...) so the - product name is correct. - @param filterName - @return - ''' - - def getFilterUIName(self, filterName): - prodName = Configuration.getProductName(self.xMSF) - s = [[self.getFilterUIName_(filterName)]] - s[0][0] = s[0][0].replace("%productname%", prodName) - return s[0][0] - - ''' note the result should go through conversion of the product name. @param filterName @return the UI localized name of the given filter name. ''' - def getFilterUIName_(self, filterName): + def getFilterUIName(self, filterName): try: oFactory = self.xMSF.createInstance( "com.sun.star.document.FilterFactory") @@ -167,7 +153,7 @@ class SystemDialog(object): xPropertyValue = list(oObject) for i in xPropertyValue: if i is not None and i.Name == "UIName": - return str(i.Value) + return str(i.Value).replace("%productname%", "LibreOffice") raise NullPointerException( "UIName property not found for Filter " + filterName); @@ -178,10 +164,10 @@ class SystemDialog(object): @classmethod def showErrorBox(self, xMSF, ResName, ResPrefix, ResID, AddTag=None, AddString=None): - ProductName = Configuration.getProductName(xMSF) + from .Resource import Resource oResource = Resource(xMSF, ResPrefix) sErrorMessage = oResource.getResText(ResID) - sErrorMessage = sErrorMessage.replace( ProductName, "%PRODUCTNAME") + sErrorMessage = sErrorMessage.replace("%PRODUCTNAME", "LibreOffice" ) sErrorMessage = sErrorMessage.replace(str(13), "<BR>") if AddTag and AddString: sErrorMessage = sErrorMessage.replace( AddString, AddTag) |