summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2013-09-08 19:56:06 +0200
committerAndras Timar <andras.timar@collabora.com>2013-11-21 11:49:59 +0100
commit850b79a65cbce157a154a709eb71806c35e19570 (patch)
treeb235f8f4a0c6da0bf6e99dc45041bb92e7467895 /wizards
parent13f764fd91307b168da1a2336beabe47d42d4be4 (diff)
pywizards: Fix date and time fields
Change-Id: I7be16558bab7c4dde2d326808b9fb115a6878894 Signed-off-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'wizards')
-rw-r--r--wizards/com/sun/star/wizards/agenda/AgendaDocument.py33
-rw-r--r--wizards/com/sun/star/wizards/ui/event/DataAware.py13
-rw-r--r--wizards/com/sun/star/wizards/ui/event/UnoDataAware.py21
3 files changed, 34 insertions, 33 deletions
diff --git a/wizards/com/sun/star/wizards/agenda/AgendaDocument.py b/wizards/com/sun/star/wizards/agenda/AgendaDocument.py
index 2a74597b8c10..a8dcece9d826 100644
--- a/wizards/com/sun/star/wizards/agenda/AgendaDocument.py
+++ b/wizards/com/sun/star/wizards/agenda/AgendaDocument.py
@@ -22,7 +22,7 @@ from ..text.TextDocument import TextDocument
from ..text.TextSectionHandler import TextSectionHandler
from ..common.FileAccess import FileAccess
-from datetime import date as dateTimeObject
+from datetime import datetime
from com.sun.star.text.PlaceholderType import TEXT
from com.sun.star.i18n.NumberFormatIndex import TIME_HHMM, DATE_SYSTEM_LONG
@@ -142,7 +142,7 @@ class AgendaDocument(TextDocument):
except Exception:
traceback.print_exc()
self.xTextDocument.unlockControllers()
-
+
'''
checks the data model if the
item corresponding to the given string should be shown
@@ -367,8 +367,7 @@ class AgendaDocument(TextDocument):
self.getDateString(self.agenda.cp_Date)
self.teDate.write(self.trDate)
elif controlName == "txtTime":
- self.teTime.placeHolderText = \
- self.getTimeString(self.agenda.cp_Time)
+ self.teTime.placeHolderText = self.agenda.cp_Time
self.teTime.write(self.trTime)
elif controlName == "cbLocation":
self.teLocation.placeHolderText = self.agenda.cp_Location
@@ -378,25 +377,12 @@ class AgendaDocument(TextDocument):
except Exception:
traceback.print_exc()
- def getDateString(self, d):
- if not d:
+ def getDateString(self, date):
+ if not date:
return ""
- date = int(d)
- year = int(date / 10000)
- month = int((date % 10000) / 100)
- day = int(date % 100)
- dateObject = dateTimeObject(year, month, day)
+ dateObject = datetime.strptime(date, '%d/%m/%y').date()
return self.dateUtils.format(self.dateFormat, dateObject)
- def getTimeString(self, s):
- if s is None or s == "":
- return ""
- time = int(s)
- t = ((time / float(1000000)) / float(24)) \
- + ((time % 1000000) / float(1000000)) / float(35)
- return self.formatter.convertNumberToString(
- self.timeFormat, t)
-
def finish(self, topics):
self.createMinutes(topics)
self.deleteHiddenSections()
@@ -468,8 +454,7 @@ class AgendaDocument(TextDocument):
self.resources.resPlaceHolderDate)
elif itemText == \
self.templateConsts.FILLIN_MINUTES_TIME:
- self.fillMinutesItem(
- item, getTimeString(self.agenda.cp_Time),
+ self.fillMinutesItem( item, self.agenda.cp_Time,
self.resources.resPlaceHolderTime)
self.items.clear()
@@ -510,9 +495,9 @@ class AgendaDocument(TextDocument):
if topicTime == 0 or topicStartTime == 0:
time = topic[3].Value
else:
- time = getTimeString(str(topicStartTime)) + " - "
+ time = str(topicStartTime) + " - "
topicStartTime += topicTime * 1000
- time += getTimeString(str(topicStartTime))
+ time += str(topicStartTime)
fillMinutesItem(item, time, "")
diff --git a/wizards/com/sun/star/wizards/ui/event/DataAware.py b/wizards/com/sun/star/wizards/ui/event/DataAware.py
index 9628f0cd27ba..0fae91a559f6 100644
--- a/wizards/com/sun/star/wizards/ui/event/DataAware.py
+++ b/wizards/com/sun/star/wizards/ui/event/DataAware.py
@@ -20,6 +20,10 @@ import uno
from abc import ABCMeta, abstractmethod
from ...common.PropertyNames import PropertyNames
+from com.sun.star.util import Date
+from com.sun.star.util import Time
+from datetime import datetime
+
'''
@author rpiterman
DataAware objects are used to live-synchronize UI and DataModel/DataObject.
@@ -118,9 +122,12 @@ class DataAware(object):
data = uno.invoke(self._dataObject, "get" + self._field, ())
ui = self.getFromUI()
if data is not ui:
- #if isinstance(ui,tuple):
- #Selected Element listbox
- # ui = ui[0]
+ if isinstance(ui,Date):
+ d = datetime(ui.Year, ui.Month, ui.Day)
+ ui = d.strftime('%d/%m/%y')
+ elif isinstance(ui,Time):
+ t = datetime(1, 1, 1, ui.Hours, ui.Minutes)
+ ui = t.strftime('%H:%M')
if useUno:
uno.invoke(self._dataObject, "set" + self._field, (ui,))
else:
diff --git a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
index ea728b9687f6..1ed80a10dbc6 100644
--- a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
+++ b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py
@@ -17,7 +17,9 @@
#
import uno
from .CommonListener import ItemListenerProcAdapter, TextListenerProcAdapter
-from .DataAware import DataAware, PropertyNames
+from .DataAware import DataAware, PropertyNames, datetime, Date, Time
+
+from com.sun.star.script import CannotConvertException
'''
@author rpiterman
@@ -47,14 +49,21 @@ class UnoDataAware(DataAware):
def setToUI(self, value):
if (isinstance(value, list)):
- length = len(value)
value = tuple(value)
elif self.isShort:
value = uno.Any("[]short", (value,))
- if (hasattr(self.unoModel, self.unoPropName)):
- setattr(self.unoModel, self.unoPropName, value)
- else:
- uno.invoke(self.unoModel, "set" + self.unoPropName, (value,))
+ if value:
+ if(hasattr(self.unoModel, self.unoPropName)):
+ if self.unoPropName == "Date":
+ d = datetime.strptime(value, '%d/%m/%y')
+ value = Date(d.day, d.month, d.year)
+ elif self.unoPropName == "Time":
+ t = datetime.strptime(value, '%H:%M')
+ value = Time(0, 0, t.minute, t.hour, False)
+
+ setattr(self.unoModel, self.unoPropName, value)
+ else:
+ uno.invoke(self.unoModel, "set" + self.unoPropName, (value,))
# Try to get from an arbitrary object a boolean value.
# Null returns Boolean.FALSE;