diff --git a/docs/source/application.rst b/docs/source/application.rst index a80764d..8d4388a 100644 --- a/docs/source/application.rst +++ b/docs/source/application.rst @@ -158,6 +158,12 @@ Set value Caution with modify registry, not all nodes we can change. +Some nodes and keys: + +* `/org.openoffice.Office.Common/Save/Document` + * AutoSave + * AutoSaveTimeIntervall + Shortcuts --------- diff --git a/docs/source/calc_doc.rst b/docs/source/calc_doc.rst index d710a46..856ab63 100644 --- a/docs/source/calc_doc.rst +++ b/docs/source/calc_doc.rst @@ -1,4 +1,3 @@ - Active document --------------- diff --git a/docs/source/tools.rst b/docs/source/tools.rst index 69eb486..46acba5 100644 --- a/docs/source/tools.rst +++ b/docs/source/tools.rst @@ -422,7 +422,7 @@ You can execute any macro, for default call macros Python. 'library': 'test', 'name': 'show_message', } - app.call_macro(args) + app.macro.call(args) return Of course is better call directly if both macros are the same languaje, but, you can call macro in Basic too. diff --git a/docs/source/tools_debug.rst b/docs/source/tools_debug.rst index 4886ee1..353cc98 100644 --- a/docs/source/tools_debug.rst +++ b/docs/source/tools_debug.rst @@ -185,5 +185,32 @@ install before call it. .. image:: _static/images/toolsdebug_07.png +Inspect +------- + +Show info in shell debug + +.. code-block:: python + + import easymacro as app + + def inspect(): + obj = app.active + data = app.inspect(doc) + for p in data.properties: + app.debug(p) + for m in data.methods: + app.debug(m) + return + + +Or show in new Calc document. + +.. code-block:: python + + obj = app.active + app.inspect(doc, True) + + .. _MRI: https://github.com/hanya/MRI .. _open issue: https://git.cuates.net/elmau/easymacro/issues diff --git a/source/easymacro.py b/source/easymacro.py index 25f941a..c58bdd7 100644 --- a/source/easymacro.py +++ b/source/easymacro.py @@ -475,24 +475,65 @@ def render(template, data): # Classes class LOInspect(): + """Classe inspect + + Inspired by `MRI `_ + """ TYPE_CLASSES = { 'INTERFACE': '-Interface-', 'SEQUENCE': '-Sequence-', 'STRUCT': '-Struct-', } - introspection = create_instance('com.sun.star.beans.Introspection') def __init__(self, obj: Any, to_doc: bool=False): - if hasattr(obj, 'obj'): - obj = obj.obj + """Introspection objects pyUno + + :param obj: Object to inspect + :type obj: Any pyUno + :param to_doc: If show info in new doc Calc + :type to_doc: bool + """ self._obj = obj - self._result = self.introspection.inspect(obj) - self._properties = self._get_properties() - if to_doc: - doc = LODocuments.new() - sheet = doc[0] - sheet.name = 'Properties' - sheet['A1'].data = self.properties + if hasattr(obj, 'obj'): + self._obj = obj.obj + self._properties = () + self._methods = () + self._interfaces = () + self._services = () + self._listeners = () + + introspection = create_instance('com.sun.star.beans.Introspection') + result = introspection.inspect(self._obj) + if result: + self._properties = self._get_properties(result) + self._methods = self._get_methods(result) + self._interfaces = self._get_interfaces(result) + self._services = self._get_services(self._obj) + self._listeners = self._get_listeners(result) + self._to_doc(to_doc) + + def _to_doc(self, to_doc: bool): + if not to_doc: + return + + doc = LODocuments().new() + sheet = doc[0] + sheet.name = 'Properties' + sheet['A1'].data = self.properties + + sheet = doc.insert('Methods') + sheet['A1'].data = self.methods + + sheet = doc.insert('Interfaces') + sheet['A1'].data = self.interfaces + + sheet = doc.insert('Services') + sheet['A1'].data = self.services + + sheet = doc.insert('Listeners') + sheet['A1'].data = self.listeners + + return def _get_value(self, p: Any): type_class = p.Type.typeClass.value @@ -511,7 +552,7 @@ class LOInspect(): except: value = '-error-' - return value + return str(value) def _get_attributes(self, a: Any): PA = {1 : 'Maybe Void', 16 : 'Read Only'} @@ -525,19 +566,71 @@ class LOInspect(): attr = self._get_attributes(p.Attributes) return name, tipo, value, attr - def _get_properties(self): - if self._result is None: - return [] - - properties = self._result.getProperties(ALL) + def _get_properties(self, result: Any): + properties = result.getProperties(ALL) data = [('Name', 'Type', 'Value', 'Attributes')] data += [self._get_property(p) for p in properties] return data + def _get_arguments(self, m: Any): + arguments = '( {} )'.format(', '.join( + [' '.join(( + f'[{p.aMode.value.lower()}]', + p.aName, + p.aType.Name)) for p in m.ParameterInfos] + )) + return arguments + + def _get_method(self, m: Any): + name = m.Name + arguments = self._get_arguments(m) + return_type = m.ReturnType.Name + class_name = m.DeclaringClass.Name + return name, arguments, return_type, class_name + + def _get_methods(self, result: Any): + methods = result.getMethods(ALL) + data = [('Name', 'Arguments', 'Return Type', 'Class')] + data += [self._get_method(m) for m in methods] + return data + + def _get_interfaces(self, result: Any): + methods = result.getMethods(ALL) + interfaces = {m.DeclaringClass.Name for m in methods} + return tuple(zip(interfaces)) + + def _get_services(self, obj: Any): + try: + data = [str(s) for s in obj.getSupportedServiceNames()] + data = tuple(zip(data)) + except: + data = () + return data + + def _get_listeners(self, result: Any): + data = [l.typeName for l in result.getSupportedListeners()] + return tuple(zip(data)) + @property def properties(self): return self._properties + @property + def methods(self): + return self._methods + + @property + def interfaces(self): + return self._interfaces + + @property + def services(self): + return self._services + + @property + def listeners(self): + return self._listeners + # ~ https://github.com/django/django/blob/main/django/utils/functional.py#L61 class classproperty: @@ -746,6 +839,7 @@ class Macro(object): url = 'vnd.sun.star.script' url = f'{url}:{library}{module}{name}?language={language}&location={location}' + debug(url) return url @classmethod @@ -3059,6 +3153,21 @@ class LODocCalc(LODocument): """Get active sheet""" return LOCalcSheet(self._cc.ActiveSheet) + def insert(self, name: Union[str, list, tuple]): + """Insert new sheet + + :param name: Name new sheet, or iterable with names. + :type name: str, list or tuple + :return: New instance sheet. + :rtype: LOCalcSheet + """ + names = name + if isinstance(name, str): + names = (name,) + for n in names: + self._sheets[n] = self._create_instance('com.sun.star.sheet.Spreadsheet') + return LOCalcSheet(self._sheets[n]) + class LOCalcSheet(object): @@ -3108,9 +3217,40 @@ class LOCalcSheet(object): class LOCalcRange(object): + CELL = 'ScCellObj' def __init__(self, obj): self._obj = obj + self._is_cell = obj.ImplementationName == self.CELL + + @property + def obj(self): + return self._obj + + @property + def data(self): + return self.obj.getDataArray() + @data.setter + def data(self, values): + if self._is_cell: + self.to_size(len(values[0]), len(values)).data = values + else: + self.obj.setDataArray(values) + + @property + def sheet(self): + return LOCalcSheet(self.obj.Spreadsheet) + + @property + def cursor(self): + cursor = self.obj.Spreadsheet.createCursorByRange(self.obj) + return cursor + + def to_size(self, cols: int, rows: int): + cursor = self.cursor + cursor.collapseToSize(cols, rows) + rango = self.obj.Spreadsheet[cursor.AbsoluteName] + return LOCalcRange(rango) class LODocWriter(LODocument):