Create main module
This commit is contained in:
parent
5d7c642903
commit
cff22afb63
Binary file not shown.
|
@ -1,119 +1,21 @@
|
||||||
import uno
|
import uno
|
||||||
import unohelper
|
import unohelper
|
||||||
from com.sun.star.task import XJobExecutor
|
from com.sun.star.task import XJobExecutor
|
||||||
import easymacro as app
|
import main
|
||||||
|
|
||||||
|
|
||||||
ID_EXTENSION = 'net.elmau.zaz.Favorites'
|
ID_EXTENSION = 'net.elmau.zaz.Favorites'
|
||||||
SERVICE = ('com.sun.star.task.Job',)
|
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):
|
class ZAZFavorites(unohelper.Base, XJobExecutor):
|
||||||
cmd = 'service:' + ID_EXTENSION + '?'
|
|
||||||
IMAGES = 'images'
|
|
||||||
TITLE = _('ZAZ Favorites')
|
|
||||||
|
|
||||||
def __init__(self, ctx):
|
def __init__(self, ctx):
|
||||||
self.ctx = 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):
|
def trigger(self, args):
|
||||||
if args == 'config':
|
main.ID_EXTENSION = ID_EXTENSION
|
||||||
return self._config()
|
main.run(args, __file__)
|
||||||
|
|
||||||
app.open_doc(args)
|
|
||||||
return
|
|
||||||
|
|
||||||
def _config(self):
|
|
||||||
dlg = self._create_dialog()
|
|
||||||
dlg.open()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _create_dialog(self):
|
def _create_dialog(self):
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue