diff options
author | Javier Fernandez <jfernandez@igalia.com> | 2013-03-28 12:13:36 +0000 |
---|---|---|
committer | Javier Fernandez <jfernandez@igalia.com> | 2013-04-11 13:16:09 +0000 |
commit | ed83d99e0188bc79a17a816b67b5a556ae351d82 (patch) | |
tree | e0c17f91742879f2cb488c46d806c172e2a6accb | |
parent | 84ef5588593f59972486df2189272b99da6142ea (diff) |
Implementing the Design DataAware features and ItemListeners.
Change-Id: I22ac7c16110a9f92a575dc23f2d3477d163ddb07
-rw-r--r-- | wizards/Pyuno_commonwizards.mk | 1 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/ui/ImageList.py | 72 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/ui/event/DataAware.py | 14 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/ui/event/SimpleDataAware.py | 33 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/ui/event/UnoDataAware.py | 7 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/web/WWD_Startup.py | 19 |
6 files changed, 110 insertions, 36 deletions
diff --git a/wizards/Pyuno_commonwizards.mk b/wizards/Pyuno_commonwizards.mk index a62b35620a26..82d867f8f128 100644 --- a/wizards/Pyuno_commonwizards.mk +++ b/wizards/Pyuno_commonwizards.mk @@ -71,6 +71,7 @@ $(eval $(call gb_Pyuno_add_files,wizards,\ ui/event/ListModelBinder.py \ ui/event/RadioDataAware.py \ ui/event/UnoDataAware.py \ + ui/event/SimpleDataAware.py \ ui/event/Task.py \ ui/event/TaskEvent.py \ ui/event/TaskListener.py \ diff --git a/wizards/com/sun/star/wizards/ui/ImageList.py b/wizards/com/sun/star/wizards/ui/ImageList.py index 6e46908a7b6c..38a0ea5c5a2b 100644 --- a/wizards/com/sun/star/wizards/ui/ImageList.py +++ b/wizards/com/sun/star/wizards/ui/ImageList.py @@ -82,6 +82,7 @@ class ImageList(ListDataListener): self.renderer = None self.counterRenderer = self.SimpleCounterRenderer() self.MOVE_SELECTION_VALS = list(range(3)) + self.itemListenerList = None def onMousePressed(self, event): print ("DEBUG !!! onMousePressed -- Mouse pressed.") @@ -219,6 +220,7 @@ class ImageList(ListDataListener): (self.imageSize.Height + self.gap.Height) + self.gap.Height def refreshImages(self): + print ("DEBUG !!! refreshImages -- ") if self.showButtons: self.refreshCounterText() @@ -261,6 +263,10 @@ class ImageList(ListDataListener): return i def refreshSelection(self): + print ("DEBUG !!! refreshSelection -- selected: ", self.selected) + print ("DEBUG !!! refreshSelection -- pageStart: ", self.pageStart) + print ("DEBUG !!! refreshSelection -- rows: ", self.rows) + print ("DEBUG !!! refreshSelection -- cols: ", self.cols) if self.selected < self.pageStart or \ self.selected >= (self.pageStart + self.rows * self.cols): self.hideSelection() @@ -268,6 +274,7 @@ class ImageList(ListDataListener): self.moveSelection(self.getImageIndexFor(self.selected)) def hideSelection(self): + print ("DEBUG !!! -- hideSelection") self.grbxSelectedImage.Model.Step = ImageList.HIDE_PAGE self.grbxSelectedImage.Visible = False @@ -292,7 +299,7 @@ class ImageList(ListDataListener): uno.invoke(self.grbxSelectedImage.Model, "setPropertyValues", ((ImageList.MOVE_SELECTION), (tuple(self.MOVE_SELECTION_VALS)))) - if (self.grbxSelectedImage.Model.Step == self.step): + if (self.dialogModel.Step == self.step): self.grbxSelectedImage.Visible = True #now focus... @@ -336,8 +343,8 @@ class ImageList(ListDataListener): self.selected += event.getIndex1() - event.getIndex0() + 1 if event.getIndex0() < self.pageStart or \ - event.getIndex1() < (self.pageStart + getRows() + getCols()): - refreshImages() + event.getIndex1() < (self.pageStart + self.rows + self.cols): + self.refreshImages() ''' Registers ItemListener to receive events. @@ -346,9 +353,9 @@ class ImageList(ListDataListener): @synchronized(lock) def addItemListener(self, listener): + print ("DEBUG !!!! ImageList.addItemListener -") if self.itemListenerList is None: - self.itemListenerList = java.util.ArrayList.ArrayList() - + self.itemListenerList = [] self.itemListenerList.append(listener) ''' @@ -358,6 +365,7 @@ class ImageList(ListDataListener): @synchronized(lock) def removeItemListener(self, listener): + print ("DEBUG !!!! ImageList.addItemListener -") if self.itemListenerList is not None: self.itemListenerList.remove(listener) @@ -367,15 +375,17 @@ class ImageList(ListDataListener): ''' def fireItemSelected(self): - with ImageList.lock: - if self.itemListenerList is None: - return - - auxlist = self.itemListenerList.clone() - + print ("DEBUG !!!! ImageList.fireItemSelected -") + if self.itemListenerList is None: + return + auxlist = list(self.itemListenerList) for i in auxlist: i.itemStateChanged(None) + def getSelected(self): + print ("DEBUG !!!! ImageList.getSelected - selected: ", self.selected) + return self.selected + def setSelected(self, _object): print ("DEBUG !!!! ImageList.setSelected - _object: ", _object) if (isinstance (_object, int)): @@ -393,9 +403,11 @@ class ImageList(ListDataListener): i += 1 def setSelected1(self, index): - print ("DEBUG !!!! ImageList.setSelected - _index: ", index) + print ("DEBUG !!!! ImageList.setSelected1 - _index: ", index) + print ("DEBUG !!!! ImageList.setSelected1 - selected: ", self.selected) if self.rowSelect and (index >= 0): - index = int((index / self.cols) * self.cols) + index = int(index / self.cols) * self.cols + print ("DEBUG !!!! ImageList.setSelected1 - index: ", index) if self.selected == index: return @@ -403,8 +415,7 @@ class ImageList(ListDataListener): self.selected = index self.refreshImageText() self.refreshSelection() - #COMMENTED - #self.fireItemSelected() + self.fireItemSelected() def refreshImageText(self): @@ -500,6 +511,7 @@ class ImageList(ListDataListener): return None def showSelected(self): + print ("DEBUG !!! showSelected -- ") oldPageStart = self.pageStart if self.selected != -1: self.pageStart = \ @@ -510,34 +522,40 @@ class ImageList(ListDataListener): self.refreshImages() def keyPressed(self, ke): - image = getImageFromEvent(ke) - r = image / getCols() - c = image - (r * getCols()) - d = getKeyMove(ke, r, c) + print ("DEBUG !!! keyPressed -- ") + image = self.getImageFromEvent(ke) + r = image / self.cols + c = image - (r * self.cols) + d = self.getKeyMove(ke, r, c) newImage = image + d if newImage == image: return - if isFocusable(newImage): - changeFocus(image, newImage) + if self.isFocusable(newImage): + self.changeFocus(image, newImage) def isFocusable(self, image): + print ("DEBUG !!! isFocusable -- ") return (image >= 0) and \ - (getIndexFor(image) < self.listModel.getSize()) + (self.getIndexFor(image) < self.listModel.getSize()) def changeFocus(self, oldFocusImage, newFocusImage): - focus(newFocusImage) - defocus(oldFocusImage) + print ("DEBUG !!! changeFocus -- ") + self.focus(newFocusImage) + self.defocus(oldFocusImage) def select(self, ke): - setSelected(getIndexFor(getImageFromEvent(ke))) + print ("DEBUG !!! select -- ") + self.setSelected(self.getIndexFor(self.getImageFromEvent(ke))) def focus(self, image): + print ("DEBUG !!! focus -- ") self.m_aImages[image].Model.Tabstop = True xWindow = self.m_aImages[image] xWindow.setFocus() def defocus(self, image): + print ("DEBUG !!! defocus -- ") self.m_aImages[image].Model.Tabstop = False '''jump to the given item (display the screen @@ -546,11 +564,13 @@ class ImageList(ListDataListener): ''' def display(self, i): - isAux = (getCols() * getRows()) + print ("DEBUG !!! display -- ") + isAux = (self.cols * self.rows) ps = (self.listModel.getSize() / isAux) * isAux self.setPageStart(ps) def setenabled(self, b): + print ("DEBUG !!! setenabled -- ") i = 0 while i < len(self.m_aImages): UnoDialog2.setEnabled(self.m_aImages[i], b) diff --git a/wizards/com/sun/star/wizards/ui/event/DataAware.py b/wizards/com/sun/star/wizards/ui/event/DataAware.py index aa794b8e786e..c3b37604bdd7 100644 --- a/wizards/com/sun/star/wizards/ui/event/DataAware.py +++ b/wizards/com/sun/star/wizards/ui/event/DataAware.py @@ -78,7 +78,7 @@ class DataAware(object): try: data = getattr(self._dataObject, self._field) except Exception: - print ("DEBUG !!! dataObject hasn't the attribute, su using the 'getter' method.") + print ("DEBUG !!! DataAware.updateUI -- dataObject hasn't the attribute, su using the 'getter' method.") data = uno.invoke(self._dataObject, "get" + self._field, ()) ui = self.getFromUI() if data is not ui: @@ -111,18 +111,26 @@ class DataAware(object): ''' def updateData(self): + print ("DEBUG !!! DataAware.updateData -- field: ", self._field) + useUno = False try: try: data = getattr(self._dataObject, self._field) except Exception: - print ("DEBUG !!! dataObject hasn't the attribute, su using the 'getter' method.") + print ("DEBUG !!! DataAware.updateData -- dataObject hasn't the attribute, su using the 'getter' method.") + useUno = True data = uno.invoke(self._dataObject, "get" + self._field, ()) + print ("DEBUG !!! DataAware.updateData -- data: ", data) ui = self.getFromUI() + print ("DEBUG !!! DataAware.updateData -- ui: ", ui) if data is not ui: if isinstance(ui,tuple): #Selected Element listbox ui = ui[0] - setattr(self._dataObject, self._field, ui) + if useUno: + uno.invoke(self._dataObject, "set" + self._field, (ui,)) + else: + setattr(self._dataObject, self._field, ui) self.enableControls(ui) except Exception: traceback.print_exc() diff --git a/wizards/com/sun/star/wizards/ui/event/SimpleDataAware.py b/wizards/com/sun/star/wizards/ui/event/SimpleDataAware.py new file mode 100644 index 000000000000..cb1cdc3806b3 --- /dev/null +++ b/wizards/com/sun/star/wizards/ui/event/SimpleDataAware.py @@ -0,0 +1,33 @@ +# +# 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 . +# +import uno + +from .DataAware import DataAware + +class SimpleDataAware(DataAware): + + def __init__(self, dataObject, field, control_, controlField_): + super(SimpleDataAware, self).__init__(dataObject, field) + self.control = control_ + self.controlField = controlField_ + + def setToUI(self, value): + uno.invoke(self.control, "set" + self.controlField, (value,)) + + def getFromUI(self): + return uno.invoke(self.control, "get" + self.controlField, ()) diff --git a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py index 13d5f080dafe..b739dd4fdb56 100644 --- a/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py +++ b/wizards/com/sun/star/wizards/ui/event/UnoDataAware.py @@ -53,7 +53,12 @@ class UnoDataAware(DataAware): elif self.isShort: print ("DEBUG !!! value is sort: ", value) value = uno.Any("[]short", (value,)) - setattr(self.unoModel, self.unoPropName, value) + if (hasattr(self.unoModel, self.unoPropName)): + setattr(self.unoModel, self.unoPropName, value) + else: + print ("DEBUG !!! UnoDataAware.setToUI -- dataObject hasn't the attribute, su using the 'setter' method.") + uno.invoke(self.unoModel, "set" + self.unoPropName, (ui,)) + def getFromUI(self): return getattr(self.unoModel, self.unoPropName) diff --git a/wizards/com/sun/star/wizards/web/WWD_Startup.py b/wizards/com/sun/star/wizards/web/WWD_Startup.py index 5a1b47718dec..3ca83d99620a 100644 --- a/wizards/com/sun/star/wizards/web/WWD_Startup.py +++ b/wizards/com/sun/star/wizards/web/WWD_Startup.py @@ -24,6 +24,7 @@ from .StylePreview import StylePreview from ..common.Configuration import Configuration from ..common.FileAccess import FileAccess from ..common.Desktop import Desktop +from ..common.Properties import Properties from ..document.OfficeDocument import OfficeDocument from .data.CGSettings import CGSettings from .data.CGDocument import CGDocument @@ -31,6 +32,8 @@ from .data.CGSessionName import CGSessionName from ..ui.event.ListModelBinder import ListModelBinder from ..ui.event.UnoDataAware import UnoDataAware from ..ui.event.RadioDataAware import RadioDataAware +from ..ui.event.SimpleDataAware import SimpleDataAware +from ..ui.event.CommonListener import ItemListenerProcAdapter from ..ui.DocumentPreview import DocumentPreview from ..ui.event.DataAware import DataAware from ..ui.event.Task import Task @@ -360,6 +363,10 @@ class WWD_Startup(WWD_General): self.lstLoadSettings.Model.SelectedItems = (selectedSession,) + def designItemChanged(self, itemEvent): + print ("DEBUG !!! designItemChanged --") + self.sda.updateData() + ''' attaches to each ui-data-control (like checkbox, groupbox or textbox, no buttons though), a DataObject's JavaBean Property, @@ -368,8 +375,8 @@ class WWD_Startup(WWD_General): def makeDataAware(self): #page 1 - ListModelBinder( - self.lstLoadSettings, self.settings.cp_SavedSessions) + ListModelBinder(self.lstLoadSettings, self.settings.cp_SavedSessions) + #page 2 : document properties self.docListDA = UnoDataAware.attachListBox( self, "selectedDoc", self.lstDocuments, False) @@ -390,13 +397,13 @@ class WWD_Startup(WWD_General): doc, "cp_Author", self.txtDocAuthor, True)) self.docAware.append(UnoDataAware.attachListBox( doc, "Exporter", self.lstDocTargetType, False)) + #page 3 : Layout design = self.settings.cp_DefaultSession.cp_Design + self.sda = SimpleDataAware(design, "Layout", self.ilLayouts, "Selected") + self.ilLayouts.addItemListener(ItemListenerProcAdapter(self.designItemChanged)) + self.designAware.append(self.sda); - #COMMENTED - #self.sda = SimpleDataAware.SimpleDataAware_unknown(design, DataAware.PropertyValue ("Layout", design), ilLayouts, DataAware.PropertyValue ("Selected", ilLayouts)) - - #self.ilLayouts.addItemListener(None) #page 4 : layout 2 self.designAware.append(UnoDataAware.attachCheckBox( design, "cp_DisplayDescription", self.chbDocDesc, True)) |