diff --git a/CHANGELOG b/CHANGELOG index f1ec520..c8aae2b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,6 @@ -v 0.1.0 [07-jul-2021] - - Initial version +# Lista de cambios + +v 0.1.0 [15-jul-2021] + - Versión inicial + - Importa txt de pólizas + - Genera txt de pólizas diff --git a/README.md b/README.md index 5cedc78..aa89164 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,25 @@ -# zaz-polizas +# zaz-compaqi -Importa y exporta polizas en TXT para el sistema contable Conpaq \ No newline at end of file +Importa y exporta diversos archivos TXT para el sistema contable Compaqi + + +## Software libre, no software "gratis" + + +En orden de preferencia + +Mauricio Baeza +``` +Euros +IBAN: BE60 9671 0556 5870 +SWIFT / BIC: TRWIBEB1XXX +``` + +* BCH: `qztd3l00xle5tffdqvh2snvadkuau2ml0uqm4n875d` +* FairCoin: `fJ7emvtyGfvcMuxk1nHSnS7gmeScdcZXL5` +* Monero: `43H43TpQKYdYcw2ZCnn2nbjDh3imNQg8RGYS4oP4p7Z8aeBHg6VpeaFfBoMzDTUUDdQBiGkiQUSydJB96m6MqiEuEeyoopQ` + +* ETH: `0x61a4f614a30ff686445751ed8328b82b77ecfc69` +* XRP: `rLSn6Z3T8uCxbcd1oxwfGQN1Fdn5CyGujK` Tag: `6643162` +* LTC: `MBcgQ3LQJA4W2wsXknTdm2fxRSysLaBJHS` +* BTC: `3FhiXcXmAesmQzrNEngjHFnvaJRhU1AGWV` diff --git a/conf.py b/conf.py index a5ccce5..7527f7d 100644 --- a/conf.py +++ b/conf.py @@ -26,14 +26,14 @@ import logging TYPE_EXTENSION = 1 # ~ Your great extension name, not used spaces -NAME = 'ZAZPolizas' +NAME = 'ZAZCompaqi' # ~ https://semver.org/ VERSION = '0.1.0' # ~ Should be unique, used URL inverse -ID = 'net.elmau.zaz.polizas' +ID = 'net.elmau.zaz.compaqi' # ~ If you extension will be multilanguage set: True # ~ This feature used gettext, set pythonpath and easymacro in True @@ -48,9 +48,10 @@ PATH_MSGMERGE = 'msgmerge' # ~ Show in extension manager +URL_GIT = 'https://git.cuates.net/elmau/zaz-compaqi' PUBLISHER = { - 'en': {'text': 'El Mau', 'link': 'https://gitlab.com/mauriciobaeza'}, - 'es': {'text': 'El Mau', 'link': 'https://gitlab.com/mauriciobaeza'}, + 'en': {'text': 'El Mau', 'link': URL_GIT}, + 'es': {'text': 'El Mau', 'link': URL_GIT}, } # ~ Name in this folder for copy @@ -79,13 +80,13 @@ LICENSE_ES = LICENSE_EN INFO = { 'en': { - 'display_name': 'ZAZ Polizas', - 'description': 'Process polizas from txt', + 'display_name': 'ZAZ Compaqi', + 'description': 'Import and export txt files from Compaqi', 'license': LICENSE_EN, }, 'es': { - 'display_name': 'ZAZ Polizas', - 'description': 'Procesa pólizas desde un archivo txt', + 'display_name': 'ZAZ Compaqi', + 'description': 'Importa y exporta archivos txt para Compaqi', 'license': LICENSE_ES, }, } @@ -104,21 +105,21 @@ INFO = { # ~ For example: Shift+Ctrl+Alt+T -> T_SHIFT_MOD1_MOD2 PARENT = 'OfficeMenuBar' MENU_MAIN = { - 'en': 'Polizas', - 'es': 'Polizas', + 'en': 'Compaqi', + 'es': 'Compaqi', } MENUS = ( { - 'title': {'en': 'Process...', 'es': 'Procesar...'}, - 'argument': 'procesar', + 'title': {'en': 'Import TXT Polizas', 'es': 'Importar TXT de Pólizas'}, + 'argument': 'import_polizas', 'context': 'calc', 'icon': 'icon', 'toolbar': False, 'shortcut': 'P_SHIFT_MOD1_MOD2', }, { - 'title': {'en': 'Generate TXT...', 'es': 'Generar TXT...'}, - 'argument': 'generar', + 'title': {'en': 'Generate TXT Polizas...', 'es': 'Generar TXT de Pólizas...'}, + 'argument': 'export_polizas', 'context': 'calc', 'icon': 'icon', 'toolbar': False, diff --git a/easymacro.py b/easymacro.py index 27ca1aa..246e2f5 100644 --- a/easymacro.py +++ b/easymacro.py @@ -83,7 +83,6 @@ from com.sun.star.table.CellContentType import EMPTY, VALUE, TEXT, FORMULA from com.sun.star.util import Time, Date, DateTime from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK -from com.sun.star.text.TextContentAnchorType import AS_CHARACTER from com.sun.star.lang import Locale from com.sun.star.lang import XEventListener @@ -165,13 +164,23 @@ OBJ_RANGE = 'ScCellRangeObj' OBJ_RANGES = 'ScCellRangesObj' TYPE_RANGES = (OBJ_CELL, OBJ_RANGE) -OBJ_SHAPES = 'com.sun.star.drawing.SvxShapeCollection' OBJ_SHAPE = 'com.sun.star.comp.sc.ScShapeObj' +OBJ_SHAPES = 'com.sun.star.drawing.SvxShapeCollection' OBJ_GRAPHIC = 'SwXTextGraphicObject' OBJ_TEXTS = 'SwXTextRanges' OBJ_TEXT = 'SwXTextRange' +CLSID = { + 'FORMULA': '078B7ABA-54FC-457F-8551-6147e776a997', +} + +SERVICES = { + 'TEXT_EMBEDDED': 'com.sun.star.text.TextEmbeddedObject', + 'TEXT_TABLE': 'com.sun.star.text.TextTable', + 'GRAPHIC': 'com.sun.star.text.GraphicObject', +} + # ~ from com.sun.star.sheet.FilterOperator import EMPTY, NO_EMPTY, EQUAL, NOT_EQUAL class FilterOperator(IntEnum): @@ -225,6 +234,17 @@ class CellDeleteMode(): CDM = CellDeleteMode +class FormButtonType(): + from com.sun.star.form.FormButtonType import PUSH, SUBMIT, RESET, URL +FBT = FormButtonType + + +class TextContentAnchorType(): + from com.sun.star.text.TextContentAnchorType \ + import AT_PARAGRAPH, AS_CHARACTER, AT_PAGE, AT_FRAME, AT_CHARACTER +TCAT = TextContentAnchorType + + OS = platform.system() IS_WIN = OS == 'Windows' IS_MAC = OS == 'Darwin' @@ -710,7 +730,8 @@ def sha512(data): def get_config(key='', prefix='conf', default={}): name_file = FILE_NAME_CONFIG.format(prefix) values = None - path = _P.join(_P.config('UserConfig'), name_file) + # ~ path = _P.join(_P.config('UserConfig'), name_file) + path = _P.join(_P.user_config, name_file) if not _P.exists(path): return default @@ -723,7 +744,8 @@ def get_config(key='', prefix='conf', default={}): def set_config(key, value, prefix='conf'): name_file = FILE_NAME_CONFIG.format(prefix) - path = _P.join(_P.config('UserConfig'), name_file) + # ~ path = _P.join(_P.config('UserConfig'), name_file) + path = _P.join(_P.user_config, name_file) values = get_config(default={}, prefix=prefix) values[key] = value result = _P.to_json(path, values) @@ -1469,7 +1491,7 @@ class LOCalc(LODocument): self._sheets.removeByName(name) return - def copy(self, name, new_name='', pos=-1): + def copy_sheet(self, name, new_name='', pos=-1): if isinstance(name, LOCalcSheet): name = name.name index = pos @@ -1750,7 +1772,8 @@ class LOSheetTables(object): return -class LOFormControl(LOBaseObject): +# ~ class LOFormControl(LOBaseObject): +class LOFormControl(): EVENTS = { 'action': 'actionPerformed', 'click': 'mousePressed', @@ -1761,21 +1784,25 @@ class LOFormControl(LOBaseObject): } def __init__(self, obj, view, form): - super().__init__(obj) + self._obj = obj self._view = view self._form = form self._m = view.Model self._index = -1 - def __setattr__(self, name, value): - if name in ('_form', '_view', '_m', '_index'): - self.__dict__[name] = value - else: - super().__setattr__(name, value) + # ~ def __setattr__(self, name, value): + # ~ if name in ('_form', '_view', '_m', '_index'): + # ~ self.__dict__[name] = value + # ~ else: + # ~ super().__setattr__(name, value) def __str__(self): return f'{self.name} ({self.type}) {[self.index]}' + @property + def obj(self): + return self._obj + @property def form(self): return self._form @@ -1812,6 +1839,30 @@ class LOFormControl(LOBaseObject): def enabled(self, value): self._m.Enabled = value + @property + def anchor(self): + return self.obj.Anchor + @anchor.setter + def anchor(self, value): + size = None + if hasattr(value, 'obj'): + size = getattr(value, 'size', None) + value = value.obj + self.obj.Anchor = value + if not size is None: + self.size = size + try: + self.obj.ResizeWithCell = True + except: + pass + + @property + def size(self): + return self.obj.Size + @size.setter + def size(self, value): + self.obj.Size = value + @property def events(self): return self.form.getScriptEvents(self.index) @@ -1891,6 +1942,14 @@ class LOFormControlButton(LOFormControl): def value(self, value): self._m.Text = Label + @property + def url(self): + return self._m.TargetURL + @url.setter + def url(self, value): + self._m.TargetURL = value + self._m.ButtonType = FormButtonType.URL + FORM_CONTROL_CLASS = { 'label': LOFormControlLabel, @@ -1941,7 +2000,7 @@ class LOForm(object): name = control.Name tipo = types[control.ImplementationName] view = self.doc.CurrentController.getControl(control) - control = FORM_CONTROL_CLASS[tipo](control, view) + control = FORM_CONTROL_CLASS[tipo](control, view, self._obj) control.index = i setattr(self, name, control) self._controls[name] = control @@ -1994,8 +2053,8 @@ class LOForm(object): def add(self, args): name = args['Name'] tipo = args.pop('Type').lower() - w = args.pop('Width') - h = args.pop('Height') + w = args.pop('Width', 1000) + h = args.pop('Height', 200) x = args.pop('X', 0) y = args.pop('Y', 0) control = self.doc.createInstance('com.sun.star.drawing.ControlShape') @@ -2053,7 +2112,9 @@ class LOSheetForms(object): def names(self): return self.obj.ElementNames - def insert(self, name): + def insert(self, name=''): + if not name: + name = f'form{self.count + 1}' form = self.doc.createInstance('com.sun.star.form.component.Form') self.obj.insertByName(name, form) return LOForm(form, self._dp) @@ -2624,8 +2685,8 @@ class LOCalcRange(object): def visible(self): cursor = self.cursor rangos = cursor.queryVisibleCells() - rangos = [LOCalcRange(self.sheet[r.AbsoluteName].obj) for r in rangos] - return tuple(rangos) + rangos = LOCalcRanges(rangos) + return rangos @property def merged_area(self): @@ -3001,6 +3062,10 @@ class LOCalcRanges(object): self._obj = obj self._ranges = {} self._index = 0 + for r in obj: + sheet = r.Spreadsheet + rango = LOCalcRange(sheet[r.AbsoluteName]) + self._ranges[rango.name] = rango def __enter__(self): return self @@ -3252,6 +3317,17 @@ class LOWriterTextRange(object): self.text.insertTextContent(cursor, data, replace) return + def insert_math(self, formula, + anchor_type=TextContentAnchorType.AS_CHARACTER, + cursor=None, replace=False): + + math = self._doc.create_instance(SERVICES['TEXT_EMBEDDED']) + math.CLSID = CLSID['FORMULA'] + math.AnchorType = anchor_type + self.insert_content(math, cursor, replace) + math.EmbeddedObject.Component.Formula = formula + return math + def new_line(self, count=1): cursor = self.cursor for i in range(count): @@ -3259,7 +3335,7 @@ class LOWriterTextRange(object): return self._doc.selection def insert_table(self, data): - table = self._doc.create_instance('com.sun.star.text.TextTable') + table = self._doc.create_instance(SERVICES['TEXT_TABLE']) rows = len(data) cols = len(data[0]) table.initialize(rows, cols) @@ -3272,9 +3348,10 @@ class LOWriterTextRange(object): def insert_image(self, path, args={}): w = args.get('Width', 1000) h = args.get('Height', 1000) - image = self._doc.create_instance('com.sun.star.text.GraphicObject') + + image = self._doc.create_instance(SERVICES['GRAPHIC']) image.GraphicURL = _P.to_url(path) - image.AnchorType = AS_CHARACTER + image.AnchorType = TextContentAnchorType.AS_CHARACTER image.Width = w image.Height = h self.insert_content(image) @@ -6470,6 +6547,17 @@ class Paths(object): path = sys.executable return path + @classproperty + def user_profile(self): + path = self.config('UserConfig') + path = str(Path(path).parent) + return path + + @classproperty + def user_config(self): + path = self.config('UserConfig') + return path + @classmethod def dir_tmp(self, only_name=False): dt = tempfile.TemporaryDirectory() @@ -6619,8 +6707,12 @@ class Paths(object): return result @classmethod - def read(cls, path, encoding='utf-8'): - data = Path(path).read_text(encoding=encoding) + def read(cls, path, get_lines=False, encoding='utf-8'): + if get_lines: + with Path(path).open(encoding=encoding) as f: + data = f.readlines() + else: + data = Path(path).read_text(encoding=encoding) return data @classmethod diff --git a/files/Plantilla_Compaqi.ods b/files/Plantilla_Compaqi.ods new file mode 100644 index 0000000..ae539f0 Binary files /dev/null and b/files/Plantilla_Compaqi.ods differ diff --git a/files/ZAZCompaqi_v0.1.0.oxt b/files/ZAZCompaqi_v0.1.0.oxt new file mode 100644 index 0000000..2dfab87 Binary files /dev/null and b/files/ZAZCompaqi_v0.1.0.oxt differ diff --git a/files/ZAZPolizas_v0.1.0.oxt b/files/ZAZPolizas_v0.1.0.oxt deleted file mode 100644 index 0f1b1a6..0000000 Binary files a/files/ZAZPolizas_v0.1.0.oxt and /dev/null differ diff --git a/images/logo.png b/images/logo.png index 37d9be2..4e0d53f 100644 Binary files a/images/logo.png and b/images/logo.png differ diff --git a/source/Addons.xcu b/source/Addons.xcu index 6adfc56..c5ecd9d 100644 --- a/source/Addons.xcu +++ b/source/Addons.xcu @@ -2,10 +2,10 @@ - + - Polizas - Polizas + Compaqi + Compaqi _self @@ -13,14 +13,14 @@ - Process... - Procesar... + Import TXT Polizas + Importar TXT de Pólizas com.sun.star.sheet.SpreadsheetDocument - service:net.elmau.zaz.polizas?procesar + service:net.elmau.zaz.compaqi?import_polizas _self @@ -31,14 +31,14 @@ - Generate TXT... - Generar TXT... + Generate TXT Polizas... + Generar TXT de Pólizas... com.sun.star.sheet.SpreadsheetDocument - service:net.elmau.zaz.polizas?generar + service:net.elmau.zaz.compaqi?export_polizas _self diff --git a/source/META-INF/manifest.xml b/source/META-INF/manifest.xml index 5db3ab0..347620d 100644 --- a/source/META-INF/manifest.xml +++ b/source/META-INF/manifest.xml @@ -1,6 +1,6 @@ - + diff --git a/source/Office/Accelerators.xcu b/source/Office/Accelerators.xcu index 1c89221..f6057ec 100644 --- a/source/Office/Accelerators.xcu +++ b/source/Office/Accelerators.xcu @@ -5,14 +5,14 @@ - service:net.elmau.zaz.polizas?procesar + service:net.elmau.zaz.compaqi?import_polizas - service:net.elmau.zaz.polizas?generar + service:net.elmau.zaz.compaqi?export_polizas diff --git a/source/ZAZPolizas.py b/source/ZAZCompaqi.py similarity index 62% rename from source/ZAZPolizas.py rename to source/ZAZCompaqi.py index 9f3c254..e59964c 100644 --- a/source/ZAZPolizas.py +++ b/source/ZAZCompaqi.py @@ -1,13 +1,14 @@ import uno import unohelper from com.sun.star.task import XJobExecutor -from main import main +from zcompaqi import main -ID_EXTENSION = 'net.elmau.zaz.polizas' + +ID_EXTENSION = 'net.elmau.zaz.compaqi' SERVICE = ('com.sun.star.task.Job',) -class ZAZPolizas(unohelper.Base, XJobExecutor): +class ZAZCompaqi(unohelper.Base, XJobExecutor): def __init__(self, ctx): self.ctx = ctx @@ -18,4 +19,4 @@ class ZAZPolizas(unohelper.Base, XJobExecutor): g_ImplementationHelper = unohelper.ImplementationHelper() -g_ImplementationHelper.addImplementation(ZAZPolizas, ID_EXTENSION, SERVICE) +g_ImplementationHelper.addImplementation(ZAZCompaqi, ID_EXTENSION, SERVICE) diff --git a/source/description.xml b/source/description.xml index db1e795..cd5facd 100644 --- a/source/description.xml +++ b/source/description.xml @@ -1,21 +1,21 @@ - + - ZAZ Polizas - ZAZ Polizas + ZAZ Compaqi + ZAZ Compaqi - + - El Mau - El Mau + El Mau + El Mau diff --git a/source/description/desc_en.txt b/source/description/desc_en.txt index 86aecee..baf5e0f 100644 --- a/source/description/desc_en.txt +++ b/source/description/desc_en.txt @@ -1 +1 @@ -Process polizas from txt \ No newline at end of file +Import and export txt files from Compaqi \ No newline at end of file diff --git a/source/description/desc_es.txt b/source/description/desc_es.txt index 25a4035..cff6fba 100644 --- a/source/description/desc_es.txt +++ b/source/description/desc_es.txt @@ -1 +1 @@ -Procesa pólizas desde un archivo txt \ No newline at end of file +Importa y exporta archivos txt para Compaqi \ No newline at end of file diff --git a/source/images/zazcompaqi.png b/source/images/zazcompaqi.png new file mode 100644 index 0000000..4e0d53f Binary files /dev/null and b/source/images/zazcompaqi.png differ diff --git a/source/images/zazpolizas.png b/source/images/zazpolizas.png deleted file mode 100644 index 37d9be2..0000000 Binary files a/source/images/zazpolizas.png and /dev/null differ diff --git a/source/pythonpath/easymacro.py b/source/pythonpath/easymacro.py index 27ca1aa..246e2f5 100644 --- a/source/pythonpath/easymacro.py +++ b/source/pythonpath/easymacro.py @@ -83,7 +83,6 @@ from com.sun.star.table.CellContentType import EMPTY, VALUE, TEXT, FORMULA from com.sun.star.util import Time, Date, DateTime from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK -from com.sun.star.text.TextContentAnchorType import AS_CHARACTER from com.sun.star.lang import Locale from com.sun.star.lang import XEventListener @@ -165,13 +164,23 @@ OBJ_RANGE = 'ScCellRangeObj' OBJ_RANGES = 'ScCellRangesObj' TYPE_RANGES = (OBJ_CELL, OBJ_RANGE) -OBJ_SHAPES = 'com.sun.star.drawing.SvxShapeCollection' OBJ_SHAPE = 'com.sun.star.comp.sc.ScShapeObj' +OBJ_SHAPES = 'com.sun.star.drawing.SvxShapeCollection' OBJ_GRAPHIC = 'SwXTextGraphicObject' OBJ_TEXTS = 'SwXTextRanges' OBJ_TEXT = 'SwXTextRange' +CLSID = { + 'FORMULA': '078B7ABA-54FC-457F-8551-6147e776a997', +} + +SERVICES = { + 'TEXT_EMBEDDED': 'com.sun.star.text.TextEmbeddedObject', + 'TEXT_TABLE': 'com.sun.star.text.TextTable', + 'GRAPHIC': 'com.sun.star.text.GraphicObject', +} + # ~ from com.sun.star.sheet.FilterOperator import EMPTY, NO_EMPTY, EQUAL, NOT_EQUAL class FilterOperator(IntEnum): @@ -225,6 +234,17 @@ class CellDeleteMode(): CDM = CellDeleteMode +class FormButtonType(): + from com.sun.star.form.FormButtonType import PUSH, SUBMIT, RESET, URL +FBT = FormButtonType + + +class TextContentAnchorType(): + from com.sun.star.text.TextContentAnchorType \ + import AT_PARAGRAPH, AS_CHARACTER, AT_PAGE, AT_FRAME, AT_CHARACTER +TCAT = TextContentAnchorType + + OS = platform.system() IS_WIN = OS == 'Windows' IS_MAC = OS == 'Darwin' @@ -710,7 +730,8 @@ def sha512(data): def get_config(key='', prefix='conf', default={}): name_file = FILE_NAME_CONFIG.format(prefix) values = None - path = _P.join(_P.config('UserConfig'), name_file) + # ~ path = _P.join(_P.config('UserConfig'), name_file) + path = _P.join(_P.user_config, name_file) if not _P.exists(path): return default @@ -723,7 +744,8 @@ def get_config(key='', prefix='conf', default={}): def set_config(key, value, prefix='conf'): name_file = FILE_NAME_CONFIG.format(prefix) - path = _P.join(_P.config('UserConfig'), name_file) + # ~ path = _P.join(_P.config('UserConfig'), name_file) + path = _P.join(_P.user_config, name_file) values = get_config(default={}, prefix=prefix) values[key] = value result = _P.to_json(path, values) @@ -1469,7 +1491,7 @@ class LOCalc(LODocument): self._sheets.removeByName(name) return - def copy(self, name, new_name='', pos=-1): + def copy_sheet(self, name, new_name='', pos=-1): if isinstance(name, LOCalcSheet): name = name.name index = pos @@ -1750,7 +1772,8 @@ class LOSheetTables(object): return -class LOFormControl(LOBaseObject): +# ~ class LOFormControl(LOBaseObject): +class LOFormControl(): EVENTS = { 'action': 'actionPerformed', 'click': 'mousePressed', @@ -1761,21 +1784,25 @@ class LOFormControl(LOBaseObject): } def __init__(self, obj, view, form): - super().__init__(obj) + self._obj = obj self._view = view self._form = form self._m = view.Model self._index = -1 - def __setattr__(self, name, value): - if name in ('_form', '_view', '_m', '_index'): - self.__dict__[name] = value - else: - super().__setattr__(name, value) + # ~ def __setattr__(self, name, value): + # ~ if name in ('_form', '_view', '_m', '_index'): + # ~ self.__dict__[name] = value + # ~ else: + # ~ super().__setattr__(name, value) def __str__(self): return f'{self.name} ({self.type}) {[self.index]}' + @property + def obj(self): + return self._obj + @property def form(self): return self._form @@ -1812,6 +1839,30 @@ class LOFormControl(LOBaseObject): def enabled(self, value): self._m.Enabled = value + @property + def anchor(self): + return self.obj.Anchor + @anchor.setter + def anchor(self, value): + size = None + if hasattr(value, 'obj'): + size = getattr(value, 'size', None) + value = value.obj + self.obj.Anchor = value + if not size is None: + self.size = size + try: + self.obj.ResizeWithCell = True + except: + pass + + @property + def size(self): + return self.obj.Size + @size.setter + def size(self, value): + self.obj.Size = value + @property def events(self): return self.form.getScriptEvents(self.index) @@ -1891,6 +1942,14 @@ class LOFormControlButton(LOFormControl): def value(self, value): self._m.Text = Label + @property + def url(self): + return self._m.TargetURL + @url.setter + def url(self, value): + self._m.TargetURL = value + self._m.ButtonType = FormButtonType.URL + FORM_CONTROL_CLASS = { 'label': LOFormControlLabel, @@ -1941,7 +2000,7 @@ class LOForm(object): name = control.Name tipo = types[control.ImplementationName] view = self.doc.CurrentController.getControl(control) - control = FORM_CONTROL_CLASS[tipo](control, view) + control = FORM_CONTROL_CLASS[tipo](control, view, self._obj) control.index = i setattr(self, name, control) self._controls[name] = control @@ -1994,8 +2053,8 @@ class LOForm(object): def add(self, args): name = args['Name'] tipo = args.pop('Type').lower() - w = args.pop('Width') - h = args.pop('Height') + w = args.pop('Width', 1000) + h = args.pop('Height', 200) x = args.pop('X', 0) y = args.pop('Y', 0) control = self.doc.createInstance('com.sun.star.drawing.ControlShape') @@ -2053,7 +2112,9 @@ class LOSheetForms(object): def names(self): return self.obj.ElementNames - def insert(self, name): + def insert(self, name=''): + if not name: + name = f'form{self.count + 1}' form = self.doc.createInstance('com.sun.star.form.component.Form') self.obj.insertByName(name, form) return LOForm(form, self._dp) @@ -2624,8 +2685,8 @@ class LOCalcRange(object): def visible(self): cursor = self.cursor rangos = cursor.queryVisibleCells() - rangos = [LOCalcRange(self.sheet[r.AbsoluteName].obj) for r in rangos] - return tuple(rangos) + rangos = LOCalcRanges(rangos) + return rangos @property def merged_area(self): @@ -3001,6 +3062,10 @@ class LOCalcRanges(object): self._obj = obj self._ranges = {} self._index = 0 + for r in obj: + sheet = r.Spreadsheet + rango = LOCalcRange(sheet[r.AbsoluteName]) + self._ranges[rango.name] = rango def __enter__(self): return self @@ -3252,6 +3317,17 @@ class LOWriterTextRange(object): self.text.insertTextContent(cursor, data, replace) return + def insert_math(self, formula, + anchor_type=TextContentAnchorType.AS_CHARACTER, + cursor=None, replace=False): + + math = self._doc.create_instance(SERVICES['TEXT_EMBEDDED']) + math.CLSID = CLSID['FORMULA'] + math.AnchorType = anchor_type + self.insert_content(math, cursor, replace) + math.EmbeddedObject.Component.Formula = formula + return math + def new_line(self, count=1): cursor = self.cursor for i in range(count): @@ -3259,7 +3335,7 @@ class LOWriterTextRange(object): return self._doc.selection def insert_table(self, data): - table = self._doc.create_instance('com.sun.star.text.TextTable') + table = self._doc.create_instance(SERVICES['TEXT_TABLE']) rows = len(data) cols = len(data[0]) table.initialize(rows, cols) @@ -3272,9 +3348,10 @@ class LOWriterTextRange(object): def insert_image(self, path, args={}): w = args.get('Width', 1000) h = args.get('Height', 1000) - image = self._doc.create_instance('com.sun.star.text.GraphicObject') + + image = self._doc.create_instance(SERVICES['GRAPHIC']) image.GraphicURL = _P.to_url(path) - image.AnchorType = AS_CHARACTER + image.AnchorType = TextContentAnchorType.AS_CHARACTER image.Width = w image.Height = h self.insert_content(image) @@ -6470,6 +6547,17 @@ class Paths(object): path = sys.executable return path + @classproperty + def user_profile(self): + path = self.config('UserConfig') + path = str(Path(path).parent) + return path + + @classproperty + def user_config(self): + path = self.config('UserConfig') + return path + @classmethod def dir_tmp(self, only_name=False): dt = tempfile.TemporaryDirectory() @@ -6619,8 +6707,12 @@ class Paths(object): return result @classmethod - def read(cls, path, encoding='utf-8'): - data = Path(path).read_text(encoding=encoding) + def read(cls, path, get_lines=False, encoding='utf-8'): + if get_lines: + with Path(path).open(encoding=encoding) as f: + data = f.readlines() + else: + data = Path(path).read_text(encoding=encoding) return data @classmethod diff --git a/source/pythonpath/main.py b/source/pythonpath/zcompaqi.py similarity index 92% rename from source/pythonpath/main.py rename to source/pythonpath/zcompaqi.py index a291665..00a5381 100644 --- a/source/pythonpath/main.py +++ b/source/pythonpath/zcompaqi.py @@ -14,11 +14,12 @@ FILE_TARGET = 'polizas.txt' def main(args): - if args == 'procesar': - _procesar() + if args == 'import_polizas': + _import_polizas() + return - if args == 'generar': - _generar() + if args == 'export_polizas': + _export_polizas() return @@ -78,7 +79,7 @@ def _get_mov(row): return line, uuid -def _generar(): +def _export_polizas(): doc = app.active if not 'POLIZA' in doc: @@ -134,8 +135,8 @@ def _generar(): return - -def _procesar(): +@app.catch_exception +def _import_polizas(): if not _validate_sheets(): return @@ -149,16 +150,19 @@ def _procesar(): doc = app.active sheet_catalogo = doc['Catalogo'] - source = doc['TXT'] target = doc['POLIZA'] data = sheet_catalogo['A1'].current_region.data catalog = {str(int(r[1])): r[2] for r in data} + path_txt = app.paths.get_file(filters='txt') + try: + data = app.paths.read(path_txt, True) + except UnicodeDecodeError: + data = app.paths.read(path_txt, True, 'ISO-8859-1') + rows = [] - data = source['A1'].current_region.data - for row in data: - r = row[0] + for r in data: header = r[:2].strip() if header == IS_HEADER: date = app.dates.str_to_date(r[3:11].strip(), '%Y%m%d', True) @@ -202,12 +206,6 @@ def _validate_sheets(): app.errorbox(message) return False - if not 'TXT' in doc: - message = 'No se encontró la hoja: TXT' - app.error(message) - app.errorbox(message) - return False - if not 'POLIZA' in doc: message = 'No se encontró la hoja: POLIZA' app.error(message) diff --git a/source/registration/license_en.txt b/source/registration/license_en.txt index 70374a1..29caa8f 100644 --- a/source/registration/license_en.txt +++ b/source/registration/license_en.txt @@ -1,14 +1,14 @@ -This file is part of ZAZPolizas. +This file is part of ZAZCompaqi. - ZAZPolizas is free software: you can redistribute it and/or modify + ZAZCompaqi is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - ZAZPolizas is distributed in the hope that it will be useful, + ZAZCompaqi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with ZAZPolizas. If not, see . + along with ZAZCompaqi. If not, see . diff --git a/source/registration/license_es.txt b/source/registration/license_es.txt index 70374a1..29caa8f 100644 --- a/source/registration/license_es.txt +++ b/source/registration/license_es.txt @@ -1,14 +1,14 @@ -This file is part of ZAZPolizas. +This file is part of ZAZCompaqi. - ZAZPolizas is free software: you can redistribute it and/or modify + ZAZCompaqi is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - ZAZPolizas is distributed in the hope that it will be useful, + ZAZCompaqi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with ZAZPolizas. If not, see . + along with ZAZCompaqi. If not, see .