From ba5f79d6f230d06ac3ff87a43579c4ef14992ec7 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Tue, 26 Jul 2011 19:36:03 +0200 Subject: Add Textfield listeners and fix a bug found in the java wizard BUG: The time was showed wrongly --- .../com/sun/star/wizards/agenda/AgendaTemplate.py | 151 +++++++++++---------- .../sun/star/wizards/agenda/AgendaWizardDialog.py | 11 +- .../star/wizards/agenda/AgendaWizardDialogConst.py | 4 + .../star/wizards/agenda/AgendaWizardDialogImpl.py | 13 ++ 4 files changed, 100 insertions(+), 79 deletions(-) (limited to 'wizards/com/sun/star/wizards/agenda') diff --git a/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py b/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py index e810c6c47970..3d6c0cf2c0e9 100644 --- a/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py +++ b/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py @@ -23,16 +23,18 @@ def synchronized(lock): ''' The classes here implement the whole document-functionality of the agenda wizard: -the live-preview and the final "creation" of the document, when the user clicks "finish".
+the live-preview and the final "creation" of the document, +when the user clicks "finish".

Some terminology:

items are names or headings. we don't make any distinction.
-The Agenda Template is used as general "controller" of the whole document, whereas the -two child-classes ItemsTable and TopicsTable control the item tables (note plural!) and the -topics table (note singular). -

+The Agenda Template is used as general "controller" +of the whole document, whereas the two child-classes ItemsTable +and TopicsTable control the item tables (note plural!) and the +topics table (note singular).
+
Other small classes are used to abstract the handling of cells and text and we try to use them as components.

@@ -42,7 +44,8 @@ To keep the template flexible the following decisions were made:
1. Item tables.
1.a. there might be arbitrary number of Item tables.
1.b. Item tables design (bordewr, background) is arbitrary.
-1.c. Items text styles are individual, and use stylelist styles with predefined names.
+1.c. Items text styles are individual, +and use stylelist styles with predefined names.
As result the following limitations:
Pairs of Name->value for each item.
Tables contain *only* those pairs.
@@ -75,6 +78,7 @@ class AgendaTemplate(TextDocument): template = None agenda = None lock = RLock() + initDictionary = False '''constructor. The document is *not* loaded here. only some formal members are set. @@ -88,6 +92,10 @@ class AgendaTemplate(TextDocument): "WIZARD_LIVE_PREVIEW") AgendaTemplate.agenda = agenda_ self.resources = resources_ + + if not AgendaTemplate.initDictionary: + self.initializeDictionary() + if AgendaTemplate.itemsCache is None: self.initItemsCache() @@ -166,6 +174,20 @@ class AgendaTemplate(TextDocument): def setTemplateTitle(self, newTitle): self.m_xDocProps.Title = newTitle + def initializeDictionary(self): + AgendaTemplate.isShowItemDict = \ + {FILLIN_MEETING_TYPE:AgendaTemplate.agenda.cp_ShowMeetingType, + FILLIN_READ:AgendaTemplate.agenda.cp_ShowRead, + FILLIN_BRING:AgendaTemplate.agenda.cp_ShowBring, + FILLIN_NOTES:AgendaTemplate.agenda.cp_ShowNotes, + FILLIN_FACILITATOR:AgendaTemplate.agenda.cp_ShowFacilitator, + FILLIN_TIMEKEEPER:AgendaTemplate.agenda.cp_ShowTimekeeper, + FILLIN_NOTETAKER:AgendaTemplate.agenda.cp_ShowNotetaker, + FILLIN_PARTICIPANTS:AgendaTemplate.agenda.cp_ShowAttendees, + FILLIN_CALLED_BY:AgendaTemplate.agenda.cp_ShowCalledBy, + FILLIN_OBSERVERS:AgendaTemplate.agenda.cp_ShowObservers, + FILLIN_RESOURCE_PERSONS:AgendaTemplate.agenda.cp_ShowResourcePersons} + '''checks the data model if the item corresponding to the given string should be shown @param itemName a string representing an Item (name or heading). @@ -174,29 +196,9 @@ class AgendaTemplate(TextDocument): @classmethod def isShowItem(self, itemName): - if itemName == FILLIN_MEETING_TYPE: - return AgendaTemplate.agenda.cp_ShowMeetingType - elif itemName == FILLIN_READ: - return AgendaTemplate.agenda.cp_ShowRead - elif itemName == FILLIN_BRING: - return AgendaTemplate.agenda.cp_ShowBring - elif itemName == FILLIN_NOTES: - return AgendaTemplate.agenda.cp_ShowNotes - elif itemName == FILLIN_FACILITATOR: - return AgendaTemplate.agenda.cp_ShowFacilitator - elif itemName == FILLIN_TIMEKEEPER: - return AgendaTemplate.agenda.cp_ShowTimekeeper - elif itemName == FILLIN_NOTETAKER: - return AgendaTemplate.agenda.cp_ShowNotetaker - elif itemName == FILLIN_PARTICIPANTS: - return AgendaTemplate.agenda.cp_ShowAttendees - elif itemName == FILLIN_CALLED_BY: - return AgendaTemplate.agenda.cp_ShowCalledBy - elif itemName == FILLIN_OBSERVERS: - return AgendaTemplate.agenda.cp_ShowObservers - elif itemName == FILLIN_RESOURCE_PERSONS: - return AgendaTemplate.agenda.cp_ShowResourcePersons - else: + try: + return AgendaTemplate.isShowItemDict[itemName] + except KeyError: raise ValueError("No such item") '''itemsCache is a Map containing all agenda item. These are object which @@ -292,9 +294,9 @@ class AgendaTemplate(TextDocument): and create the date and time formatters. ''' dateUtils = Helper.DateUtils(self.xMSF, AgendaTemplate.document) - self.formatter = dateUtils.formatter - self.dateFormat = dateUtils.getFormat(DATE_SYSTEM_LONG) - self.timeFormat = dateUtils.getFormat(TIME_HHMM) + AgendaTemplate.formatter = dateUtils.formatter + AgendaTemplate.dateFormat = dateUtils.getFormat(DATE_SYSTEM_LONG) + AgendaTemplate.timeFormat = dateUtils.getFormat(TIME_HHMM) ''' get the document properties object. @@ -322,35 +324,35 @@ class AgendaTemplate(TextDocument): workwith = AgendaTemplate._allItems[i] text = workwith.String.lstrip().lower() if text == FILLIN_TITLE: - self.teTitle = PlaceholderTextElement( + AgendaTemplate.teTitle = PlaceholderTextElement( workwith, self.resources.resPlaceHolderTitle, self.resources.resPlaceHolderHint, AgendaTemplate.document) - self.trTitle = workwith + AgendaTemplate.trTitle = workwith del AgendaTemplate._allItems[i] i -= 1 elif text == FILLIN_DATE: - self.teDate = PlaceholderTextElement( + AgendaTemplate.teDate = PlaceholderTextElement( workwith, self.resources.resPlaceHolderDate, self.resources.resPlaceHolderHint, AgendaTemplate.document) - self.trDate = workwith + AgendaTemplate.trDate = workwith del AgendaTemplate._allItems[i] i -= 1 elif text == FILLIN_TIME: - self.teTime = PlaceholderTextElement( + AgendaTemplate.teTime = PlaceholderTextElement( workwith, self.resources.resPlaceHolderTime, self.resources.resPlaceHolderHint, AgendaTemplate.document) - self.trTime = workwith + AgendaTemplate.trTime = workwith del AgendaTemplate._allItems[i] i -= 1 elif text == FILLIN_LOCATION: - self.teLocation = PlaceholderTextElement( + AgendaTemplate.teLocation = PlaceholderTextElement( workwith, self.resources.resPlaceHolderLocation, self.resources.resPlaceHolderHint, AgendaTemplate.document) - self.trLocation = workwith + AgendaTemplate.trLocation = workwith del AgendaTemplate._allItems[i] i -= 1 i += 1 @@ -409,38 +411,32 @@ class AgendaTemplate(TextDocument): def getTable(self, name): return getattr(AgendaTemplate.document.TextTables, name) - ''' - implementation of DataAware.Listener, is - called when title/date/time or location are - changed. - ''' - - @synchronized(lock) - def eventPerformed(self, param): - controlName = Helper.getUnoPropertyValue( - UnoDialog2.getModel(param.Source), PropertyNames.PROPERTY_NAME) - self.redrawTitle(controlName) - + @classmethod @synchronized(lock) def redrawTitle(self, controlName): - if controlName == "txtTitle": - self.writeTitle( - self.teTitle, self.trTitle, AgendaTemplate.agenda.cp_Title) - elif controlName == "txtDate": - self.writeTitle( - self.teDate, self.trDate, - self.getDateString(AgendaTemplate.agenda.cp_Date)) - elif controlName == "txtTime": - self.writeTitle( - self.teTime, self.trTime, - self.getTimeString(AgendaTemplate.agenda.cp_Time)) - elif controlName == "cbLocation": - self.writeTitle( - self.teLocation, self.trLocation, - AgendaTemplate.agenda.cp_Location) - else: - raise IllegalArgumentException ("No such title control...") + try: + if controlName == "txtTitle": + self.writeTitle( + AgendaTemplate.teTitle, AgendaTemplate.trTitle, + AgendaTemplate.agenda.cp_Title) + elif controlName == "txtDate": + self.writeTitle( + AgendaTemplate.teDate, AgendaTemplate.trDate, + self.getDateString(AgendaTemplate.agenda.cp_Date)) + elif controlName == "txtTime": + self.writeTitle( + AgendaTemplate.teTime, AgendaTemplate.trTime, + self.getTimeString(AgendaTemplate.agenda.cp_Time)) + elif controlName == "cbLocation": + self.writeTitle( + AgendaTemplate.teLocation, AgendaTemplate.trLocation, + AgendaTemplate.agenda.cp_Location) + else: + raise IllegalArgumentException ("No such title control...") + except Exception: + traceback.print_exc() + @classmethod def writeTitle(self, te, tr, text): if text is None: te.text = "" @@ -448,6 +444,7 @@ class AgendaTemplate(TextDocument): te.text = text te.write(tr) + @classmethod def getDateString(self, d): if d is None or d == "": return "" @@ -461,15 +458,17 @@ class AgendaTemplate(TextDocument): I need a day... ''' daysDiff = (date1 - self.docNullTime) / self.__class__.DAY_IN_MILLIS + 1 - return self.formatter.convertNumberToString(self.dateFormat, daysDiff) + return AgendaTemplate.formatter.convertNumberToString( + self.dateFormat, daysDiff) + @classmethod def getTimeString(self, s): if s is None or s == "": return "" - time = int(s) - #t = (int(s) / 1000000) / 24) + (time % 1000000) / 1000) / (24 * 60) - return self.formatter.convertNumberToString(self.timeFormat, t) + t = ((time / float(1000000)) / float(24)) \ + + ((time % 1000000) / float(1000000)) / float(35) + return self.formatter.convertNumberToString(AgendaTemplate.timeFormat, t) @synchronized(lock) def finish(self, topics): @@ -1191,6 +1190,7 @@ class ParaStyled(object): def format(self, textRange): if textRange is None: textRange = textRange.Text + cursor = textRange.createTextCursorByRange(textRange) Helper.setUnoPropertyValue( cursor, "ParaStyleName", ParaStyled.paraStyle) @@ -1218,8 +1218,9 @@ class TextElement(ParaStyled): def write(self, textRange): textRange.String = self.text - if not self.text == "": - super(TextElement,self).write(textRange) + #COMMENTED + #if not self.text == "": + # super(TextElement,self).write(textRange) ''' A Text element which, if the text to write is empty (null or "") diff --git a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialog.py b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialog.py index 6d19ebb48a0b..1090717e4fc7 100644 --- a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialog.py +++ b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialog.py @@ -130,11 +130,12 @@ class AgendaWizardDialog(WizardDialog): self.resources.reslblTitle2_value, True,91, 8, 2, 200,212)) self.insertLabel("lblDate", self.PROPS_TEXT, (8, self.resources.reslblDate_value, 97, 32, 2, 201,66)) - self.txtDate = self.insertDateField("txtDate", None, self.PROPS_LIST, + self.txtDate = self.insertDateField( + "txtDate", TXTDATE_TEXT_CHANGED, self.PROPS_LIST, (True, 12, TXTDATE_HID,166,30, 2, 202,70), self) self.insertLabel("lblTime", self.PROPS_TEXT, (8, self.resources.reslblTime_value, 97, 50, 2, 203, 66)) - self.txtTime = self.insertTimeField("txtTime", None, + self.txtTime = self.insertTimeField("txtTime", TXTTIME_TEXT_CHANGED, (PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, @@ -146,7 +147,8 @@ class AgendaWizardDialog(WizardDialog): (12, TXTTIME_HID, 166, 48, 2, True, 204,70), self) self.insertLabel("lblTitle", self.PROPS_TEXT, (8, self.resources.reslblTitle_value, 97, 68, 2, 205,66)) - self.txtTitle = self.insertTextField("txtTitle", None, + self.txtTitle = self.insertTextField( + "txtTitle", TXTTITLE_TEXT_CHANGED, (PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_MULTILINE, @@ -158,7 +160,8 @@ class AgendaWizardDialog(WizardDialog): (26, TXTTITLE_HID, True, 166, 66, 2, 206, 138), self) self.insertLabel("lblLocation", self.PROPS_TEXT, (8, self.resources.reslblLocation_value, 97, 100, 2, 207, 66)) - self.cbLocation = self.insertTextField("cbLocation", None, + self.cbLocation = self.insertTextField( + "cbLocation", TXTLOCATION_TEXT_CHANGED, (PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_MULTILINE, diff --git a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogConst.py b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogConst.py index c97501cbb944..2ad9cca1cd1a 100644 --- a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogConst.py +++ b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogConst.py @@ -1,5 +1,9 @@ from common.HelpIds import HelpIds +TXTTITLE_TEXT_CHANGED = "txtTitleTextChanged" +TXTDATE_TEXT_CHANGED = "txtDateTextChanged" +TXTTIME_TEXT_CHANGED = "txtTimeTextChanged" +TXTLOCATION_TEXT_CHANGED = "txtLocationTextChanged" CHKUSEMEETINGTYPE_ITEM_CHANGED = "chkUseMeetingTypeItemChanged" CHKUSEREAD_ITEM_CHANGED = "chkUseReadItemChanged" CHKUSEBRING_ITEM_CHANGED = "chkUseBringItemChanged" diff --git a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py index 0cedfb02aaee..6d85b27dfd5c 100644 --- a/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py +++ b/wizards/com/sun/star/wizards/agenda/AgendaWizardDialogImpl.py @@ -267,6 +267,19 @@ class AgendaWizardDialogImpl(AgendaWizardDialog): title = Helper.getUnoPropertyValue(getModel(txtTemplateName), "Text") self.agendaTemplate.setTemplateTitle(title) + #textFields listeners + def txtTitleTextChanged(self): + AgendaTemplate.redrawTitle("txtTitle") + + def txtDateTextChanged(self): + AgendaTemplate.redrawTitle("txtDate") + + def txtTimeTextChanged(self): + AgendaTemplate.redrawTitle("txtTime") + + def txtLocationTextChanged(self): + AgendaTemplate.redrawTitle("cbLocation") + #checkbox listeners def chkUseMeetingTypeItemChanged(self): AgendaTemplate.redraw(FILLIN_MEETING_TYPE) -- cgit v1.2.3