This commit is contained in:
Jane
2024-07-16 15:58:23 +08:00
parent 29bc31ade5
commit 0bbdcd9ef7
1621 changed files with 300787 additions and 0 deletions

View File

@@ -0,0 +1,176 @@
#
# 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 .
#
import traceback
from .UnoDialog import UnoDialog
from ..common.Desktop import Desktop
from ..common.PropertyNames import PropertyNames
from ..common.HelpIds import HelpIds
from com.sun.star.awt.ScrollBarOrientation import VERTICAL
class ControlScroller(object):
SORELFIRSTPOSY = 3
iScrollBarWidth = 10
# TODO add parameters for tabindices and helpindex
def __init__(self, _CurUnoDialog, _xMSF, _iStep, _iCompPosX, _iCompPosY,
_iCompWidth, _nblockincrement, _nlinedistance, _firsthelpindex):
self.xMSF = _xMSF
self.scrollfields = []
self.ControlGroupVector = []
ControlScroller.nblockincrement = _nblockincrement
self.CurUnoDialog = _CurUnoDialog
self.iStep = _iStep
self.curHelpIndex = _firsthelpindex
self.curtabindex = self.iStep * 100
self.linedistance = _nlinedistance
self.iCompPosX = _iCompPosX
self.iCompPosY = _iCompPosY
self.iCompWidth = _iCompWidth
self.iCompHeight = 2 * ControlScroller.SORELFIRSTPOSY + \
ControlScroller.nblockincrement * self.linedistance
self.iStartPosY = self.iCompPosY + ControlScroller.SORELFIRSTPOSY
ScrollHeight = self.iCompHeight - 2
self.nlineincrement = 1
self.sincSuffix = Desktop.getIncrementSuffix(
self.CurUnoDialog.xDialogModel, "imgBackground")
self.xScrollBar = self.CurUnoDialog.insertScrollBar(
"TitleScrollBar" + self.sincSuffix,
("Border", PropertyNames.PROPERTY_ENABLED,
PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_HELPURL, "Orientation",
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_WIDTH),
(0, True, ScrollHeight,
HelpIds.getHelpIdString(self.curHelpIndex),
VERTICAL, self.iCompPosX + self.iCompWidth - \
ControlScroller.iScrollBarWidth - 1,
self.iCompPosY + 1, self.iStep,
ControlScroller.iScrollBarWidth), 0, self)
self.nscrollvalue = 0
ypos = self.iStartPosY + ControlScroller.SORELFIRSTPOSY
for i in range(ControlScroller.nblockincrement):
self.insertControlGroup(i, ypos)
ypos += self.linedistance
def fillupControls(self, binitialize):
for i in range(ControlScroller.nblockincrement):
if i < self.ncurfieldcount:
self.fillupControl(i)
if binitialize:
self.CurUnoDialog.repaintDialogStep()
def fillupControl(self, guiRow):
nameProps = self.scrollfields[guiRow]
valueProps = self.scrollfields[guiRow + self.nscrollvalue]
for index, item in enumerate(nameProps):
if self.CurUnoDialog.xDialogModel.hasByName(item.Name):
self.setControlData(item.Name, valueProps[index].Value)
else:
raise AttributeError("No such control !")
self.ControlGroupVector[guiRow].setEnabled(True)
def setScrollValue(self, _nscrollvalue, _ntotfieldcount=None):
if _ntotfieldcount is not None:
self.setTotalFieldCount(_ntotfieldcount)
if _nscrollvalue >= 0:
self.xScrollBar.Model.ScrollValue = _nscrollvalue
self.scrollControls()
def setCurFieldCount(self):
if self.ntotfieldcount > ControlScroller.nblockincrement:
self.ncurfieldcount = ControlScroller.nblockincrement
else:
self.ncurfieldcount = self.ntotfieldcount
def setTotalFieldCount(self, _ntotfieldcount):
self.ntotfieldcount = _ntotfieldcount
self.setCurFieldCount()
if self.ntotfieldcount > ControlScroller.nblockincrement:
self.xScrollBar.Model.Enabled = True
self.xScrollBar.Model.ScrollValueMax = \
self.ntotfieldcount - ControlScroller.nblockincrement
else:
self.xScrollBar.Model.Enabled = False
def scrollControls(self):
try:
self.nscrollvalue = \
int(self.xScrollBar.Model.ScrollValue)
if self.nscrollvalue + ControlScroller.nblockincrement \
>= self.ntotfieldcount:
self.nscrollvalue = \
self.ntotfieldcount - ControlScroller.nblockincrement
self.fillupControls(False)
except Exception:
traceback.print_exc()
'''
updates the corresponding data to
the control in guiRow and column
@param guiRow 0 based row index
@param column 0 based column index
@return the propertyValue object corresponding to
this control.
'''
def fieldInfo(self, guiRow, column):
if guiRow + self.nscrollvalue < len(self.scrollfields):
valueProp = (self.scrollfields[guiRow + self.nscrollvalue])[column]
nameProp = (self.scrollfields[guiRow])[column]
if self.CurUnoDialog.xDialogModel.hasByName(nameProp.Name):
valueProp.Value = self.getControlData(nameProp.Name)
else:
valueProp.Value = nameProp.Value
return valueProp
else:
return None
def unregisterControlGroup(self, _index):
del self.scrollfields[_index]
def registerControlGroup(self, _currowproperties, _i):
if _i == 0:
del self.scrollfields[:]
if _i >= len(self.scrollfields):
self.scrollfields.append(_currowproperties)
else:
self.scrollfields.insert(_currowproperties, _i)
def setControlData(self, controlname, newvalue):
oControlModel = self.CurUnoDialog.xUnoDialog.getControl(
controlname).Model
propertyname = UnoDialog.getDisplayProperty(oControlModel)
if propertyname:
setattr(oControlModel, propertyname, newvalue)
def getControlData(self, controlname):
oControlModel = self.CurUnoDialog.xUnoDialog.getControl(
controlname).Model
propertyname = UnoDialog.getDisplayProperty(oControlModel)
if propertyname:
return getattr(oControlModel, propertyname)
else:
return None

View File

@@ -0,0 +1,96 @@
#
# 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 .
#
import traceback
from ..common.Properties import Properties
from com.sun.star.awt import WindowDescriptor
from com.sun.star.awt import Rectangle
from com.sun.star.awt.WindowClass import SIMPLE
from com.sun.star.awt.VclWindowPeerAttribute import CLIPCHILDREN
from com.sun.star.awt.WindowAttribute import SHOW
'''
To change the template for this generated type comment go to
Window>Preferences>Java>Code Generation>Code and Comments
'''
class DocumentPreview(object):
PREVIEW_MODE = 1
'''
create new frame with window inside
load a component as preview into this frame
'''
def __init__(self, xmsf, control):
self.xControl = control
self.createPreviewFrame(xmsf, self.xControl)
def setDocument(self, url_, propNames, propValues=None):
if propValues is None:
if propNames == DocumentPreview.PREVIEW_MODE:
self.setDocument(url_, ("Preview", "ReadOnly"), (True, True))
else:
self.loadArgs = propNames
self.xFrame.activate()
self.xComponent = self.xFrame.loadComponentFromURL(url_, "_self", 0, tuple(self.loadArgs))
return self.xComponent
else:
self.url = url_
ps = Properties()
for index,item in enumerate(propNames):
ps[item] = propValues[index]
return self.setDocument(self.url, ps.getProperties1())
def closeFrame(self):
if self.xFrame is not None:
self.xFrame.close(False)
'''
create a new frame with a new container window inside,
which is not part of the global frame tree.
Attention:
a) This frame won't be destroyed by the office. It must be closed by you!
Do so - please call XCloseable::close().
b) The container window is part of the frame. Don't hold it alive - nor try to kill it.
It will be destroyed inside close().
'''
def createPreviewFrame(self, xmsf, xControl):
controlPeer = xControl.Peer
r = xControl.PosSize
toolkit = xmsf.createInstance("com.sun.star.awt.Toolkit")
aDescriptor = WindowDescriptor()
aDescriptor.Type = SIMPLE
aDescriptor.WindowServiceName = "window"
aDescriptor.ParentIndex = -1
aDescriptor.Parent = controlPeer
#xWindowPeer; #argument !
aDescriptor.Bounds = Rectangle(0, 0, r.Width, r.Height)
aDescriptor.WindowAttributes = CLIPCHILDREN | SHOW
self.xWindow = toolkit.createWindow(aDescriptor)
self.xFrame = xmsf.createInstance("com.sun.star.frame.Frame")
self.xFrame.initialize(self.xWindow)
self.xWindow.setVisible(True)
def dispose(self):
try:
self.closeFrame()
except Exception:
traceback.print_exc()

View File

@@ -0,0 +1,137 @@
#
# 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 .
#
import traceback
from ..common.PropertyNames import PropertyNames
from ..common.FileAccess import FileAccess
from ..common.SystemDialog import SystemDialog
class PathSelection(object):
class DialogTypes(object):
FOLDER = 0
FILE = 1
class TransferMode(object):
SAVE = 0
LOAD = 1
def __init__(self, xMSF, CurUnoDialog, TransferMode, DialogType):
self.CurUnoDialog = CurUnoDialog
self.xMSF = xMSF
self.iDialogType = DialogType
self.iTransferMode = TransferMode
self.sDefaultDirectory = ""
self.sDefaultName = ""
self.sDefaultFilter = ""
self.usedPathPicker = False
self.CMDSELECTPATH = 1
self.TXTSAVEPATH = 1
def insert(
self, DialogStep, XPos, YPos, Width,
CurTabIndex, LabelText, Enabled, TxtHelpURL, BtnHelpURL):
self.CurUnoDialog.insertControlModel(
"com.sun.star.awt.UnoControlFixedTextModel", "lblSaveAs",
(PropertyNames.PROPERTY_ENABLED,
PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_LABEL,
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_TABINDEX,
PropertyNames.PROPERTY_WIDTH),
(Enabled, 8, LabelText, XPos, YPos, DialogStep,
CurTabIndex, Width))
self.xSaveTextBox = self.CurUnoDialog.insertTextField(
"txtSavePath", "callXPathSelectionListener",
(PropertyNames.PROPERTY_ENABLED,
PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_HELPURL,
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_TABINDEX,
PropertyNames.PROPERTY_WIDTH),
(Enabled, 12, TxtHelpURL, XPos, YPos + 10, DialogStep,
(CurTabIndex + 1), Width - 26), self)
self.CurUnoDialog.xDialogModel.txtSavePath.Enabled = False
self.CurUnoDialog.insertButton("cmdSelectPath", "triggerPathPicker",
(PropertyNames.PROPERTY_ENABLED,
PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_HELPURL,
PropertyNames.PROPERTY_LABEL,
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_TABINDEX,
PropertyNames.PROPERTY_WIDTH),
(Enabled, 14, BtnHelpURL, "...",XPos + Width - 16, YPos + 9,
DialogStep, (CurTabIndex + 2), 16), self)
def addSelectionListener(self, xAction):
self.xAction = xAction
def getSelectedPath(self):
return self.xSaveTextBox.Text
def initializePath(self):
try:
myFA = FileAccess(self.xMSF)
self.xSaveTextBox.setText(
myFA.getPath(self.sDefaultDirectory + \
"/" + \
self.sDefaultName, None))
except Exception:
traceback.print_exc()
def triggerPathPicker(self):
try:
if self.iTransferMode == self.TransferMode.SAVE:
if self.iDialogType == self.DialogTypes.FOLDER:
#TODO: write code for picking a folder for saving
return
elif self.iDialogType == self.DialogTypes.FILE:
self.usedPathPicker = True
myFilePickerDialog = \
SystemDialog.createStoreDialog(self.xMSF)
myFilePickerDialog.callStoreDialog(
self.sDefaultDirectory,
self.sDefaultName, self.sDefaultFilter)
sStorePath = myFilePickerDialog.sStorePath
if sStorePath is not None:
myFA = FileAccess(self.xMSF)
self.xSaveTextBox.Text = myFA.getPath(sStorePath, None)
self.sDefaultDirectory = \
FileAccess.getParentDir(sStorePath)
self.sDefaultName = myFA.getFilename(sStorePath)
return
elif self.iTransferMode == self.TransferMode.LOAD:
if self.iDialogType == self.DialogTypes.FOLDER:
#TODO: write code for picking a folder for loading
return
elif self.iDialogType == self.DialogTypes.FILE:
#TODO: write code for picking a file for loading
return
except Exception:
traceback.print_exc()
def callXPathSelectionListener(self):
if self.xAction is not None:
self.xAction.validatePath()

View File

@@ -0,0 +1,61 @@
#
# 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 .
#
import traceback
from .event.CommonListener import WindowListenerProcAdapter
'''
To change the template for this generated type comment go to
Window>Preferences>Java>Code Generation>Code and Comments
'''
class PeerConfig(object):
def __init__(self, _oUnoDialog):
self.oUnoDialog = _oUnoDialog
self.oUnoDialog.xUnoDialog.addWindowListener(
WindowListenerProcAdapter(self.windowShown))
self.m_aPeerTasks = []
self.aImageUrlTasks = []
class PeerTask(object):
def __init__(self, _xControl, _propNames, _propValues):
self.propnames = _propNames
self.propvalues = _propValues
self.xControl = _xControl
class ImageUrlTask(object):
def __init__(self, _oModel, _oResource):
self.oModel = _oModel
self.oResource = _oResource
def windowShown(self):
try:
for i in self.m_aPeerTasks:
xVclWindowPeer = i.xControl.Peer
xVclWindowPeer.setProperty(i.propnames, i.propvalues)
for aImageUrlTask in self.aImageUrlTasks:
sImageUrl = aImageUrlTask.oResource
if sImageUrl != "":
aImageUrlTask.oModel.ImageURL = sImageUrl
except Exception:
traceback.print_exc()

View File

@@ -0,0 +1,38 @@
#
# 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 .
#
class UIConsts():
INVISIBLESTEP = 99
INFOIMAGEURL = "private:graphicrepository/dbaccess/res/exinfo.png"
'''
The tabindex of the navigation buttons in a wizard must be assigned a very
high tabindex because on every step their taborder must appear at the end
'''
SOFIRSTWIZARDNAVITABINDEX = 30000
# Steps of the QueryWizard
SOFIELDSELECTIONPAGE = 1
SOSORTINGPAGE = 2
SOFILTERPAGE = 3
SOAGGREGATEPAGE = 4
SOGROUPSELECTIONPAGE = 5
SOGROUPFILTERPAGE = 6
SOTITLESPAGE = 7
SOSUMMARYPAGE = 8

View File

@@ -0,0 +1,254 @@
#
#
# 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 .
#
import uno
import traceback
from .PeerConfig import PeerConfig
from .UIConsts import UIConsts
from ..common.PropertyNames import PropertyNames
from com.sun.star.awt import Rectangle
from com.sun.star.awt.PosSize import POS
class UnoDialog(object):
createDict = False
dictProperties = None
BisHighContrastModeActivated = None
xVclWindowPeer = None
def __init__(self, xMSF, PropertyNames, PropertyValues):
try:
self.xMSF = xMSF
self.ControlList = {}
self.xDialogModel = xMSF.createInstance(
"com.sun.star.awt.UnoControlDialogModel")
self.xUnoDialog = xMSF.createInstance(
"com.sun.star.awt.UnoControlDialog")
self.xUnoDialog.setModel(self.xDialogModel)
self.m_oPeerConfig = None
self.xWindowPeer = None
except Exception:
traceback.print_exc()
# repaints the currentDialogStep
def repaintDialogStep(self):
try:
ncurstep = int(self.xDialogModel.Step)
self.xDialogModel.Step = 99
self.xDialogModel.Step = ncurstep
except Exception:
traceback.print_exc()
def insertControlModel(self, serviceName, componentName, sPropNames, oPropValues):
try:
xControlModel = self.xDialogModel.createInstance(serviceName)
uno.invoke(xControlModel, "setPropertyValues",
(sPropNames, oPropValues))
self.xDialogModel.insertByName(componentName, xControlModel)
xControlModel.Name = componentName
except Exception:
traceback.print_exc()
aObj = self.xUnoDialog.getControl(componentName)
return aObj
def setFocus(self, ControlName):
oFocusControl = self.xUnoDialog.getControl(ControlName)
oFocusControl.setFocus()
def calculateDialogPosition(self, FramePosSize):
# Todo:check if it would be useful or possible to create a dialog peer
# that can be used for the messageboxes to
# maintain modality when they pop up.
CurPosSize = self.xUnoDialog.getPosSize()
WindowHeight = FramePosSize.Height
WindowWidth = FramePosSize.Width
DialogWidth = CurPosSize.Width
DialogHeight = CurPosSize.Height
iXPos = ((WindowWidth / 2) - (DialogWidth / 2))
iYPos = ((WindowHeight / 2) - (DialogHeight / 2))
self.xUnoDialog.setPosSize(
iXPos, iYPos, DialogWidth, DialogHeight, POS)
'''
@param FramePosSize
@return 0 for cancel, 1 for ok
@throws com.sun.star.uno.Exception
'''
def executeDialog(self, FramePosSize):
if self.xUnoDialog.getPeer() is None:
raise AttributeError(
"Please create a peer, using your own frame")
self.calculateDialogPosition(FramePosSize)
if self.xWindowPeer is None:
self.createWindowPeer()
self.xVclWindowPeer = self.xWindowPeer
self.BisHighContrastModeActivated = self.isHighContrastModeActivated()
return self.xUnoDialog.execute()
def setVisible(self, parent):
self.calculateDialogPosition(parent.xUnoDialog.getPosSize())
if self.xWindowPeer == None:
self.createWindowPeer()
self.xUnoDialog.setVisible(True)
'''
@param XComponent
@return 0 for cancel, 1 for ok
@throws com.sun.star.uno.Exception
'''
def executeDialogFromComponent(self, xComponent):
if xComponent is not None:
w = xComponent.ComponentWindow
if w is not None:
return self.executeDialog(w.PosSize)
return self.executeDialog( Rectangle (0, 0, 640, 400))
'''
create a peer for this
dialog, using the given
peer as a parent.
@param parentPeer
@return
@throws java.lang.Exception
'''
def createWindowPeer(self, parentPeer=None):
self.xUnoDialog.setVisible(False)
xToolkit = self.xMSF.createInstance("com.sun.star.awt.Toolkit")
if parentPeer is None:
parentPeer = xToolkit.getDesktopWindow()
self.xUnoDialog.createPeer(xToolkit, parentPeer)
self.xWindowPeer = self.xUnoDialog.getPeer()
return self.xUnoDialog.getPeer()
@classmethod
def setEnabled(self, control, enabled):
control.Model.Enabled = enabled
@classmethod
def getModel(self, control):
return control.getModel()
@classmethod
def getDisplayProperty(self, xServiceInfo):
if xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlFixedTextModel"):
return PropertyNames.PROPERTY_LABEL
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlButtonModel"):
return PropertyNames.PROPERTY_LABEL
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlCurrencyFieldModel"):
return "Value"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlDateFieldModel"):
return "Date"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlFixedLineModel"):
return PropertyNames.PROPERTY_LABEL
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlFormattedFieldModel"):
return "EffectiveValue"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlNumericFieldModel"):
return "Value"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlPatternFieldModel"):
return "Text"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlProgressBarModel"):
return "ProgressValue"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlTimeFieldModel"):
return "Time"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlImageControlModel"):
return PropertyNames.PROPERTY_IMAGEURL
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlRadioButtonModel"):
return PropertyNames.PROPERTY_STATE
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlCheckBoxModel"):
return PropertyNames.PROPERTY_STATE
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlEditModel"):
return "Text"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlComboBoxModel"):
return "Text"
elif xServiceInfo.supportsService(
"com.sun.star.awt.UnoControlListBoxModel"):
return "SelectedItems"
else:
return ""
def isHighContrastModeActivated(self):
if (self.xVclWindowPeer is not None):
if (self.BisHighContrastModeActivated is None):
nUIColor = 0
try:
nUIColor = self.xVclWindowPeer.getProperty("DisplayBackgroundColor")
except Exception:
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

View File

@@ -0,0 +1,204 @@
#
# 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 .UnoDialog import UnoDialog, UIConsts
from ..common.Desktop import Desktop
from ..common.PropertyNames import PropertyNames
from ..common.SystemDialog import SystemDialog
from .event.CommonListener import ItemListenerProcAdapter, \
ActionListenerProcAdapter, TextListenerProcAdapter, \
AdjustmentListenerProcAdapter
'''
This class contains convenience methods for inserting components to a dialog.
It was created for use with the automatic conversion of Basic XML Dialog
description files to a Java class which builds
the same dialog through the UNO API.<br/>
It uses an Event-Listener method, which calls a method through reflection
when an event on a component is triggered.
see the classes CommonListener for details
'''
class UnoDialog2(UnoDialog):
'''
Override this method to return another listener.
@return
'''
def __init__(self, xmsf):
super(UnoDialog2,self).__init__(xmsf,(), ())
ControlList = {}
def insertButton(
self, sName, actionPerformed, sPropNames, oPropValues, listener):
xButton = self.insertControlModel(
"com.sun.star.awt.UnoControlButtonModel",
sName, sPropNames, oPropValues)
if actionPerformed is not None:
actionPerformed = getattr(listener, actionPerformed)
xButton.addActionListener(
ActionListenerProcAdapter(actionPerformed))
return xButton
def insertCheckBox(
self, sName, itemChanged, sPropNames, oPropValues, listener):
xCheckBox = self.insertControlModel(
"com.sun.star.awt.UnoControlCheckBoxModel",
sName, sPropNames, oPropValues)
if itemChanged is not None:
itemChanged = getattr(listener, itemChanged)
xCheckBox.addItemListener(ItemListenerProcAdapter(itemChanged))
return xCheckBox
def insertComboBox(
self, sName, actionPerformed, itemChanged,
textChanged, sPropNames, oPropValues, listener):
xComboBox = self.insertControlModel(
"com.sun.star.awt.UnoControlComboBoxModel",
sName, sPropNames, oPropValues)
if actionPerformed is not None:
actionPerformed = getattr(listener, actionPerformed)
xComboBox.addActionListener(
ActionListenerProcAdapter(actionPerformed))
if itemChanged is not None:
itemChanged = getattr(listener, itemChanged)
xComboBox.addItemListener(ItemListenerProcAdapter(itemChanged))
if textChanged is not None:
textChanged = getattr(listener, textChanged)
xComboBox.addTextListener(TextListenerProcAdapter(textChanged))
return xComboBox
def insertListBox(
self, sName, actionPerformed, itemChanged,
sPropNames, oPropValues, listener):
xListBox = self.insertControlModel(
"com.sun.star.awt.UnoControlListBoxModel",
sName, sPropNames, oPropValues)
if itemChanged is not None:
itemChanged = getattr(listener, itemChanged)
xListBox.addItemListener(ItemListenerProcAdapter(itemChanged))
return xListBox
def insertRadioButton(
self, sName, itemChanged, sPropNames, oPropValues, listener):
xRadioButton = self.insertControlModel(
"com.sun.star.awt.UnoControlRadioButtonModel",
sName, sPropNames, oPropValues)
if itemChanged is not None:
itemChanged = getattr(listener, itemChanged)
xRadioButton.addItemListener(
ItemListenerProcAdapter(itemChanged))
return xRadioButton
def insertTextField(
self, sName, sTextChanged, sPropNames, oPropValues, listener):
return self.insertEditField(
sName, sTextChanged, "com.sun.star.awt.UnoControlEditModel",
sPropNames, oPropValues, listener)
def insertImage(self, sName, sPropNames, oPropValues):
return self.insertControlModel(
"com.sun.star.awt.UnoControlImageControlModel",
sName, sPropNames, oPropValues)
def insertInfoImage(self, _posx, _posy, _iStep):
xImgControl = self.insertImage(
Desktop.getUniqueName(self.xDialogModel, "imgHint"),
("Border",
PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_IMAGEURL,
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y, "ScaleImage",
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_WIDTH),
(0, 10, UIConsts.INFOIMAGEURL, _posx, _posy, False, _iStep, 10))
return xImgControl
'''
This method is used for creating Edit, Currency, Date, Formatted,
Pattern, File and Time edit components.
'''
def insertEditField(
self, sName, sTextChanged, sModelClass,
sPropNames, oPropValues, listener):
xField = self.insertControlModel(sModelClass,
sName, sPropNames, oPropValues)
if sTextChanged is not None:
sTextChanged = getattr(listener, sTextChanged)
xField.addTextListener(TextListenerProcAdapter(sTextChanged))
return xField
def insertDateField(
self, sName, sTextChanged, sPropNames, oPropValues, listener):
return self.insertEditField(
sName, sTextChanged,
"com.sun.star.awt.UnoControlDateFieldModel",
sPropNames, oPropValues, listener)
def insertNumericField(
self, sName, sTextChanged, sPropNames, oPropValues, listener):
return self.insertEditField(
sName, sTextChanged,
"com.sun.star.awt.UnoControlNumericFieldModel",
sPropNames, oPropValues, listener)
def insertTimeField(
self, sName, sTextChanged, sPropNames, oPropValues, listener):
return self.insertEditField(
sName, sTextChanged,
"com.sun.star.awt.UnoControlTimeFieldModel",
sPropNames, oPropValues, listener)
def insertFixedLine(self, sName, sPropNames, oPropValues):
oLine = self.insertControlModel(
"com.sun.star.awt.UnoControlFixedLineModel",
sName, sPropNames, oPropValues)
return oLine
def insertLabel(self, sName, sPropNames, oPropValues):
oFixedText = self.insertControlModel(
"com.sun.star.awt.UnoControlFixedTextModel",
sName, sPropNames, oPropValues)
return oFixedText
def insertScrollBar(self, sName, sPropNames, oPropValues,
iControlKey, listener):
oScrollBar = self.insertControlModel(
"com.sun.star.awt.UnoControlScrollBarModel",
sName, sPropNames, oPropValues)
if listener is not None:
method = getattr(listener, "scrollControls")
oScrollBar.addAdjustmentListener(
AdjustmentListenerProcAdapter(method))
if self.ControlList is not None:
self.ControlList[sName] = iControlKey
return oScrollBar
def showMessageBox(self, windowServiceName, windowAttribute, MessageText):
return SystemDialog.showMessageBox(
super().xMSF, self.xControl.Peer,
windowServiceName, windowAttribute, MessageText)

View File

@@ -0,0 +1,470 @@
#
# 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 .
#
import uno
import traceback
from abc import ABCMeta, abstractmethod
from .UnoDialog2 import UnoDialog2, Desktop, PropertyNames, UIConsts, \
ItemListenerProcAdapter
from ..common.HelpIds import HelpIds
from ..common.FileAccess import FileAccess
from com.sun.star.lang import NoSuchMethodException
from com.sun.star.frame import TerminationVetoException
from com.sun.star.awt.PushButtonType import HELP, STANDARD
from com.sun.star.awt.FontWeight import BOLD
import sys, os
if sys.version_info < (3,4):
import imp
imp.load_source('strings', os.path.join(os.path.dirname(__file__), '../common/strings.hrc'))
import strings
elif sys.version_info < (3,7):
# imp is deprecated since Python v.3.4
from importlib.machinery import SourceFileLoader
SourceFileLoader('strings', os.path.join(os.path.dirname(__file__), '../common/strings.hrc')).load_module()
import strings
else:
# have to jump through hoops since 3.7, partly because python does not like loading modules that do have a .py extension
import importlib
import importlib.util
import importlib.machinery
module_name = 'strings'
path = os.path.join(os.path.dirname(__file__), '../common/strings.hrc')
spec = importlib.util.spec_from_loader(
module_name,
importlib.machinery.SourceFileLoader(module_name, path)
)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
sys.modules[module_name] = module
strings = module
class WizardDialog(UnoDialog2):
__metaclass__ = ABCMeta
__NEXT_ACTION_PERFORMED = "gotoNextAvailableStep"
__BACK_ACTION_PERFORMED = "gotoPreviousAvailableStep"
__FINISH_ACTION_PERFORMED = "finishWizard_1"
__CANCEL_ACTION_PERFORMED = "cancelWizard_1"
__HELP_ACTION_PERFORMED = None
'''
Creates a new instance of WizardDialog
the hid is used as following :
"HID:(hid)" - the dialog
"HID:(hid+1) - the help button
"HID:(hid+2)" - the back button
"HID:(hid+3)" - the next button
"HID:(hid+4)" - the create button
"HID:(hid+5)" - the cancel button
@param xMSF
@param hid_
'''
def __init__(self, xMSF, hid_):
super(WizardDialog,self).__init__(xMSF)
self.__hid = hid_
self.iButtonWidth = 50
self.nNewStep = 1
self.nOldStep = 1
self.nMaxStep = 1
self.bTerminateListenermustberemoved = True
self.oRoadmap = None
self.terminateListener = None
def activate(self):
try:
self.xUnoDialog.toFront()
except Exception:
pass
# do nothing;
def itemStateChanged(self, itemEvent):
try:
self.nNewStep = itemEvent.ItemId
self.nOldStep = int(self.xDialogModel.Step)
if self.nNewStep != self.nOldStep:
self.switchToStep()
except Exception:
traceback.print_exc()
def setDialogProperties(self, closeable, height, moveable, position_x,
position_Y, step, tabIndex, title, width):
uno.invoke(self.xDialogModel, "setPropertyValues",
((PropertyNames.PROPERTY_CLOSEABLE,
PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_MOVEABLE,
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_TABINDEX,
PropertyNames.PROPERTY_TITLE,
PropertyNames.PROPERTY_WIDTH),
(closeable, height, moveable, position_x, position_Y, step,
tabIndex, title, width)))
def setRoadmapInteractive(self, _bInteractive):
self.oRoadmap.Activated = _bInteractive
def setRoadmapComplete(self, bComplete):
self.oRoadmap.Complete = bComplete
def isRoadmapComplete(self):
try:
return bool(self.oRoadmap.Complete)
except Exception:
traceback.print_exc()
return False
def setCurrentRoadmapItemID(self, ID):
if self.oRoadmap is not None:
nCurItemID = self.getCurrentRoadmapItemID()
if nCurItemID != ID:
self.oRoadmap.CurrentItemID = ID
def getCurrentRoadmapItemID(self):
try:
return int(self.oRoadmap.CurrentItemID)
except Exception:
traceback.print_exc()
return -1
def initializePaths(self):
xPropertySet = \
self.xMSF.createInstance("com.sun.star.util.PathSettings")
self.sUserTemplatePath = \
xPropertySet.getPropertyValue("Template_writable")
myFA = FileAccess(self.xMSF)
aInternalPaths = xPropertySet.getPropertyValue("Template_internal")
self.sTemplatePath = ""
for path in aInternalPaths:
if myFA.exists(path + "/wizard", False):
self.sTemplatePath = path
break
if self.sTemplatePath == "":
raise Exception("could not find wizard templates")
def addRoadmap(self):
try:
iDialogHeight = self.xDialogModel.Height
# the roadmap control has got no real TabIndex ever
# that is not correct, but changing this would need time,
# so it is used without TabIndex as before
xRoadmapControl = self.insertControlModel(
"com.sun.star.awt.UnoControlRoadmapModel",
"rdmNavi",
(PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_TABINDEX, "Tabstop",
PropertyNames.PROPERTY_WIDTH),
((iDialogHeight - 26), 0, 0, 0,
0, True, 85))
self.oRoadmap = xRoadmapControl.Model
method = getattr(self, "itemStateChanged")
xRoadmapControl.addItemListener(
ItemListenerProcAdapter(method))
self.oRoadmap.Text = strings.RID_COMMON_START_16
except NoSuchMethodException:
from com.sun.star.awt.VclWindowPeerAttribute import OK
from .SystemDialog import SystemDialog
sError = "The files required could not be found.\n" + \
"Please start the LibreOffice Setup and choose 'Repair'."
SystemDialog.showMessageBox(super().xMSF, "ErrorBox", OK, sError)
except Exception:
traceback.print_exc()
def getRoadmapItemByID(self, _ID):
try:
getByIndex = self.oRoadmap.getByIndex
for i in list(range(self.oRoadmap.Count)):
CurRoadmapItem = getByIndex(i)
CurID = int(CurRoadmapItem.ID)
if CurID == _ID:
return CurRoadmapItem
return None
except Exception:
traceback.print_exc()
return None
def switchToStep(self,_nOldStep=None, _nNewStep=None):
if _nOldStep is not None and _nNewStep is not None:
self.nOldStep = _nOldStep
self.nNewStep = _nNewStep
self.leaveStep(self.nOldStep, self.nNewStep)
if self.nNewStep != self.nOldStep:
if self.nNewStep == self.nMaxStep:
self.xDialogModel.btnWizardNext.DefaultButton = False
self.xDialogModel.btnWizardFinish.DefaultButton = True
else:
self.xDialogModel.btnWizardNext.DefaultButton = True
self.xDialogModel.btnWizardFinish.DefaultButton = False
self.changeToStep(self.nNewStep)
self.enterStep(self.nOldStep, self.nNewStep)
return True
return False
@abstractmethod
def leaveStep(self, nOldStep, nNewStep):
pass
@abstractmethod
def enterStep(self, nOldStep, nNewStep):
pass
def changeToStep(self, nNewStep):
self.xDialogModel.Step = nNewStep
self.setCurrentRoadmapItemID(nNewStep)
self.enableNextButton(self.getNextAvailableStep() > 0)
self.enableBackButton(nNewStep != 1)
def drawNaviBar(self):
try:
curtabindex = UIConsts.SOFIRSTWIZARDNAVITABINDEX
iButtonWidth = self.iButtonWidth
iButtonHeight = 14
iCurStep = 0
iDialogHeight = self.xDialogModel.Height
iDialogWidth = self.xDialogModel.Width
iHelpPosX = 8
iBtnPosY = iDialogHeight - iButtonHeight - 6
iCancelPosX = iDialogWidth - self.iButtonWidth - 6
iFinishPosX = iCancelPosX - 6 - self.iButtonWidth
iNextPosX = iFinishPosX - 6 - self.iButtonWidth
iBackPosX = iNextPosX - 3 - self.iButtonWidth
self.insertControlModel(
"com.sun.star.awt.UnoControlFixedLineModel",
"lnNaviSep",
(PropertyNames.PROPERTY_HEIGHT, "Orientation",
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_WIDTH),
(1, 0, 0, iDialogHeight - 26, iCurStep, iDialogWidth))
self.insertControlModel(
"com.sun.star.awt.UnoControlFixedLineModel",
"lnRoadSep",
(PropertyNames.PROPERTY_HEIGHT,
"Orientation",
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_WIDTH),
(iBtnPosY - 6, 1, 85, 0, iCurStep, 1))
propNames = (PropertyNames.PROPERTY_ENABLED,
PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_HELPURL,
PropertyNames.PROPERTY_LABEL,
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
"PushButtonType",
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_TABINDEX,
PropertyNames.PROPERTY_WIDTH)
self.xDialogModel.HelpURL = HelpIds.getHelpIdString(self.__hid)
self.insertButton("btnWizardHelp",
WizardDialog.__HELP_ACTION_PERFORMED,
(PropertyNames.PROPERTY_ENABLED,
PropertyNames.PROPERTY_HEIGHT,
PropertyNames.PROPERTY_LABEL,
PropertyNames.PROPERTY_POSITION_X,
PropertyNames.PROPERTY_POSITION_Y,
"PushButtonType",
PropertyNames.PROPERTY_STEP,
PropertyNames.PROPERTY_TABINDEX,
PropertyNames.PROPERTY_WIDTH),
(True, iButtonHeight,
strings.RID_COMMON_START_15,
iHelpPosX, iBtnPosY,
uno.Any("short",HELP), iCurStep,
uno.Any("short",(curtabindex + 1)), iButtonWidth), self)
self.insertButton("btnWizardBack",
WizardDialog.__BACK_ACTION_PERFORMED, propNames,
(False, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 2),
strings.RID_COMMON_START_13,
iBackPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep,
uno.Any("short",(curtabindex + 1)), iButtonWidth), self)
self.insertButton("btnWizardNext",
WizardDialog.__NEXT_ACTION_PERFORMED, propNames,
(True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 3),
strings.RID_COMMON_START_14,
iNextPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep,
uno.Any("short",(curtabindex + 1)), iButtonWidth), self)
self.insertButton("btnWizardFinish",
WizardDialog.__FINISH_ACTION_PERFORMED, propNames,
(True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 4),
strings.RID_COMMON_START_12,
iFinishPosX, iBtnPosY, uno.Any("short",STANDARD),
iCurStep,
uno.Any("short",(curtabindex + 1)),
iButtonWidth), self)
self.insertButton("btnWizardCancel",
WizardDialog.__CANCEL_ACTION_PERFORMED, propNames,
(True, iButtonHeight, HelpIds.getHelpIdString(self.__hid + 5),
strings.RID_COMMON_START_11,
iCancelPosX, iBtnPosY, uno.Any("short",STANDARD), iCurStep,
uno.Any("short",(curtabindex + 1)),
iButtonWidth), self)
self.xDialogModel.btnWizardNext.DefaultButton = True
except Exception:
traceback.print_exc()
def insertRoadMapItems(self, items, enabled):
for index, item in enumerate(items):
try:
oRoadmapItem = self.oRoadmap.createInstance()
oRoadmapItem.Label = item
oRoadmapItem.Enabled = enabled[index]
oRoadmapItem.ID = index + 1
self.oRoadmap.insertByIndex(index, oRoadmapItem)
except Exception:
traceback.print_exc()
def enableBackButton(self, enabled):
self.xDialogModel.btnWizardBack.Enabled = enabled
def enableNextButton(self, enabled):
self.xDialogModel.btnWizardNext.Enabled = enabled
def enableFinishButton(self, enabled):
self.xDialogModel.btnWizardFinish.Enabled = enabled
def isStepEnabled(self, _nStep):
try:
xRoadmapItem = self.getRoadmapItemByID(_nStep)
# Todo: In this case an exception should be thrown
if xRoadmapItem is None:
return False
bIsEnabled = bool(xRoadmapItem.Enabled)
return bIsEnabled
except Exception:
traceback.print_exc()
return False
def gotoPreviousAvailableStep(self):
try:
if self.nNewStep > 1:
self.nOldStep = self.nNewStep
self.nNewStep -= 1
while self.nNewStep > 0:
bIsEnabled = self.isStepEnabled(self.nNewStep)
if bIsEnabled:
break;
self.nNewStep -= 1
if (self.nNewStep == 0):
self.nNewStep = self.nOldStep
self.switchToStep()
except Exception:
traceback.print_exc()
def getNextAvailableStep(self):
if self.isRoadmapComplete():
i = self.nNewStep + 1
while i <= self.nMaxStep:
if self.isStepEnabled(i):
return i
i += 1
return -1
def gotoNextAvailableStep(self):
try:
self.nOldStep = self.nNewStep
self.nNewStep = self.getNextAvailableStep()
if self.nNewStep > -1:
self.switchToStep()
except Exception:
traceback.print_exc()
@abstractmethod
def finishWizard(self):
pass
def finishWizard_1(self):
'''This function will call
if the finish button is pressed on the UI'''
try:
self.enableFinishButton(False)
success = False
try:
success = self.finishWizard()
finally:
if not success:
self.enableFinishButton(True)
if success:
self.removeTerminateListener()
except Exception:
traceback.print_exc()
def getCurrentStep(self):
try:
return int(self.xDialogModel.Step)
except Exception:
traceback.print_exc()
return -1
def cancelWizard(self):
#can be overwritten by extending class
self.xUnoDialog.endExecute()
def removeTerminateListener(self):
if self.bTerminateListenermustberemoved:
Desktop.getDesktop(self.xMSF).removeTerminateListener(self.terminateListener)
self.bTerminateListenermustberemoved = False
'''
called by the cancel button and
by the window hidden event.
if this method was not called before,
perform a cancel.
'''
def cancelWizard_1(self):
try:
self.cancelWizard()
self.removeTerminateListener()
except Exception:
traceback.print_exc()
def windowHidden(self):
self.cancelWizard_1()
def queryTermination(self):
self.activate()
raise TerminationVetoException()
def disposing(self, arg0):
self.cancelWizard_1()
def optCreateFromTemplateItemChanged(self):
self.bEditTemplate = False
def optMakeChangesItemChanged(self):
self.bEditTemplate = True

View File

@@ -0,0 +1,125 @@
#
# 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 .
#
import unohelper
from com.sun.star.awt import XActionListener
class ActionListenerProcAdapter( unohelper.Base, XActionListener ):
def __init__(self, oProcToCall):
self.oProcToCall = oProcToCall
def actionPerformed( self, oActionEvent ):
if callable( self.oProcToCall ):
self.oProcToCall()
def disposing(self, Event):
# TODO: Implement ?
pass
from com.sun.star.awt import XItemListener
class ItemListenerProcAdapter( unohelper.Base, XItemListener ):
def __init__(self, oProcToCall):
self.oProcToCall = oProcToCall
def itemStateChanged( self, oItemEvent ):
if callable( self.oProcToCall ):
try:
self.oProcToCall()
except:
self.oProcToCall(oItemEvent)
def disposing(self, Event):
# TODO: Implement ?
pass
from com.sun.star.awt import XTextListener
class TextListenerProcAdapter( unohelper.Base, XTextListener ):
def __init__(self, oProcToCall):
self.oProcToCall = oProcToCall
def textChanged( self, oTextEvent ):
if callable( self.oProcToCall ):
self.oProcToCall()
def disposing(self, Event):
# TODO: Implement ?
pass
from com.sun.star.frame import XTerminateListener
class TerminateListenerProcAdapter( unohelper.Base, XTerminateListener ):
def __init__(self, oProcToCall):
self.oProcToCall = oProcToCall
def queryTermination(self, TerminateEvent):
if callable( self.oProcToCall ):
self.oProcToCall()
from com.sun.star.awt import XWindowListener
class WindowListenerProcAdapter( unohelper.Base, XWindowListener ):
def __init__(self, oProcToCall):
self.oProcToCall = oProcToCall
def windowShown(self, TerminateEvent):
if callable( self.oProcToCall ):
self.oProcToCall()
def windowHidden(self, Event):
# TODO: Implement ?
pass
def windowResized(self, Event):
# TODO: Implement ?
pass
def windowMoved(self, Event):
# TODO: Implement ?
pass
def disposing(self, Event):
# TODO: Implement ?
pass
from com.sun.star.awt import XAdjustmentListener
class AdjustmentListenerProcAdapter( unohelper.Base, XAdjustmentListener ):
def __init__(self, oProcToCall):
self.oProcToCall = oProcToCall
def adjustmentValueChanged(self, TerminateEvent):
if callable( self.oProcToCall ):
self.oProcToCall()
from com.sun.star.awt import XFocusListener
class FocusListenerProcAdapter( unohelper.Base, XFocusListener ):
def __init__( self, oProcToCall):
self.oProcToCall = oProcToCall
def focusGained(self, FocusEvent):
if callable( self.oProcToCall ):
self.oProcToCall(FocusEvent)
from com.sun.star.awt import XKeyListener
class KeyListenerProcAdapter( unohelper.Base, XKeyListener ):
def __init__(self, oProcToCall):
self.oProcToCall = oProcToCall
def keyPressed(self, KeyEvent):
if callable( self.oProcToCall ):
self.oProcToCall(KeyEvent)
def disposing(self, Event):
# TODO: Implement ?
pass

View File

@@ -0,0 +1,117 @@
#
# 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 .
#
import traceback
import uno
from abc import ABCMeta, abstractmethod
from com.sun.star.util import Date
from com.sun.star.util import Time
from datetime import datetime
'''
DataAware objects are used to live-synchronize UI and DataModel/DataObject.
It is used as listener on UI events, to keep the DataObject up to date.
This class, as a base abstract class, sets a frame of functionality,
delegating the data Object get/set methods to a Value object,
and leaving the UI get/set methods abstract.
Note that event listening is *not* a part of this model.
the updateData() or updateUI() methods should be programmatically called.
in child classes, the updateData() will be bound to UI event calls.
<br><br>
This class holds references to a Data Object and a Value object.
The Value object "knows" how to get and set a value from the
Data Object.
'''
class DataAware(object):
__metaclass__ = ABCMeta
'''
creates a DataAware object for the given data object and Value object.
@param dataObject_
@param value_
'''
def __init__(self, dataObject_, field_):
self._dataObject = dataObject_
self._field = field_
'''
sets the given value to the UI control
@param newValue the value to set to the ui control.
'''
@abstractmethod
def setToUI (self,newValue):
pass
'''
gets the current value from the UI control.
@return the current value from the UI control.
'''
@abstractmethod
def getFromUI (self):
pass
'''
updates the UI control according to the
current state of the data object.
'''
def updateUI(self):
try:
data = getattr(self._dataObject, self._field)
except Exception:
data = uno.invoke(self._dataObject, "get" + self._field, ())
ui = self.getFromUI()
if data is not ui:
try:
self.setToUI(data)
except Exception:
traceback.print_exc()
'''
updates the DataObject according to
the current state of the UI control.
'''
def updateData(self):
useUno = False
try:
try:
data = getattr(self._dataObject, self._field)
except Exception:
useUno = True
data = uno.invoke(self._dataObject, "get" + self._field, ())
ui = self.getFromUI()
if data is not ui:
if isinstance(ui,Date):
d = datetime(ui.Year, ui.Month, ui.Day)
ui = d.strftime('%d/%m/%y')
elif isinstance(ui,Time):
t = datetime(1, 1, 1, ui.Hours, ui.Minutes)
ui = t.strftime('%H:%M')
if useUno:
uno.invoke(self._dataObject, "set" + self._field, (ui,))
else:
if isinstance(ui,tuple):
#Listbox Element
ui = ui[0]
setattr(self._dataObject, self._field, ui)
except Exception:
traceback.print_exc()

View File

@@ -0,0 +1,27 @@
#
# 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 .
#
class EventListenerList(object):
def __init__(self):
self.list = []
def add(self, listener):
self.list.append(listener)
def remove(self, listener):
self.list.remove(listener)

View File

@@ -0,0 +1,67 @@
#
# 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 abc import abstractmethod
from .ListDataListener import ListDataListener
class ListModelBinder(ListDataListener):
def __init__(self, unoListBox, listModel_):
self.unoList = unoListBox
self.unoListModel = unoListBox.Model
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(self)
def update(self, i):
self.remove(i, i)
self.insert(i)
def remove(self, i1, i2):
self.unoList.removeItems(i1, i2 - i1 + 1)
def insert(self, i):
self.unoList.addItem(self.getItemString(i), i)
def getItemString(self, i):
return self.getItemString1(self.listModel.getElementAt(i))
def getItemString1(self, item):
return self.renderer.render(item)
def getSelectedItems(self):
return self.unoListModel.SelectedItems
class Renderer:
@abstractmethod
def render(self, item):
if (item is None):
return ""
elif (isinstance(item, int)):
return str(item)
else:
return item.toString()

View File

@@ -0,0 +1,48 @@
#
# 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 .CommonListener import ItemListenerProcAdapter
from .DataAware import DataAware
class RadioDataAware(DataAware):
def __init__(self, data, value, radioButtons):
super(RadioDataAware,self).__init__(data, value)
self.radioButtons = radioButtons
def setToUI(self, value):
selected = int(value)
if selected == -1:
for i in self.radioButtons:
i.State = False
else:
self.radioButtons[selected].State = True
def getFromUI(self):
for index, workwith in enumerate(self.radioButtons):
if workwith.State:
return index
return -1
@classmethod
def attachRadioButtons(self, data, prop, buttons, field):
da = RadioDataAware(data, prop, buttons)
method = getattr(da,"updateData")
for i in da.radioButtons:
i.addItemListener(ItemListenerProcAdapter(method))
return da

View File

@@ -0,0 +1,76 @@
#
# 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 .
import traceback
from .TaskEvent import TaskEvent
class Task:
successful = 0
failed = 0
maximum = 0
taskName = ""
listeners = []
subtaskName = ""
def __init__(self, taskName_, subtaskName_, max_):
self.taskName = taskName_
self.subtaskName = subtaskName_
self.maximum = max_
def start(self):
self.fireTaskStarted()
def fail(self):
self.fireTaskFailed()
def getMax(self):
return self.maximum
def setMax(self, max_):
self.maximum = max_
self.fireTaskStatusChanged()
def advance(self, success_):
if success_:
self.successful += 1
print ("Success :", self.successful)
else:
self.failed += 1
print ("Failed :", self.failed)
self.fireTaskStatusChanged()
if (self.failed + self.successful == self.maximum):
self.fireTaskFinished()
def fireTaskStatusChanged(self):
te = TaskEvent(self, TaskEvent.TASK_STATUS_CHANGED)
for i in range(len(self.listeners)):
self.listeners[i].taskStatusChanged(te)
def fireTaskStarted(self):
te = TaskEvent(self, TaskEvent.TASK_STARTED)
for i in range(len(self.listeners)):
self.listeners[i].taskStarted(te)
def fireTaskFailed(self):
te = TaskEvent(self, TaskEvent.TASK_FAILED)
for i in range(len(self.listeners)):
self.listeners[i].taskFinished(te)
def fireTaskFinished(self):
te = TaskEvent(self, TaskEvent.TASK_FINISHED)
for i in range(len(self.listeners)):
self.listeners[i].taskFinished(te)

View File

@@ -0,0 +1,34 @@
#
# 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 .
class TaskEvent:
TASK_STARTED = 1
TASK_FINISHED = 2
TASK_STATUS_CHANGED = 3
SUBTASK_NAME_CHANGED = 4
TASK_FAILED = 5
taskType = 0
source = None
#general constructor-
# @param source
# @param type_
def __init__(self, source_, type_):
#super(TaskEvent, self).__init__(source)
self.taskType = type_
self.source = source_

View File

@@ -0,0 +1,35 @@
#
# 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 abc import abstractmethod
from com.sun.star.script import EventListener
class TaskListener(EventListener):
@abstractmethod
def taskStarted(self, te):
pass
@abstractmethod
def taskFinished(self, te):
pass
# is called when the status of the task has advanced.
# @param te
@abstractmethod
def taskStatusChanged(self, te):
pass

View File

@@ -0,0 +1,104 @@
#
# 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 .
#
import uno
from .CommonListener import ItemListenerProcAdapter, TextListenerProcAdapter
from .DataAware import DataAware, datetime, Date, Time
from ...common.PropertyNames import PropertyNames
'''
This class supports simple cases where a UI control can
be directly synchronized with a data property.
Such controls are: the different text controls
(synchronizing the "Text" , "Value", "Date", "Time" property),
Checkbox controls, Dropdown listbox controls (synchronizing the
SelectedItems[] property.
For those controls, static convenience methods are offered, to simplify use.
'''
class UnoDataAware(DataAware):
def __init__(self, dataObject, field, unoObject_, unoPropName_, isShort=False):
super(UnoDataAware,self).__init__(dataObject, field)
self.unoControl = unoObject_
self.unoModel = self.unoControl.Model
self.unoPropName = unoPropName_
self.isShort = isShort
def setToUI(self, value):
if (isinstance(value, list)):
value = tuple(value)
elif self.isShort:
value = uno.Any("[]short", (value,))
if value:
if(hasattr(self.unoModel, self.unoPropName)):
if self.unoPropName == "Date":
d = datetime.strptime(value, '%d/%m/%y')
value = Date(d.day, d.month, d.year)
elif self.unoPropName == "Time":
t = datetime.strptime(value, '%H:%M')
value = Time(0, 0, t.minute, t.hour, False)
setattr(self.unoModel, self.unoPropName, value)
else:
uno.invoke(self.unoModel, "set" + self.unoPropName, (value,))
def getFromUI(self):
return getattr(self.unoModel, self.unoPropName)
@classmethod
def __attachTextControl(
self, data, prop, unoText, unoProperty, field, value):
uda = UnoDataAware(data, prop, unoText, unoProperty)
method = getattr(uda,"updateData")
unoText.addTextListener(TextListenerProcAdapter(method))
return uda
@classmethod
def attachEditControl(self, data, prop, unoControl, field):
return self.__attachTextControl(
data, prop, unoControl, "Text", field, "")
@classmethod
def attachDateControl(self, data, prop, unoControl, field):
return self.__attachTextControl(
data, prop, unoControl, "Date", field, 0)
@classmethod
def attachTimeControl(self, data, prop, unoControl, field):
return self.__attachTextControl(
data, prop, unoControl, "Time", field, 0)
@classmethod
def attachNumericControl(self, data, prop, unoControl, field):
return self.__attachTextControl(
data, prop, unoControl, "Value", field, float(0))
@classmethod
def attachCheckBox(
self, data, prop, checkBox, field):
uda = UnoDataAware(data, prop, checkBox, PropertyNames.PROPERTY_STATE)
method = getattr(uda,"updateData")
checkBox.addItemListener(ItemListenerProcAdapter(method))
return uda
@classmethod
def attachListBox(self, data, prop, listBox, field):
uda = UnoDataAware(data, prop, listBox, "SelectedItems", True)
method = getattr(uda,"updateData")
listBox.addItemListener(ItemListenerProcAdapter(method))
return uda