diff options
author | Xisco Fauli <anistenis@gmail.com> | 2012-11-28 02:05:43 +0100 |
---|---|---|
committer | Xisco Fauli <anistenis@gmail.com> | 2012-11-28 02:07:15 +0100 |
commit | 47e7436d61539a77aa4e97de952262d858483cb7 (patch) | |
tree | 327a6342a55ff616f0d23b3d69b96864d005e964 | |
parent | 03a0ea88e94205bf14feffccf981e4aac82a28ae (diff) |
pywizards: remove helper class
Change-Id: I899cab320edb3712b17e339b0931a0deed4425e8
14 files changed, 122 insertions, 342 deletions
diff --git a/wizards/com/sun/star/wizards/common/Configuration.py b/wizards/com/sun/star/wizards/common/Configuration.py index 69e150c8f7be..f467c224d30f 100644 --- a/wizards/com/sun/star/wizards/common/Configuration.py +++ b/wizards/com/sun/star/wizards/common/Configuration.py @@ -18,7 +18,6 @@ import uno import traceback from .PropertyNames import PropertyNames -from .Helper import Helper class Configuration(object): '''This class gives access to the OO configuration api.''' diff --git a/wizards/com/sun/star/wizards/common/Helper.py b/wizards/com/sun/star/wizards/common/Helper.py deleted file mode 100644 index 3a19e64fef6d..000000000000 --- a/wizards/com/sun/star/wizards/common/Helper.py +++ /dev/null @@ -1,177 +0,0 @@ -# -# This file is part of the LibreOffice project. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This file incorporates work covered by the following license notice: -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed -# with this work for additional information regarding copyright -# ownership. The ASF licenses this file to you under the Apache -# License, Version 2.0 (the "License"); you may not use this file -# except in compliance with the License. You may obtain a copy of -# the License at http://www.apache.org/licenses/LICENSE-2.0 . -# -import uno -import traceback -from datetime import date as DateTime -from .NumberFormatter import NumberFormatter - -from com.sun.star.uno import RuntimeException - -class Helper(object): - - @classmethod - def setUnoPropertyValue(self, xPSet, PropertyName, PropertyValue): - try: - if PropertyValue is not None: - setattr(xPSet, PropertyName, PropertyValue) - - except AttributeError: - raise AttributeError( "No Such Property: '%s'" % PropertyName) - except Exception: - traceback.print_exc() - - @classmethod - def getUnoObjectbyName(self, xName, ElementName): - try: - if xName.hasByName(ElementName): - return xName.getByName(ElementName) - else: - raise RuntimeException() - - except Exception: - traceback.print_exc() - return None - - @classmethod - def getPropertyValue(self, CurPropertyValue, PropertyName): - for i in CurPropertyValue: - if i is not None: - if i.Name == PropertyName: - return i.Value - - raise RuntimeException() - - @classmethod - def getUnoPropertyValue(self, xPSet, PropertyName): - try: - if xPSet is not None: - oObject = xPSet.getPropertyValue(PropertyName) - return oObject - return None - - except Exception: - traceback.print_exc() - return None - - @classmethod - def getUnoArrayPropertyValue(self, xPSet, PropertyName): - try: - if xPSet is not None: - oObject = xPSet.getPropertyValue(PropertyName) - if isinstance(oObject,list): - return getArrayValue(oObject) - - except Exception: - traceback.print_exc() - - return None - - @classmethod - def getUnoStructValue(self, xPSet, PropertyName): - try: - if xPSet is not None: - if xPSet.getPropertySetInfo().hasPropertyByName(PropertyName): - oObject = xPSet.getPropertyValue(PropertyName) - return oObject - - return None - except Exception: - traceback.print_exc() - return None - - @classmethod - def setUnoPropertyValues(self, xMultiPSetLst, PropertyNames, - PropertyValues): - try: - if xMultiPSetLst is not None: - uno.invoke(xMultiPSetLst, "setPropertyValues", - (PropertyNames, PropertyValues)) - else: - for index, workwith in enumerate(PropertyNames): - self.setUnoPropertyValue( - xMultiPSetLst, PropertyNames[index], workwith) - - except Exception: - traceback.print_exc() - - ''' - checks if the value of an object that represents an array is null. - check beforehand if the Object is really an array with - "AnyConverter.IsArray(oObject) - @param oValue the paramter that has to represent an object - @return a null reference if the array is empty - ''' - - @classmethod - def getArrayValue(self, oValue): - try: - #VetoableChangeSupport Object - oPropList = list(oValue) - nlen = len(oPropList) - if nlen == 0: - return None - else: - return oPropList - - except Exception: - traceback.print_exc() - return None - - def getComponentContext(_xMSF): - #Get the path to the extension and - #try to add the path to the class loader - aHelper = PropertySetHelper(_xMSF); - aDefaultContext = aHelper.getPropertyValueAsObject("DefaultContext") - return aDefaultContext - - def getMacroExpander(_xMSF): - xComponentContext = self.getComponentContext(_xMSF); - aSingleton = xComponentContext.getValueByName( - "/singletons/com.sun.star.util.theMacroExpander") - return aSingleton - - class DateUtils(object): - - def __init__(self, xmsf, document): - defaults = xmsf.createInstance("com.sun.star.text.Defaults") - l = Helper.getUnoStructValue(defaults, "CharLocale") - self.formatSupplier = document - formatSettings = self.formatSupplier.getNumberFormatSettings() - date = Helper.getUnoPropertyValue(formatSettings, "NullDate") - self.calendar = DateTime(date.Year, date.Month, date.Day) - self.formatter = NumberFormatter.createNumberFormatter(xmsf, - self.formatSupplier) - - ''' - @param format a constant of the enumeration NumberFormatIndex - @return - ''' - - def getFormat(self, format): - return NumberFormatter.getNumberFormatterKey( - self.formatSupplier, format) - - ''' - @param date a VCL date in form of 20041231 - @return a document relative date - ''' - - def format(self, formatIndex, date): - difference = date - self.calendar - return self.formatter.convertNumberToString(formatIndex, - difference.days) diff --git a/wizards/com/sun/star/wizards/common/SystemDialog.py b/wizards/com/sun/star/wizards/common/SystemDialog.py index 9d7e84b3a23f..ab9b463f2106 100644 --- a/wizards/com/sun/star/wizards/common/SystemDialog.py +++ b/wizards/com/sun/star/wizards/common/SystemDialog.py @@ -17,7 +17,6 @@ # import traceback from .Desktop import Desktop -from .Helper import Helper from com.sun.star.ui.dialogs.TemplateDescription import \ FILESAVE_AUTOEXTENSION, FILEOPEN_SIMPLE @@ -149,7 +148,7 @@ class SystemDialog(object): try: oFactory = self.xMSF.createInstance( "com.sun.star.document.FilterFactory") - oObject = Helper.getUnoObjectbyName(oFactory, filterName) + oObject = oFactory.getByName(filterName) xPropertyValue = list(oObject) for i in xPropertyValue: if i is not None and i.Name == "UIName": diff --git a/wizards/com/sun/star/wizards/fax/FaxDocument.py b/wizards/com/sun/star/wizards/fax/FaxDocument.py index 215b355562e0..a483343d9d72 100644 --- a/wizards/com/sun/star/wizards/fax/FaxDocument.py +++ b/wizards/com/sun/star/wizards/fax/FaxDocument.py @@ -15,7 +15,7 @@ # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # -from ..text.TextDocument import TextDocument, traceback, Helper, \ +from ..text.TextDocument import TextDocument, traceback, \ TextFieldHandler, Configuration from ..text.TextSectionHandler import TextSectionHandler from ..common.PropertyNames import PropertyNames @@ -39,7 +39,7 @@ class FaxDocument(TextDocument): self.xTextDocument) oSection = \ mySectionHandler.xTextDocument.TextSections.getByName(sElement) - Helper.setUnoPropertyValue(oSection,"IsVisible",bState) + oSection.IsVisible = bState except Exception: traceback.print_exc() @@ -58,8 +58,7 @@ class FaxDocument(TextDocument): if bState: xPageStyle.setPropertyValue("FooterIsOn", True) - xFooterText = \ - Helper.getUnoPropertyValue(xPageStyle, "FooterText") + xFooterText = xPageStyle.FooterText xFooterText.String = sText if bPageNumber: @@ -78,8 +77,7 @@ class FaxDocument(TextDocument): xFooterText.insertTextContent(xFooterText.End, xPageNumberField, False) else: - Helper.setUnoPropertyValue(xPageStyle, "FooterIsOn", - False) + xPageStyle.FooterIsOn = False self.xTextDocument.unlockControllers() except Exception: @@ -108,19 +106,17 @@ class FaxDocument(TextDocument): oUserDataAccess = Configuration.getConfigurationRoot( self.xMSF, "org.openoffice.UserProfile/Data", False) myFieldHandler.changeUserFieldContent("Company", - Helper.getUnoObjectbyName(oUserDataAccess, "o")) + oUserDataAccess.hasByName("o")) myFieldHandler.changeUserFieldContent("Street", - Helper.getUnoObjectbyName(oUserDataAccess, "street")) + oUserDataAccess.hasByName("street")) myFieldHandler.changeUserFieldContent("PostCode", - Helper.getUnoObjectbyName(oUserDataAccess, "postalcode")) + oUserDataAccess.hasByName("postalcode")) myFieldHandler.changeUserFieldContent( - PropertyNames.PROPERTY_STATE, - Helper.getUnoObjectbyName(oUserDataAccess, "st")) + PropertyNames.PROPERTY_STATE, oUserDataAccess.hasByName("st")) myFieldHandler.changeUserFieldContent("City", - Helper.getUnoObjectbyName(oUserDataAccess, "l")) + oUserDataAccess.hasByName("l")) myFieldHandler.changeUserFieldContent("Fax", - Helper.getUnoObjectbyName(oUserDataAccess, - "facsimiletelephonenumber")) + oUserDataAccess.hasByName("facsimiletelephonenumber")) except Exception: traceback.print_exc() diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialog.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialog.py index 9f033d784557..308238bc01ca 100644 --- a/wizards/com/sun/star/wizards/fax/FaxWizardDialog.py +++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialog.py @@ -17,8 +17,7 @@ # from .FaxWizardDialogResources import FaxWizardDialogResources from .FaxWizardDialogConst import FaxWizardDialogConst, HIDMAIN, HID -from ..ui.WizardDialog import WizardDialog, uno, Helper, UIConsts, \ - PropertyNames +from ..ui.WizardDialog import WizardDialog, uno, UIConsts, PropertyNames from com.sun.star.awt.FontUnderline import SINGLE @@ -31,14 +30,14 @@ class FaxWizardDialog(WizardDialog): self.resources = FaxWizardDialogResources(xmsf) #set dialog properties... - Helper.setUnoPropertyValues(self.xDialogModel, - ("Closeable", PropertyNames.PROPERTY_HEIGHT, "Moveable", + uno.invoke(self.xDialogModel, "setPropertyValues", + (("Closeable", PropertyNames.PROPERTY_HEIGHT, "Moveable", PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Title", PropertyNames.PROPERTY_WIDTH), (True, 210, True, 104, 52, 1, 1, - self.resources.resFaxWizardDialog_title, 310)) + self.resources.resFaxWizardDialog_title, 310))) self.fontDescriptor1 = \ uno.createUnoStruct('com.sun.star.awt.FontDescriptor') diff --git a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py index 4f7352cc1976..1074f14b47ee 100644 --- a/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py +++ b/wizards/com/sun/star/wizards/fax/FaxWizardDialogImpl.py @@ -17,7 +17,7 @@ # import traceback import os.path -from .FaxWizardDialog import FaxWizardDialog, Helper, PropertyNames, uno, HID +from .FaxWizardDialog import FaxWizardDialog, PropertyNames, uno, HID from .CGFaxWizard import CGFaxWizard from .FaxDocument import FaxDocument from ..ui.PathSelection import PathSelection @@ -613,8 +613,7 @@ class FaxWizardDialogImpl(FaxWizardDialog): #enable/disable roadmap item for footer page BPaperItem = self.getRoadmapItemByID( \ FaxWizardDialogImpl.RM_FOOTER) - Helper.setUnoPropertyValue(BPaperItem, - PropertyNames.PROPERTY_ENABLED, bFooterPossible) + BPaperItem.Enabled = bFooterPossible except Exception: traceback.print_exc() @@ -685,14 +684,12 @@ class FaxWizardDialogImpl(FaxWizardDialog): def __enableSenderReceiver(self): BPaperItem = self.getRoadmapItemByID( \ FaxWizardDialogImpl.RM_SENDERRECEIVER) - Helper.setUnoPropertyValue(BPaperItem, - PropertyNames.PROPERTY_ENABLED, True) + BPaperItem.Enabled = True def __disableSenderReceiver(self): BPaperItem = self.getRoadmapItemByID( \ FaxWizardDialogImpl.RM_SENDERRECEIVER) - Helper.setUnoPropertyValue(BPaperItem, - PropertyNames.PROPERTY_ENABLED, False) + BPaperItem.Enabled = False def validatePath(self): if self.myPathSelection.usedPathPicker: diff --git a/wizards/com/sun/star/wizards/letter/LetterDocument.py b/wizards/com/sun/star/wizards/letter/LetterDocument.py index f8c1cedf693b..60fecc30bebc 100644 --- a/wizards/com/sun/star/wizards/letter/LetterDocument.py +++ b/wizards/com/sun/star/wizards/letter/LetterDocument.py @@ -15,7 +15,7 @@ # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # -from ..text.TextDocument import TextDocument, traceback, Helper, \ +from ..text.TextDocument import TextDocument, traceback, \ TextFieldHandler, Configuration from ..text.TextSectionHandler import TextSectionHandler from ..common.PropertyNames import PropertyNames @@ -51,7 +51,7 @@ class LetterDocument(TextDocument): self.xMSF, self.xTextDocument) oSection = \ mySectionHandler.xTextDocument.TextSections.getByName(sElement) - Helper.setUnoPropertyValue(oSection, "IsVisible", bState) + oSection.IsVisible = bState except Exception: traceback.print_exc() @@ -68,9 +68,8 @@ class LetterDocument(TextDocument): xPageStyleCollection = xNameAccess.getByName("PageStyles") xPageStyle = xPageStyleCollection.getByName(sPageStyle) if bState: - Helper.setUnoPropertyValue(xPageStyle, "FooterIsOn", True) - xFooterText = \ - Helper.getUnoPropertyValue(xPageStyle, "FooterText") + xPageStyle.FooterIsOn = True + xFooterText = xPageStyle.FooterText xFooterText.String = sText if bPageNumber: #Adding the Page Number @@ -89,8 +88,7 @@ class LetterDocument(TextDocument): xPageNumberField, False) else: - Helper.setUnoPropertyValue( - xPageStyle, "FooterIsOn", False) + xPageStyle.FooterIsOn = False self.xTextDocument.unlockControllers() except Exception: @@ -118,17 +116,16 @@ class LetterDocument(TextDocument): oUserDataAccess = Configuration.getConfigurationRoot( self.xMSF, "org.openoffice.UserProfile/Data", False) myFieldHandler.changeUserFieldContent( - "Company", Helper.getUnoObjectbyName(oUserDataAccess, "o")) + "Company", oUserDataAccess.getByName("o")) myFieldHandler.changeUserFieldContent( - "Street", Helper.getUnoObjectbyName(oUserDataAccess, "street")) + "Street", oUserDataAccess.getByName("street")) myFieldHandler.changeUserFieldContent( - "PostCode", - Helper.getUnoObjectbyName(oUserDataAccess, "postalcode")) + "PostCode", oUserDataAccess.getByName("postalcode")) myFieldHandler.changeUserFieldContent( - "City", Helper.getUnoObjectbyName(oUserDataAccess, "l")) + "City", oUserDataAccess.getByName("l")) myFieldHandler.changeUserFieldContent( PropertyNames.PROPERTY_STATE, - Helper.getUnoObjectbyName(oUserDataAccess, "st")) + oUserDataAccess.getByName("st")) except Exception: traceback.print_exc() diff --git a/wizards/com/sun/star/wizards/letter/LetterWizardDialog.py b/wizards/com/sun/star/wizards/letter/LetterWizardDialog.py index 76c74a4109f0..e73142a5402b 100644 --- a/wizards/com/sun/star/wizards/letter/LetterWizardDialog.py +++ b/wizards/com/sun/star/wizards/letter/LetterWizardDialog.py @@ -18,7 +18,7 @@ from .LetterWizardDialogConst import LetterWizardDialogConst, HIDMAIN, HID from .LetterWizardDialogResources import LetterWizardDialogResources from ..common.HelpIds import HelpIds -from ..ui.WizardDialog import WizardDialog, uno, Helper, PropertyNames +from ..ui.WizardDialog import WizardDialog, uno, PropertyNames from com.sun.star.awt.FontUnderline import SINGLE @@ -28,9 +28,8 @@ class LetterWizardDialog(WizardDialog): super(LetterWizardDialog, self).__init__(xmsf, HIDMAIN ) self.resources = LetterWizardDialogResources(xmsf) - Helper.setUnoPropertyValues( - self.xDialogModel, - ("Closeable", + uno.invoke(self.xDialogModel, "setPropertyValues", + (("Closeable", PropertyNames.PROPERTY_HEIGHT, "Moveable", PropertyNames.PROPERTY_NAME, @@ -42,7 +41,8 @@ class LetterWizardDialog(WizardDialog): PropertyNames.PROPERTY_WIDTH), (True, 210, True, "LetterWizardDialog", 104, 52, 1, 1, - self.resources.resLetterWizardDialog_title, 310)) + self.resources.resLetterWizardDialog_title, 310))) + self.fontDescriptor1 = \ uno.createUnoStruct('com.sun.star.awt.FontDescriptor') self.fontDescriptor2 = \ diff --git a/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py b/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py index c109b6546155..2c451335c25c 100644 --- a/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py +++ b/wizards/com/sun/star/wizards/letter/LetterWizardDialogImpl.py @@ -17,8 +17,8 @@ # import traceback import os.path -from .LetterWizardDialog import LetterWizardDialog, Helper, \ - PropertyNames, uno, HelpIds, HID +from .LetterWizardDialog import LetterWizardDialog, PropertyNames, uno, \ + HelpIds, HID from .LetterDocument import LetterDocument, BusinessPaperObject from .CGLetterWizard import CGLetterWizard from ..common.NoValidPathException import NoValidPathException @@ -570,12 +570,9 @@ class LetterWizardDialogImpl(LetterWizardDialog): try: xReceiverFrame = self.myLetterDoc.getFrameByName( "Receiver Address", self.myLetterDoc.xTextDocument) - iFrameWidth = int(Helper.getUnoPropertyValue( - xReceiverFrame, PropertyNames.PROPERTY_WIDTH)) - iFrameX = int(Helper.getUnoPropertyValue( - xReceiverFrame, "HoriOrientPosition")) - iFrameY = int(Helper.getUnoPropertyValue( - xReceiverFrame, "VertOrientPosition")) + iFrameWidth = int(xReceiverFrame.Width) + iFrameX = int(xReceiverFrame.HoriOrientPosition) + iFrameY = int(xReceiverFrame.VertOrientPosition) iReceiverHeight = int(0.5 * 1000) self.BusCompanyAddressReceiver = BusinessPaperObject( self.myLetterDoc.xTextDocument, " ", iFrameWidth, iReceiverHeight, @@ -689,8 +686,7 @@ class LetterWizardDialogImpl(LetterWizardDialog): BPaperItem = \ self.getRoadmapItemByID(LetterWizardDialogImpl.RM_FOOTER) - Helper.setUnoPropertyValue( - BPaperItem, PropertyNames.PROPERTY_ENABLED, bFooterPossible) + BPaperItem.Enabled = bFooterPossible except Exception: traceback.print_exc() @@ -823,21 +819,18 @@ class LetterWizardDialogImpl(LetterWizardDialog): def enableSenderReceiver(self): BPaperItem = self.getRoadmapItemByID( LetterWizardDialogImpl.RM_SENDERRECEIVER) - Helper.setUnoPropertyValue( - BPaperItem, PropertyNames.PROPERTY_ENABLED, True) + BPaperItem.Enabled = True def disableSenderReceiver(self): BPaperItem = self.getRoadmapItemByID( LetterWizardDialogImpl.RM_SENDERRECEIVER) - Helper.setUnoPropertyValue( - BPaperItem, PropertyNames.PROPERTY_ENABLED, False) + BPaperItem.Enabled = False def enableBusinessPaper(self): try: BPaperItem = self.getRoadmapItemByID( LetterWizardDialogImpl.RM_BUSINESSPAPER) - Helper.setUnoPropertyValue( - BPaperItem, PropertyNames.PROPERTY_ENABLED, True) + BPaperItem.Enabled = True self.chkPaperCompanyLogoItemChanged() self.chkPaperCompanyAddressItemChanged() self.chkPaperFooterItemChanged() @@ -849,8 +842,7 @@ class LetterWizardDialogImpl(LetterWizardDialog): try: BPaperItem = self.getRoadmapItemByID( LetterWizardDialogImpl.RM_BUSINESSPAPER) - Helper.setUnoPropertyValue( - BPaperItem, PropertyNames.PROPERTY_ENABLED, False) + BPaperItem.Enabled = False if self.BusCompanyLogo != None: self.BusCompanyLogo.removeFrame() diff --git a/wizards/com/sun/star/wizards/text/TextDocument.py b/wizards/com/sun/star/wizards/text/TextDocument.py index da9761da0948..150b0bfb1a90 100644 --- a/wizards/com/sun/star/wizards/text/TextDocument.py +++ b/wizards/com/sun/star/wizards/text/TextDocument.py @@ -21,10 +21,10 @@ import time from datetime import date as dateTimeObject from .ViewHandler import ViewHandler from .TextFieldHandler import TextFieldHandler -from ..common.Desktop import Desktop -from ..common.Helper import Helper from ..document.OfficeDocument import OfficeDocument +from ..common.Desktop import Desktop from ..common.Configuration import Configuration +from ..common.NumberFormatter import NumberFormatter from com.sun.star.container import NoSuchElementException from com.sun.star.lang import WrappedTargetException @@ -65,8 +65,7 @@ class TextDocument(object): xFrame, URL, "_self", xArgs); self.xWindowPeer = xFrame.getComponentWindow() self.m_xDocProps = self.xTextDocument.DocumentProperties - CharLocale = Helper.getUnoStructValue( - self.xTextDocument, "CharLocale"); + CharLocale = self.xTextDocument.CharLocale return else: @@ -110,8 +109,7 @@ class TextDocument(object): def init(self): self.xWindowPeer = self.xFrame.getComponentWindow() self.m_xDocProps = self.xTextDocument.DocumentProperties - self.CharLocale = Helper.getUnoStructValue( - self.xTextDocument, "CharLocale") + self.CharLocale = self.xTextDocument.CharLocale self.xText = self.xTextDocument.Text def showStatusIndicator(self): @@ -159,7 +157,7 @@ class TextDocument(object): xNameAccess = self.xTextDocument.StyleFamilies xPageStyleCollection = xNameAccess.getByName("PageStyles") xPageStyle = xPageStyleCollection.getByName("First Page") - return Helper.getUnoPropertyValue(xPageStyle, "Size") + return xPageStyle.Size except Exception: traceback.print_exc() return None @@ -196,7 +194,7 @@ class TextDocument(object): day = time.strftime("%d", now) dateObject = dateTimeObject(int(year), int(month), int(day)) - du = Helper.DateUtils(self.xMSF, self.xTextDocument) + du = self.DateUtils(self.xMSF, self.xTextDocument) ff = du.getFormat(DATE_SYS_DDMMYY) myDate = du.format(ff, dateObject) xDocProps2 = self.xTextDocument.DocumentProperties @@ -248,3 +246,32 @@ class TextDocument(object): auxList.append(allItems.getByIndex(i)) return auxList + + class DateUtils(object): + + def __init__(self, xmsf, document): + self.formatSupplier = document + formatSettings = self.formatSupplier.getNumberFormatSettings() + date = formatSettings.NullDate + self.calendar = dateTimeObject(date.Year, date.Month, date.Day) + self.formatter = NumberFormatter.createNumberFormatter(xmsf, + self.formatSupplier) + + ''' + @param format a constant of the enumeration NumberFormatIndex + @return + ''' + + def getFormat(self, format): + return NumberFormatter.getNumberFormatterKey( + self.formatSupplier, format) + + ''' + @param date a VCL date in form of 20041231 + @return a document relative date + ''' + + def format(self, formatIndex, date): + difference = date - self.calendar + return self.formatter.convertNumberToString(formatIndex, + difference.days) diff --git a/wizards/com/sun/star/wizards/text/TextSectionHandler.py b/wizards/com/sun/star/wizards/text/TextSectionHandler.py index 7e3c6e64477f..4a35fb4ac48d 100644 --- a/wizards/com/sun/star/wizards/text/TextSectionHandler.py +++ b/wizards/com/sun/star/wizards/text/TextSectionHandler.py @@ -17,7 +17,6 @@ # import uno import traceback -from ..common.Helper import Helper class TextSectionHandler(object): '''Creates a new instance of TextSectionHandler''' @@ -86,8 +85,8 @@ class TextSectionHandler(object): oSectionLink = \ uno.createUnoStruct('com.sun.star.text.SectionFileLink') oSectionLink.FileURL = "" - Helper.setUnoPropertyValues( - oTextSection, ("FileLink", "LinkRegion"),(oSectionLink, "")) + oTextSection.FileLink = oSectionLink + oTextSection.LinkRegion = "" except Exception: traceback.print_exc() @@ -100,9 +99,8 @@ class TextSectionHandler(object): oSectionLink = \ uno.createUnoStruct('com.sun.star.text.SectionFileLink') oSectionLink.FileURL = TemplateName - Helper.setUnoPropertyValues( - oTextSection, ("FileLink", "LinkRegion"), - (oSectionLink, SectionName)) + oTextSection.FileLink = oSectionLink + oTextSection.LinkRegion = SectionName NewSectionName = oTextSection.Name if NewSectionName is not SectionName: oTextSection.Name = SectionName diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog.py b/wizards/com/sun/star/wizards/ui/UnoDialog.py index 7cbeb2a3a42b..e20c1ff7672c 100644 --- a/wizards/com/sun/star/wizards/ui/UnoDialog.py +++ b/wizards/com/sun/star/wizards/ui/UnoDialog.py @@ -15,11 +15,11 @@ # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # +import uno import traceback from .PeerConfig import PeerConfig from .UIConsts import UIConsts from ..common.PropertyNames import PropertyNames -from ..common.Helper import Helper from com.sun.star.awt import Rectangle from com.sun.star.awt.PosSize import POS @@ -72,23 +72,10 @@ class UnoDialog(object): traceback.print_exc() return None - - def printControlProperties(self, ControlName): - try: - xControlModel = self.xDialogModel().getByName(ControlName) - allProps = xControlModel.PropertySetInfo.Properties - i = 0 - while i < allProps.length: - sName = allProps[i].Name - i += 1 - except Exception: - traceback.print_exc() - def getMAPConversionFactor(self, ControlName): xControl2 = self.xUnoDialog.getControl(ControlName) aSize = xControl2.Size - dblMAPWidth = Helper.getUnoPropertyValue(xControl2.Model, - int(PropertyNames.PROPERTY_WIDTH)) + dblMAPWidth = xControl2.Model.Width return (aSize.Width / dblMAPWidth) def getpreferredLabelSize(self, LabelName, sLabel): @@ -111,25 +98,17 @@ class UnoDialog(object): # This function may look ugly, but this is the only way to check # the count of values in the model,which is always right. # the control is only a view and could be right or not. - fieldnames = Helper.getUnoPropertyValue(getModel(_xListBox), - "StringItemList") + fieldnames = getModel(_xListBox).StringItemList return fieldnames.length def getSelectedItemPos(self, _xListBox): - ipos = Helper.getUnoPropertyValue(getModel(_xListBox), - "SelectedItems") + ipos = getModel(_xListBox).SelectedItems return ipos[0] def isListBoxSelected(self, _xListBox): - ipos = Helper.getUnoPropertyValue(getModel(_xListBox), - "SelectedItems") + ipos = getModel(_xListBox).SelectedItems return ipos.length > 0 - def addSingleItemtoListbox(self, xListBox, ListItem, iSelIndex): - xListBox.addItem(ListItem, xListBox.getItemCount()) - if iSelIndex != -1: - xListBox.selectItemPos(iSelIndex, True) - ''' The problem with setting the visibility of controls is that changing the current step of a dialog will automatically make @@ -147,8 +126,7 @@ class UnoDialog(object): try: iCurControlStep = int(getControlProperty( controlname, PropertyNames.PROPERTY_STEP)) - iCurDialogStep = int(Helper.getUnoPropertyValue( - self.xDialogModel, PropertyNames.PROPERTY_STEP)) + iCurDialogStep = int(self.xDialogModel.Step) if bIsVisible: setControlProperty( controlname, PropertyNames.PROPERTY_STEP, iCurDialogStep) @@ -164,12 +142,9 @@ class UnoDialog(object): def repaintDialogStep(self): try: - ncurstep = int(Helper.getUnoPropertyValue( - self.xDialogModel, PropertyNames.PROPERTY_STEP)) - Helper.setUnoPropertyValue( - self.xDialogModel, PropertyNames.PROPERTY_STEP, 99) - Helper.setUnoPropertyValue( - self.xDialogModel, PropertyNames.PROPERTY_STEP, ncurstep) + ncurstep = int(self.xDialogModel.Step) + self.xDialogModel.Step = 99 + self.xDialogModel.Step = ncurstep except Exception: traceback.print_exc() @@ -177,11 +152,10 @@ class UnoDialog(object): self, serviceName, componentName, sPropNames, oPropValues): try: xControlModel = self.xDialogModel.createInstance(serviceName) - Helper.setUnoPropertyValues( - xControlModel, sPropNames, oPropValues) + uno.invoke(xControlModel, "setPropertyValues", + (sPropNames, oPropValues)) self.xDialogModel.insertByName(componentName, xControlModel) - Helper.setUnoPropertyValue(xControlModel, - PropertyNames.PROPERTY_NAME, componentName) + xControlModel.Name = componentName except Exception: traceback.print_exc() @@ -202,12 +176,11 @@ class UnoDialog(object): xListBox.selectItemPos((short)(iFieldsSelIndex - 1), True) # deselects a Listbox. MultipleMode is not supported - def deselectListBox(self, _xBasisListBox): oListBoxModel = getModel(_xBasisListBox) - sList = Helper.getUnoPropertyValue(oListBoxModel, "StringItemList") - Helper.setUnoPropertyValue(oListBoxModel, "StringItemList", [[],[]]) - Helper.setUnoPropertyValue(oListBoxModel, "StringItemList", sList) + sList = oListBoxModel.StringItemList + oListBoxModel.StringItemList = [[],[]] + oListBoxModel.StringItemList = sList def calculateDialogPosition(self, FramePosSize): # Todo:check if it would be useful or possible to create a dialog peer @@ -309,8 +282,7 @@ class UnoDialog(object): @classmethod def setEnabled(self, control, enabled): - Helper.setUnoPropertyValue( - control.Model, PropertyNames.PROPERTY_ENABLED, enabled) + control.Model.Enabled = enabled @classmethod def getControlModelType(self, xServiceInfo): diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.py b/wizards/com/sun/star/wizards/ui/WizardDialog.py index 7ccd2ce381aa..eef56271372f 100644 --- a/wizards/com/sun/star/wizards/ui/WizardDialog.py +++ b/wizards/com/sun/star/wizards/ui/WizardDialog.py @@ -21,7 +21,6 @@ from abc import ABCMeta, abstractmethod from .UnoDialog2 import UnoDialog2, Desktop, PropertyNames, UIConsts, \ ItemListenerProcAdapter from .event.CommonListener import TerminateListenerProcAdapter -from ..common.Helper import Helper from ..common.Resource import Resource from ..common.HelpIds import HelpIds from ..document.OfficeDocument import OfficeDocument @@ -70,9 +69,7 @@ class WizardDialog(UnoDialog2): def itemStateChanged(self, itemEvent): try: self.nNewStep = itemEvent.ItemId - self.nOldStep = int(Helper.getUnoPropertyValue( - self.xDialogModel, - PropertyNames.PROPERTY_STEP)) + self.nOldStep = int(self.xDialogModel.Step) if self.nNewStep != self.nOldStep: self.switchToStep() @@ -80,14 +77,14 @@ class WizardDialog(UnoDialog2): traceback.print_exc() def setRoadmapInteractive(self, _bInteractive): - Helper.setUnoPropertyValue(self.oRoadmap, "Activated", _bInteractive) + self.oRoadmap.Activated = _bInteractive def setRoadmapComplete(self, bComplete): - Helper.setUnoPropertyValue(self.oRoadmap, "Complete", bComplete) + self.oRoadmap.Complete = bComplete def isRoadmapComplete(self): try: - return bool(Helper.getUnoPropertyValue(self.oRoadmap, "Complete")) + return bool(self.oRoadmap.Complete) except Exception: traceback.print_exc() return False @@ -96,21 +93,18 @@ class WizardDialog(UnoDialog2): if self.oRoadmap is not None: nCurItemID = self.getCurrentRoadmapItemID() if nCurItemID != ID: - Helper.setUnoPropertyValue(self.oRoadmap, "CurrentItemID",ID) + self.oRoadmap.CurrentItemID = ID def getCurrentRoadmapItemID(self): try: - return int(Helper.getUnoPropertyValue( - self.oRoadmap, "CurrentItemID")) + return int(self.oRoadmap.CurrentItemID) except Exception: traceback.print_exc() return -1 def addRoadmap(self): try: - iDialogHeight = Helper.getUnoPropertyValue( - self.xDialogModel, - PropertyNames.PROPERTY_HEIGHT) + iDialogHeight = self.xDialogModel.Height # the roadmap control has got no real TabIndex ever # that is not correct, but changing this would need time, # so it is used without TabIndex as before @@ -131,9 +125,8 @@ class WizardDialog(UnoDialog2): xRoadmapControl.addItemListener( ItemListenerProcAdapter(method)) - Helper.setUnoPropertyValue( - self.oRoadmap, "Text", - self.__oWizardResource.getResText(UIConsts.RID_COMMON + 16)) + self.oRoadmap.Text = \ + self.__oWizardResource.getResText(UIConsts.RID_COMMON + 16) except NoSuchMethodException: Resource.showCommonResourceError(xMSF) except Exception: @@ -148,11 +141,9 @@ class WizardDialog(UnoDialog2): if isinstance(_sLabel, int): _sLabel = self.sRMItemLabels(_sLabel) oRoadmapItem = self.oRoadmap.createInstance() - Helper.setUnoPropertyValue(oRoadmapItem, - PropertyNames.PROPERTY_LABEL, _sLabel) - Helper.setUnoPropertyValue(oRoadmapItem, - PropertyNames.PROPERTY_ENABLED, _bEnabled) - Helper.setUnoPropertyValue(oRoadmapItem, "ID", _CurItemID) + oRoadmapItem.Label = _sLabel + oRoadmapItem.Enabled = _bEnabled + oRoadmapItem.ID = _CurItemID self.oRoadmap.insertByIndex(Index, oRoadmapItem) except Exception: traceback.print_exc() @@ -162,7 +153,7 @@ class WizardDialog(UnoDialog2): getByIndex = self.oRoadmap.getByIndex for i in list(range(self.oRoadmap.Count)): CurRoadmapItem = getByIndex(i) - CurID = int(Helper.getUnoPropertyValue(CurRoadmapItem, "ID")) + CurID = int(CurRoadmapItem.ID) if CurID == _ID: return CurRoadmapItem @@ -204,8 +195,7 @@ class WizardDialog(UnoDialog2): pass def changeToStep(self, nNewStep): - Helper.setUnoPropertyValue(self.xDialogModel, - PropertyNames.PROPERTY_STEP, nNewStep) + self.xDialogModel.Step = nNewStep self.setCurrentRoadmapItemID(nNewStep) self.enableNextButton(self.getNextAvailableStep() > 0) self.enableBackButton(nNewStep != 1) @@ -216,10 +206,8 @@ class WizardDialog(UnoDialog2): iButtonWidth = self.__iButtonWidth iButtonHeight = 14 iCurStep = 0 - iDialogHeight = Helper.getUnoPropertyValue(self.xDialogModel, - PropertyNames.PROPERTY_HEIGHT) - iDialogWidth = Helper.getUnoPropertyValue(self.xDialogModel, - PropertyNames.PROPERTY_WIDTH) + iDialogHeight = self.xDialogModel.Height + iDialogWidth = self.xDialogModel.Width iHelpPosX = 8 iBtnPosY = iDialogHeight - iButtonHeight - 6 iCancelPosX = iDialogWidth - self.__iButtonWidth - 6 @@ -255,9 +243,7 @@ class WizardDialog(UnoDialog2): PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH) - Helper.setUnoPropertyValue( - self.xDialogModel, PropertyNames.PROPERTY_HELPURL, - HelpIds.getHelpIdString(self.__hid)) + self.xDialogModel.HelpURL = HelpIds.getHelpIdString(self.__hid) self.insertButton("btnWizardHelp", WizardDialog.__HELP_ACTION_PERFORMED, (PropertyNames.PROPERTY_ENABLED, @@ -312,8 +298,7 @@ class WizardDialog(UnoDialog2): def setStepEnabled(self, _nStep, bEnabled, enableNextButton=None): xRoadmapItem = self.getRoadmapItemByID(_nStep) if xRoadmapItem is not None: - Helper.setUnoPropertyValue(xRoadmapItem, - PropertyNames.PROPERTY_ENABLED, bEnabled) + xRoadmapItem.Enabled = bEnabled if enableNextButton is not None: if self.getNextAvailableStep() > 0: self.enableNextButton(bEnabled) @@ -352,8 +337,7 @@ class WizardDialog(UnoDialog2): # Todo: In this case an exception should be thrown if xRoadmapItem is None: return False - bIsEnabled = bool(Helper.getUnoPropertyValue(xRoadmapItem, - PropertyNames.PROPERTY_ENABLED)) + bIsEnabled = bool(xRoadmapItem.Enabled) return bIsEnabled except Exception: traceback.print_exc() @@ -422,8 +406,7 @@ class WizardDialog(UnoDialog2): def getCurrentStep(self): try: - return int(Helper.getUnoPropertyValue(self.xDialogModel, - PropertyNames.PROPERTY_STEP)) + return int(self.xDialogModel.Step) except Exception: traceback.print_exc() return -1 diff --git a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py index c753a9be256b..6f1e9b2c4992 100644 --- a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py +++ b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py @@ -18,7 +18,6 @@ import uno from .CommonListener import ItemListenerProcAdapter, TextListenerProcAdapter from .DataAware import DataAware, PropertyNames -from ...common.Helper import Helper ''' @author rpiterman @@ -44,16 +43,15 @@ class UnoDataAware(DataAware): def enableControls(self, value): for i in self.disableObjects: - Helper.setUnoPropertyValue( - i.Model, PropertyNames.PROPERTY_ENABLED, bool(value)) + i.Model.Enabled = bool(value) def setToUI(self, value): if self.isShort: value = uno.Any("[]short", (value,)) - Helper.setUnoPropertyValue(self.unoModel, self.unoPropName, value) + setattr(self.unoModel, self.unoPropName, value) def getFromUI(self): - return Helper.getUnoPropertyValue(self.unoModel, self.unoPropName) + return getattr(self.unoModel, self.unoPropName) @classmethod def __attachTextControl( |