diff options
author | Xisco Fauli <anistenis@gmail.com> | 2012-11-26 22:39:19 +0100 |
---|---|---|
committer | Xisco Fauli <anistenis@gmail.com> | 2012-11-26 23:39:47 +0100 |
commit | 4024753450099e60f671e2c73c089a3b5e7e7648 (patch) | |
tree | 91225de556f56ac25de3e1ab3926bb7a700c9582 /wizards | |
parent | 9ed87bd9a4011fab10c69739884e60e30731481f (diff) |
pyagenda: let's delete the locks and see what happens later on
Change-Id: I6f878d454a264f2c5a9c450b09d690b0230fb89a
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/com/sun/star/wizards/agenda/AgendaTemplate.py | 157 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/agenda/CGTopic.py | 1 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/agenda/TopicsControl.py | 111 |
3 files changed, 114 insertions, 155 deletions
diff --git a/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py b/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py index b6d00651df34..3dbcf63f752b 100644 --- a/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py +++ b/wizards/com/sun/star/wizards/agenda/AgendaTemplate.py @@ -17,7 +17,6 @@ # import uno import traceback -from threading import RLock from ..text.TextElement import TextElement from ..text.TextDocument import TextDocument from ..common.FileAccess import FileAccess @@ -29,18 +28,6 @@ from datetime import date as dateTimeObject from com.sun.star.text.PlaceholderType import TEXT from com.sun.star.i18n.NumberFormatIndex import TIME_HHMM, DATE_SYSTEM_LONG -def synchronized(lock): - ''' Synchronization decorator. ''' - def wrap(f): - def newFunction(*args, **kw): - lock.acquire() - try: - return f(*args, **kw) - finally: - lock.release() - return newFunction - return wrap - ''' The classes here implement the whole document-functionality of the agenda wizard: the live-preview and the final "creation" of the document, @@ -87,8 +74,6 @@ events fired too often. ''' class AgendaTemplate(TextDocument): - lock = RLock() - ''' constructor. The document is *not* loaded here. only some formal members are set. @@ -103,7 +88,6 @@ class AgendaTemplate(TextDocument): self.itemsMap = {} self.allItems = [] - @synchronized(lock) def load(self, templateURL, topics): self.template = self.calcTemplateName(templateURL) self.loadAsPreview(templateURL, False) @@ -148,7 +132,6 @@ class AgendaTemplate(TextDocument): The table is being found, in which the item is, and redrawn. ''' - @synchronized(lock) def redraw(self, itemName): self.xTextDocument.lockControllers() try: @@ -381,7 +364,6 @@ class AgendaTemplate(TextDocument): def getTable(self, name): return getattr(self.xTextDocument.TextTables, name) - @synchronized(lock) def redrawTitle(self, controlName): try: if controlName == "txtTitle": @@ -435,7 +417,6 @@ class AgendaTemplate(TextDocument): return self.formatter.convertNumberToString( AgendaTemplate.timeFormat, t) - @synchronized(lock) def finish(self, topics): self.createMinutes(topics) self.deleteHiddenSections() @@ -470,7 +451,6 @@ class AgendaTemplate(TextDocument): the values for the topics. ''' - @synchronized(lock) def createMinutes(self, topicsData): # if the minutes section should be removed (the # user did not check "create minutes") @@ -693,83 +673,82 @@ class ItemsTable(object): ''' def write(self, dummy): - with AgendaTemplate.lock: - name = self.section.Name - # link and unlink the section to the template. - self.agenda.textSectionHandler.linkSectiontoTemplate( - self.agenda.template, name, self.section) - self.agenda.textSectionHandler.breakLinkOfTextSection( - self.section) - # we need to get a instance after linking. - ItemsTable.table = self.agenda.getTable(name) - self.section = self.agenda.getSection(name) - cursor = ItemsTable.table.createCursorByCellName("A1") - # should this section be visible? - visible = False - # write items - # =========== - cellName = "" - ''' - now go through all items that belong to this - table. Check each one agains the model. If it should - be display, call it's write method. - All items are of type AgendaItem which means they write - two cells to the table: a title (text) and a placeholder. - see AgendaItem class below. - ''' - for i in self.items: - if self.agenda.isShowItem(i.name): - visible = True - i.table = ItemsTable.table - i.write(cursor) - # I store the cell name which was last written... - cellName = cursor.RangeName - cursor.goRight(1, False) - - if visible: - boolean = True - else: - boolean = False - Helper.setUnoPropertyValue(self.section, "IsVisible", boolean) - if not visible: - return - ''' - remove obsolete rows - ==================== - if the cell that was last written is the current cell, - it means this is the end of the table, so we end here. - (because after getting the cellName above, - I call the goRight method. - If it did not go right, it means its the last cell. - ''' - - if cellName == cursor.RangeName: - return - ''' - if not, we continue and clear all cells until - we are at the end of the row. - ''' - - while not cellName == cursor.RangeName and \ - not cursor.RangeName.startswith("A"): - cell = ItemsTable.table.getCellByName(cursor.RangeName) - cell.String = "" + name = self.section.Name + # link and unlink the section to the template. + self.agenda.textSectionHandler.linkSectiontoTemplate( + self.agenda.template, name, self.section) + self.agenda.textSectionHandler.breakLinkOfTextSection( + self.section) + # we need to get a instance after linking. + ItemsTable.table = self.agenda.getTable(name) + self.section = self.agenda.getSection(name) + cursor = ItemsTable.table.createCursorByCellName("A1") + # should this section be visible? + visible = False + # write items + # =========== + cellName = "" + ''' + now go through all items that belong to this + table. Check each one agains the model. If it should + be display, call it's write method. + All items are of type AgendaItem which means they write + two cells to the table: a title (text) and a placeholder. + see AgendaItem class below. + ''' + for i in self.items: + if self.agenda.isShowItem(i.name): + visible = True + i.table = ItemsTable.table + i.write(cursor) + # I store the cell name which was last written... cellName = cursor.RangeName cursor.goRight(1, False) + if visible: + boolean = True + else: + boolean = False + Helper.setUnoPropertyValue(self.section, "IsVisible", boolean) + if not visible: + return ''' - again: if we are at the end of the table, end here. + remove obsolete rows + ==================== + if the cell that was last written is the current cell, + it means this is the end of the table, so we end here. + (because after getting the cellName above, + I call the goRight method. + If it did not go right, it means its the last cell. ''' - if cellName == cursor.RangeName: - return - rowIndex = AgendaTemplate.getRowIndex(cursor) - rowsCount = AgendaTemplate.getRowCount(ItemsTable.table) + if cellName == cursor.RangeName: + return ''' - now before deleteing i move the cursor up so it - does not disappear, because it will crash office. + if not, we continue and clear all cells until + we are at the end of the row. ''' - cursor.gotoStart(False) + + while not cellName == cursor.RangeName and \ + not cursor.RangeName.startswith("A"): + cell = ItemsTable.table.getCellByName(cursor.RangeName) + cell.String = "" + cellName = cursor.RangeName + cursor.goRight(1, False) + + ''' + again: if we are at the end of the table, end here. + ''' + if cellName == cursor.RangeName: + return + + rowIndex = AgendaTemplate.getRowIndex(cursor) + rowsCount = AgendaTemplate.getRowCount(ItemsTable.table) + ''' + now before deleteing i move the cursor up so it + does not disappear, because it will crash office. + ''' + cursor.gotoStart(False) ''' This class handles the preview of the topics table. diff --git a/wizards/com/sun/star/wizards/agenda/CGTopic.py b/wizards/com/sun/star/wizards/agenda/CGTopic.py index 88de1712fa42..8e60561d43f8 100644 --- a/wizards/com/sun/star/wizards/agenda/CGTopic.py +++ b/wizards/com/sun/star/wizards/agenda/CGTopic.py @@ -16,7 +16,6 @@ # the License at http://www.apache.org/licenses/LICENSE-2.0 . # from wizards.common.ConfigGroup import * -from wizards.common.ConfigGroup import * ''' CGTopic means: Configuration Group Topic. diff --git a/wizards/com/sun/star/wizards/agenda/TopicsControl.py b/wizards/com/sun/star/wizards/agenda/TopicsControl.py index 67b4ad34a60b..e28fe6e972e3 100644 --- a/wizards/com/sun/star/wizards/agenda/TopicsControl.py +++ b/wizards/com/sun/star/wizards/agenda/TopicsControl.py @@ -15,7 +15,6 @@ # except in compliance with the License. You may obtain a copy of # the License at http://www.apache.org/licenses/LICENSE-2.0 . # -from threading import RLock from .CGTopic import CGTopic from ..ui.ControlScroller import * from .AgendaWizardDialogConst import HID @@ -82,21 +81,8 @@ This one is not synchronized "live", since it is unnecessary... instead, it is synchronized on call, before the settings should be saved. ''' -def synchronized(lock): - ''' Synchronization decorator. ''' - def wrap(f): - def newFunction(*args, **kw): - lock.acquire() - try: - return f(*args, **kw) - finally: - lock.release() - return newFunction - return wrap - class TopicsControl(ControlScroller): - lock = RLock() LABEL = "lblTopicCnt_" TOPIC = "txtTopicTopic_" RESP = "cbTopicResp_" @@ -376,55 +362,54 @@ class TopicsControl(ControlScroller): @classmethod def fieldChanged(self, guiRow, column): - with TopicsControl.lock: - try: - # First, I update the document - data = self.getTopicData(guiRow + ControlScroller.nscrollvalue) - if data is None: - return - - dataValue = [i.Value for i in data] - if dataValue == TopicsControl.oldData: - return - else: - TopicsControl.oldData = dataValue - - self.updateDocumentCell( - guiRow + ControlScroller.nscrollvalue, column, data) - if self.isRowEmpty(guiRow + ControlScroller.nscrollvalue): - ''' - if this is the row before the last one - (the last row is always empty) - delete the last row... + try: + # First, I update the document + data = self.getTopicData(guiRow + ControlScroller.nscrollvalue) + if data is None: + return + + dataValue = [i.Value for i in data] + if dataValue == TopicsControl.oldData: + return + else: + TopicsControl.oldData = dataValue + + self.updateDocumentCell( + guiRow + ControlScroller.nscrollvalue, column, data) + if self.isRowEmpty(guiRow + ControlScroller.nscrollvalue): + ''' + if this is the row before the last one + (the last row is always empty) + delete the last row... + ''' + if (guiRow + ControlScroller.nscrollvalue) \ + == len(ControlScroller.scrollfields) - 2: + self.removeLastRow() + '''now consequentially check the last two rows, + and remove the last one if they are both empty. + (actually I check always the "before last" row, + because the last one is always empty... ''' - if (guiRow + ControlScroller.nscrollvalue) \ - == len(ControlScroller.scrollfields) - 2: - self.removeLastRow() - '''now consequentially check the last two rows, - and remove the last one if they are both empty. - (actually I check always the "before last" row, - because the last one is always empty... - ''' - while len(ControlScroller.scrollfields) > 1 \ - and self.isRowEmpty(len(ControlScroller.scrollfields) - 2): - removeLastRow() - cr = self.ControlGroupVector[ - ControlScroller.scrollfields.size - ControlScroller.nscrollvalue - 1] - # if a remove was performed, set focus - #to the last row with some data in it... - self.focus(getControl(cr, column)) - # update the preview document. - self.reduceDocumentToTopics() + while len(ControlScroller.scrollfields) > 1 \ + and self.isRowEmpty(len(ControlScroller.scrollfields) - 2): + removeLastRow() + cr = self.ControlGroupVector[ + ControlScroller.scrollfields.size - ControlScroller.nscrollvalue - 1] + # if a remove was performed, set focus + #to the last row with some data in it... + self.focus(getControl(cr, column)) + # update the preview document. + self.reduceDocumentToTopics() + + else: + # row contains data + # is this the last row? + if (guiRow + ControlScroller.nscrollvalue + 1) \ + == len(ControlScroller.scrollfields): + self.insertRowAtEnd() - else: - # row contains data - # is this the last row? - if (guiRow + ControlScroller.nscrollvalue + 1) \ - == len(ControlScroller.scrollfields): - self.insertRowAtEnd() - - except Exception: - traceback.print_exc() + except Exception: + traceback.print_exc() ''' return the corresponding row data for the given index. @@ -490,7 +475,6 @@ class TopicsControl(ControlScroller): @param control the control to gain focus after moving. ''' - @synchronized(lock) def rowDown(self, guiRow=None, control=None): try: if guiRow is None and control is None: @@ -523,7 +507,6 @@ class TopicsControl(ControlScroller): move the current row up ''' - @synchronized(lock) def rowUp(self, guiRow=None, control=None): try: if guiRow is None and control is None: @@ -554,7 +537,6 @@ class TopicsControl(ControlScroller): ''' @classmethod - @synchronized(lock) def cursorUp(self, guiRow, control): # is this the last full row ? actuallRow = guiRow + ControlScroller.nscrollvalue @@ -579,7 +561,6 @@ class TopicsControl(ControlScroller): ''' @classmethod - @synchronized(lock) def cursorDown(self, guiRow, control): # is this the last full row ? actuallRow = guiRow + ControlScroller.nscrollvalue |