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]
|
v 0.9.0 [19-oct-2019]
|
||||||
- Add support for generate locales
|
- Add support for generate locales
|
||||||
- Start support for forms
|
- Start support for forms
|
||||||
|
|
|
@ -2416,7 +2416,7 @@ class UnoListBox(UnoBaseObject):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def value(self):
|
def value(self):
|
||||||
return self.obj.SelectedItem
|
return self.obj.getSelectedItem()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def count(self):
|
def count(self):
|
||||||
|
@ -2430,6 +2430,10 @@ class UnoListBox(UnoBaseObject):
|
||||||
self.model.StringItemList = list(sorted(values))
|
self.model.StringItemList = list(sorted(values))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def unselect(self):
|
||||||
|
self.obj.selectItem(self.value, False)
|
||||||
|
return
|
||||||
|
|
||||||
def select(self, pos=0):
|
def select(self, pos=0):
|
||||||
if isinstance(pos, str):
|
if isinstance(pos, str):
|
||||||
self.obj.selectItem(pos, True)
|
self.obj.selectItem(pos, True)
|
||||||
|
@ -2438,7 +2442,7 @@ class UnoListBox(UnoBaseObject):
|
||||||
return
|
return
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.obj.removeItems(0, self.count)
|
self.model.removeAllItems()
|
||||||
return
|
return
|
||||||
|
|
||||||
def _set_image_url(self, image):
|
def _set_image_url(self, image):
|
||||||
|
@ -2609,6 +2613,61 @@ class UnoRoadmap(UnoBaseObject):
|
||||||
return
|
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):
|
def get_custom_class(tipo, obj):
|
||||||
classes = {
|
classes = {
|
||||||
'label': UnoLabel,
|
'label': UnoLabel,
|
||||||
|
@ -2618,11 +2677,11 @@ def get_custom_class(tipo, obj):
|
||||||
'grid': UnoGrid,
|
'grid': UnoGrid,
|
||||||
'link': UnoLabelLink,
|
'link': UnoLabelLink,
|
||||||
'roadmap': UnoRoadmap,
|
'roadmap': UnoRoadmap,
|
||||||
|
'tree': UnoTree,
|
||||||
# ~ 'tab': UnoTab,
|
# ~ 'tab': UnoTab,
|
||||||
# ~ 'image': UnoImage,
|
# ~ 'image': UnoImage,
|
||||||
# ~ 'radio': UnoRadio,
|
# ~ 'radio': UnoRadio,
|
||||||
# ~ 'groupbox': UnoGroupBox,
|
# ~ 'groupbox': UnoGroupBox,
|
||||||
# ~ 'tree': UnoTree,
|
|
||||||
'formbutton': FormButton,
|
'formbutton': FormButton,
|
||||||
}
|
}
|
||||||
return classes[tipo](obj)
|
return classes[tipo](obj)
|
||||||
|
@ -3144,11 +3203,11 @@ class LODialog(object):
|
||||||
def _get_type_control(self, name):
|
def _get_type_control(self, name):
|
||||||
types = {
|
types = {
|
||||||
'stardiv.Toolkit.UnoFixedTextControl': 'label',
|
'stardiv.Toolkit.UnoFixedTextControl': 'label',
|
||||||
'stardiv.Toolkit.UnoButtonControl': 'button',
|
|
||||||
'stardiv.Toolkit.UnoEditControl': 'text',
|
|
||||||
'stardiv.Toolkit.UnoRoadmapControl': 'roadmap',
|
|
||||||
'stardiv.Toolkit.UnoFixedHyperlinkControl': 'link',
|
'stardiv.Toolkit.UnoFixedHyperlinkControl': 'link',
|
||||||
|
'stardiv.Toolkit.UnoEditControl': 'text',
|
||||||
|
'stardiv.Toolkit.UnoButtonControl': 'button',
|
||||||
'stardiv.Toolkit.UnoListBoxControl': 'listbox',
|
'stardiv.Toolkit.UnoListBoxControl': 'listbox',
|
||||||
|
'stardiv.Toolkit.UnoRoadmapControl': 'roadmap',
|
||||||
}
|
}
|
||||||
return types[name]
|
return types[name]
|
||||||
|
|
||||||
|
@ -3235,17 +3294,17 @@ class LODialog(object):
|
||||||
|
|
||||||
def _get_control_model(self, control):
|
def _get_control_model(self, control):
|
||||||
services = {
|
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',
|
'label': 'com.sun.star.awt.UnoControlFixedTextModel',
|
||||||
'link': 'com.sun.star.awt.UnoControlFixedHyperlinkModel',
|
'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',
|
'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',
|
'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]
|
return services[control]
|
||||||
|
|
||||||
|
@ -3285,6 +3344,8 @@ class LODialog(object):
|
||||||
|
|
||||||
def add_control(self, properties):
|
def add_control(self, properties):
|
||||||
tipo = properties.pop('Type').lower()
|
tipo = properties.pop('Type').lower()
|
||||||
|
root = properties.pop('Root', '')
|
||||||
|
|
||||||
properties = self._special_properties(tipo, properties)
|
properties = self._special_properties(tipo, properties)
|
||||||
model = self.model.createInstance(self._get_control_model(tipo))
|
model = self.model.createInstance(self._get_control_model(tipo))
|
||||||
set_properties(model, properties)
|
set_properties(model, properties)
|
||||||
|
@ -3293,6 +3354,10 @@ 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 = get_custom_class(tipo, control)
|
control = get_custom_class(tipo, control)
|
||||||
|
|
||||||
|
if tipo == 'tree' and root:
|
||||||
|
control.root = root
|
||||||
|
|
||||||
setattr(self, name, control)
|
setattr(self, name, control)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -3704,6 +3769,10 @@ def get_path_extension(id):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def get_home():
|
||||||
|
return Path.home()
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
# ~ Export ok
|
||||||
def inputbox(message, default='', title=TITLE, echochar=''):
|
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