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,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