Fix in Windows

This commit is contained in:
Mauricio Baeza 2019-09-20 17:19:10 -05:00
parent ced8ac7386
commit 32e6fb7df1
4 changed files with 105 additions and 52 deletions

View File

@ -134,7 +134,7 @@ MENUS_APP = {
}
FILE_NAME_DEBUG = 'zaz-debug.log'
FILE_NAME_DEBUG = 'debug.odt'
FILE_NAME_CONFIG = 'zaz-{}.json'
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
LOG_DATE = '%d/%m/%Y %H:%M:%S'
@ -195,7 +195,10 @@ def catch_exception(f):
try:
return f(*args, **kwargs)
except Exception as e:
log.error(f.__name__, exc_info=True)
name = f.__name__
if IS_WIN:
debug(traceback.format_exc())
log.error(name, exc_info=True)
return func
@ -203,6 +206,7 @@ class LogWin(object):
def __init__(self, doc):
self.doc = doc
# ~ self.doc.Title = FILE_NAME_DEBUG
def write(self, info):
text = self.doc.Text
@ -219,14 +223,10 @@ def info(data):
def debug(info):
if IS_WIN:
# ~ app = LOApp(self.ctx, self.sm, self.desktop, self.toolkit)
# ~ doc = app.getDoc(FILE_NAME_DEBUG)
# ~ if not doc:
# ~ doc = app.newDoc(WRITER)
# ~ out = OutputDoc(doc)
# ~ sys.stdout = out
# ~ pprint(info)
doc = LogWin(new_doc('writer').obj)
doc = get_document(FILE_NAME_DEBUG)
if doc is None:
doc = new_doc('writer')
doc = LogWin(doc.obj)
doc.write(info)
return
@ -254,20 +254,19 @@ def run_in_thread(fn):
return run
def get_config(key='', prefix='config'):
def get_config(key='', default=None, prefix='config'):
path_json = FILE_NAME_CONFIG.format(prefix)
values = {}
values = None
path = join(get_config_path('UserConfig'), path_json)
if not exists_path(path):
return values
return default
with open(path, 'r', encoding='utf-8') as fh:
data = fh.read()
if data:
values = json.loads(data)
values = json.loads(data)
if key:
return values.get(key, None)
return values.get(key, default)
return values
@ -275,7 +274,7 @@ def get_config(key='', prefix='config'):
def set_config(key, value, prefix='config'):
path_json = FILE_NAME_CONFIG.format(prefix)
path = join(get_config_path('UserConfig'), path_json)
values = get_config(prefix=prefix)
values = get_config(default={}, prefix=prefix)
values[key] = value
with open(path, 'w', encoding='utf-8') as fh:
json.dump(values, fh, ensure_ascii=False, sort_keys=True, indent=4)
@ -516,6 +515,10 @@ class LODocument(object):
def path(self):
return _path_system(self.obj.getURL())
@property
def statusbar(self):
return self._cc.getStatusIndicator()
@property
def visible(self):
w = self._cc.getFrame().getContainerWindow()
@ -1419,16 +1422,28 @@ def _get_class_doc(obj):
return classes[type_doc](obj)
def get_document():
def get_document(title=''):
doc = None
desktop = get_desktop()
try:
if not title:
doc = _get_class_doc(desktop.getCurrentComponent())
except Exception as e:
log.error(e)
return doc
for d in desktop.getComponents():
if d.Title == title:
doc = d
break
return doc
def get_documents():
docs = []
desktop = get_desktop()
for doc in desktop.getComponents():
docs.append(_get_class_doc(doc))
return docs
def get_selection():
return get_document().selection
@ -1592,6 +1607,14 @@ def new_doc(type_doc=CALC):
return _get_class_doc(doc)
def new_db(path):
dbc = create_instance('com.sun.star.sdb.DatabaseContext')
db = dbc.createInstance()
db.URL = 'sdbc:embedded:firebird' # hsqldb
db.DatabaseDocument.storeAsURL(_path_url(path), ())
return _get_class_doc(db)
def open_doc(path, **kwargs):
""" Open document in path
Usually options:
@ -1944,7 +1967,8 @@ def insert_menu(type_doc, name_menu, **kwargs):
index_menu = _get_index_menu(menu, command)
if index_menu:
msg = 'Exists: %s' % command
debug(msg)
if not IS_WIN:
debug(msg)
return 0
sub_menu = kwargs.get('Submenu', ())
@ -1987,7 +2011,8 @@ def remove_menu(type_doc, name_menu, command):
index = _get_index_menu(menu, command)
if not index:
debug('Not exists: %s' % command)
if not IS_WIN:
debug('Not exists: %s' % command)
return False
_store_menu(ui, menus, menu, index, remove=True)
@ -1999,7 +2024,8 @@ def _get_app_submenus(menus, count=0):
data = property_to_dict(menu)
cmd = data.get('CommandURL', '')
msg = ' ' * count + '├─' + cmd
debug(msg)
if not IS_WIN:
debug(msg)
submenu = data.get('ItemDescriptorContainer', None)
if not submenu is None:
_get_app_submenus(submenu, count + 1)
@ -2015,7 +2041,8 @@ def get_app_menus(name_app, index=-1):
if index == -1:
for menu in menus:
data = property_to_dict(menu)
debug(data.get('CommandURL', ''))
if not IS_WIN:
debug(data.get('CommandURL', ''))
else:
menus = property_to_dict(menus[index])['ItemDescriptorContainer']
_get_app_submenus(menus)

Binary file not shown.

View File

@ -43,7 +43,6 @@ class Controllers(object):
self.d.grid.sort(0)
return
@app.catch_exception
def button_save_action(self, event):
msg = _('¿You want save your favorites?')
if not app.question(msg, self.TITLE):
@ -167,7 +166,7 @@ class ZAZFavorites(unohelper.Base, XJobExecutor):
}
dlg.add_control(args)
dlg.grid.set_column_image(1, app.join(self.IMAGES, 'delete.png'))
paths = app.get_config('paths')
paths = app.get_config('paths', [])
for path in paths:
p, filename, n, e = app.get_info_path(path)
dlg.grid.add_row((filename, '', path))

View File

@ -134,7 +134,7 @@ MENUS_APP = {
}
FILE_NAME_DEBUG = 'zaz-debug.log'
FILE_NAME_DEBUG = 'debug.odt'
FILE_NAME_CONFIG = 'zaz-{}.json'
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
LOG_DATE = '%d/%m/%Y %H:%M:%S'
@ -195,7 +195,10 @@ def catch_exception(f):
try:
return f(*args, **kwargs)
except Exception as e:
log.error(f.__name__, exc_info=True)
name = f.__name__
if IS_WIN:
debug(traceback.format_exc())
log.error(name, exc_info=True)
return func
@ -203,6 +206,7 @@ class LogWin(object):
def __init__(self, doc):
self.doc = doc
# ~ self.doc.Title = FILE_NAME_DEBUG
def write(self, info):
text = self.doc.Text
@ -219,14 +223,10 @@ def info(data):
def debug(info):
if IS_WIN:
# ~ app = LOApp(self.ctx, self.sm, self.desktop, self.toolkit)
# ~ doc = app.getDoc(FILE_NAME_DEBUG)
# ~ if not doc:
# ~ doc = app.newDoc(WRITER)
# ~ out = OutputDoc(doc)
# ~ sys.stdout = out
# ~ pprint(info)
doc = LogWin(new_doc('writer').obj)
doc = get_document(FILE_NAME_DEBUG)
if doc is None:
doc = new_doc('writer')
doc = LogWin(doc.obj)
doc.write(info)
return
@ -254,20 +254,19 @@ def run_in_thread(fn):
return run
def get_config(key='', prefix='config'):
def get_config(key='', default=None, prefix='config'):
path_json = FILE_NAME_CONFIG.format(prefix)
values = {}
values = None
path = join(get_config_path('UserConfig'), path_json)
if not exists_path(path):
return values
return default
with open(path, 'r', encoding='utf-8') as fh:
data = fh.read()
if data:
values = json.loads(data)
values = json.loads(data)
if key:
return values.get(key, None)
return values.get(key, default)
return values
@ -275,7 +274,7 @@ def get_config(key='', prefix='config'):
def set_config(key, value, prefix='config'):
path_json = FILE_NAME_CONFIG.format(prefix)
path = join(get_config_path('UserConfig'), path_json)
values = get_config(prefix=prefix)
values = get_config(default={}, prefix=prefix)
values[key] = value
with open(path, 'w', encoding='utf-8') as fh:
json.dump(values, fh, ensure_ascii=False, sort_keys=True, indent=4)
@ -516,6 +515,10 @@ class LODocument(object):
def path(self):
return _path_system(self.obj.getURL())
@property
def statusbar(self):
return self._cc.getStatusIndicator()
@property
def visible(self):
w = self._cc.getFrame().getContainerWindow()
@ -1419,16 +1422,28 @@ def _get_class_doc(obj):
return classes[type_doc](obj)
def get_document():
def get_document(title=''):
doc = None
desktop = get_desktop()
try:
if not title:
doc = _get_class_doc(desktop.getCurrentComponent())
except Exception as e:
log.error(e)
return doc
for d in desktop.getComponents():
if d.Title == title:
doc = d
break
return doc
def get_documents():
docs = []
desktop = get_desktop()
for doc in desktop.getComponents():
docs.append(_get_class_doc(doc))
return docs
def get_selection():
return get_document().selection
@ -1592,6 +1607,14 @@ def new_doc(type_doc=CALC):
return _get_class_doc(doc)
def new_db(path):
dbc = create_instance('com.sun.star.sdb.DatabaseContext')
db = dbc.createInstance()
db.URL = 'sdbc:embedded:firebird' # hsqldb
db.DatabaseDocument.storeAsURL(_path_url(path), ())
return _get_class_doc(db)
def open_doc(path, **kwargs):
""" Open document in path
Usually options:
@ -1944,7 +1967,8 @@ def insert_menu(type_doc, name_menu, **kwargs):
index_menu = _get_index_menu(menu, command)
if index_menu:
msg = 'Exists: %s' % command
debug(msg)
if not IS_WIN:
debug(msg)
return 0
sub_menu = kwargs.get('Submenu', ())
@ -1987,7 +2011,8 @@ def remove_menu(type_doc, name_menu, command):
index = _get_index_menu(menu, command)
if not index:
debug('Not exists: %s' % command)
if not IS_WIN:
debug('Not exists: %s' % command)
return False
_store_menu(ui, menus, menu, index, remove=True)
@ -1999,7 +2024,8 @@ def _get_app_submenus(menus, count=0):
data = property_to_dict(menu)
cmd = data.get('CommandURL', '')
msg = ' ' * count + '├─' + cmd
debug(msg)
if not IS_WIN:
debug(msg)
submenu = data.get('ItemDescriptorContainer', None)
if not submenu is None:
_get_app_submenus(submenu, count + 1)
@ -2015,7 +2041,8 @@ def get_app_menus(name_app, index=-1):
if index == -1:
for menu in menus:
data = property_to_dict(menu)
debug(data.get('CommandURL', ''))
if not IS_WIN:
debug(data.get('CommandURL', ''))
else:
menus = property_to_dict(menus[index])['ItemDescriptorContainer']
_get_app_submenus(menus)