Add listbox control
This commit is contained in:
parent
dbf793c6db
commit
d22873f53b
159
source/diff.py
159
source/diff.py
|
@ -1218,96 +1218,11 @@ class UnoBaseObject(object):
|
||||||
self._model = self.obj.Model
|
self._model = self.obj.Model
|
||||||
self._rules = {}
|
self._rules = {}
|
||||||
|
|
||||||
@property
|
|
||||||
def obj(self):
|
|
||||||
return self._obj
|
|
||||||
|
|
||||||
@property
|
|
||||||
def model(self):
|
|
||||||
return self._model
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
return self.model.Name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
ps = self.obj.getContext().PosSize
|
ps = self.obj.getContext().PosSize
|
||||||
return self.obj.getContext()
|
return self.obj.getContext()
|
||||||
|
|
||||||
def _get_possize(self, name):
|
|
||||||
ps = self.obj.getPosSize()
|
|
||||||
return getattr(ps, name)
|
|
||||||
|
|
||||||
def _set_possize(self, name, value):
|
|
||||||
ps = self.obj.getPosSize()
|
|
||||||
setattr(ps, name, value)
|
|
||||||
self.obj.setPosSize(ps.X, ps.Y, ps.Width, ps.Height, POSSIZE)
|
|
||||||
return
|
|
||||||
|
|
||||||
@property
|
|
||||||
def x(self):
|
|
||||||
if hasattr(self.model, 'PositionX'):
|
|
||||||
return self.model.PositionX
|
|
||||||
return self._get_possize('X')
|
|
||||||
@x.setter
|
|
||||||
def x(self, value):
|
|
||||||
if hasattr(self.model, 'PositionX'):
|
|
||||||
self.model.PositionX = value
|
|
||||||
else:
|
|
||||||
self._set_possize('X', value)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def y(self):
|
|
||||||
if hasattr(self.model, 'PositionY'):
|
|
||||||
return self.model.PositionY
|
|
||||||
return self._get_possize('Y')
|
|
||||||
@y.setter
|
|
||||||
def y(self, value):
|
|
||||||
if hasattr(self.model, 'PositionY'):
|
|
||||||
self.model.PositionY = value
|
|
||||||
else:
|
|
||||||
self._set_possize('Y', value)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def width(self):
|
|
||||||
return self._model.Width
|
|
||||||
@width.setter
|
|
||||||
def width(self, value):
|
|
||||||
self.model.Width = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ps_width(self):
|
|
||||||
return self._get_possize('Width')
|
|
||||||
@ps_width.setter
|
|
||||||
def ps_width(self, value):
|
|
||||||
self._set_possize('Width', value)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def height(self):
|
|
||||||
return self.model.Height
|
|
||||||
@height.setter
|
|
||||||
def height(self, value):
|
|
||||||
self.model.Height = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ps_height(self):
|
|
||||||
return self._get_possize('Height')
|
|
||||||
@ps_height.setter
|
|
||||||
def ps_height(self, value):
|
|
||||||
self._set_possize('Height', value)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def size(self):
|
|
||||||
ps = self.obj.getPosSize()
|
|
||||||
return (ps.Width, ps.Height)
|
|
||||||
@size.setter
|
|
||||||
def size(self, value):
|
|
||||||
ps = self.obj.getPosSize()
|
|
||||||
ps.Width = value[0]
|
|
||||||
ps.Height = value[1]
|
|
||||||
self.obj.setPosSize(ps.X, ps.Y, ps.Width, ps.Height, SIZE)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tag(self):
|
def tag(self):
|
||||||
return self.model.Tag
|
return self.model.Tag
|
||||||
|
@ -1350,10 +1265,6 @@ class UnoBaseObject(object):
|
||||||
def rules(self, value):
|
def rules(self, value):
|
||||||
self._rules = value
|
self._rules = value
|
||||||
|
|
||||||
def set_focus(self):
|
|
||||||
self.obj.setFocus()
|
|
||||||
return
|
|
||||||
|
|
||||||
def center(self, horizontal=True, vertical=False):
|
def center(self, horizontal=True, vertical=False):
|
||||||
p = self.parent.Model
|
p = self.parent.Model
|
||||||
w = p.Width
|
w = p.Width
|
||||||
|
@ -1450,69 +1361,6 @@ class UnoText(UnoBaseObject):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
class UnoListBox(UnoBaseObject):
|
|
||||||
|
|
||||||
def __init__(self, obj):
|
|
||||||
super().__init__(obj)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def type(self):
|
|
||||||
return 'listbox'
|
|
||||||
|
|
||||||
@property
|
|
||||||
def value(self):
|
|
||||||
return self.obj.getSelectedItem()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def count(self):
|
|
||||||
return len(self.data)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def data(self):
|
|
||||||
return self.model.StringItemList
|
|
||||||
@data.setter
|
|
||||||
def data(self, values):
|
|
||||||
self.model.StringItemList = list(sorted(values))
|
|
||||||
return
|
|
||||||
|
|
||||||
def unselect(self):
|
|
||||||
self.obj.selectItem(self.value, False)
|
|
||||||
return
|
|
||||||
|
|
||||||
def select(self, pos=0):
|
|
||||||
if isinstance(pos, str):
|
|
||||||
self.obj.selectItem(pos, True)
|
|
||||||
else:
|
|
||||||
self.obj.selectItemPos(pos, True)
|
|
||||||
return
|
|
||||||
|
|
||||||
def clear(self):
|
|
||||||
self.model.removeAllItems()
|
|
||||||
return
|
|
||||||
|
|
||||||
def _set_image_url(self, image):
|
|
||||||
if exists_path(image):
|
|
||||||
return _path_url(image)
|
|
||||||
|
|
||||||
if not ID_EXTENSION:
|
|
||||||
return ''
|
|
||||||
|
|
||||||
path = get_path_extension(ID_EXTENSION)
|
|
||||||
path = join(path, DIR['images'], image)
|
|
||||||
return _path_url(path)
|
|
||||||
|
|
||||||
def insert(self, value, path='', pos=-1, show=True):
|
|
||||||
if pos < 0:
|
|
||||||
pos = self.count
|
|
||||||
if path:
|
|
||||||
self.model.insertItem(pos, value, self._set_image_url(path))
|
|
||||||
else:
|
|
||||||
self.model.insertItemText(pos, value)
|
|
||||||
if show:
|
|
||||||
self.select(pos)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
class UnoGrid(UnoBaseObject):
|
class UnoGrid(UnoBaseObject):
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
|
@ -2392,13 +2240,6 @@ class LODialog(object):
|
||||||
COLOR_ON_FOCUS = get_color(value)
|
COLOR_ON_FOCUS = get_color(value)
|
||||||
self._color_on_focus = COLOR_ON_FOCUS
|
self._color_on_focus = COLOR_ON_FOCUS
|
||||||
|
|
||||||
@property
|
|
||||||
def step(self):
|
|
||||||
return self.model.Step
|
|
||||||
@step.setter
|
|
||||||
def step(self, value):
|
|
||||||
self.model.Step = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def events(self):
|
def events(self):
|
||||||
return self._events
|
return self._events
|
||||||
|
|
|
@ -67,6 +67,7 @@ import unohelper
|
||||||
from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS
|
from com.sun.star.awt import MessageBoxButtons as MSG_BUTTONS
|
||||||
from com.sun.star.awt.MessageBoxResults import YES
|
from com.sun.star.awt.MessageBoxResults import YES
|
||||||
from com.sun.star.awt import Rectangle, Size, Point
|
from com.sun.star.awt import Rectangle, Size, Point
|
||||||
|
from com.sun.star.awt.PosSize import POSSIZE
|
||||||
from com.sun.star.awt import Key, KeyModifier, KeyEvent
|
from com.sun.star.awt import Key, KeyModifier, KeyEvent
|
||||||
from com.sun.star.container import NoSuchElementException
|
from com.sun.star.container import NoSuchElementException
|
||||||
from com.sun.star.datatransfer import XTransferable, DataFlavor
|
from com.sun.star.datatransfer import XTransferable, DataFlavor
|
||||||
|
@ -399,19 +400,6 @@ def _get_class_doc(obj: Any) -> Any:
|
||||||
return classes[type_doc](obj)
|
return classes[type_doc](obj)
|
||||||
|
|
||||||
|
|
||||||
# ~ def _get_class_uno(obj: Any) -> Any:
|
|
||||||
# ~ classes = dict(
|
|
||||||
# ~ SwXTextGraphicObject = LOImage,
|
|
||||||
# ~ SvxShapeText = LOImage,
|
|
||||||
# ~ )
|
|
||||||
# ~ name = obj.ImplementationName
|
|
||||||
# ~ print(f'ImplementationName = {name}')
|
|
||||||
# ~ instance = obj
|
|
||||||
# ~ if name in classes:
|
|
||||||
# ~ instance = classes[name](obj)
|
|
||||||
# ~ return instance
|
|
||||||
|
|
||||||
|
|
||||||
def dict_to_property(values: dict, uno_any: bool=False):
|
def dict_to_property(values: dict, uno_any: bool=False):
|
||||||
ps = tuple([PropertyValue(Name=n, Value=v) for n, v in values.items()])
|
ps = tuple([PropertyValue(Name=n, Value=v) for n, v in values.items()])
|
||||||
if uno_any:
|
if uno_any:
|
||||||
|
@ -429,6 +417,14 @@ def _property_to_dict(values):
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
def json_dumps(data):
|
||||||
|
return json.dumps(data, indent=4, sort_keys=True)
|
||||||
|
|
||||||
|
|
||||||
|
def json_loads(data):
|
||||||
|
return json.loads(data)
|
||||||
|
|
||||||
|
|
||||||
def data_to_dict(data):
|
def data_to_dict(data):
|
||||||
if isinstance(data, tuple) and isinstance(data[0], tuple):
|
if isinstance(data, tuple) and isinstance(data[0], tuple):
|
||||||
return _array_to_dict(data)
|
return _array_to_dict(data)
|
||||||
|
@ -438,12 +434,6 @@ def data_to_dict(data):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
def _path_url(path: str) -> str:
|
|
||||||
if path.startswith('file://'):
|
|
||||||
return path
|
|
||||||
return uno.systemPathToFileUrl(path)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_dispatch() -> Any:
|
def _get_dispatch() -> Any:
|
||||||
return create_instance('com.sun.star.frame.DispatchHelper')
|
return create_instance('com.sun.star.frame.DispatchHelper')
|
||||||
|
|
||||||
|
@ -1145,7 +1135,7 @@ class LODocument(object):
|
||||||
opt = dict_to_property(args)
|
opt = dict_to_property(args)
|
||||||
if path:
|
if path:
|
||||||
try:
|
try:
|
||||||
self.obj.storeAsURL(_path_url(path), opt)
|
self.obj.storeAsURL(_P.to_url(path), opt)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error(e)
|
error(e)
|
||||||
result = False
|
result = False
|
||||||
|
@ -2828,7 +2818,7 @@ class LODocs(object):
|
||||||
http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1frame_1_1XComponentLoader.html
|
http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1frame_1_1XComponentLoader.html
|
||||||
http://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1document_1_1MediaDescriptor.html
|
http://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1document_1_1MediaDescriptor.html
|
||||||
"""
|
"""
|
||||||
path = _path_url(path)
|
path = _P.to_url(path)
|
||||||
opt = dict_to_property(args)
|
opt = dict_to_property(args)
|
||||||
doc = cls._desktop.loadComponentFromURL(path, '_default', 0, opt)
|
doc = cls._desktop.loadComponentFromURL(path, '_default', 0, opt)
|
||||||
if doc is None:
|
if doc is None:
|
||||||
|
@ -2994,9 +2984,10 @@ class EventsFocus(EventsListenerBase, XFocusListener):
|
||||||
# ~ HelpURL = ?
|
# ~ HelpURL = ?
|
||||||
class UnoBaseObject(object):
|
class UnoBaseObject(object):
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj, path=''):
|
||||||
self._obj = obj
|
self._obj = obj
|
||||||
self._model = obj.Model
|
self._model = obj.Model
|
||||||
|
# ~ self._path = path
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
exists = hasattr(self, name)
|
exists = hasattr(self, name)
|
||||||
|
@ -3199,6 +3190,22 @@ class UnoBaseObject(object):
|
||||||
def tab_stop(self, value):
|
def tab_stop(self, value):
|
||||||
self.model.Tabstop = value
|
self.model.Tabstop = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ps(self):
|
||||||
|
ps = self.obj.getPosSize()
|
||||||
|
return ps
|
||||||
|
@ps.setter
|
||||||
|
def ps(self, ps):
|
||||||
|
self.obj.setPosSize(ps.X, ps.Y, ps.Width, ps.Height, POSSIZE)
|
||||||
|
|
||||||
|
def set_focus(self):
|
||||||
|
self.obj.setFocus()
|
||||||
|
return
|
||||||
|
|
||||||
|
def ps_from(self, source):
|
||||||
|
self.ps = source.ps
|
||||||
|
return
|
||||||
|
|
||||||
def center(self, horizontal=True, vertical=False):
|
def center(self, horizontal=True, vertical=False):
|
||||||
p = self.parent.Model
|
p = self.parent.Model
|
||||||
w = p.Width
|
w = p.Width
|
||||||
|
@ -3361,6 +3368,78 @@ class UnoImage(UnoBaseObject):
|
||||||
self.m.ImageURL = _P.to_url(value)
|
self.m.ImageURL = _P.to_url(value)
|
||||||
|
|
||||||
|
|
||||||
|
class UnoListBox(UnoBaseObject):
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
super().__init__(obj)
|
||||||
|
self._path = ''
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
if name in ('_path',):
|
||||||
|
self.__dict__[name] = value
|
||||||
|
else:
|
||||||
|
super().__setattr__(name, value)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def type(self):
|
||||||
|
return 'listbox'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self):
|
||||||
|
return self.obj.getSelectedItem()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def count(self):
|
||||||
|
return len(self.data)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def data(self):
|
||||||
|
return self.model.StringItemList
|
||||||
|
@data.setter
|
||||||
|
def data(self, values):
|
||||||
|
self.model.StringItemList = list(sorted(values))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def path(self):
|
||||||
|
return self._path
|
||||||
|
@path.setter
|
||||||
|
def path(self, value):
|
||||||
|
self._path = value
|
||||||
|
|
||||||
|
def unselect(self):
|
||||||
|
self.obj.selectItem(self.value, False)
|
||||||
|
return
|
||||||
|
|
||||||
|
def select(self, pos=0):
|
||||||
|
if isinstance(pos, str):
|
||||||
|
self.obj.selectItem(pos, True)
|
||||||
|
else:
|
||||||
|
self.obj.selectItemPos(pos, True)
|
||||||
|
return
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self.model.removeAllItems()
|
||||||
|
return
|
||||||
|
|
||||||
|
def _set_image_url(self, image):
|
||||||
|
if _P.exists(image):
|
||||||
|
return _P.to_url(image)
|
||||||
|
|
||||||
|
path = _P.join(self._path, DIR['images'], image)
|
||||||
|
return _P.to_url(path)
|
||||||
|
|
||||||
|
def insert(self, value, path='', pos=-1, show=True):
|
||||||
|
if pos < 0:
|
||||||
|
pos = self.count
|
||||||
|
if path:
|
||||||
|
self.model.insertItem(pos, value, self._set_image_url(path))
|
||||||
|
else:
|
||||||
|
self.model.insertItemText(pos, value)
|
||||||
|
if show:
|
||||||
|
self.select(pos)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
UNO_CLASSES = {
|
UNO_CLASSES = {
|
||||||
'label': UnoLabel,
|
'label': UnoLabel,
|
||||||
'link': UnoLabelLink,
|
'link': UnoLabelLink,
|
||||||
|
@ -3369,6 +3448,7 @@ UNO_CLASSES = {
|
||||||
'check': UnoCheck,
|
'check': UnoCheck,
|
||||||
'text': UnoText,
|
'text': UnoText,
|
||||||
'image': UnoImage,
|
'image': UnoImage,
|
||||||
|
'listbox': UnoListBox,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3382,9 +3462,9 @@ class LODialog(object):
|
||||||
'check': 'com.sun.star.awt.UnoControlCheckBoxModel',
|
'check': 'com.sun.star.awt.UnoControlCheckBoxModel',
|
||||||
'text': 'com.sun.star.awt.UnoControlEditModel',
|
'text': 'com.sun.star.awt.UnoControlEditModel',
|
||||||
'image': 'com.sun.star.awt.UnoControlImageControlModel',
|
'image': 'com.sun.star.awt.UnoControlImageControlModel',
|
||||||
|
'listbox': 'com.sun.star.awt.UnoControlListBoxModel',
|
||||||
# ~ 'grid': 'com.sun.star.awt.grid.UnoControlGridModel',
|
# ~ 'grid': 'com.sun.star.awt.grid.UnoControlGridModel',
|
||||||
# ~ 'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
# ~ 'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
||||||
# ~ 'listbox': 'com.sun.star.awt.UnoControlListBoxModel',
|
|
||||||
# ~ 'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel',
|
# ~ 'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel',
|
||||||
# ~ 'tree': 'com.sun.star.awt.tree.TreeControlModel',
|
# ~ 'tree': 'com.sun.star.awt.tree.TreeControlModel',
|
||||||
# ~ 'pages': 'com.sun.star.awt.UnoMultiPageModel',
|
# ~ 'pages': 'com.sun.star.awt.UnoMultiPageModel',
|
||||||
|
@ -3405,7 +3485,7 @@ class LODialog(object):
|
||||||
path = args.pop('Path', '')
|
path = args.pop('Path', '')
|
||||||
if path:
|
if path:
|
||||||
dp = create_instance(service, True)
|
dp = create_instance(service, True)
|
||||||
dlg = dp.createDialog(_path_url(path))
|
dlg = dp.createDialog(_P.to_url(path))
|
||||||
return dlg
|
return dlg
|
||||||
|
|
||||||
if 'Location' in args:
|
if 'Location' in args:
|
||||||
|
@ -3446,6 +3526,9 @@ class LODialog(object):
|
||||||
return self._controls
|
return self._controls
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
def path(self):
|
||||||
|
return self._path
|
||||||
|
@property
|
||||||
def id(self):
|
def id(self):
|
||||||
return self._id
|
return self._id
|
||||||
@id.setter
|
@id.setter
|
||||||
|
@ -3474,6 +3557,13 @@ class LODialog(object):
|
||||||
def visible(self, value):
|
def visible(self, value):
|
||||||
self.obj.Visible = value
|
self.obj.Visible = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def step(self):
|
||||||
|
return self.model.Step
|
||||||
|
@step.setter
|
||||||
|
def step(self, value):
|
||||||
|
self.model.Step = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def events(self):
|
def events(self):
|
||||||
return self._events
|
return self._events
|
||||||
|
@ -3539,6 +3629,8 @@ class LODialog(object):
|
||||||
control = self.obj.getControl(name)
|
control = self.obj.getControl(name)
|
||||||
_add_listeners(self.events, control, name)
|
_add_listeners(self.events, control, name)
|
||||||
control = UNO_CLASSES[tipo](control)
|
control = UNO_CLASSES[tipo](control)
|
||||||
|
if tipo in ('listbox',):
|
||||||
|
control.path = self.path
|
||||||
|
|
||||||
if tipo == 'tree' and root:
|
if tipo == 'tree' and root:
|
||||||
control.root = root
|
control.root = root
|
||||||
|
|
Loading…
Reference in New Issue