Add support for tree control
This commit is contained in:
parent
8d55809aab
commit
e8dc0c8e99
|
@ -1,3 +1,7 @@
|
|||
v 0.10.0 [21-oct-2019]
|
||||
- Add suuport for tree control
|
||||
|
||||
|
||||
v 0.9.0 [19-oct-2019]
|
||||
- Add support for generate locales
|
||||
- Start support for forms
|
||||
|
|
|
@ -2416,7 +2416,7 @@ class UnoListBox(UnoBaseObject):
|
|||
|
||||
@property
|
||||
def value(self):
|
||||
return self.obj.SelectedItem
|
||||
return self.obj.getSelectedItem()
|
||||
|
||||
@property
|
||||
def count(self):
|
||||
|
@ -2430,6 +2430,10 @@ class UnoListBox(UnoBaseObject):
|
|||
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)
|
||||
|
@ -2438,7 +2442,7 @@ class UnoListBox(UnoBaseObject):
|
|||
return
|
||||
|
||||
def clear(self):
|
||||
self.obj.removeItems(0, self.count)
|
||||
self.model.removeAllItems()
|
||||
return
|
||||
|
||||
def _set_image_url(self, image):
|
||||
|
@ -2609,6 +2613,61 @@ class UnoRoadmap(UnoBaseObject):
|
|||
return
|
||||
|
||||
|
||||
class UnoTree(UnoBaseObject):
|
||||
|
||||
@catch_exception
|
||||
def __init__(self, obj, ):
|
||||
super().__init__(obj)
|
||||
self._tdm = None
|
||||
self._data = []
|
||||
|
||||
@property
|
||||
def selection(self):
|
||||
return self.obj.Selection
|
||||
|
||||
@property
|
||||
def root(self):
|
||||
if self._tdm is None:
|
||||
return ''
|
||||
return self._tdm.Root.DisplayValue
|
||||
|
||||
@root.setter
|
||||
def root(self, value):
|
||||
self._add_data_model(value)
|
||||
|
||||
def _add_data_model(self, name):
|
||||
tdm = create_instance('com.sun.star.awt.tree.MutableTreeDataModel')
|
||||
root = tdm.createNode(name, True)
|
||||
root.DataValue = 0
|
||||
tdm.setRoot(root)
|
||||
self.model.DataModel = tdm
|
||||
self._tdm = self.model.DataModel
|
||||
self._add_data()
|
||||
return
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
@data.setter
|
||||
def data(self, values):
|
||||
self._data = list(values)
|
||||
self._add_data()
|
||||
|
||||
def _add_data(self):
|
||||
if not self.data:
|
||||
return
|
||||
|
||||
parents = {}
|
||||
for node in self.data:
|
||||
parent = parents.get(node[1], self._tdm.Root)
|
||||
child = self._tdm.createNode(node[2], False)
|
||||
child.DataValue = node[0]
|
||||
parent.appendChild(child)
|
||||
parents[node[0]] = child
|
||||
self.obj.expandNode(self._tdm.Root)
|
||||
return
|
||||
|
||||
|
||||
def get_custom_class(tipo, obj):
|
||||
classes = {
|
||||
'label': UnoLabel,
|
||||
|
@ -2618,11 +2677,11 @@ def get_custom_class(tipo, obj):
|
|||
'grid': UnoGrid,
|
||||
'link': UnoLabelLink,
|
||||
'roadmap': UnoRoadmap,
|
||||
'tree': UnoTree,
|
||||
# ~ 'tab': UnoTab,
|
||||
# ~ 'image': UnoImage,
|
||||
# ~ 'radio': UnoRadio,
|
||||
# ~ 'groupbox': UnoGroupBox,
|
||||
# ~ 'tree': UnoTree,
|
||||
'formbutton': FormButton,
|
||||
}
|
||||
return classes[tipo](obj)
|
||||
|
@ -3144,11 +3203,11 @@ class LODialog(object):
|
|||
def _get_type_control(self, name):
|
||||
types = {
|
||||
'stardiv.Toolkit.UnoFixedTextControl': 'label',
|
||||
'stardiv.Toolkit.UnoButtonControl': 'button',
|
||||
'stardiv.Toolkit.UnoEditControl': 'text',
|
||||
'stardiv.Toolkit.UnoRoadmapControl': 'roadmap',
|
||||
'stardiv.Toolkit.UnoFixedHyperlinkControl': 'link',
|
||||
'stardiv.Toolkit.UnoEditControl': 'text',
|
||||
'stardiv.Toolkit.UnoButtonControl': 'button',
|
||||
'stardiv.Toolkit.UnoListBoxControl': 'listbox',
|
||||
'stardiv.Toolkit.UnoRoadmapControl': 'roadmap',
|
||||
}
|
||||
return types[name]
|
||||
|
||||
|
@ -3235,17 +3294,17 @@ class LODialog(object):
|
|||
|
||||
def _get_control_model(self, control):
|
||||
services = {
|
||||
'button': 'com.sun.star.awt.UnoControlButtonModel',
|
||||
'grid': 'com.sun.star.awt.grid.UnoControlGridModel',
|
||||
'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
||||
'image': 'com.sun.star.awt.UnoControlImageControlModel',
|
||||
'label': 'com.sun.star.awt.UnoControlFixedTextModel',
|
||||
'link': 'com.sun.star.awt.UnoControlFixedHyperlinkModel',
|
||||
'listbox': 'com.sun.star.awt.UnoControlListBoxModel',
|
||||
'radio': 'com.sun.star.awt.UnoControlRadioButtonModel',
|
||||
'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel',
|
||||
'text': 'com.sun.star.awt.UnoControlEditModel',
|
||||
'listbox': 'com.sun.star.awt.UnoControlListBoxModel',
|
||||
'button': 'com.sun.star.awt.UnoControlButtonModel',
|
||||
'roadmap': 'com.sun.star.awt.UnoControlRoadmapModel',
|
||||
'grid': 'com.sun.star.awt.grid.UnoControlGridModel',
|
||||
'tree': 'com.sun.star.awt.tree.TreeControlModel',
|
||||
'groupbox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
||||
'image': 'com.sun.star.awt.UnoControlImageControlModel',
|
||||
'radio': 'com.sun.star.awt.UnoControlRadioButtonModel',
|
||||
}
|
||||
return services[control]
|
||||
|
||||
|
@ -3285,6 +3344,8 @@ class LODialog(object):
|
|||
|
||||
def add_control(self, properties):
|
||||
tipo = properties.pop('Type').lower()
|
||||
root = properties.pop('Root', '')
|
||||
|
||||
properties = self._special_properties(tipo, properties)
|
||||
model = self.model.createInstance(self._get_control_model(tipo))
|
||||
set_properties(model, properties)
|
||||
|
@ -3293,6 +3354,10 @@ class LODialog(object):
|
|||
control = self.obj.getControl(name)
|
||||
add_listeners(self.events, control, name)
|
||||
control = get_custom_class(tipo, control)
|
||||
|
||||
if tipo == 'tree' and root:
|
||||
control.root = root
|
||||
|
||||
setattr(self, name, control)
|
||||
return
|
||||
|
||||
|
@ -3704,6 +3769,10 @@ def get_path_extension(id):
|
|||
return path
|
||||
|
||||
|
||||
def get_home():
|
||||
return Path.home()
|
||||
|
||||
|
||||
# ~ Export ok
|
||||
def inputbox(message, default='', title=TITLE, echochar=''):
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in New Issue