summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/web/IconsDialog.py
blob: 210d4c65425992e7962fb65d8e4d882a77568185 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
# 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 .
#

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

'''
@author rpiterman
The dialog class for choosing an icon set.
This class simulates a model, though it does not functions really as one,
since it does not cast events.
It also implements the ImageList.ImageRenderer interface, to handle
its own objects.
'''

class IconsDialog(ImageListDialog, ImageList.IImageRenderer, ListModel):

    def __init__(self, xmsf, set_, resources):
        super(IconsDialog, self).__init__(xmsf, HID_IS,
            (resources.resIconsDialog,
                resources.resIconsDialogCaption,
                resources.resOK,
                resources.resCancel,
                resources.resHelp,
                resources.resDeselect,
                resources.resOther,
                resources.resCounter))
        self.htmlexpDirectory = FileAccess.getOfficePath2(
            xmsf, "Gallery", "share", "")
        self.icons = \
            ["firs", "prev", "next", "last", "nav", "text", "up", "down"]
        self.set = set_
        self.objects = range(self.set.getSize() * len(self.icons))

        self.il.listModel = self
        self.il.renderer = self
        self.il.rows = 4
        self.il.cols = 8
        self.il.ImageSize = Size (20, 20)
        self.il.showButtons = False
        self.il.rowSelect = True
        self.il.scaleImages = False
        self.showDeselectButton = True
        self.showOtherButton = False
        self.build()

    def getIconset(self):
        print ("DEBUG !!! getIconset -- ")
        if self.getSelected() is None:
            print ("DEBUG !!! getIconset -- selected is None")
            return None
        else:
            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):
        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]
        self.setSelected(aux)

    def getSize(self):
        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):
        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]
        return sRetUrls

    def render(self, object):
        if object is None:
            return ""

        i = object
        iset = self.getIconsetNum(i)
        return self.getIconset1(iset).cp_Name

    def getIconsetNum(self, i):
        return int(i / len(self.icons))

    def getIconNum(self, i):
        return i % len(self.icons)

    def getIconsetPref(self, iconset):
        return self.getIconset1(iconset).cp_FNPrefix

    def getIconsetPostfix(self, iconset):
        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)