summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/web
diff options
context:
space:
mode:
authorJavier Fernandez <jfernandez@igalia.com>2013-05-03 14:21:23 +0000
committerJavier Fernandez <jfernandez@igalia.com>2013-05-08 09:36:39 +0000
commit8583086da2b982699e254126585a4d9abdf23766 (patch)
treeade4515d5ef8de303135a55ece3883a26b462542 /wizards/com/sun/star/wizards/web
parent3fe37133401faef81b09c9bb59b6e57b61931fe9 (diff)
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
Diffstat (limited to 'wizards/com/sun/star/wizards/web')
-rw-r--r--wizards/com/sun/star/wizards/web/BackgroundsDialog.py60
-rw-r--r--wizards/com/sun/star/wizards/web/IconsDialog.py33
-rw-r--r--wizards/com/sun/star/wizards/web/ImageListDialog.py5
-rw-r--r--wizards/com/sun/star/wizards/web/WWD_Events.py51
-rw-r--r--wizards/com/sun/star/wizards/web/WebConfigSet.py58
5 files changed, 141 insertions, 66 deletions
diff --git a/wizards/com/sun/star/wizards/web/BackgroundsDialog.py b/wizards/com/sun/star/wizards/web/BackgroundsDialog.py
index 936aa167a6ee..67fa94362510 100644
--- a/wizards/com/sun/star/wizards/web/BackgroundsDialog.py
+++ b/wizards/com/sun/star/wizards/web/BackgroundsDialog.py
@@ -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]
diff --git a/wizards/com/sun/star/wizards/web/IconsDialog.py b/wizards/com/sun/star/wizards/web/IconsDialog.py
index 09191e341015..31f834bb8dc1 100644
--- a/wizards/com/sun/star/wizards/web/IconsDialog.py
+++ b/wizards/com/sun/star/wizards/web/IconsDialog.py
@@ -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)
diff --git a/wizards/com/sun/star/wizards/web/ImageListDialog.py b/wizards/com/sun/star/wizards/web/ImageListDialog.py
index 746f71cbec09..156ea150f74f 100644
--- a/wizards/com/sun/star/wizards/web/ImageListDialog.py
+++ b/wizards/com/sun/star/wizards/web/ImageListDialog.py
@@ -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.
diff --git a/wizards/com/sun/star/wizards/web/WWD_Events.py b/wizards/com/sun/star/wizards/web/WWD_Events.py
index b227912578a3..b72032fb301f 100644
--- a/wizards/com/sun/star/wizards/web/WWD_Events.py
+++ b/wizards/com/sun/star/wizards/web/WWD_Events.py
@@ -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()
diff --git a/wizards/com/sun/star/wizards/web/WebConfigSet.py b/wizards/com/sun/star/wizards/web/WebConfigSet.py
index 88b49f227666..bdf9bdb5a1ce 100644
--- a/wizards/com/sun/star/wizards/web/WebConfigSet.py
+++ b/wizards/com/sun/star/wizards/web/WebConfigSet.py
@@ -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)