Kaydet (Commit) 1d615fee authored tarafından Xisco Fauli's avatar Xisco Fauli

Revert "pyagenda: rework AgendaTemplate.py. Still some work to do"

This reverts commit 9545c85d.
üst 88e457dc
...@@ -15,14 +15,11 @@ ...@@ -15,14 +15,11 @@
# except in compliance with the License. You may obtain a copy of # except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0 . # the License at http://www.apache.org/licenses/LICENSE-2.0 .
# #
import traceback
import uno import uno
from .TemplateConsts import * from .TemplateConsts import *
from threading import RLock from threading import RLock
from ..text.TextDocument import TextDocument from ..text.TextDocument import *
from ..common.FileAccess import FileAccess from ..common.FileAccess import FileAccess
from ..common.TextElement import TextElement
from ..common.Helper import Helper
from ..text.TextSectionHandler import TextSectionHandler from ..text.TextSectionHandler import TextSectionHandler
from datetime import date as dateTimeObject from datetime import date as dateTimeObject
...@@ -79,7 +76,7 @@ One compolsary Heading row.<br/> ...@@ -79,7 +76,7 @@ One compolsary Heading row.<br/>
<br/><br/> <br/><br/>
To let the template be flexible, we use a kind of "detection": we look where To let the template be flexible, we use a kind of "detection": we look where
the items are read the design of each table, reaplying it after writing the the items are read the design of each table, reaplying it after writing the
table.AgendaTemplate.xTextDocument table.AgendaTemplate.document
<br/><br/> <br/><br/>
A note about threads:<br/> A note about threads:<br/>
Many methods here are synchronized, in order to avoid colission made by Many methods here are synchronized, in order to avoid colission made by
...@@ -89,6 +86,8 @@ events fired too often. ...@@ -89,6 +86,8 @@ events fired too often.
class AgendaTemplate(TextDocument): class AgendaTemplate(TextDocument):
writtenTopics = [] writtenTopics = []
itemsCache = None
_allItems = []
items = [] items = []
itemsMap = {} itemsMap = {}
document = None document = None
...@@ -104,16 +103,21 @@ class AgendaTemplate(TextDocument): ...@@ -104,16 +103,21 @@ class AgendaTemplate(TextDocument):
@param resources_ resources. @param resources_ resources.
''' '''
def __init__(self, xmsf, agenda, resources, listener): def __init__(self, xmsf_, agenda_, resources_, listener):
super(AgendaTemplate,self).__init__(xmsf,listener, None, super(AgendaTemplate,self).__init__(xmsf_,listener, None,
"WIZARD_LIVE_PREVIEW") "WIZARD_LIVE_PREVIEW")
self.agenda = agenda AgendaTemplate.agenda = agenda_
self.resources = resources self.resources = resources_
if AgendaTemplate.itemsCache is None:
self.initItemsCache()
AgendaTemplate._allItems = None
@synchronized(lock) @synchronized(lock)
def load(self, templateURL, topics): def load(self, templateURL, topics):
AgendaTemplate.template = self.calcTemplateName(templateURL) AgendaTemplate.template = self.calcTemplateName(templateURL)
AgendaTemplate.xTextDocument = self.loadAsPreview(templateURL, False) AgendaTemplate.document = self.loadAsPreview(templateURL, False)
self.xFrame.ComponentWindow.Enable = False self.xFrame.ComponentWindow.Enable = False
self.xTextDocument.lockControllers() self.xTextDocument.lockControllers()
self.initialize() self.initialize()
...@@ -151,9 +155,9 @@ class AgendaTemplate(TextDocument): ...@@ -151,9 +155,9 @@ class AgendaTemplate(TextDocument):
self.redrawTitle("txtDate") self.redrawTitle("txtDate")
self.redrawTitle("txtTime") self.redrawTitle("txtTime")
self.redrawTitle("cbLocation") self.redrawTitle("cbLocation")
if self.agenda.cp_TemplateName is None: if AgendaTemplate.agenda.cp_TemplateName is None:
self.agenda.cp_TemplateName = "" AgendaTemplate.agenda.cp_TemplateName = ""
self.setTemplateTitle(self.agenda.cp_TemplateName) self.setTemplateTitle(AgendaTemplate.agenda.cp_TemplateName)
'''redraws/rewrites the table which contains the given item '''redraws/rewrites the table which contains the given item
This method is called when the user checks/unchecks an item. This method is called when the user checks/unchecks an item.
...@@ -184,30 +188,111 @@ class AgendaTemplate(TextDocument): ...@@ -184,30 +188,111 @@ class AgendaTemplate(TextDocument):
'''checks the data model if the '''checks the data model if the
item corresponding to the given string should be shown item corresponding to the given string should be shown
@param itemName a string representing an Item (name or heading).
@return true if the model specifies that the item should be displayed.
''' '''
@classmethod
def isShowItem(self, itemName): def isShowItem(self, itemName):
if itemName is "<meeting-type>": if itemName == FILLIN_MEETING_TYPE:
return self.agenda.cp_ShowMeetingType return AgendaTemplate.agenda.cp_ShowMeetingType
elif itemName is "<read>": elif itemName == FILLIN_READ:
return self.agenda.cp_ShowRead return AgendaTemplate.agenda.cp_ShowRead
elif itemName is "<bring>": elif itemName == FILLIN_BRING:
return self.agenda.cp_ShowBring return AgendaTemplate.agenda.cp_ShowBring
elif itemName is "<notes>": elif itemName == FILLIN_NOTES:
return self.agenda.cp_ShowNotes return AgendaTemplate.agenda.cp_ShowNotes
elif itemName is "<facilitator>": elif itemName == FILLIN_FACILITATOR:
return self.agenda.cp_ShowFacilitator return AgendaTemplate.agenda.cp_ShowFacilitator
elif itemName is "<timekeeper>": elif itemName == FILLIN_TIMEKEEPER:
return self.agenda.cp_ShowTimekeeper return AgendaTemplate.agenda.cp_ShowTimekeeper
elif itemName is "<notetaker>": elif itemName == FILLIN_NOTETAKER:
return self.agenda.cp_ShowNotetaker return AgendaTemplate.agenda.cp_ShowNotetaker
elif itemName is "<attendees>": elif itemName == FILLIN_PARTICIPANTS:
return self.agenda.cp_ShowAttendees return AgendaTemplate.agenda.cp_ShowAttendees
elif itemName is "<called-by>": elif itemName == FILLIN_CALLED_BY:
return self.agenda.cp_ShowCalledBy return AgendaTemplate.agenda.cp_ShowCalledBy
elif itemName is "<observers>": elif itemName == FILLIN_OBSERVERS:
return self.agenda.cp_ShowObservers return AgendaTemplate.agenda.cp_ShowObservers
elif itemName is "<resource-persons>": elif itemName == FILLIN_RESOURCE_PERSONS:
return self.agenda.cp_ShowResourcePersons return AgendaTemplate.agenda.cp_ShowResourcePersons
else:
raise ValueError("No such item")
'''itemsCache is a Map containing all agenda item. These are object which
"write themselfs" to the table, given a table cursor.
A cache is used in order to reuse the objects, instead of recreate them.
This method fills the cache will all items objects (names and headings).
'''
def initItemsCache(self):
AgendaTemplate.itemsCache = {}
# Headings
AgendaTemplate.itemsCache[FILLIN_MEETING_TYPE] = AgendaItem(
FILLIN_MEETING_TYPE,
TextElement (self.resources.itemMeetingType),
PlaceholderElement(
self.resources.reschkMeetingTitle_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_BRING] = AgendaItem(
FILLIN_BRING, TextElement (self.resources.itemBring),
PlaceholderElement (
self.resources.reschkBring_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_READ] = AgendaItem (
FILLIN_READ, TextElement (self.resources.itemRead),
PlaceholderElement (
self.resources.reschkRead_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_NOTES] = AgendaItem (
FILLIN_NOTES, TextElement (self.resources.itemNote),
PlaceholderElement (
self.resources.reschkNotes_value,
self.resources.resPlaceHolderHint, self.xMSF))
# Names
AgendaTemplate.itemsCache[FILLIN_CALLED_BY] = AgendaItem(
FILLIN_CALLED_BY,
TextElement (self.resources.itemCalledBy),
PlaceholderElement (
self.resources.reschkConvenedBy_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_FACILITATOR] = AgendaItem(
FILLIN_FACILITATOR,
TextElement (self.resources.itemFacilitator),
PlaceholderElement (
self.resources.reschkPresiding_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_PARTICIPANTS] = AgendaItem(
FILLIN_PARTICIPANTS,
TextElement (self.resources.itemAttendees),
PlaceholderElement(
self.resources.reschkAttendees_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_NOTETAKER] = AgendaItem(
FILLIN_NOTETAKER,
TextElement(self.resources.itemNotetaker),
PlaceholderElement(
self.resources.reschkNoteTaker_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_TIMEKEEPER] = AgendaItem(
FILLIN_TIMEKEEPER,
TextElement (self.resources.itemTimekeeper),
PlaceholderElement(
self.resources.reschkTimekeeper_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_OBSERVERS] = AgendaItem(
FILLIN_OBSERVERS,
TextElement(self.resources.itemObservers),
PlaceholderElement(
self.resources.reschkObservers_value,
self.resources.resPlaceHolderHint, self.xMSF))
AgendaTemplate.itemsCache[FILLIN_RESOURCE_PERSONS] = AgendaItem(
FILLIN_RESOURCE_PERSONS,
TextElement(self.resources.itemResource),
PlaceholderElement(
self.resources.reschkResourcePersons_value,
self.resources.resPlaceHolderHint, self.xMSF))
'''Initializes a template.<br/> '''Initializes a template.<br/>
This method does the following tasks:<br/> This method does the following tasks:<br/>
...@@ -227,7 +312,7 @@ class AgendaTemplate(TextDocument): ...@@ -227,7 +312,7 @@ class AgendaTemplate(TextDocument):
and create the date and time formatters. and create the date and time formatters.
''' '''
AgendaTemplate.dateUtils = Helper.DateUtils( AgendaTemplate.dateUtils = Helper.DateUtils(
self.xMSF, AgendaTemplate.xTextDocument) self.xMSF, AgendaTemplate.document)
AgendaTemplate.formatter = AgendaTemplate.dateUtils.formatter AgendaTemplate.formatter = AgendaTemplate.dateUtils.formatter
AgendaTemplate.dateFormat = AgendaTemplate.dateUtils.getFormat(DATE_SYSTEM_LONG) AgendaTemplate.dateFormat = AgendaTemplate.dateUtils.getFormat(DATE_SYSTEM_LONG)
AgendaTemplate.timeFormat = AgendaTemplate.dateUtils.getFormat(TIME_HHMM) AgendaTemplate.timeFormat = AgendaTemplate.dateUtils.getFormat(TIME_HHMM)
...@@ -236,39 +321,60 @@ class AgendaTemplate(TextDocument): ...@@ -236,39 +321,60 @@ class AgendaTemplate(TextDocument):
get the document properties object. get the document properties object.
''' '''
self.m_xDocProps = AgendaTemplate.xTextDocument.DocumentProperties self.m_xDocProps = AgendaTemplate.document.DocumentProperties
self.addTitlesToPlaceHoldersDict() self.initItemsCache()
self.initializePlaceHolders() AgendaTemplate._allItems = self.searchFillInItems()
#self.initializeItemsSections() self.initializeTitles()
self.initializeItemsSections()
AgendaTemplate.textSectionHandler = TextSectionHandler( AgendaTemplate.textSectionHandler = TextSectionHandler(
AgendaTemplate.xTextDocument, AgendaTemplate.xTextDocument) AgendaTemplate.document, AgendaTemplate.document)
self.topics = Topics() self.topics = Topics()
del AgendaTemplate._allItems[:]
AgendaTemplate._allItems = None
'''
locates the titles (name, location, date, time)
and saves a reference to thier Text ranges.
'''
def addTitlesToPlaceHoldersDict(self): def initializeTitles(self):
#We add them here because we can't in AgendaWizardDialogResources.py i = 0
self.resources.dictTemplatePlaceHolders["<minutes-title>"] = \ while i < len(AgendaTemplate._allItems):
self.agenda.cp_Title workwith = AgendaTemplate._allItems[i]
self.resources.dictTemplatePlaceHolders["<minutes-location>"] = \ text = workwith.String.lstrip().lower()
self.agenda.cp_Location if text == FILLIN_TITLE:
self.resources.dictTemplatePlaceHolders["<minutes-date>"] = \ AgendaTemplate.teTitle = PlaceholderTextElement(
self.agenda.cp_Date workwith, self.resources.resPlaceHolderTitle,
self.resources.dictTemplatePlaceHolders["<minutes-time>"] = \ self.resources.resPlaceHolderHint,
self.agenda.cp_Time AgendaTemplate.document)
AgendaTemplate.trTitle = workwith
def initializePlaceHolders(self): del AgendaTemplate._allItems[i]
# Looks for all the placeholders in the template with the following i -= 1
# pattern: "<[^>]+>" and create a TextElement for each one of them elif text == FILLIN_DATE:
allItems = self.searchFillInItems(0) AgendaTemplate.teDate = PlaceholderTextElement(
for i in xrange(allItems.Count): workwith, self.resources.resPlaceHolderDate,
item = allItems.getByIndex(i) self.resources.resPlaceHolderHint,
text = item.String.lower() AgendaTemplate.document)
aux = TextElement( AgendaTemplate.trDate = workwith
item, self.resources.dictTemplatePlaceHolders[text], del AgendaTemplate._allItems[i]
self.resources.resPlaceHolderHint, self.xMSF) i -= 1
if self.isShowItem(text): elif text == FILLIN_TIME:
aux.write() AgendaTemplate.teTime = PlaceholderTextElement(
workwith, self.resources.resPlaceHolderTime,
self.resources.resPlaceHolderHint,
AgendaTemplate.document)
AgendaTemplate.trTime = workwith
del AgendaTemplate._allItems[i]
i -= 1
elif text == FILLIN_LOCATION:
AgendaTemplate.teLocation = PlaceholderTextElement(
workwith, self.resources.resPlaceHolderLocation,
self.resources.resPlaceHolderHint,
AgendaTemplate.document)
AgendaTemplate.trLocation = workwith
del AgendaTemplate._allItems[i]
i -= 1
i += 1
''' '''
analyze the item sections in the template. analyze the item sections in the template.
...@@ -276,7 +382,7 @@ class AgendaTemplate(TextDocument): ...@@ -276,7 +382,7 @@ class AgendaTemplate(TextDocument):
''' '''
def initializeItemsSections(self): def initializeItemsSections(self):
sections = self.getSections(AgendaTemplate.xTextDocument, SECTION_ITEMS) sections = self.getSections(AgendaTemplate.document, SECTION_ITEMS)
# for each section - there is a table... # for each section - there is a table...
self.itemsTables = [] self.itemsTables = []
for i in sections: for i in sections:
...@@ -286,8 +392,8 @@ class AgendaTemplate(TextDocument): ...@@ -286,8 +392,8 @@ class AgendaTemplate(TextDocument):
except Exception, ex: except Exception, ex:
traceback.print_exc() traceback.print_exc()
raise AttributeError ( raise AttributeError (
"Fatal Error while initialilzing" + "Fatal Error while initialilzing \
"Template: items table in section " + i) Template: items table in section " + i)
def getSections(self, document, s): def getSections(self, document, s):
...@@ -296,11 +402,11 @@ class AgendaTemplate(TextDocument): ...@@ -296,11 +402,11 @@ class AgendaTemplate(TextDocument):
@classmethod @classmethod
def getSection(self, name): def getSection(self, name):
return getattr(AgendaTemplate.xTextDocument.TextSections, name) return getattr(AgendaTemplate.document.TextSections, name)
@classmethod @classmethod
def getTable(self, name): def getTable(self, name):
return getattr(AgendaTemplate.xTextDocument.TextTables, name) return getattr(AgendaTemplate.document.TextTables, name)
@classmethod @classmethod
@synchronized(lock) @synchronized(lock)
...@@ -309,19 +415,19 @@ class AgendaTemplate(TextDocument): ...@@ -309,19 +415,19 @@ class AgendaTemplate(TextDocument):
if controlName == "txtTitle": if controlName == "txtTitle":
self.writeTitle( self.writeTitle(
AgendaTemplate.teTitle, AgendaTemplate.trTitle, AgendaTemplate.teTitle, AgendaTemplate.trTitle,
self.agenda.cp_Title) AgendaTemplate.agenda.cp_Title)
elif controlName == "txtDate": elif controlName == "txtDate":
self.writeTitle( self.writeTitle(
AgendaTemplate.teDate, AgendaTemplate.trDate, AgendaTemplate.teDate, AgendaTemplate.trDate,
self.getDateString(self.agenda.cp_Date)) self.getDateString(AgendaTemplate.agenda.cp_Date))
elif controlName == "txtTime": elif controlName == "txtTime":
self.writeTitle( self.writeTitle(
AgendaTemplate.teTime, AgendaTemplate.trTime, AgendaTemplate.teTime, AgendaTemplate.trTime,
self.getTimeString(self.agenda.cp_Time)) self.getTimeString(AgendaTemplate.agenda.cp_Time))
elif controlName == "cbLocation": elif controlName == "cbLocation":
self.writeTitle( self.writeTitle(
AgendaTemplate.teLocation, AgendaTemplate.trLocation, AgendaTemplate.teLocation, AgendaTemplate.trLocation,
self.agenda.cp_Location) AgendaTemplate.agenda.cp_Location)
else: else:
raise IllegalArgumentException ("No such title control...") raise IllegalArgumentException ("No such title control...")
except Exception: except Exception:
...@@ -369,7 +475,7 @@ class AgendaTemplate(TextDocument): ...@@ -369,7 +475,7 @@ class AgendaTemplate(TextDocument):
''' '''
def deleteHiddenSections(self): def deleteHiddenSections(self):
allSections = AgendaTemplate.xTextDocument.TextSections.ElementNames allSections = AgendaTemplate.document.TextSections.ElementNames
try: try:
for i in allSections: for i in allSections:
self.section = self.getSection(i) self.section = self.getSection(i)
...@@ -394,7 +500,7 @@ class AgendaTemplate(TextDocument): ...@@ -394,7 +500,7 @@ class AgendaTemplate(TextDocument):
def createMinutes(self, topicsData): def createMinutes(self, topicsData):
# if the minutes section should be removed (the # if the minutes section should be removed (the
# user did not check "create minutes") # user did not check "create minutes")
if not self.agenda.cp_IncludeMinutes \ if not AgendaTemplate.agenda.cp_IncludeMinutes \
or len(topicsData) <= 1: or len(topicsData) <= 1:
try: try:
minutesAllSection = self.getSection(SECTION_MINUTES_ALL) minutesAllSection = self.getSection(SECTION_MINUTES_ALL)
...@@ -405,6 +511,30 @@ class AgendaTemplate(TextDocument): ...@@ -405,6 +511,30 @@ class AgendaTemplate(TextDocument):
# the user checked "create minutes" # the user checked "create minutes"
else: else:
try: try:
topicStartTime = int(AgendaTemplate.agenda.cp_Time)
#first I replace the minutes titles...
AgendaTemplate.items = TextDocument.searchFillInItems()
itemIndex = 0
for item in self.items:
itemText = item.String.lstrip().lower()
if itemText == FILLIN_MINUTES_TITLE:
self.fillMinutesItem(
item, AgendaTemplate.agenda.cp_Title,
self.resources.resPlaceHolderTitle)
elif itemText == FILLIN_MINUTES_LOCATION:
self.fillMinutesItem(
item, AgendaTemplate.agenda.cp_Location,
self.resources.resPlaceHolderLocation)
elif itemText == FILLIN_MINUTES_DATE:
self.fillMinutesItem(
item, getDateString(AgendaTemplate.agenda.cp_Date),
self.resources.resPlaceHolderDate)
elif itemText == FILLIN_MINUTES_TIME:
self.fillMinutesItem(
item, getTimeString(AgendaTemplate.agenda.cp_Time),
self.resources.resPlaceHolderTime)
self.items.clear()
''' '''
now add minutes for each topic. now add minutes for each topic.
The template contains *one* minutes section, so The template contains *one* minutes section, so
...@@ -417,6 +547,20 @@ class AgendaTemplate(TextDocument): ...@@ -417,6 +547,20 @@ class AgendaTemplate(TextDocument):
AgendaTemplate.items = TextDocument.searchFillInItems() AgendaTemplate.items = TextDocument.searchFillInItems()
itemIndex = 0 itemIndex = 0
for item in self.items: for item in self.items:
itemText = item.String.lstrip().lower()
if itemText == FILLIN_MINUTE_NUM:
fillMinutesItem(item, topic[0].Value, "")
elif itemText == FILLIN_MINUTE_TOPIC:
fillMinutesItem(item, topic[1].Value, "")
elif itemText == FILLIN_MINUTE_RESPONSIBLE:
fillMinutesItem(item, topic[2].Value, "")
elif itemText == FILLIN_MINUTE_TIME:
topicTime = 0
try:
topicTime = topic[3].Value
except Exception, ex:
pass
''' '''
if the topic has no time, we do not if the topic has no time, we do not
display any time here. display any time here.
...@@ -440,6 +584,53 @@ class AgendaTemplate(TextDocument): ...@@ -440,6 +584,53 @@ class AgendaTemplate(TextDocument):
except Exception, ex: except Exception, ex:
traceback.print_exc() traceback.print_exc()
'''given a text range and a text, fills the given
text range with the given text.
If the given text is empty, uses a placeholder with the giveb
placeholder text.
@param range text range to fill
@param text the text to fill to the text range object.
@param placeholder the placeholder text to use, if the
text argument is empty (null or "")
'''
def fillMinutesItem(self, Range, text, placeholder):
paraStyle = Helper.getUnoPropertyValue(Range, "ParaStyleName")
Range.setString(text)
Helper.setUnoPropertyValue(Range, "ParaStyleName", paraStyle)
if text == None or text == "":
if placeholder != None and not placeholder == "":
placeHolder = createPlaceHolder(
AgendaTemplate.document, placeholder,
self.resources.resPlaceHolderHint)
try:
Range.Start.Text.insertTextContent(
Range.Start, placeHolder, True)
except Exception, ex:
traceback.print_exc()
'''creates a placeholder field with the given text and given hint.
@param AgendaTemplate.document service factory
@param ph place holder text
@param hint hint text
@return the place holder field.
'''
@classmethod
def createPlaceHolder(self, xmsf, ph, hint):
try:
placeHolder = xmsf.createInstance(
"com.sun.star.text.TextField.JumpEdit")
except Exception, ex:
traceback.print_exc()
return None
Helper.setUnoPropertyValue(placeHolder, "PlaceHolder", ph)
Helper.setUnoPropertyValue(placeHolder, "Hint", hint)
Helper.setUnoPropertyValue(
placeHolder, "PlaceHolderType", uno.Any("short",TEXT))
return placeHolder
def getNamesWhichStartWith(self, allNames, prefix): def getNamesWhichStartWith(self, allNames, prefix):
v = [] v = []
for i in allNames: for i in allNames:
...@@ -489,6 +680,26 @@ class ItemsTable(object): ...@@ -489,6 +680,26 @@ class ItemsTable(object):
ItemsTable.table = table_ ItemsTable.table = table_
self.section = section_ self.section = section_
self.items = [] self.items = []
'''
go through all <*> items in the document
and each one if it is in this table.
If they are, register them to belong here, notice their order
and remove them from the list of all <*> items, so the next
search will be faster.
'''
i = 0
while i < len(AgendaTemplate._allItems):
workwith = AgendaTemplate._allItems[i]
t = Helper.getUnoPropertyValue(workwith, "TextTable")
if t == ItemsTable.table:
iText = workwith.String.lower().lstrip()
ai = AgendaTemplate.itemsCache[iText]
if ai is not None:
self.items.append(ai)
del AgendaTemplate._allItems[i]
AgendaTemplate.itemsMap[iText] = self
i -= 1
i += 1
''' '''
link the section to the template. this will restore the original table link the section to the template. this will restore the original table
...@@ -634,6 +845,22 @@ class Topics(object): ...@@ -634,6 +845,22 @@ class Topics(object):
"Fatal error while loading template: table " + \ "Fatal error while loading template: table " + \
SECTION_TOPICS + " could not load.") SECTION_TOPICS + " could not load.")
'''
first I store all <*> ranges
which are in the topics table.
I store each <*> range in this - the key
is the cell it is in. Later when analyzing the topic,
cell by cell, I check in this map to know
if a cell contains a <*> or not.
'''
items = {}
for i in AgendaTemplate._allItems:
t = Helper.getUnoPropertyValue(i, "TextTable")
if t == Topics.table:
cell = Helper.getUnoPropertyValue(i, "Cell")
iText = cell.CellName
items[iText] = i
''' '''
in the topics table, there are always one in the topics table, there are always one
title row and three topics defined. title row and three topics defined.
...@@ -649,16 +876,18 @@ class Topics(object): ...@@ -649,16 +876,18 @@ class Topics(object):
# analyze the structure of the topic rows. # analyze the structure of the topic rows.
while not cursor.RangeName == afterLastCell: while not cursor.RangeName == afterLastCell:
cell = Topics.table.getCellByName(cursor.RangeName) cell = Topics.table.getCellByName(cursor.RangeName)
# first I store the content and para style of the cell
ae = TextElement(cell)
# if the cell contains a relevant <...> # if the cell contains a relevant <...>
# i add the text element to the hash, # i add the text element to the hash,
# so it's text can be updated later. # so it's text can be updated later.
try: try:
if items[cell.CellName] is not None: if items[cell.CellName] is not None:
self.topicItems[cell.String.lower().lstrip()] = cell self.topicItems[cell.String.lower().lstrip()] = ae
except KeyError: except KeyError:
pass pass
Topics.topicCells.append(cell) Topics.topicCells.append(ae)
# goto next cell. # goto next cell.
cursor.goRight(1, False) cursor.goRight(1, False)
''' '''
...@@ -874,6 +1103,68 @@ class Topics(object): ...@@ -874,6 +1103,68 @@ class Topics(object):
else: else:
cursor.goRight(1, False) cursor.goRight(1, False)
'''
A basic implementation of AgendaElement:
writes a String to the given XText/XTextRange, and applies
a ParaStyle to it (using the parent class).
@author rp143992
'''
class TextElement(object):
def __init__(self, text_):
self.text = text_
def write(self, textRange):
textRange.String = self.text
'''
A Text element which, if the text to write is empty (null or "")
inserts a placeholder instead.
@author rp143992
'''
class PlaceholderTextElement(TextElement):
def __init__(self, textRange, placeHolderText_, hint_, xmsf_):
super(PlaceholderTextElement,self).__init__(textRange)
self.placeHolderText = placeHolderText_
self.hint = hint_
self.xmsf = xmsf_
def write(self, textRange):
textRange.String = self.text
if self.text is None or self.text == "":
try:
xTextContent = AgendaTemplate.createPlaceHolder(
self.xmsf, self.placeHolderText, self.hint)
textRange.Text.insertTextContent(
textRange.Start, xTextContent, True)
except Exception, ex:
traceback.print_exc()
'''
An Agenda element which writes no text, but inserts a placeholder, and formats
it using a ParaStyleName.
@author rp143992
'''
class PlaceholderElement(object):
def __init__(self, placeHolderText_, hint_, xmsf_):
self.placeHolderText = placeHolderText_
self.hint = hint_
self.xmsf = xmsf_
def write(self, textRange):
try:
xTextContent = AgendaTemplate.createPlaceHolder(
AgendaTemplate.document, self.placeHolderText, self.hint)
textRange.Text.insertTextContent(
textRange.Start, xTextContent, True)
except Exception, ex:
traceback.print_exc()
''' '''
An implementation of AgendaElement which An implementation of AgendaElement which
gets as a parameter a table cursor, and writes gets as a parameter a table cursor, and writes
...@@ -884,15 +1175,15 @@ a place holder to the next cell. ...@@ -884,15 +1175,15 @@ a place holder to the next cell.
class AgendaItem(object): class AgendaItem(object):
def __init__(self, name, textRange, field): def __init__(self, name_, te, f):
self.name = name self.name = name_
self.field = field self.field = f
self.textRange = textRange self.textElement = te
def write(self, tableCursor): def write(self, tableCursor):
cellname = tableCursor.RangeName cellname = tableCursor.RangeName
cell = ItemsTable.table.getCellByName(cellname) cell = ItemsTable.table.getCellByName(cellname)
self.textElement.String = cell self.textElement.write(cell)
tableCursor.goRight(1, False) tableCursor.goRight(1, False)
#second field is actually always null... #second field is actually always null...
# this is a preparation for adding placeholders. # this is a preparation for adding placeholders.
......
...@@ -57,7 +57,7 @@ class AgendaWizardDialogImpl(AgendaWizardDialog): ...@@ -57,7 +57,7 @@ class AgendaWizardDialogImpl(AgendaWizardDialog):
"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
xLocMSF = Desktop.connect(ConnectStr) xLocMSF = Desktop.connect(ConnectStr)
lw = AgendaWizardDialogImpl(xLocMSF) lw = AgendaWizardDialogImpl(xLocMSF)
lw.startWizard(xLocMSF) lw.startWizard()
except Exception as e: except Exception as e:
print ("Wizard failure exception " + str(type(e)) + print ("Wizard failure exception " + str(type(e)) +
" message " + str(e) + " args " + str(e.args) + " message " + str(e) + " args " + str(e.args) +
......
...@@ -166,53 +166,5 @@ class AgendaWizardDialogResources(Resource): ...@@ -166,53 +166,5 @@ class AgendaWizardDialogResources(Resource):
self.resButtonDown = self.getResText( self.resButtonDown = self.getResText(
AgendaWizardDialogResources.RID_AGENDAWIZARDDIALOG_START + 71) AgendaWizardDialogResources.RID_AGENDAWIZARDDIALOG_START + 71)
#Create a dictionary for localising the template placeholders
self.dictTemplatePlaceHolders = {
"<title>" : self.resPlaceHolderTitle,
"<date>" : self.resPlaceHolderDate,
"<time>" : self.resPlaceHolderTime,
"<location>" : self.resPlaceHolderLocation,
"<meeting-type>" : self.reschkMeetingTitle_value,
"<bring>" : self.reschkBring_value,
"<read>" : self.reschkRead_value,
"<notes>" : self.reschkNotes_value,
"<called-by>" : self.itemCalledBy,
"<facilitator>" : self.itemFacilitator,
"<attendees>" : self.itemAttendees,
"<notetaker>" : self.itemNotetaker,
"<timekeeper>" : self.itemTimekeeper,
"<observers>" : self.itemObservers,
"<resource-persons>" : self.itemResource,
"<num>" : "",
"<topic>" : "",
"<responsible>" : "",
"<topic-time>" : "",
"<mnum>" : "",
"<mtopic>" : "",
"<mresponsible>" : "",
"<mtime>" : ""}
'''
section name <b>prefix</b> for sections that contain items.
this is also used as table name prefix, since each items section
must contain a table whos name is identical name to the section's name.
'''
SECTION_ITEMS = "AGENDA_ITEMS"
'''
the name of the section which contains the topics.
'''
SECTION_TOPICS = "AGENDA_TOPICS"
'''
the name of the parent minutes section.
'''
SECTION_MINUTES_ALL = "MINUTES_ALL"
'''
the name of the child nimutes section.
This section will be duplicated for each topic.
'''
SECTION_MINUTES = "MINUTES"
#Common Resources
self.resOverwriteWarning = self.getResText( self.resOverwriteWarning = self.getResText(
AgendaWizardDialogResources.RID_COMMON_START + 19) AgendaWizardDialogResources.RID_COMMON_START + 19)
#
# 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 .
#
FILLIN_TITLE = "<title>"
FILLIN_TITLE = "<title>"
FILLIN_DATE = "<date>"
FILLIN_TIME = "<time>"
FILLIN_LOCATION = "<location>"
'''
section name <b>prefix</b> for sections that contain items.
this is also used as table name prefix, since each items section
must contain a table whos name is identical name to the section's name.
'''
SECTION_ITEMS = "AGENDA_ITEMS"
'''
the name of the section which contains the topics.
'''
SECTION_TOPICS = "AGENDA_TOPICS"
'''
the name of the parent minutes section.
'''
SECTION_MINUTES_ALL = "MINUTES_ALL"
'''
the name of the child nimutes section.
This section will be duplicated for each topic.
'''
SECTION_MINUTES = "MINUTES"
'''
taged headings and names.
These will be searched in item tables (in the template) and will be
replaced with resource strings.
headings...
'''
FILLIN_MEETING_TYPE = "<meeting-type>"
FILLIN_BRING = "<bring>"
FILLIN_READ = "<read>"
FILLIN_NOTES = "<notes>"
'''
names...
'''
FILLIN_CALLED_BY = "<called-by>"
FILLIN_FACILITATOR = "<facilitator>"
FILLIN_PARTICIPANTS = "<attendees>"
FILLIN_NOTETAKER = "<notetaker>"
FILLIN_TIMEKEEPER = "<timekeeper>"
FILLIN_OBSERVERS = "<observers>"
FILLIN_RESOURCE_PERSONS = "<resource-persons>"
'''
Fillins for the topic table.
These strings will be searched inside the topic table as
part of detecting its structure.
'''
FILLIN_TOPIC_NUMBER = "<num>"
FILLIN_TOPIC_TOPIC = "<topic>"
FILLIN_TOPIC_RESPONSIBLE = "<responsible>"
FILLIN_TOPIC_TIME = "<topic-time>"
'''
fillins for minutes.
These will be searched in the minutes section and will be replaced
with the appropriate data.
'''
FILLIN_MINUTES_TITLE = "<minutes-title>"
FILLIN_MINUTES_LOCATION = "<minutes-location>"
FILLIN_MINUTES_DATE = "<minutes-date>"
FILLIN_MINUTES_TIME = "<minutes-time>"
'''
Minutes-topic fillins
These will be searched in the minutes-child-section, and
will be replaced with topic data.
'''
FILLIN_MINUTE_NUM = "<mnum>"
FILLIN_MINUTE_TOPIC = "<mtopic>"
FILLIN_MINUTE_RESPONSIBLE = "<mresponsible>"
FILLIN_MINUTE_TIME = "<mtime>"
...@@ -30,7 +30,7 @@ class TextElement(object): ...@@ -30,7 +30,7 @@ class TextElement(object):
def write(self): def write(self):
try: try:
if self.item is not None and not self.placeHolderText: if self.item is not None:
self.item.String = "" self.item.String = ""
cursor = self.item.Text.createTextCursorByRange( cursor = self.item.Text.createTextCursorByRange(
self.item.Start) self.item.Start)
......
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