Create main module

This commit is contained in:
Mauricio Baeza 2020-12-24 21:26:05 -06:00
parent 5d7c642903
commit cff22afb63
3 changed files with 129 additions and 101 deletions

Binary file not shown.

View File

@ -1,119 +1,21 @@
import uno
import unohelper
from com.sun.star.task import XJobExecutor
import easymacro as app
import main
ID_EXTENSION = 'net.elmau.zaz.Favorites'
SERVICE = ('com.sun.star.task.Job',)
_ = app.install_locales(__file__)
class Controllers(object):
def __init__(self, dlg):
self.d = dlg
self.paths = []
def button_add_action(self, event):
path = app.get_file()
if not path:
return
if path in self.paths:
msg = _('Path previously added')
app.msgbox(msg, self.TITLE)
return
self.paths.append(path)
p, filename, n, e = app.get_info_path(path)
self.d.grid.add_row((filename, '', path))
self.d.grid.set_cell_tooltip(0, self.d.grid.rows-1, p)
self.d.grid.sort(0)
return
def button_save_action(self, event):
msg = _('¿Want you save your favorites?')
if not app.question(msg, self.TITLE):
return
base = 'service:net.elmau.zaz.Favorites?{}'
paths = []
submenus = []
for row in range(self.d.grid.rows):
label = '{}. {}'.format(row + 1, self.d.grid[0, row])
path = self.d.grid[2, row]
paths.append(path)
path = app._path_url(path)
sm = {'Label': label, 'CommandURL': base.format(path)}
submenus.append(sm)
sm = {'Label': '-'}
submenus.append(sm)
sm = {'Label': _('Favorites...'), 'CommandURL': base.format('config')}
submenus.append(sm)
command = 'menu.zaz.favorites'
data = {
'Label': 'Favorites',
'CommandURL': command,
'After': '.uno:RecentFileList',
'Submenu': submenus,
}
for doc_type in ('main', 'calc', 'writer'):
app.remove_menu(doc_type, 'File', command)
app.insert_menu(doc_type, 'File', **data)
app.set_config('paths', paths)
self.d.close(1)
msg = _('Favorites saved correctly')
app.msgbox(msg, self.TITLE)
return
def grid_click(self, event):
col = self.d.grid.column
row = self.d.grid.row
if col != 1:
return
msg = _('¿Want you delete this file?')
if app.question(msg, self.TITLE):
path = self.d.grid[2, row]
self.paths.remove(path)
self.d.grid.remove_row(row)
return
def grid_double_click(self, event):
col = self.d.grid.column
row = self.d.grid.row
if col == -1 or row == -1 or col != 0:
return
app.msgbox(self.d.grid.get_cell_tooltip(col, row))
return
class ZAZFavorites(unohelper.Base, XJobExecutor):
cmd = 'service:' + ID_EXTENSION + '?'
IMAGES = 'images'
TITLE = _('ZAZ Favorites')
def __init__(self, ctx):
self.ctx = ctx
self.path_ext = app.get_path_extension(ID_EXTENSION)
self.IMAGES = app.join(self.path_ext, self.IMAGES)
def trigger(self, args):
if args == 'config':
return self._config()
app.open_doc(args)
return
def _config(self):
dlg = self._create_dialog()
dlg.open()
main.ID_EXTENSION = ID_EXTENSION
main.run(args, __file__)
return
def _create_dialog(self):

126
source/pythonpath/main.py Normal file
View File

@ -0,0 +1,126 @@
#!/usr/bin/env python3
import easymacro as app
ID_EXTENSION = ''
_ = None
# ~ cmd = 'service:' + ID_EXTENSION + '?'
class Controllers(object):
def __init__(self, dlg):
self.d = dlg
self.paths = []
def button_add_action(self, event):
path = app.get_file()
if not path:
return
if path in self.paths:
msg = _('Path previously added')
app.msgbox(msg, self.TITLE)
return
self.paths.append(path)
p, filename, n, e = app.get_info_path(path)
self.d.grid.add_row((filename, '', path))
self.d.grid.set_cell_tooltip(0, self.d.grid.rows-1, p)
self.d.grid.sort(0)
return
def button_save_action(self, event):
msg = _('¿Want you save your favorites?')
if not app.question(msg, self.TITLE):
return
base = 'service:net.elmau.zaz.Favorites?{}'
paths = []
submenus = []
for row in range(self.d.grid.rows):
label = '{}. {}'.format(row + 1, self.d.grid[0, row])
path = self.d.grid[2, row]
paths.append(path)
path = app._path_url(path)
sm = {'Label': label, 'CommandURL': base.format(path)}
submenus.append(sm)
sm = {'Label': '-'}
submenus.append(sm)
sm = {'Label': _('Favorites...'), 'CommandURL': base.format('config')}
submenus.append(sm)
command = 'menu.zaz.favorites'
data = {
'Label': 'Favorites',
'CommandURL': command,
'After': '.uno:RecentFileList',
'Submenu': submenus,
}
for doc_type in ('main', 'calc', 'writer'):
app.remove_menu(doc_type, 'File', command)
app.insert_menu(doc_type, 'File', **data)
app.set_config('paths', paths)
self.d.close(1)
msg = _('Favorites saved correctly')
app.msgbox(msg, self.TITLE)
return
def grid_click(self, event):
col = self.d.grid.column
row = self.d.grid.row
if col != 1:
return
msg = _('¿Want you delete this file?')
if app.question(msg, self.TITLE):
path = self.d.grid[2, row]
self.paths.remove(path)
self.d.grid.remove_row(row)
return
def grid_double_click(self, event):
col = self.d.grid.column
row = self.d.grid.row
if col == -1 or row == -1 or col != 0:
return
app.msgbox(self.d.grid.get_cell_tooltip(col, row))
return
def _config():
dlg = _create_dialog()
dlg.open()
return
def _create_dialog():
TITLE = _('ZAZ Favorites')
args = {
'Name': 'dialog',
'Title': TITLE,
'Width': 160,
'Height': 160,
}
dlg = app.create_dialog(args)
dlg.events = Controllers
return dlg
@app.catch_exception
def run(args, path_locales):
global _
_ = app.install_locales(path_locales)
app.debug(args)
if args == 'config':
_config()
return
app.docs.open(args)
return