Kaydet (Commit) 09f2d543 authored tarafından Xisco Fauli's avatar Xisco Fauli

pywizards: cleanup common code

Change-Id: I6e64ec407326b5759664ace286eb67b2c6cd3b04
üst 0d8e34f6
......@@ -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
......@@ -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
......@@ -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)
......@@ -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
......@@ -140,26 +139,13 @@ class SystemDialog(object):
except Exception, ex:
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment