<commit_before>#
# 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 *
from ImageListDialog import *
from WWHID import HID_IS
from common.FileAccess import FileAccess

'''
@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):

    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 = (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):
        if getSelected() is None:
            return None
        else:
            return self.set.getKey((getSelected()) / len(self.icons))

    def setIconset(self, iconset):
        #COMMENTED
        icon = 0 #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):
        return self.objects[arg0]

    def getImageUrls(self, listItem):
        i = (listItem).intValue()
        iset = getIconsetNum(i)
        icon = getIconNum(i)
        sRetUrls = range(2)
        sRetUrls[0] = self.htmlexpDirectory + "/htmlexpo/" \
            + getIconsetPref(iset) + self.icons[icon] + getIconsetPostfix(iset)
        sRetUrls[1] = sRetUrls[0]
        return sRetUrls

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

        i = (object).intValue()
        iset = getIconsetNum(i)
        return getIconset(iset).cp_Name

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

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

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

    def getIconsetPostfix(self, iconset):
        return getIconset(iconset).cp_FNPostfix

    def getIconset(self, i):
        return self.set.getElementAt(i)<commit_msg>Init: Pythonize the IconsDialog class.<commit_after>#
# 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 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):

    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 = (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):
        if self.getSelected() is None:
            return None
        else:
            return self.set.getKey((self.getSelected()) / len(self.icons))

    def setIconset(self, iconset):
        #COMMENTED
        icon = 0 #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):
        return self.objects[arg0]

    def getImageUrls(self, listItem):
        i = (listItem).intValue()
        iset = getIconsetNum(i)
        icon = getIconNum(i)
        sRetUrls = 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).intValue()
        iset = self.getIconsetNum(i)
        return self.getIconset1(iset).cp_Name

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

    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):
        return self.set.getElementAt(i)
{'fraction_non_alphanumeric': 0.09734513274336283, 'fraction_numerical': 0.006507027589796981, 'mean_word_length': 2.4477344100493497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3010617', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2265, 'n_words': 669}