Kaydet (Commit) 8583086d authored tarafından Javier Fernandez's avatar Javier Fernandez

PyWebWizard: Fixing bugs and implementation of mising features.

Implementing the Iconset and Background selection dialogs.

- Using the new ListModel interface.
- Connected the ListModelListeners.
- Implemented the Renderer capabilities.

Change-Id: I7a4003db662dbae14b7e1a45d21685776a58d2c3
üst 3fe37133
......@@ -93,3 +93,20 @@ class KeyListenerProcAdapter( unohelper.Base, XKeyListener ):
def keyPressed(self, KeyEvent):
if callable( self.oProcToCall ):
self.oProcToCall(KeyEvent)
def disposing(self, Event):
# TODO: Implement ?
pass
from com.sun.star.awt import XMouseListener
class OMouseListenerProcAdapter( unohelper.Base, XMouseListener ):
def __init__(self, oProcToCall):
self.oProcToCall = oProcToCall
def mousePressed(self, MouseEvent):
if callable( self.oProcToCall ):
self.oProcToCall(MouseEvent)
def disposing(self, Event):
# TODO: Implement ?
pass
......@@ -16,20 +16,25 @@
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
class ListModelBinder(object):
from abc import abstractmethod
from .ListDataListener import ListDataListener
class ListModelBinder(ListDataListener):
def __init__(self, unoListBox, listModel_):
self.unoList = unoListBox
self.unoListModel = unoListBox.Model
#COMMENTED
#self.setListModel(listModel_)
self.listModel = None
self.setListModel(listModel_)
self.renderer = self.Renderer()
def setListModel(self, newListModel):
if self.listModel is not None:
self.listModel.removeListDataListener(self)
self.listModel = newListModel
self.listModel.addListDataListener(this)
self.listModel.addListDataListener(self)
def contentsChanged(self, lde):
selected = self.getSelectedItems()
......@@ -50,9 +55,9 @@ class ListModelBinder(object):
self.unoList.addItem(self.getItemString(i), i)
def getItemString(self, i):
return self.getItemString(self.listModel.getElementAt(i))
return self.getItemString1(self.listModel.getElementAt(i))
def getItemString(self, item):
def getItemString1(self, item):
return self.renderer.render(item)
def getSelectedItems(self):
......@@ -62,11 +67,24 @@ class ListModelBinder(object):
self.unoListModel.SelectedItems = selected;
def intervalAdded(self, lde):
for i in xrange(lde.Index0, lde.Index1):
i = lde.getIndex0()
while (i <= lde.getIndex1()):
self.insert(i)
i += 1
def intervalRemoved(self, lde):
self.remove(lde.Index0, lde.Index1)
self.remove(lde.getIndex0(), lde.getIndex1())
class Renderer:
@abstractmethod
def render(self, item):
if (item is None):
return ""
elif (isinstance(item, int)):
return str(item)
else:
return item.toString()
@classmethod
def fillList(self, xlist, items, renderer):
......@@ -76,7 +94,7 @@ class ListModelBinder(object):
if renderer is not None:
aux = renderer.render(index)
else:
aux = item.cp_Name
aux = item.toString()
xlist.addItem(aux, index)
@classmethod
......
......@@ -24,6 +24,8 @@ from .WebWizardConst import *
from ..common.SystemDialog import SystemDialog
from ..common.FileAccess import FileAccess
from ..common.Configuration import Configuration
from ..common.ListModel import ListModel
from ..ui.ImageList import ImageList
from com.sun.star.awt import Size
......@@ -47,8 +49,9 @@ class BackgroundsDialog(ImageListDialog):
self.fileAccess = FileAccess(xmsf)
#COMMENTED
#self.il.setListModel(Model(set_))
self.il.listModel = self.Model(set_, self)
self.il.imageSize = Size (40, 40)
#self.il.setRenderer(BGRenderer (0))
self.il.renderer = self.BGRenderer(0, self)
self.build()
'''
......@@ -106,26 +109,22 @@ class BackgroundsDialog(ImageListDialog):
@author rpiterman
'''
class BGRenderer(object):
class BGRenderer(ImageList.IImageRenderer):
cut = 0
def __init__(self, cut_):
ImageListDialog.ImageListDialog_body()
def __init__(self, cut_, parent):
self.cut = cut_
self.parent = parent
def getImageUrls(self, listItem):
sRetUrls = []
if (listItem is not None):
sRetUrls.append(listItem)
return sRetUrls
return None
def render(self, _object):
if _object is None:
return ""
else:
return FileAccess.getPathFilename(
self.fileAccess.getPath(_object, None))
def render(self, obj):
return "" if (obj is None) else FileAccess.getFilename(self.parent.fileAccess.getPath(obj, None))
'''
This is a list model for the image list of the
......@@ -138,7 +137,11 @@ class BackgroundsDialog(ImageListDialog):
@author rpiterman
'''
class Model(object):
class Model(ListModel):
parent = None
listModel = []
'''
constructor. </br>
see class description for a description of
......@@ -146,17 +149,18 @@ class BackgroundsDialog(ImageListDialog):
@param model the configuration set of the background images.
'''
def __init__(self, model):
def __init__(self, model, parent):
self.parent = parent
try:
i = 0
while i < model.getSize():
image = model.getElementAt(i)
path = self.sd.xStringSubstitution.substituteVariables(
path = parent.sd.xStringSubstitution.substituteVariables(
image.cp_Href, False)
if self.fileAccess.exists(path, False):
addDir(path)
if parent.fileAccess.exists(path, False):
self.addDir(path)
else:
remove(model.getKey(image))
self.remove(model.getKey(image))
i += 1
except Exception:
......@@ -173,7 +177,7 @@ class BackgroundsDialog(ImageListDialog):
def remove(self, imageName):
try:
conf = Configuration.getConfigurationRoot(
self.xMSF, WebWizardConst.CONFIG_PATH + "/BackgroundImages",
self.parent.xMSF, CONFIG_PATH + "/BackgroundImages",
True)
Configuration.removeNode(conf, imageName)
except Exception:
......@@ -187,10 +191,10 @@ class BackgroundsDialog(ImageListDialog):
'''
def addDir(self, url):
if self.fileAccess.isDirectory(url):
self.add(self.fileAccess.listFiles(url, False))
if self.parent.fileAccess.isDirectory(url):
self.add(self.parent.fileAccess.listFiles(url, False))
else:
self.add(url)
self.add1(url)
'''
adds the given filenames (urls) to
......@@ -212,7 +216,13 @@ class BackgroundsDialog(ImageListDialog):
'''
def add1(self, filename):
lcase = filename.toLowerCase()
if lcase.endsWith("jpg") or lcase.endsWith("jpeg") or \
lcase.endsWith("gif"):
Model.this.addElement(filename)
lcase = filename.lower()
if lcase.endswith("jpg") or lcase.endswith("jpeg") or \
lcase.endswith("gif"):
self.listModel.append(filename)
def getSize(self):
return len(self.listModel)
def getElementAt(self, arg0):
return self.listModel[arg0]
......@@ -19,6 +19,8 @@
from .ImageListDialog import ImageListDialog
from .WWHID import HID_IS
from ..common.FileAccess import FileAccess
from ..common.ListModel import ListModel
from ..ui.ImageList import ImageList
from com.sun.star.awt import Size
......@@ -31,7 +33,7 @@ It also implements the ImageList.ImageRenderer interface, to handle
its own objects.
'''
class IconsDialog(ImageListDialog):
class IconsDialog(ImageListDialog, ImageList.IImageRenderer, ListModel):
def __init__(self, xmsf, set_, resources):
super(IconsDialog, self).__init__(xmsf, HID_IS,
......@@ -48,7 +50,7 @@ class IconsDialog(ImageListDialog):
self.icons = \
["firs", "prev", "next", "last", "nav", "text", "up", "down"]
self.set = set_
self.objects = (self.set.getSize() * len(self.icons),)
self.objects = range(self.set.getSize() * len(self.icons))
self.il.listModel = self
self.il.renderer = self
......@@ -66,16 +68,24 @@ class IconsDialog(ImageListDialog):
if self.getSelected() is None:
return None
else:
return self.set.getKey((self.getSelected()) / len(self.icons))
selected = self.getSelected()
value = int(selected / len(self.icons))
return "iconset" + str(value)
#return self.set.getKey(value)
def setIconset(self, iconset):
#COMMENTED
icon = 0 #self.set.getIndexOf(self.set.getElement(iconset)) * len(self.icons)
icon = self.set.getIndexOf(self.set.getElement(iconset)) * len(self.icons)
aux = None
if icon >=0:
aux = self.objects[icon]
self.setSelected(aux)
def addListDataListener(self, listener):
pass
def removeListDataListener(self, listener):
pass
def getSize(self):
return self.set.getSize() * len(self.icons)
......@@ -83,10 +93,10 @@ class IconsDialog(ImageListDialog):
return self.objects[arg0]
def getImageUrls(self, listItem):
i = (listItem).intValue()
iset = getIconsetNum(i)
icon = getIconNum(i)
sRetUrls = range(2)
i = listItem
iset = self.getIconsetNum(i)
icon = self.getIconNum(i)
sRetUrls = list(range(2))
sRetUrls[0] = self.htmlexpDirectory + "/htmlexpo/" \
+ self.getIconsetPref(iset) + self.icons[icon] + self.getIconsetPostfix(iset)
sRetUrls[1] = sRetUrls[0]
......@@ -95,12 +105,13 @@ class IconsDialog(ImageListDialog):
def render(self, object):
if object is None:
return ""
i = (object).intValue()
i = object
iset = self.getIconsetNum(i)
return self.getIconset1(iset).cp_Name
def getIconsetNum(self, i):
return i / self.icons.length
return int(i / len(self.icons))
def getIconNum(self, i):
return i % len(self.icons)
......
......@@ -21,6 +21,7 @@ from ..ui.UnoDialog2 import UnoDialog2
from ..ui.ImageList import ImageList
from ..common.HelpIds import HelpIds
from ..common.PropertyNames import PropertyNames
from ..common.IRenderer import IRenderer
from com.sun.star.awt import FontDescriptor
from com.sun.star.awt.PushButtonType import OK, CANCEL, HELP, STANDARD
......@@ -93,7 +94,6 @@ class ImageListDialog(UnoDialog2):
'''
def build(self):
print ("DEBUG !!!! ImageListDialog build 1")
#set dialog properties...
ilWidth = (self.il.imageSize.Width + self.il.gap.Width) \
* self.il.cols + self.il.gap.Width
......@@ -169,7 +169,6 @@ class ImageListDialog(UnoDialog2):
self.il.helpURL = self.hid + 5
self.il.tabIndex = 1
self.il.create(self)
print ("DEBUG !!!! ImageListDialog build 2")
self.lblTitle = self.insertLabel("lblTitle",
("FontDescriptor",
PropertyNames.PROPERTY_HEIGHT,
......@@ -213,7 +212,7 @@ class ImageListDialog(UnoDialog2):
"%TOTAL" with the respective values.
@author rpiterman
'''
class ARenderer(object):
class ARenderer(IRenderer):
'''
@param aTempalte a template for this renderer.
......
......@@ -51,10 +51,6 @@ session methods.
class WWD_Events(WWD_Startup):
iconsDialog = None
bgDialog = None
docPreview = None
'''
He - my constructor !
I add a window listener, which, when
......@@ -70,6 +66,9 @@ class WWD_Events(WWD_Startup):
self.exitOnCreate = True
self.time = 0
self.count = 0
self.bgDialog = None
self.iconsDialog = None
self.docPreview = None
@classmethod
def main(self, args):
......@@ -341,18 +340,18 @@ class WWD_Events(WWD_Startup):
def chooseBackground(self):
try:
self.setEnabled(self.btnBackgrounds, False)
if WWD_Events.bgDialog is None:
WWD_Events.bgDialog = BackgroundsDialog(
self.xMSF, WWD_Startup.settings.cp_BackgroundImages,
if self.bgDialog is None:
self.bgDialog = BackgroundsDialog(
self.xMSF, self.settings.cp_BackgroundImages,
self.resources)
WWD_Events.bgDialog.createWindowPeer(self.xUnoDialog.Peer)
self.bgDialog.createWindowPeer(self.xUnoDialog.Peer)
WWD_Events.bgDialog.setSelected(
WWD_Startup.settings.cp_DefaultSession.cp_Design.cp_BackgroundImage)
i = WWD_Events.bgDialog.executeDialogFromParent(self)
self.bgDialog.setSelected(
self.settings.cp_DefaultSession.cp_Design.cp_BackgroundImage)
i = self.bgDialog.executeDialogFromParent(self)
if i == 1:
#ok
self.setBackground(WWD_Events.bgDialog.getSelected())
self.setBackground(self.bgDialog.getSelected())
except Exception:
traceback.print_exc()
finally:
......@@ -366,7 +365,7 @@ class WWD_Events(WWD_Startup):
if background is None:
background = ""
WWD_Startup.settings.cp_DefaultSession.cp_Design.cp_BackgroundImage \
self.settings.cp_DefaultSession.cp_Design.cp_BackgroundImage \
= background
self.refreshStylePreview()
......@@ -377,18 +376,18 @@ class WWD_Events(WWD_Startup):
def chooseIconset(self):
try:
self.setEnabled(self.btnIconSets, False)
if WWD_Events.iconsDialog is None:
WWD_Events.iconsDialog = IconsDialog(
self.xMSF, WWD_Startup.settings.cp_IconSets,
if self.iconsDialog is None:
self.iconsDialog = IconsDialog(
self.xMSF, self.settings.cp_IconSets,
self.resources)
WWD_Events.iconsDialog.createWindowPeer(self.xUnoDialog.Peer)
self.iconsDialog.createWindowPeer(self.xUnoDialog.Peer)
WWD_Events.iconsDialog.setIconset(
WWD_Startup.settings.cp_DefaultSession.cp_Design.cp_IconSet)
i = WWD_Events.iconsDialog.executeDialogFromParent(self)
self.iconsDialog.setIconset(
self.settings.cp_DefaultSession.cp_Design.cp_IconSet)
i = self.iconsDialog.executeDialogFromParent(self)
if i == 1:
#ok
self.setIconset(WWD_Events.iconsDialog.getIconset())
self.setIconset(self.iconsDialog.getIconset())
except Exception:
traceback.print_exc()
finally:
......@@ -399,7 +398,7 @@ class WWD_Events(WWD_Startup):
'''
def setIconset(self, icon):
WWD_Startup.settings.cp_DefaultSession.cp_Design.cp_IconSet = icon
self.settings.cp_DefaultSession.cp_Design.cp_IconSet = icon
self.updateIconsetText()
'''
......@@ -892,11 +891,11 @@ class WWD_Events(WWD_Startup):
self.dpStylePreview.dispose()
self.stylePreview.cleanup()
if WWD_Events.bgDialog is not None:
WWD_Events.bgDialog.xUnoDialog.dispose()
if self.bgDialog is not None:
self.bgDialog.xUnoDialog.dispose()
if WWD_Events.iconsDialog is not None:
WWD_Events.iconsDialog.xUnoDialog.dispose()
if self.iconsDialog is not None:
self.iconsDialog.xUnoDialog.dispose()
if self.ftpDialog is not None:
self.ftpDialog.xUnoDialog.dispose()
......
......@@ -19,6 +19,9 @@ import traceback
from ..common.ConfigGroup import ConfigGroup
from ..common.Configuration import Configuration
from ..common.XMLProvider import XMLProvider
from ..ui.event.EventListenerList import EventListenerList
from ..ui.event.ListDataEvent import ListDataEvent
from ..ui.event.ListDataListener import ListDataListener
class WebConfigSet(ConfigGroup):
'''
......@@ -36,6 +39,7 @@ class WebConfigSet(ConfigGroup):
self.childrenMap = {}
self.childrenList = []
self.noNulls = False
self.listenerList = None
def add(self, name, o):
print ("DEBUG !!! WebConfigSet.add -- name: ", name)
......@@ -49,6 +53,7 @@ class WebConfigSet(ConfigGroup):
i = int(name)
print ("DEBUG !!! WebConfigSet.add -- name IS an integer.")
self.childrenList.insert(i, o)
self.fireListDataListenerIntervalAdded(i, i);
except Exception:
print ("DEBUG !!! WebConfigSet.add -- name IS NOT an integer.")
try:
......@@ -66,6 +71,7 @@ class WebConfigSet(ConfigGroup):
self.childrenList.insert(i, o)
if oldSize > i:
oldSize = i
self.fireListDataListenerIntervalAdded(oldSize, i);
except Exception:
if (oldO is not None):
print ("DEBUG !!! WebConfigSet.add -- No cp_Index attribute, but element already present, so replace it.")
......@@ -74,6 +80,7 @@ class WebConfigSet(ConfigGroup):
else:
print ("DEBUG !!! WebConfigSet.add -- No cp_Index attribute, so just append it.")
self.childrenList.append(o)
self.fireListDataListenerIntervalAdded(self.getSize() - 1, self.getSize() - 1);
def writeConfiguration(self, configView, param):
......@@ -126,7 +133,7 @@ class WebConfigSet(ConfigGroup):
self.childrenMap.remove(key)
i = self.childrenList.indexOf(obj)
self.childrenList.remove(obj)
#fireListDataListenerIntervalRemoved(i, i)
self.fireListDataListenerIntervalRemoved(i, i)
def remove(self, i):
o = getElementAt(i)
......@@ -136,6 +143,9 @@ class WebConfigSet(ConfigGroup):
self.childrenMap.clear()
del self.childrenList[:]
def update(i):
self.fireListDataListenerContentsChanged(i, i)
def createDOM(self, parent):
items = self.childrenList
i = 0
......@@ -207,3 +217,49 @@ class WebConfigSet(ConfigGroup):
def sort(self, comparator):
self.childrenList.sort(comparator)
# Registers ListDataListener to receive events.
# @param listener The listener to register.
def addListDataListener(self, listener):
if (self.listenerList is None):
self.listenerList = EventListenerList()
self.listenerList.add(listener)
# Removes ListDataListener from the list of listeners.
# @param listener The listener to remove.
def removeListDataListener(self, listener):
self.listenerList.remove(listener)
# Notifies all registered listeners about the event.
#
# @param event The event to be fired
def fireListDataListenerIntervalAdded(self, i0, i1):
event = ListDataEvent(self, ListDataEvent.INTERVAL_ADDED, i0, i1)
if (self.listenerList is None):
return
for listener in self.listenerList.getListenerList():
if isinstance(listener, ListDataListener):
listener.intervalAdded(event)
# Notifies all registered listeners about the event.
#
# @param event The event to be fired
def fireListDataListenerIntervalRemoved(self, i0, i1):
event = ListDataEvent(self, ListDataEvent.INTERVAL_REMOVED, i0, i1)
if (self.listenerList is None):
return
for listener in self.listenerList.getListenerList():
if isinstance(listener, ListDataListener):
listener.intervalRemoved(event)
# Notifies all registered listeners about the event.
#
# @param event The event to be fired
def fireListDataListenerContentsChanged(self, i0, i1):
event = ListDataEvent(self, ListDataEvent.CONTENTS_CHANGED, i0, i1)
if (self.listenerList is None):
return
for listener in self.listenerList.getListenerList():
if isinstance(listener, ListDataListener):
listener.contentsChanged(event)
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