Add start range selecction by user
This commit is contained in:
parent
0d0cbead88
commit
9e6ac4b28e
|
@ -37,3 +37,64 @@ Hide or show tab sheets.
|
||||||
doc.tabs = not doc.tabs
|
doc.tabs = not doc.tabs
|
||||||
|
|
||||||
|
|
|
|
||||||
|
|
||||||
|
Events
|
||||||
|
------
|
||||||
|
|
||||||
|
See all the events that can be used.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
doc = app.active
|
||||||
|
event_names = doc.events.names
|
||||||
|
app.debug(event_names)
|
||||||
|
|
||||||
|
Assing some macro to event.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
doc = app.active
|
||||||
|
events = doc.events
|
||||||
|
if 'OnViewClosed' in events:
|
||||||
|
macro = {'library': 'test', 'name': 'on_view_closed'}
|
||||||
|
events['OnViewClosed'] = macro
|
||||||
|
|
||||||
|
Remove
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
events['OnViewClosed'] = {}
|
||||||
|
|
||||||
|
Or
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
events.remove('OnViewClosed')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
||||||
|
Select range by user
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
class Controllers():
|
||||||
|
|
||||||
|
def __init__(self, doc):
|
||||||
|
self.doc = doc
|
||||||
|
|
||||||
|
def range_selection_done(self, range_selection):
|
||||||
|
if range_selection:
|
||||||
|
app.debug(range_selection)
|
||||||
|
self.doc.remove_range_selection_listener()
|
||||||
|
return
|
||||||
|
|
||||||
|
def range_selection_aborted(self):
|
||||||
|
self.doc.remove_range_selection_listener()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
doc = app.active
|
||||||
|
doc.start_range_selection(Controllers)
|
||||||
|
return
|
||||||
|
|
|
@ -415,7 +415,7 @@ Get install path extension from id
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
id_ext = 'net.elmau.zaz.EasyMacro'
|
id_ext = 'net.elmau.zaz.EasyMacro'
|
||||||
path = app.path.ext(id_ext)
|
path = app.path.extension(id_ext)
|
||||||
app.debug(path)
|
app.debug(path)
|
||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
|
@ -70,6 +70,9 @@ from com.sun.star.datatransfer import XTransferable, DataFlavor
|
||||||
from com.sun.star.io import IOException, XOutputStream
|
from com.sun.star.io import IOException, XOutputStream
|
||||||
from com.sun.star.ui.dialogs import TemplateDescription
|
from com.sun.star.ui.dialogs import TemplateDescription
|
||||||
|
|
||||||
|
from com.sun.star.sheet import XRangeSelectionListener
|
||||||
|
from com.sun.star.lang import XEventListener
|
||||||
|
|
||||||
from com.sun.star.container import NoSuchElementException
|
from com.sun.star.container import NoSuchElementException
|
||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
|
@ -839,7 +842,6 @@ class Macro(object):
|
||||||
|
|
||||||
url = 'vnd.sun.star.script'
|
url = 'vnd.sun.star.script'
|
||||||
url = f'{url}:{library}{module}{name}?language={language}&location={location}'
|
url = f'{url}:{library}{module}{name}?language={language}&location={location}'
|
||||||
debug(url)
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -1398,7 +1400,7 @@ class Paths(object):
|
||||||
return folders
|
return folders
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ext(cls, id_ext: str):
|
def extension(cls, id_ext: str):
|
||||||
"""Get path extension install from id
|
"""Get path extension install from id
|
||||||
|
|
||||||
:param id_ext: ID extension
|
:param id_ext: ID extension
|
||||||
|
@ -2165,6 +2167,43 @@ class IOStream(object):
|
||||||
return cls.OutputStream()
|
return cls.OutputStream()
|
||||||
|
|
||||||
|
|
||||||
|
class EventsListenerBase(unohelper.Base, XEventListener):
|
||||||
|
|
||||||
|
def __init__(self, controller, name, window=None):
|
||||||
|
self._controller = controller
|
||||||
|
self._name = name
|
||||||
|
self._window = window
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
def disposing(self, event):
|
||||||
|
self._controller = None
|
||||||
|
if not self._window is None:
|
||||||
|
self._window.setMenuBar(None)
|
||||||
|
|
||||||
|
|
||||||
|
class EventsRangeSelectionListener(EventsListenerBase, XRangeSelectionListener):
|
||||||
|
|
||||||
|
def __init__(self, controller):
|
||||||
|
super().__init__(controller, '')
|
||||||
|
|
||||||
|
def done(self, event):
|
||||||
|
range_selection = event.RangeDescriptor
|
||||||
|
event_name = 'range_selection_done'
|
||||||
|
if hasattr(self._controller, event_name):
|
||||||
|
getattr(self._controller, event_name)(range_selection)
|
||||||
|
return
|
||||||
|
|
||||||
|
def aborted(self, event):
|
||||||
|
range_selection = event.RangeDescriptor
|
||||||
|
event_name = 'range_selection_aborted'
|
||||||
|
if hasattr(self._controller, event_name):
|
||||||
|
getattr(self._controller, event_name)()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class LOShortCuts(object):
|
class LOShortCuts(object):
|
||||||
"""Classe for manager shortcuts"""
|
"""Classe for manager shortcuts"""
|
||||||
KEYS = {getattr(Key, k): k for k in dir(Key)}
|
KEYS = {getattr(Key, k): k for k in dir(Key)}
|
||||||
|
@ -2690,6 +2729,47 @@ class LOMenus(object):
|
||||||
return LOMenuApp(index)
|
return LOMenuApp(index)
|
||||||
|
|
||||||
|
|
||||||
|
class LOEvents():
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
self._obj = obj
|
||||||
|
|
||||||
|
def __contains__(self, item):
|
||||||
|
return self.obj.hasByName(item)
|
||||||
|
|
||||||
|
def __getitem__(self, index):
|
||||||
|
"""Index access"""
|
||||||
|
return self.obj.getByName(index)
|
||||||
|
|
||||||
|
def __setitem__(self, name: str, macro: dict):
|
||||||
|
"""Set macro to event
|
||||||
|
|
||||||
|
:param name: Event name
|
||||||
|
:type name: str
|
||||||
|
:param macro: Macro execute in event
|
||||||
|
:type name: dict
|
||||||
|
"""
|
||||||
|
pv = '[]com.sun.star.beans.PropertyValue'
|
||||||
|
args = ()
|
||||||
|
if macro:
|
||||||
|
url = Macro.get_url_script(macro)
|
||||||
|
args = dict_to_property(dict(EventType='Script', Script=url))
|
||||||
|
uno.invoke(self.obj, 'replaceByName', (name, uno.Any(pv, args)))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def obj(self):
|
||||||
|
return self._obj
|
||||||
|
|
||||||
|
@property
|
||||||
|
def names(self):
|
||||||
|
return self.obj.ElementNames
|
||||||
|
|
||||||
|
def remove(self, name):
|
||||||
|
pv = '[]com.sun.star.beans.PropertyValue'
|
||||||
|
uno.invoke(self.obj, 'replaceByName', (name, uno.Any(pv, ())))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class LOMain():
|
class LOMain():
|
||||||
"""Classe for LibreOffice"""
|
"""Classe for LibreOffice"""
|
||||||
|
|
||||||
|
@ -3113,6 +3193,7 @@ class LODocCalc(LODocument):
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
super().__init__(obj)
|
super().__init__(obj)
|
||||||
self._sheets = obj.Sheets
|
self._sheets = obj.Sheets
|
||||||
|
self._listener_range_selection = None
|
||||||
|
|
||||||
def __getitem__(self, index):
|
def __getitem__(self, index):
|
||||||
"""Index access"""
|
"""Index access"""
|
||||||
|
@ -3162,6 +3243,10 @@ class LODocCalc(LODocument):
|
||||||
sheet = self._create_instance('com.sun.star.sheet.Spreadsheet')
|
sheet = self._create_instance('com.sun.star.sheet.Spreadsheet')
|
||||||
return sheet
|
return sheet
|
||||||
|
|
||||||
|
@property
|
||||||
|
def events(self):
|
||||||
|
return LOEvents(self.obj.Events)
|
||||||
|
|
||||||
def activate(self, sheet: Any):
|
def activate(self, sheet: Any):
|
||||||
"""Activate sheet
|
"""Activate sheet
|
||||||
|
|
||||||
|
@ -3279,6 +3364,28 @@ class LODocCalc(LODocument):
|
||||||
self.move(n, i)
|
self.move(n, i)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@run_in_thread
|
||||||
|
def start_range_selection(self, controllers: Any, args: dict={}):
|
||||||
|
"""Start select range selection by user
|
||||||
|
|
||||||
|
`See Api RangeSelectionArguments <https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1sheet_1_1RangeSelectionArguments.html>`_
|
||||||
|
"""
|
||||||
|
if not args:
|
||||||
|
args = dict(
|
||||||
|
Title = 'Please select a range',
|
||||||
|
CloseOnMouseRelease = True)
|
||||||
|
properties = dict_to_property(args)
|
||||||
|
|
||||||
|
self._listener_range_selection = EventsRangeSelectionListener(controllers(self))
|
||||||
|
self._cc.addRangeSelectionListener(self._listener_range_selection)
|
||||||
|
self._cc.startRangeSelection(properties)
|
||||||
|
return
|
||||||
|
|
||||||
|
def remove_range_selection_listener(self):
|
||||||
|
if not self._listener_range_selection is None:
|
||||||
|
self._cc.removeRangeSelectionListener(self._listener_range_selection)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class LOCalcSheet(object):
|
class LOCalcSheet(object):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue