From 0b8924e9fd028a6dc01e447b50b34bc89d1a7fc7 Mon Sep 17 00:00:00 2001 From: Javier Fernandez Date: Mon, 18 Mar 2013 11:55:40 +0000 Subject: IconsDialog must implement the ListModel iface. isHighContrastModeActivated. Change-Id: Ic60ee2c805ab7fe63ced84306ad20e29450c54bd --- wizards/com/sun/star/wizards/ui/PeerConfig.py | 4 +- wizards/com/sun/star/wizards/ui/UnoDialog.py | 66 +++++++++++++++++++++- wizards/com/sun/star/wizards/web/IconsDialog.py | 37 ++++++++---- .../com/sun/star/wizards/web/ImageListDialog.py | 1 + wizards/com/sun/star/wizards/web/WWD_Events.py | 4 ++ 5 files changed, 99 insertions(+), 13 deletions(-) diff --git a/wizards/com/sun/star/wizards/ui/PeerConfig.py b/wizards/com/sun/star/wizards/ui/PeerConfig.py index 442e42159b29..d22d54b0bab1 100644 --- a/wizards/com/sun/star/wizards/ui/PeerConfig.py +++ b/wizards/com/sun/star/wizards/ui/PeerConfig.py @@ -47,6 +47,7 @@ class PeerConfig(object): self.oHCResource = _oHCResource def windowShown(self): + print ("DEBUG !!! PeerConfig.windowShow --") try: for i in self.m_aPeerTasks: xVclWindowPeer = i.xControl.Peer @@ -56,7 +57,8 @@ class PeerConfig(object): if isinstance(aImageUrlTask.oResource, int): sImageUrl = oUnoDialog.getWizardImageUrl(aImageUrlTask.oResource, aImageUrlTask.oHCResource) elif isinstance(aImageUrlTask.oResource, str): - sImageUrl = oUnoDialog.getImageUrl(aImageUrlTask.oResource, aImageUrlTask.oHCResource) + sImageUrl = self.oUnoDialog.getImageUrl(aImageUrlTask.oResource, aImageUrlTask.oHCResource) + print ("DEBUG !!! PeerConfig.windowShow -- sImageUrl: ", sImageUrl) if sImageUrl != "": Helper.setUnoPropertyValue(aImageUrlTask.oModel, PropertyNames.PROPERTY_IMAGEURL, sImageUrl) diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog.py b/wizards/com/sun/star/wizards/ui/UnoDialog.py index f2b36a130ea1..64542c6edb57 100644 --- a/wizards/com/sun/star/wizards/ui/UnoDialog.py +++ b/wizards/com/sun/star/wizards/ui/UnoDialog.py @@ -28,6 +28,8 @@ class UnoDialog(object): createDict = False dictProperties = None + BisHighContrastModeActivated = None + xVclWindowPeer = None def __init__(self, xMSF, PropertyNames, PropertyValues): try: @@ -125,8 +127,7 @@ class UnoDialog(object): except Exception: traceback.print_exc() - def insertControlModel( - self, serviceName, componentName, sPropNames, oPropValues): + def insertControlModel(self, serviceName, componentName, sPropNames, oPropValues): try: xControlModel = self.xDialogModel.createInstance(serviceName) uno.invoke(xControlModel, "setPropertyValues", @@ -188,6 +189,9 @@ class UnoDialog(object): if self.xWindowPeer is None: self.createWindowPeer() + + self.xVclWindowPeer = self.xWindowPeer + self.BisHighContrastModeActivated = self.isHighContrastModeActivated() return self.xUnoDialog.execute() def setVisible(self, parent): @@ -312,3 +316,61 @@ class UnoDialog(object): def addResourceHandler(self, _Unit, _Module): self.m_oResource = Resource(self.xMSF, _Unit, _Module) + + def isHighContrastModeActivated(self): + if (self.xVclWindowPeer is not None): + if (self.BisHighContrastModeActivated is None): + nUIColor = 0 + try: + nUIColor = self.xVclWindowPeer.getProperty("DisplayBackgroundColor") + except IllegalArgumentException: + traceback.print_exc() + return False + + # TODO: The following methods could be wrapped in an own class implementation + nRed = self.getRedColorShare(nUIColor) + nGreen = self.getGreenColorShare(nUIColor) + nBlue = self.getBlueColorShare(nUIColor) + nLuminance = ((nBlue * 28 + nGreen * 151 + nRed * 77) / 256) + bisactivated = (nLuminance <= 25) + self.BisHighContrastModeActivated = bool(bisactivated) + return bisactivated; + else: + return self.BisHighContrastModeActivated + else: + return False + + + def getRedColorShare(self, _nColor): + nRed = _nColor / 65536 + nRedModulo = _nColor % 65536 + nGreen = nRedModulo / 256 + nGreenModulo = (nRedModulo % 256) + nBlue = nGreenModulo + return nRed + + def getGreenColorShare(self, _nColor): + nRed = _nColor / 65536 + nRedModulo = _nColor % 65536 + nGreen = nRedModulo / 256 + return nGreen + + def getBlueColorShare(self, _nColor): + nRed = _nColor / 65536 + nRedModulo = _nColor % 65536 + nGreen = nRedModulo / 256 + nGreenModulo = (nRedModulo % 256) + nBlue = nGreenModulo + return nBlue + + def getWizardImageUrl(self, _nResId, _nHCResId): + if (self.isHighContrastModeActivated()): + return "private:resource/wzi/image/" + str(_nHCResId) + else: + return "private:resource/wzi/image/" + str(_nResId) + + def getImageUrl(self, _surl, _shcurl): + if (self.isHighContrastModeActivated()): + return _shcurl + else: + return _surl diff --git a/wizards/com/sun/star/wizards/web/IconsDialog.py b/wizards/com/sun/star/wizards/web/IconsDialog.py index d1f1ef6e7cdc..210d4c654259 100644 --- a/wizards/com/sun/star/wizards/web/IconsDialog.py +++ b/wizards/com/sun/star/wizards/web/IconsDialog.py @@ -19,6 +19,7 @@ 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 @@ -32,7 +33,7 @@ It also implements the ImageList.ImageRenderer interface, to handle its own objects. ''' -class IconsDialog(ImageListDialog, ImageList.IImageRenderer): +class IconsDialog(ImageListDialog, ImageList.IImageRenderer, ListModel): def __init__(self, xmsf, set_, resources): super(IconsDialog, self).__init__(xmsf, HID_IS, @@ -49,7 +50,7 @@ class IconsDialog(ImageListDialog, ImageList.IImageRenderer): 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 @@ -64,14 +65,22 @@ class IconsDialog(ImageListDialog, ImageList.IImageRenderer): self.build() def getIconset(self): + print ("DEBUG !!! getIconset -- ") if self.getSelected() is None: + print ("DEBUG !!! getIconset -- selected is None") return None else: - return self.set.getKey((self.getSelected()) / len(self.icons)) + selected = self.getSelected() + print ("DEBUG !!! getIconset -- selected: ", selected) + value = int(selected / len(self.icons)) + print ("DEBUG !!! getIconset -- value: ", value) + 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) + print ("DEBUG !!! setIconset -- iconset: ", iconset) + print ("DEBUG !!! setIconset -- elements: ", self.set.childrenMap) + icon = self.set.getIndexOf(self.set.getElement(iconset)) * len(self.icons) aux = None if icon >=0: aux = self.objects[icon] @@ -81,13 +90,18 @@ class IconsDialog(ImageListDialog, ImageList.IImageRenderer): return self.set.getSize() * len(self.icons) def getElementAt(self, arg0): + print ("DEBUG !!! getElementAt -- arg0: ", arg0) + print ("DEBUG !!! getElementAt -- size: ", len(self.objects)) return self.objects[arg0] def getImageUrls(self, listItem): - i = (listItem).intValue() - iset = getIconsetNum(i) - icon = getIconNum(i) - sRetUrls = range(2) + print ("DEBUG !!! getImageUrls -- listItem: ", listItem) + i = listItem + iset = self.getIconsetNum(i) + icon = self.getIconNum(i) + print ("DEBUG !!! getImageUrls -- iset: ", iset) + print ("DEBUG !!! getImageUrls -- icon: ", icon) + sRetUrls = list(range(2)) sRetUrls[0] = self.htmlexpDirectory + "/htmlexpo/" \ + self.getIconsetPref(iset) + self.icons[icon] + self.getIconsetPostfix(iset) sRetUrls[1] = sRetUrls[0] @@ -96,7 +110,8 @@ class IconsDialog(ImageListDialog, ImageList.IImageRenderer): def render(self, object): if object is None: return "" - i = (object).intValue() + + i = object iset = self.getIconsetNum(i) return self.getIconset1(iset).cp_Name @@ -113,4 +128,6 @@ class IconsDialog(ImageListDialog, ImageList.IImageRenderer): return self.getIconset1(iconset).cp_FNPostfix def getIconset1(self, i): + print ("DEBUG !!! getIconset1 -- : i", i) + print ("DEBUG !!! getIconset1 -- : size", len(self.set.childrenList)) return self.set.getElementAt(i) diff --git a/wizards/com/sun/star/wizards/web/ImageListDialog.py b/wizards/com/sun/star/wizards/web/ImageListDialog.py index 66f3fa9885b7..47e7080521de 100644 --- a/wizards/com/sun/star/wizards/web/ImageListDialog.py +++ b/wizards/com/sun/star/wizards/web/ImageListDialog.py @@ -205,6 +205,7 @@ class ImageListDialog(UnoDialog2): ''' def setSelected(self, obj): + print ("DEBUG !!! ImageListDialog.setSelected -- obj: ", obj) self.il.setSelected(obj) self.il.showSelected() diff --git a/wizards/com/sun/star/wizards/web/WWD_Events.py b/wizards/com/sun/star/wizards/web/WWD_Events.py index 6b86594b7650..f68359e655b5 100644 --- a/wizards/com/sun/star/wizards/web/WWD_Events.py +++ b/wizards/com/sun/star/wizards/web/WWD_Events.py @@ -339,6 +339,7 @@ class WWD_Events(WWD_Startup): ''' def chooseBackground(self): + print ("DEBUG !!! chooseBackground --") try: self.setEnabled(self.btnBackgrounds, False) if WWD_Events.bgDialog is None: @@ -363,6 +364,7 @@ class WWD_Events(WWD_Startup): ''' def setBackground(self, background): + print ("DEBUG !!! setBackground -- background: ", background) if background is None: background = "" @@ -375,6 +377,7 @@ class WWD_Events(WWD_Startup): ''' def chooseIconset(self): + print ("DEBUG !!! chooseIconset --") try: self.setEnabled(self.btnIconSets, False) if WWD_Events.iconsDialog is None: @@ -399,6 +402,7 @@ class WWD_Events(WWD_Startup): ''' def setIconset(self, icon): + print ("DEBUG !!! setIconset -- icon: ", icon) WWD_Startup.settings.cp_DefaultSession.cp_Design.cp_IconSet = icon self.updateIconsetText() -- cgit v1.2.3