Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3025

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/25/3025/1

Init: Pythonize the CGSettings class; added a new internal class DateUtils.

Change-Id: I604544ae224c3a822514e479db223a6e0268fb12
---
M wizards/com/sun/star/wizards/web/data/CGSettings.py
1 file changed, 56 insertions(+), 24 deletions(-)



diff --git a/wizards/com/sun/star/wizards/web/data/CGSettings.py 
b/wizards/com/sun/star/wizards/web/data/CGSettings.py
index ff5bf55..ecada3f 100644
--- a/wizards/com/sun/star/wizards/web/data/CGSettings.py
+++ b/wizards/com/sun/star/wizards/web/data/CGSettings.py
@@ -16,19 +16,22 @@
 #   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 #
 import traceback
-from common.FileAccess import FileAccess
-from common.ConfigGroup import ConfigGroup
-from common.ConfigSet import ConfigSet
-from CGExporter import CGExporter
-from CGLayout import CGLayout
-from CGStyle import CGStyle
-from CGIconSet import CGIconSet
-from CGImage import CGImage
-from CGFilter import CGFilter
-from common.Helper import Helper
-from CGSessionName import CGSessionName
-from CGSession import CGSession
-from common.Properties import Properties
+import uno
+from datetime import date as dateTimeObject
+
+from ...common.FileAccess import FileAccess
+from ...common.ConfigGroup import ConfigGroup
+from ...common.ConfigSet import ConfigSet
+from ...common.NumberFormatter import NumberFormatter
+from ...common.Properties import Properties
+from .CGExporter import CGExporter
+from .CGLayout import CGLayout
+from .CGStyle import CGStyle
+from .CGIconSet import CGIconSet
+from .CGImage import CGImage
+from .CGFilter import CGFilter
+from .CGSessionName import CGSessionName
+from .CGSession import CGSession
 
 from com.sun.star.i18n.NumberFormatIndex import DATE_SYS_DMMMYYYY
 from com.sun.star.i18n.NumberFormatIndex import NUMBER_1000DEC2
@@ -57,10 +60,8 @@
     def __init__(self, xmsf_, resources_, document):
         self.xmsf = xmsf_
         try:
-            self.soTemplateDir = FileAccess.getOfficePath2(
-                self.xmsf, "Config", "", "")
-            self.soGalleryDir = FileAccess.getOfficePath2(
-                self.xmsf, "Gallery", "share", "")
+            self.soTemplateDir = FileAccess.getOfficePath2(self.xmsf, "Config", "", "");
+            self.soGalleryDir = FileAccess.getOfficePath2(self.xmsf, "Gallery", "share", "");
             ConfigGroup.root = self
             self.formatter = self.Formatter(self.xmsf, document)
             self.resources = resources_
@@ -85,9 +86,10 @@
                 if i.supports(mime):
                     try:
                         v.append(i)
-                    except Exception, ex:
+                    except Exception:
                         traceback.print_exc()
-
+            else:
+                print ("DEBUG !!! Exporter is None")
         return v
 
     '''
@@ -100,19 +102,25 @@
         self.workPath = FileAccess.connectURLs(
             self.soTemplateDir, self.cp_WorkDir)
         #COMMENTED
-        #self.calcExportersTargetTypeNames(xmsf)
+        self.calcExportersTargetTypeNames(xmsf)
 
     def calcExportersTargetTypeNames(self, xmsf):
         typeDetect = xmsf.createInstance(
             "com.sun.star.document.TypeDetection")
-        for i in xrange(self.cp_Exporters.getSize()):
+        for i in range(self.cp_Exporters.getSize()):
             self.calcExporterTargetTypeName(
                 typeDetect, self.cp_Exporters.getElementAt(i))
 
     def calcExporterTargetTypeName(self, typeDetect, exporter):
-        if not exporter.cp_TargetType == "":
-            exporter.targetTypeName = Properties.getPropertyValue(
+        if (exporter is None):
+            print ("WARNING !!!! calcExporterTargetTypeName - received None as exporter argument.")
+            return
+        print ("WARNING !!!! calcExporterTargetTypeName - targetType: ", exporter.cp_TargetType)
+        if not (exporter.cp_TargetType == "" or exporter.cp_TargetType is None):
+            targetTypeName = Properties.getPropertyValue(
                 typeDetect.getByName(exporter.cp_TargetType), "UIName")
+            print ("WARNING !!!! calcExporterTargetTypeName - targetTypeName: ", targetTypeName)
+            exporter.cp_targetTypeName = targetTypeName
 
     @classmethod
     def getFileAccess(self, xmsf = None):
@@ -124,8 +132,32 @@
         return CGSettings.fileAccess
 
     class Formatter(object):
+        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)
+
         def __init__(self, xmsf, document):
-            self.dateUtils = Helper.DateUtils(xmsf, document)
+            self.dateUtils = self.DateUtils(xmsf, document)
             self.dateFormat = self.dateUtils.getFormat(DATE_SYS_DMMMYYYY)
             self.numberFormat = self.dateUtils.getFormat(NUMBER_1000DEC2)
 

-- 
To view, visit https://gerrit.libreoffice.org/3025
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I604544ae224c3a822514e479db223a6e0268fb12
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Javier Fernandez <javier.fgb@gmail.com>


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.