Disable search

This commit is contained in:
Mauricio Baeza 2021-01-08 21:15:57 -06:00
commit 2d3f412349
25 changed files with 10749 additions and 8069 deletions

3
.gitignore vendored
View File

@ -3,8 +3,7 @@ __pycache__/
*.po~
*.log
images/
/images
docs/
# Virtualenv

View File

@ -1,5 +1,5 @@
v 0.5.0 [0-mar-2020]
-
v 0.5.0 [09-jul-2020]
- Test install pandas
v 0.4.0 [10-mar-2020]
- Update easymacro.py
@ -12,11 +12,9 @@ v 0.3.0 [12-nov-2019]
v 0.2.0 [18-oct-2019]
---------------------
- Add spanish
v 0.1.0 [18-oct-2019]
---------------------
- Initial version

View File

@ -1 +1 @@
0.5.0
0.7.0

View File

@ -26,7 +26,7 @@ import logging
TYPE_EXTENSION = 1
# ~ https://semver.org/
VERSION = '0.5.0'
VERSION = '0.7.0'
# ~ Your great extension name, not used spaces
NAME = 'ZAZPip'
@ -36,7 +36,7 @@ ID = 'net.elmau.zaz.pip'
# ~ If you extension will be multilanguage set: True
# ~ This feature used gettext, set pythonpath and easymacro in True
# ~ Yu can used PoEdit for edit PO files and generate MO files.
# ~ You can used PoEdit for edit PO files and generate MO files.
# ~ https://poedit.net/
USE_LOCALES = True
DOMAIN = 'base'
@ -112,7 +112,7 @@ MENU_MAIN = {}
MENUS = (
{
'title': {'en': 'Open Pip', 'es': 'Abrir Pip'},
'argument': 'open',
'argument': 'open_dialog_pip',
'context': '',
'icon': 'icon',
'toolbar': False,

File diff suppressed because it is too large Load Diff

Binary file not shown.

BIN
files/ZAZPip_v0.7.0.oxt Normal file

Binary file not shown.

View File

@ -11,7 +11,7 @@
<value/>
</prop>
<prop oor:name="URL" oor:type="xs:string">
<value>service:net.elmau.zaz.pip?open</value>
<value>service:net.elmau.zaz.pip?open_dialog_pip</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>

View File

@ -4,7 +4,7 @@
<node oor:name="Global">
<node oor:name="P_SHIFT_MOD1_MOD2" oor:op="fuse">
<prop oor:name="Command">
<value xml:lang="en-US">service:net.elmau.zaz.pip?open</value>
<value xml:lang="en-US">service:net.elmau.zaz.pip?open_dialog_pip</value>
</prop>
</node>
</node>

View File

@ -1,501 +1,23 @@
import uno
import unohelper
from com.sun.star.task import XJobExecutor
import easymacro as app
import main
ID_EXTENSION = 'net.elmau.zaz.pip'
SERVICE = ('com.sun.star.task.Job',)
TITLE = 'ZAZ-PIP'
URL_PIP = 'https://bootstrap.pypa.io/get-pip.py'
PIP = 'pip'
PACKAGES = {
'psycopg2-binary': 'ok.png',
'peewee': 'ok.png',
'numpy': 'ok.png',
'pillow': 'ok.png',
'pytesseract': 'ok.png',
}
_ = app.install_locales(__file__)
class Controllers(object):
OK1 = 'Successfully installed'
OK2 = 'Requirement already'
OK3 = 'Successfully uninstalled'
def __init__(self, dialog):
self.d = dialog
self.path_python = app.get_path_python()
self._states = {
'list': False,
'install': False,
'search': False,
'versions': False,
}
def _set_state(self, state):
for k in self._states.keys():
self._states[k] = False
self._states[state] = True
return
def cmd_install_pip_action(self, event):
msg = _('Do you want install PIP?')
if not app.question(msg, 'ZAZ-Pip'):
return
self._install_pip()
return
@app.run_in_thread
def _install_pip(self):
self.d.link_proyect.visible = False
self.d.lst_log.visible = True
path_pip = app.get_temp_file(True)
self.d.lst_log.insert('Download PIP...')
data, err = app.url_open(URL_PIP, verify=False)
if err:
msg = _('Do you have internet connection?')
app.errorbox('{}\n\n{}'.format(msg, err))
return
app.save_file(path_pip, 'wb', data)
if not app.is_created(path_pip):
msg = _('File PIP not save')
app.errorbox(msg)
return
self.d.lst_log.insert(_('PIP save correctly...'))
try:
self.d.lst_log.insert(_('Start installing PIP...'))
cmd = '"{}" "{}" --user'.format(self.path_python, path_pip)
for line in app.popen(cmd):
if isinstance(line, tuple):
app.errorbox(line)
break
self.d.lst_log.insert(line)
cmd = self._cmd_pip('-V')
label = app.run(cmd, True)
if label:
self.d.lbl_pip.value = label
self.d.cmd_install_pip.visible = False
self.d.cmd_admin_pip.visible = True
msg = _('PIP installed sucesfully')
app.msgbox(msg)
else:
msg = _('PIP not installed, see log')
app.warning(msg)
except Exception as e:
app.errorbox(e)
return
def _cmd_pip(self, args):
cmd = '"{}" -m pip {}'.format(self.path_python, args)
return cmd
def cmd_admin_pip_action(self, event):
self.d.lst_log.possize(self.d.lst_package)
self.d.lst_log.step = 1
self.d.step = 1
self.cmd_home_action(None)
return
def cmd_close_action(self, event):
self.d.close()
return
def cmd_home_action(self, event):
self.d.txt_search.value = ''
self._list()
return
def txt_search_key_released(self, event):
if event.KeyCode == app.KEY['enter']:
self.cmd_search_action(None)
return
if not self.d.txt_search.value.strip():
self.cmd_home_action(None)
return
@app.run_in_thread
def _list(self):
self._set_state('list')
self.d.lst_log.visible = False
self.d.lst_package.visible = True
cmd = self._cmd_pip(' list --format=json')
self.d.lst_package.clear()
result = app.run(cmd, True)
packages = app.json_loads(result)
for p in packages:
t = '{} - ({})'.format(p['name'], p['version'])
self.d.lst_package.insert(t, 'ok.png')
self.d.lst_package.select()
self.d.txt_search.set_focus()
return
@app.run_in_thread
def _search(self, value):
self._set_state('search')
line = ''
cmd = self._cmd_pip(' search {}'.format(value))
self.d.lst_package.clear()
for line in app.popen(cmd):
parts = line.split(')')
name = parts[0].strip() + ')'
description = parts[-1].strip()
parts = name.split('(')
name_verify = parts[0].strip()
package = '{} {}'.format(name, description)
image = PACKAGES.get(name_verify, 'question.png')
self.d.lst_package.insert(package, image)
if line:
self.d.lst_package.select()
else:
self.d.lst_package.insert(_('Not found...'), 'error.png', show=False)
return
def cmd_search_action(self, event):
search = self.d.txt_search.value.strip()
if not search:
self.d.txt_search.set_focus()
return
self._search(search)
return
@app.run_in_thread
def _install(self, value):
self._set_state('install')
self.d.lst_package.visible = False
self.d.lst_log.visible = True
line = ''
name = value.split(' ')[0].strip()
cmd = self._cmd_pip(' install --upgrade --user {}'.format(name))
self.d.lst_log.clear()
for line in app.popen(cmd):
if self.OK1 in line or self.OK2 in line:
self.d.lst_log.insert(line, 'ok.png')
else:
self.d.lst_log.insert(line)
return
@app.catch_exception
def lst_package_double_click(self, event):
opt = 'install'
if self._states['list']:
opt = 'upgrade'
name = self.d.lst_package.value
msg = _('Do you want {}:\n\n{} ?').format(opt, name)
if not app.question(msg, TITLE):
return
self._install(name)
return
@app.run_in_thread
def _uninstall(self, value):
self._set_state('install')
self.d.lst_package.visible = False
self.d.lst_log.visible = True
line = ''
name = value.split(' ')[0].strip()
cmd = self._cmd_pip(' uninstall -y {}'.format(name))
self.d.lst_log.clear()
for line in app.popen(cmd):
if self.OK3 in line:
self.d.lst_log.insert(line, 'ok.png')
else:
self.d.lst_log.insert(line)
return
def cmd_uninstall_action(self, event):
if not self._states['list']:
msg = _('Select installed package')
app.warning(msg)
return
name = self.d.lst_package.value
msg = _('Do you want uninstall:\n\n{} ?').format(name)
if not app.question(msg):
return
self._uninstall(name)
return
@app.catch_exception
def cmd_shell_action(self, name):
if app.IS_WIN:
cmd = '"{}"'.format(self.path_python)
app.open_file(cmd)
else:
cmd = 'exec "{}"'
if app.IS_MAC:
cmd = 'open "{}"'
elif app.DESKTOP == 'gnome':
cmd = 'gnome-terminal -- {}'
cmd = cmd.format(self.path_python)
app.run(cmd)
return
class ZAZPip(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
def trigger(self, args):
dialog = self._create_dialog()
dialog.open()
main.ID_EXTENSION = ID_EXTENSION
main.run(args, __file__)
return
def _create_dialog(self):
args= {
'Name': 'dialog',
'Title': 'Zaz-Pip',
'Width': 200,
'Height': 220,
}
dialog = app.create_dialog(args)
dialog.id_extension = ID_EXTENSION
dialog.events = Controllers(dialog)
lbl_title = '{} {} - {}'.format(app.NAME, app.VERSION, app.OS)
args = {
'Type': 'Label',
'Name': 'lbl_title',
'Label': lbl_title,
'Width': 100,
'Height': 15,
'Border': 1,
'Align': 1,
'VerticalAlign': 1,
'Step': 10,
'FontHeight': 12,
}
dialog.add_control(args)
dialog.center(dialog.lbl_title, y=5)
path_python = app.get_path_python()
cmd = '"{}" -V'.format(path_python)
label = app.run(cmd, True)
args = {
'Type': 'Label',
'Name': 'lbl_python',
'Label': str(label),
'Width': 100,
'Height': 15,
'Border': 1,
'Align': 1,
'VerticalAlign': 1,
'Step': 10,
'FontHeight': 11,
}
dialog.add_control(args)
dialog.center(dialog.lbl_python, y=25)
cmd = '"{}" -m pip -V'.format(path_python)
label = app.run(cmd, True)
exists_pip = True
if not label:
exists_pip = False
label = _('PIP not installed')
args = {
'Type': 'Label',
'Name': 'lbl_pip',
'Label': label,
'Width': 160,
'Height': 30,
'Border': 1,
'Align': 1,
'VerticalAlign': 1,
'Step': 10,
'MultiLine': True,
}
dialog.add_control(args)
dialog.center(dialog.lbl_pip, y=45)
args = {
'Type': 'Button',
'Name': 'cmd_admin_pip',
'Label': _('Admin PIP'),
'Width': 60,
'Height': 18,
'Step': 10,
'ImageURL': 'python.png',
'ImagePosition': 1,
}
dialog.add_control(args)
dialog.center(dialog.cmd_admin_pip, y=80)
args = {
'Type': 'Button',
'Name': 'cmd_install_pip',
'Label': _('Install PIP'),
'Width': 60,
'Height': 18,
'Step': 10,
'ImageURL': 'install.png',
'ImagePosition': 1,
}
dialog.add_control(args)
dialog.center(dialog.cmd_install_pip, y=80)
args = {
'Type': 'Link',
'Name': 'link_proyect',
'URL': 'https://gitlab.com/mauriciobaeza/',
'Label': 'https://gitlab.com/mauriciobaeza/',
'Border': 1,
'Width': 130,
'Height': 15,
'Align': 1,
'VerticalAlign': 1,
'Step': 10,
}
dialog.add_control(args)
dialog.center(dialog.link_proyect, y=-5)
args = {
'Type': 'Listbox',
'Name': 'lst_log',
'Width': 160,
'Height': 105,
'Step': 10,
}
dialog.add_control(args)
dialog.center(dialog.lst_log, y=105)
args = {
'Type': 'Label',
'Name': 'lbl_package',
'Label': _('Packages'),
'Width': 100,
'Height': 15,
'Border': 1,
'Align': 1,
'VerticalAlign': 1,
'Step': 1,
}
dialog.add_control(args)
args = {
'Type': 'Text',
'Name': 'txt_search',
'Width': 180,
'Height': 12,
'Step': 1,
'Border': 0,
}
dialog.add_control(args)
args = {
'Type': 'Listbox',
'Name': 'lst_package',
'Width': 180,
'Height': 128,
'Step': 1,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_close',
'Label': _('~Close'),
'Width': 60,
'Height': 18,
'Step': 1,
'ImageURL': 'close.png',
'ImagePosition': 1,
# ~ 'PushButtonType': 2,
}
dialog.add_control(args)
dialog.center(dialog.cmd_close, y=-5)
args = {
'Type': 'Button',
'Name': 'cmd_home',
'Width': 18,
'Height': 18,
'Step': 1,
'ImageURL': 'home.png',
'FocusOnClick': False,
'Y': 2,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_search',
'Width': 18,
'Height': 18,
'Step': 1,
'ImageURL': 'search.png',
'FocusOnClick': False,
'Y': 2,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_uninstall',
'Width': 18,
'Height': 18,
'Step': 1,
'ImageURL': 'uninstall.png',
'FocusOnClick': False,
'Y': 2,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_shell',
'Width': 18,
'Height': 18,
'Step': 1,
'ImageURL': 'shell.png',
'FocusOnClick': False,
'Y': 2,
}
dialog.add_control(args)
controls = (dialog.cmd_home, dialog.cmd_search,
dialog.cmd_uninstall, dialog.cmd_shell)
dialog.lbl_package.move(dialog.cmd_home)
dialog.txt_search.move(dialog.lbl_package)
dialog.lst_package.move(dialog.txt_search)
dialog.lbl_package.center()
dialog.lst_package.center()
dialog.txt_search.center()
dialog.center(controls)
dialog.step = 10
dialog.cmd_install_pip.visible = not exists_pip
dialog.cmd_admin_pip.visible = exists_pip
dialog.lst_log.visible = False
return dialog
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(ZAZPip, ID_EXTENSION, SERVICE)

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<description xmlns="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:d="http://openoffice.org/extensions/description/2006">
<identifier value="net.elmau.zaz.pip"/>
<version value="0.5.0"/>
<version value="0.7.0"/>
<display-name>
<name lang="en">ZAZ Pip</name>
<name lang="es">ZAZ Pip</name>

52
source/images/close.svg Normal file
View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 32 32"
version="1.1"
x="0px"
y="0px"
id="svg18"
width="32"
height="32">
<metadata
id="metadata24">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>9.4</dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs22" />
<title
id="title2">9.4</title>
<desc
id="desc4">Created with Sketch.</desc>
<g
stroke="none"
stroke-width="1"
fill="none"
fill-rule="evenodd"
id="g12"
transform="scale(0.66666667)">
<g
fill-rule="nonzero"
fill="#000000"
id="g10">
<g
id="g8">
<path
d="m 26.828427,24 6.366079,6.366079 c 0.779879,0.779879 0.784376,2.039815 -0.0021,2.826309 -0.781048,0.781049 -2.047059,0.781368 -2.826309,0.0021 L 24,26.828427 17.633921,33.194506 c -0.779879,0.779879 -2.039815,0.784376 -2.826309,-0.0021 -0.781049,-0.781048 -0.781368,-2.047059 -0.0021,-2.826309 L 21.171573,24 14.805494,17.633921 c -0.779879,-0.779879 -0.784376,-2.039815 0.0021,-2.826309 0.781048,-0.781049 2.047059,-0.781368 2.826309,-0.0021 L 24,21.171573 30.366079,14.805494 c 0.779879,-0.779879 2.039815,-0.784376 2.826309,0.0021 0.781049,0.781048 0.781368,2.047059 0.0021,2.826309 z M 24,48 C 10.745166,48 0,37.254834 0,24 0,10.745166 10.745166,0 24,0 37.254834,0 48,10.745166 48,24 48,37.254834 37.254834,48 24,48 Z m 0,-4 C 35.045695,44 44,35.045695 44,24 44,12.954305 35.045695,4 24,4 12.954305,4 4,12.954305 4,24 4,35.045695 12.954305,44 24,44 Z"
id="path6" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

37
source/images/home.svg Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xml:space="preserve"
version="1.1"
style="image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision"
viewBox="0 0 31.999998 31.999998"
x="0px"
y="0px"
fill-rule="evenodd"
clip-rule="evenodd"
id="svg16"
width="31.999998"
height="31.999998"><metadata
id="metadata20"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs4"><style
type="text/css"
id="style2">
.fil0 {fill:black}
</style></defs><g
id="g25"
transform="scale(0.09968847)"><g
id="g10"><path
class="fil0"
d="M 230,80 V 37 h 20 v 60 z m -93,91 h 47 v -38 h -47 z m 0,15 h 47 v 78 h 46 V 151 h 20 V 284 H 72 V 151 h 20 v 113 h 45 z M 161,62 42,162 29,147 161,37 292,147 279,162 Z"
id="path6" /><path
class="fil0"
d="m 82,0 c 52,0 104,0 156,0 46,0 83,37 83,82 0,52 0,104 0,156 0,46 -37,83 -83,83 -52,0 -104,0 -156,0 C 37,321 0,284 0,238 0,186 0,134 0,82 0,37 37,0 82,0 Z m 0,16 c 52,0 104,0 156,0 37,0 66,30 66,66 0,52 0,104 0,156 0,37 -29,66 -66,66 -52,0 -104,0 -156,0 C 46,304 16,275 16,238 16,186 16,134 16,82 16,46 46,16 82,16 Z"
id="path8" /></g></g></svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
source/images/icon_16.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

62
source/images/install.svg Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xml:space="preserve"
version="1.1"
style="image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision"
viewBox="0 0 31.999998 31.999998"
x="0px"
y="0px"
fill-rule="evenodd"
clip-rule="evenodd"
id="svg16"
width="31.999998"
height="31.999998"
sodipodi:docname="install.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1280"
inkscape:window-height="1006"
id="namedview10"
showgrid="false"
inkscape:zoom="18.185904"
inkscape:cx="27.610641"
inkscape:cy="13.076849"
inkscape:window-x="0"
inkscape:window-y="37"
inkscape:window-maximized="0"
inkscape:current-layer="svg16" /><metadata
id="metadata20"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs4"><style
type="text/css"
id="style2">
.fil0 {fill:black}
</style></defs><g
id="g49"><path
class="fil0"
d="m 8.1744545,0 c 5.1838005,0 10.3676005,0 15.5514015,0 4.585669,0 8.274143,3.6884734 8.274143,8.1744545 0,5.1838005 0,10.3676005 0,15.5514015 0,4.585669 -3.688474,8.274143 -8.274143,8.274143 -5.183801,0 -10.367601,0 -15.5514015,0 C 3.6884734,31.999999 0,28.311525 0,23.725856 0,18.542055 0,13.358255 0,8.1744545 0,3.6884734 3.6884734,0 8.1744545,0 Z m 0,1.5950155 c 5.1838005,0 10.3676005,0 15.5514015,0 3.688473,0 6.579439,2.9906541 6.579439,6.579439 0,5.1838005 0,10.3676005 0,15.5514015 0,3.688473 -2.890966,6.579439 -6.579439,6.579439 -5.183801,0 -10.367601,0 -15.5514015,0 -3.5887849,0 -6.579439,-2.890966 -6.579439,-6.579439 0,-5.183801 0,-10.367601 0,-15.5514015 0,-3.5887849 2.9906541,-6.579439 6.579439,-6.579439 z"
id="path8"
style="stroke-width:0.0996885" /><g
id="g6"
transform="matrix(0.31518698,0,0,0.29534593,1.9554552,2.2893253)"><path
d="M 59.309998,55.640045 45,69.070038 30.690002,55.640045 H 10.090027 V 77.029999 H 79.909973 V 55.640045 Z m -40.77002,13.599976 c -1.599976,0 -2.899963,-1.299988 -2.899963,-2.910034 0,-1.599976 1.299987,-2.899964 2.899963,-2.899964 1.610046,0 2.910034,1.299988 2.910034,2.899964 0,1.610046 -1.299988,2.910034 -2.910034,2.910034 z m 9.110046,0 c -1.600036,0 -2.900024,-1.299988 -2.900024,-2.910034 0,-1.599976 1.299988,-2.899964 2.900024,-2.899964 1.599976,0 2.899964,1.299988 2.899964,2.899964 0,1.610046 -1.299988,2.910034 -2.899964,2.910034 z"
id="path2" /><polygon
points="45,63.070038 59.640015,49.329987 59.640015,40.320038 49.619995,49.730011 49.619995,12.970001 40.380005,12.970001 40.380005,49.730011 30.359985,40.320038 30.359985,49.329987 "
id="polygon4" /></g></g></svg>

After

Width:  |  Height:  |  Size: 3.4 KiB

50
source/images/ok.svg Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
x="0px"
y="0px"
viewBox="0 0 24 24"
enable-background="new 0 0 100 100"
xml:space="preserve"
id="svg10"
width="24"
height="24"
sodipodi:docname="ok.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2560"
inkscape:window-height="1006"
id="namedview8"
showgrid="false"
inkscape:zoom="25.71875"
inkscape:cx="9.0330528"
inkscape:cy="13.975581"
inkscape:window-x="0"
inkscape:window-y="37"
inkscape:window-maximized="1"
inkscape:current-layer="svg10"
inkscape:document-rotation="0" /><metadata
id="metadata16"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
id="defs14" /><g
id="g20"
transform="matrix(0.26666667,0,0,0.26666667,-1.3333334,-1.3333334)"><path
d="M 50,5 C 25.2,5 5,25.2 5,50 5,74.8 25.2,95 50,95 74.8,95 95,74.8 95,50 95,25.2 74.8,5 50,5 Z m 0,80 C 30.7,85 15,69.3 15,50 15,30.7 30.7,15 50,15 69.3,15 85,30.7 85,50 85,69.3 69.3,85 50,85 Z"
id="path2" /><polygon
points="45,67.1 72.1,40 65,32.9 45,52.9 35,42.9 27.9,50 "
id="polygon4" /></g></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

57
source/images/python.svg Normal file
View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
x="0px"
y="0px"
viewBox="0 0 32 32"
enable-background="new 0 0 100 100"
xml:space="preserve"
id="svg12"
sodipodi:docname="python.svg"
width="32"
height="32"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="2560"
inkscape:window-height="1006"
id="namedview9"
showgrid="false"
inkscape:showpageshadow="false"
inkscape:zoom="4.655591"
inkscape:cx="-28.841168"
inkscape:cy="23.577791"
inkscape:window-x="0"
inkscape:window-y="37"
inkscape:window-maximized="1"
inkscape:current-layer="svg12"
inkscape:document-rotation="0" /><metadata
id="metadata18"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
id="defs16" /><g
id="g23"
transform="matrix(0.39999852,0,0,0.39999286,-3.9998495,-3.999893)"><path
d="M 86.674,33.332 H 66.66 V 13.327 c -11.106,-4.604 -23.04,-4.265 -33.334,0 v 20.005 h -20 c -4.603,11.107 -4.264,23.039 0,33.336 h 20 v 20.007 c 11.107,4.603 23.041,4.264 33.334,0 V 66.668 h 20.014 c 4.602,-11.11 4.264,-23.043 0,-33.336 z M 33.326,56.668 v 3.333 H 18.053 c -1.863,-6.563 -1.863,-13.445 0,-20.002 h 31.94 v -6.667 h -10 V 18.055 c 3.255,-0.922 6.614,-1.389 10.02,-1.389 3.391,0 6.732,0.466 9.98,1.387 v 25.28 c 0,1.841 -1.494,3.333 -3.333,3.333 H 43.327 c -5.521,0.001 -10.001,4.478 -10.001,10.002 z m 48.62,3.333 H 49.994 v 6.667 h 10 v 15.279 c -3.255,0.921 -6.611,1.387 -10.019,1.387 -3.389,0 -6.732,-0.466 -9.98,-1.387 V 56.668 c 0,-1.844 1.493,-3.334 3.333,-3.334 H 56.66 c 5.521,0 10,-4.476 10,-10 v -3.335 h 15.286 c 1.863,6.561 1.863,13.442 0,20.002 z"
id="path2" /><circle
cx="48.326"
cy="25"
r="3.3329999"
id="circle4" /><circle
cx="51.659"
cy="75"
r="3.3329999"
id="circle6" /></g></svg>

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
x="0px"
y="0px"
viewBox="0 0 24 24"
xml:space="preserve"
id="svg12"
width="24"
height="24"><metadata
id="metadata18"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs16" /><g
id="g23"
transform="matrix(0.24590164,0,0,0.24590164,-0.3442623,-0.19672131)"><path
d="m 50.2,22.7 c -8,0 -14.6,6.5 -14.6,14.6 0,2.1 1.7,3.7 3.7,3.7 2,0 3.7,-1.7 3.7,-3.7 0,-3.9 3.2,-7.1 7.1,-7.1 4.1,0 7.1,2.9 7.1,6.8 0,0 0,0.1 0,0.3 0,2.2 -0.6,7.4 -7.7,8.5 -1.8,0.3 -3.2,1.8 -3.2,3.7 v 10.1 c 0,2.1 1.7,3.7 3.7,3.7 2,0 3.7,-1.7 3.7,-3.7 V 52.5 C 63.1,49.6 64.6,41.5 64.6,37 64.8,29 58.2,22.7 50.2,22.7 Z"
id="path2" /><path
d="m 50.2,67.8 c -2.7,0 -4.8,2.2 -4.8,4.8 0,2.6 2.2,4.8 4.8,4.8 2.6,0 4.8,-2.2 4.8,-4.8 0,-2.6 -2.2,-4.8 -4.8,-4.8 z"
id="path4" /><path
d="M 50.2,0.8 C 23.3,0.8 1.4,22.7 1.4,49.6 1.4,76.5 23.3,98.4 50.2,98.4 77.1,98.4 99,76.5 99,49.6 99,22.7 77.1,0.8 50.2,0.8 Z m 0,90.2 C 27.4,91 8.8,72.4 8.8,49.6 8.8,26.8 27.4,8.2 50.2,8.2 73,8.2 91.6,26.8 91.6,49.6 91.5,72.4 73,91 50.2,91 Z"
id="path6" /></g></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

41
source/images/search.svg Normal file
View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
x="0px"
y="0px"
viewBox="0 0 32 32"
xml:space="preserve"
id="svg18"
width="32"
height="32"><metadata
id="metadata24"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs22" /><style
type="text/css"
id="style2">
.st0{fill:none;}
</style><g
id="g31"
transform="matrix(1.0666667,0,0,1.0666667,-1.0666667,-1.0666667)"><path
class="st0"
d="m 18.1,13.3 c -0.8,-0.8 -1.8,-1.2 -2.8,-1.2 -1,0 -2,0.4 -2.8,1.2 -0.8,0.8 -1.2,1.8 -1.2,2.8 0,1 0.4,2.1 1.2,2.8 1.5,1.5 4.1,1.5 5.7,0 1.5,-1.5 1.5,-4 -0.1,-5.6 z"
id="path4" /><rect
x="3"
y="3"
class="st0"
width="26"
height="2"
id="rect6" /><path
class="st0"
d="M 3,7 V 29 H 29 V 7 Z M 24.1,26.3 18.8,21 c -1,0.7 -2.2,1.1 -3.5,1.1 -1.6,0 -3.1,-0.6 -4.2,-1.8 -1.1,-1.1 -1.8,-2.6 -1.8,-4.2 0,-1.6 0.6,-3.1 1.8,-4.2 2.3,-2.3 6.1,-2.3 8.5,0 2.1,2.1 2.3,5.4 0.6,7.7 l 5.3,5.3 z"
id="path8" /><path
d="M 1,1 V 31 H 31 V 1 Z M 29,3 V 5 H 3 V 3 Z M 3,29 V 7 h 26 v 22 z"
id="path10" /><path
d="M 19.5,11.9 C 17.2,9.6 13.4,9.6 11,11.9 9.9,13 9.2,14.5 9.2,16.1 c 0,1.6 0.6,3.1 1.8,4.2 1.1,1.1 2.6,1.8 4.2,1.8 1.3,0 2.5,-0.4 3.5,-1.1 l 5.3,5.3 1.4,-1.4 -5.3,-5.3 c 1.7,-2.3 1.5,-5.6 -0.6,-7.7 z m -7,7.1 c -0.8,-0.8 -1.2,-1.8 -1.2,-2.8 0,-1 0.4,-2.1 1.2,-2.8 0.8,-0.8 1.8,-1.2 2.8,-1.2 1,0 2,0.4 2.8,1.2 1.6,1.6 1.6,4.1 0,5.7 -1.5,1.4 -4.1,1.4 -5.6,-0.1 z"
id="path12" /></g></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

48
source/images/shell.svg Normal file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
x="0px"
y="0px"
viewBox="0 0 32 32"
enable-background="new 0 0 100 100"
xml:space="preserve"
id="svg14"
width="32"
height="32"><metadata
id="metadata20"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs18"><rect
x="394.24149"
y="162.41183"
width="82.899773"
height="54.685486"
id="rect30" /></defs><g
id="g45"
transform="matrix(0.41720991,0,0,0.41720991,-124.39114,-55.888818)"><g
id="g26"
transform="translate(285.95002,122.75851)"><path
fill-rule="evenodd"
clip-rule="evenodd"
d="m 28.7,60.4 c -0.7,-0.7 -0.7,-2 0,-2.7 l 8.6,-8.6 c 0.7,-0.7 2,-0.7 2.7,0 0.7,0.7 0.7,2 0,2.7 l -8.6,8.6 c -0.7,0.7 -2,0.7 -2.7,0 z"
id="path2" /><path
fill-rule="evenodd"
clip-rule="evenodd"
d="m 37.3,51.8 -8.6,-8.6 c -0.7,-0.7 -0.7,-2 0,-2.7 0.7,-0.7 2,-0.7 2.7,0 l 8.6,8.6 c 0.7,0.7 0.7,2 0,2.7 -0.7,0.7 -2,0.7 -2.7,0 z"
id="path4" /><path
fill-rule="evenodd"
clip-rule="evenodd"
d="m 47.3,59.1 c 0,-1.1 0.9,-1.9 1.9,-1.9 h 12.1 c 1.1,0 1.9,0.9 1.9,1.9 0,1 -0.8,1.9 -1.8,1.9 H 49.2 c -1,0 -1.9,-0.9 -1.9,-1.9 z"
id="path6" /><path
fill-rule="evenodd"
clip-rule="evenodd"
d="M 85.6,11.2 H 15.4 c -1.8,0 -3.2,1.4 -3.2,3.2 v 70.3 c 0,1.8 1.4,3.2 3.2,3.2 h 70.3 c 1.8,0 3.2,-1.4 3.2,-3.2 V 14.4 c -0.1,-1.8 -1.5,-3.2 -3.3,-3.2 z m -63.8,6.4 c 1.8,0 3.2,1.4 3.2,3.2 0,1.8 -1.4,3.2 -3.2,3.2 -1.8,0 -3.2,-1.4 -3.2,-3.2 0,-1.8 1.4,-3.2 3.2,-3.2 z m 60.6,62.2 c 0,0.9 -0.7,1.6 -1.6,1.6 H 20.2 c -0.9,0 -1.6,-0.7 -1.6,-1.6 V 31.9 c 0,-0.9 0.7,-1.6 1.6,-1.6 h 60.7 c 0.9,0 1.6,0.7 1.6,1.6 v 47.9 z"
id="path8" /></g><text
xml:space="preserve"
id="text28"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;white-space:pre;shape-inside:url(#rect30);fill:#000000;fill-opacity:1;stroke:none;" /></g></svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xml:space="preserve"
version="1.1"
style="image-rendering:optimizeQuality;shape-rendering:geometricPrecision;text-rendering:geometricPrecision"
viewBox="0 0 31.999998 31.999998"
x="0px"
y="0px"
fill-rule="evenodd"
clip-rule="evenodd"
id="svg16"
width="31.999998"
height="31.999998"
sodipodi:docname="uninstall.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1280"
inkscape:window-height="1006"
id="namedview10"
showgrid="false"
inkscape:zoom="18.185904"
inkscape:cx="27.610641"
inkscape:cy="13.076849"
inkscape:window-x="0"
inkscape:window-y="37"
inkscape:window-maximized="0"
inkscape:current-layer="svg16" /><metadata
id="metadata20"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs4"><style
type="text/css"
id="style2">
.fil0 {fill:black}
</style></defs><g
id="g60"><path
class="fil0"
d="m 8.1744545,0 c 5.1838005,0 10.3676005,0 15.5514015,0 4.585669,0 8.274143,3.6884734 8.274143,8.1744545 0,5.1838005 0,10.3676005 0,15.5514015 0,4.585669 -3.688474,8.274143 -8.274143,8.274143 -5.183801,0 -10.367601,0 -15.5514015,0 C 3.6884734,31.999999 0,28.311525 0,23.725856 0,18.542055 0,13.358255 0,8.1744545 0,3.6884734 3.6884734,0 8.1744545,0 Z m 0,1.5950155 c 5.1838005,0 10.3676005,0 15.5514015,0 3.688473,0 6.579439,2.9906541 6.579439,6.579439 0,5.1838005 0,10.3676005 0,15.5514015 0,3.688473 -2.890966,6.579439 -6.579439,6.579439 -5.183801,0 -10.367601,0 -15.5514015,0 -3.5887849,0 -6.579439,-2.890966 -6.579439,-6.579439 0,-5.183801 0,-10.367601 0,-15.5514015 0,-3.5887849 2.9906541,-6.579439 6.579439,-6.579439 z"
id="path8"
style="stroke-width:0.0996885" /><path
d="m 20.649194,18.722386 -4.364368,-0.02503 -4.656282,0.02503 H 5.1357003 v 6.317436 H 27.142038 V 18.722386 Z M 7.7990149,22.739084 c -0.5042916,0 -0.9140306,-0.383946 -0.9140306,-0.859467 0,-0.472546 0.409739,-0.856493 0.9140306,-0.856493 0.5074655,0 0.9172048,0.383947 0.9172048,0.856493 0,0.475521 -0.4097393,0.859467 -0.9172048,0.859467 z m 2.8713681,0 c -0.504311,0 -0.91405,-0.383946 -0.91405,-0.859467 0,-0.472546 0.409739,-0.856493 0.91405,-0.856493 0.504291,0 0.914031,0.383947 0.914031,0.856493 0,0.475521 -0.40974,0.859467 -0.914031,0.859467 z"
id="path2"
style="stroke-width:0.305105"
sodipodi:nodetypes="ccccccccssssssssss" /><polygon
points="49.619995,12.970001 40.380005,12.970001 40.380005,49.730011 30.359985,40.320038 30.359985,49.329987 45,63.070038 59.640015,49.329987 59.640015,40.320038 49.619995,49.730011 "
id="polygon4"
transform="matrix(-0.31518698,0,0,-0.27401538,30.322283,21.402123)" /></g></svg>

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
source/images/zazpip.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,555 @@
#!/usr/bin/env python3
import easymacro as app
ID_EXTENSION = ''
_ = None
TITLE = 'ZAZ-PIP'
URL_PIP = 'https://bootstrap.pypa.io/get-pip.py'
PIP = 'pip'
URL_GIT = 'https://git.elmau.net/elmau'
ICON_OK = 'ok.svg'
ICON_QUESTION = 'question.svg'
PACKAGES = {
'cffi': ICON_OK,
'cryptography': ICON_OK,
'httpx': ICON_OK,
'lxml': ICON_OK,
'numpy': ICON_OK,
'pandas': ICON_OK,
'psycopg2-binary': ICON_OK,
'peewee': ICON_OK,
'pillow': ICON_OK,
'pytesseract': ICON_OK,
'sounddevice': ICON_OK,
}
def open_dialog_pip():
dialog = _create_dialog()
dialog.open()
return
def run(args, path_locales):
global _
_ = app.install_locales(path_locales)
globals()[args]()
return
class Controllers(object):
OK1 = 'Successfully installed'
OK2 = 'Requirement already'
OK3 = 'Successfully uninstalled'
def __init__(self, dialog):
self.d = dialog
self.path_python = app.paths.python
def _set_state(self, state):
self._states = {
'list': False,
'install': False,
'search': False,
'versions': False,
}
self._states[state] = True
return
def cmd_install_pip_action(self, event):
msg = _('Do you want install PIP?')
if not app.question(msg, TITLE):
return
self._install_pip()
return
@app.run_in_thread
def _install_pip(self):
self.d.link_proyect.visible = False
self.d.lst_log.visible = True
path_pip = app.paths.tmp()
self.d.lst_log.insert(_('Download PIP...'))
data, h, err = app.url_open(URL_PIP, verify=False)
if err:
msg = _('Do you have internet connection?')
app.errorbox('{}\n\n{}'.format(msg, err))
return
app.paths.save_bin(path_pip, data)
if not app.paths.exists(path_pip):
msg = _('File PIP not save')
app.errorbox(msg)
return
self.d.lst_log.insert(_('PIP save correctly...'))
try:
self.d.lst_log.insert(_('Start installing PIP...'))
cmd = f'"{self.path_python}" "{path_pip}" --user'
for line in app.popen(cmd):
if isinstance(line, tuple):
app.errorbox(line)
break
self.d.lst_log.insert(line)
cmd = self._cmd_pip('-V')
label = app.run(cmd, True)
if label:
self.d.lbl_pip.value = label
self.d.cmd_install_pip.visible = False
self.d.cmd_admin_pip.visible = True
msg = _('PIP installed sucesfully')
app.msgbox(msg)
else:
msg = _('PIP not installed, see log')
app.warning(msg)
except Exception as e:
app.errorbox(e)
return
def _cmd_pip(self, args):
cmd = '"{}" -m pip {}'.format(self.path_python, args)
return cmd
def cmd_admin_pip_action(self, event):
self.d.lst_log.ps_from(self.d.lst_package)
self.d.lst_log.step = 1
self.d.step = 1
self.cmd_home_action(None)
return
def cmd_close_action(self, event):
self.d.close()
return
def cmd_home_action(self, event):
self.d.txt_search.value = ''
self._list()
return
def txt_search_key_released(self, event):
if event.KeyCode == app.KEY['enter']:
self.cmd_search_action(None)
return
if not self.d.txt_search.value.strip():
self.cmd_home_action(None)
return
@app.run_in_thread
def _list(self):
self._set_state('list')
self.d.lst_log.visible = False
self.d.lst_package.visible = True
cmd = self._cmd_pip(' list --format=json')
self.d.lst_package.clear()
result = app.run(cmd, True)
packages = app.json_loads(result)
for p in packages:
t = '{} - ({})'.format(p['name'], p['version'])
self.d.lst_package.insert(t, ICON_OK)
self.d.lst_package.select()
self.d.txt_search.set_focus()
return
@app.run_in_thread
def _search(self, value):
self._set_state('search')
line = ''
cmd = self._cmd_pip(' search {}'.format(value))
self.d.lst_package.clear()
for line in app.popen(cmd):
parts = line.split(')')
name = parts[0].strip() + ')'
description = parts[-1].strip()
parts = name.split('(')
name_verify = parts[0].strip()
package = '{} {}'.format(name, description)
image = PACKAGES.get(name_verify, ICON_QUESTION)
self.d.lst_package.insert(package, image)
if line:
self.d.lst_package.select()
else:
self.d.lst_package.insert(_('Not found...'), 'error.png', show=False)
return
def cmd_search_action(self, event):
search = self.d.txt_search.value.strip()
if not search:
self.d.txt_search.set_focus()
return
self._search(search)
return
def cmd_install_action(self, event):
name = self.d.txt_search.value.strip()
if not name:
msg = _('Enter package name to install')
app.warning(msg)
self.d.txt_search.set_focus()
return
msg = _(f'Install package: {name} ?')
if not app.question(msg):
return
self._install(name)
return
@app.run_in_thread
def _install(self, value: str='', path: str=''):
self._set_state('install')
self.d.lst_package.visible = False
self.d.lst_log.visible = True
line = ''
cmd = ' install --upgrade --user'
if value:
name = value.split(' ')[0].strip()
cmd = self._cmd_pip(f'{cmd} {name}')
else:
cmd = self._cmd_pip(f'{cmd} -r "{path}"')
self.d.lst_log.clear()
for line in app.popen(cmd):
if self.OK1 in line or self.OK2 in line:
self.d.lst_log.insert(line, 'ok.png')
else:
self.d.lst_log.insert(line)
return
def lst_package_double_click(self, event):
opt = 'install'
if self._states['list']:
opt = 'upgrade'
name = self.d.lst_package.value
msg = _('Do you want {}:\n\n{} ?').format(opt, name)
if not app.question(msg, TITLE):
return
self._install(name)
return
@app.run_in_thread
def _uninstall(self, value):
self._set_state('install')
self.d.lst_package.visible = False
self.d.lst_log.visible = True
line = ''
name = value.split(' ')[0].strip()
cmd = self._cmd_pip(' uninstall -y {}'.format(name))
self.d.lst_log.clear()
for line in app.popen(cmd):
if self.OK3 in line:
self.d.lst_log.insert(line, 'ok.png')
else:
self.d.lst_log.insert(line)
return
def cmd_uninstall_action(self, event):
if not self._states['list']:
msg = _('Select installed package')
app.warning(msg)
return
name = self.d.lst_package.value
msg = _('Do you want uninstall:\n\n{} ?').format(name)
if not app.question(msg):
return
self._uninstall(name)
return
def cmd_shell_action(self, event):
if app.IS_WIN:
cmd = '"{}"'.format(self.path_python)
app.paths.open(cmd)
else:
cmd = 'exec "{}"'
if app.IS_MAC:
cmd = 'open "{}"'
elif app.DESKTOP == 'gnome':
cmd = 'gnome-terminal -- {}'
cmd = cmd.format(self.path_python)
app.run(cmd)
return
def cmd_explore_action(self, event):
path = app.paths.get_file(filters='txt')
if not path:
return
msg = _(f'Confirm install from:\n\n{path}')
if not app.question(msg):
return
self._install(path=path)
return
def _create_dialog():
BUTTON_WH = 20
args= {
'Name': 'dialog',
'Title': 'Zaz-Pip',
'Width': 200,
'Height': 220,
}
dialog = app.create_dialog(args)
dialog.id = ID_EXTENSION
dialog.events = Controllers
lbl_title = '{} {} - {}'.format(app.NAME, app.VERSION, app.OS)
args = {
'Type': 'Label',
'Name': 'lbl_title',
'Label': lbl_title,
'Width': 100,
'Height': 15,
'Border': 1,
'Align': 1,
'VerticalAlign': 1,
'Step': 10,
'FontHeight': 12,
}
dialog.add_control(args)
dialog.center(dialog.lbl_title, y=5)
path_python = app.paths.python
cmd = '"{}" -V'.format(path_python)
label = app.run(cmd, True)
args = {
'Type': 'Label',
'Name': 'lbl_python',
'Label': str(label),
'Width': 100,
'Height': 15,
'Border': 1,
'Align': 1,
'VerticalAlign': 1,
'Step': 10,
'FontHeight': 11,
}
dialog.add_control(args)
dialog.center(dialog.lbl_python, y=25)
cmd = '"{}" -m pip -V'.format(path_python)
label = app.run(cmd, True)
exists_pip = True
if not label:
exists_pip = False
label = _('PIP not installed')
args = {
'Type': 'Label',
'Name': 'lbl_pip',
'Label': label,
'Width': 160,
'Height': 30,
'Border': 1,
'Align': 1,
'VerticalAlign': 1,
'Step': 10,
'MultiLine': True,
}
dialog.add_control(args)
dialog.center(dialog.lbl_pip, y=45)
args = {
'Type': 'Button',
'Name': 'cmd_admin_pip',
'Label': _('Admin PIP'),
'Width': 70,
'Height': BUTTON_WH,
'Step': 10,
'ImageURL': 'python.svg',
'ImagePosition': 1,
}
dialog.add_control(args)
dialog.center(dialog.cmd_admin_pip, y=80)
args = {
'Type': 'Button',
'Name': 'cmd_install_pip',
'Label': _('Install PIP'),
'Width': 60,
'Height': BUTTON_WH,
'Step': 10,
'ImageURL': 'install.svg',
'ImagePosition': 1,
}
dialog.add_control(args)
dialog.center(dialog.cmd_install_pip, y=80)
args = {
'Type': 'Link',
'Name': 'link_proyect',
'URL': URL_GIT,
'Label': URL_GIT,
'Border': 1,
'Width': 130,
'Height': 15,
'Align': 1,
'VerticalAlign': 1,
'Step': 10,
}
dialog.add_control(args)
dialog.center(dialog.link_proyect, y=-5)
args = {
'Type': 'Listbox',
'Name': 'lst_log',
'Width': 160,
'Height': 105,
'Step': 10,
}
dialog.add_control(args)
dialog.center(dialog.lst_log, y=105)
args = {
'Type': 'Label',
'Name': 'lbl_package',
'Label': _('Packages'),
'Width': 100,
'Height': 15,
'Border': 1,
'Align': 1,
'VerticalAlign': 1,
'Step': 1,
}
lbl = dialog.add_control(args)
args = {
'Type': 'Text',
'Name': 'txt_search',
'Width': 165,
'Height': 12,
'Step': 1,
'Border': 0,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_explore',
'Label': '...',
'Width': 12,
'Height': 12,
'Step': 1,
}
dialog.add_control(args)
args = {
'Type': 'Listbox',
'Name': 'lst_package',
'Width': 180,
'Height': 128,
'Step': 1,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_close',
'Label': _('~Close'),
'Width': 70,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'close.svg',
'ImagePosition': 1,
}
dialog.add_control(args)
dialog.center(dialog.cmd_close, y=-5)
args = {
'Type': 'Button',
'Name': 'cmd_home',
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'home.svg',
'FocusOnClick': False,
'Y': 2,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_search',
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'search.svg',
'FocusOnClick': False,
'Enabled': False,
'Y': 2,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_uninstall',
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'uninstall.svg',
'FocusOnClick': False,
'Y': 2,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_install',
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'install.svg',
'FocusOnClick': False,
'Y': 2,
}
dialog.add_control(args)
args = {
'Type': 'Button',
'Name': 'cmd_shell',
'Width': BUTTON_WH,
'Height': BUTTON_WH,
'Step': 1,
'ImageURL': 'shell.svg',
'FocusOnClick': False,
'Y': 2,
}
dialog.add_control(args)
controls = (dialog.cmd_home, dialog.cmd_search,
dialog.cmd_install, dialog.cmd_uninstall, dialog.cmd_shell)
dialog.lbl_package.move(dialog.cmd_home)
dialog.txt_search.move(dialog.lbl_package)
dialog.cmd_explore.move(dialog.txt_search, x=0, y=0)
dialog.lst_package.move(dialog.txt_search)
dialog.lbl_package.center()
dialog.lst_package.center()
dialog.txt_search.center()
dialog.center(controls)
dialog.center((dialog.txt_search, dialog.cmd_explore))
dialog.step = 10
dialog.cmd_install_pip.visible = not exists_pip
dialog.cmd_admin_pip.visible = exists_pip
dialog.lst_log.visible = False
return dialog

79
zaz.py Normal file → Executable file
View File

@ -4,6 +4,8 @@
# ~ This file is part of ZAZ.
# ~ https://git.elmau.net/elmau/zaz
# ~ ZAZ 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
@ -19,6 +21,7 @@
import argparse
import os
import py_compile
import re
import sys
import zipfile
@ -43,6 +46,10 @@ from conf import (
log)
EASYMACRO_TMP = 'easymacro2.py'
EASYMACRO = 'easymacro.py'
class LiboXML(object):
CONTEXT = {
'calc': 'com.sun.star.sheet.SpreadsheetDocument',
@ -55,6 +62,7 @@ class LiboXML(object):
}
TYPES = {
'py': 'application/vnd.sun.star.uno-component;type=Python',
'pyc': 'application/binary',
'zip': 'application/binary',
'xcu': 'application/vnd.sun.star.configuration-data',
'rdb': 'application/vnd.sun.star.uno-typelibrary;type=RDB',
@ -121,8 +129,8 @@ class LiboXML(object):
def parse_manifest(self, data):
ET.register_namespace('manifest', self.NS_MANIFEST['manifest'])
self._manifest = ET.fromstring(data)
data = {'xmlns:loext': self.NS_MANIFEST['xmlns:loext']}
self._manifest.attrib.update(**data)
attr = {'xmlns:loext': self.NS_MANIFEST['xmlns:loext']}
self._manifest.attrib.update(**attr)
self._clean('manifest', self._manifest)
return
@ -547,7 +555,7 @@ def _update_files():
copyfile(source, target)
if FILES['easymacro']:
source = 'easymacro.py'
source = EASYMACRO
target = _join(path_source, 'pythonpath', source)
copyfile(source, target)
@ -593,7 +601,7 @@ def _update_files():
return
def _new():
def _create():
if not _validate_new():
return
@ -615,7 +623,7 @@ def _get_info_path(path):
def _zip_embed(source, files):
PATH = 'Scripts/python/'
EASYMACRO = 'easymacro.'
FILE_PYC = 'easymacro.pyc'
p, f, name, e = _get_info_path(source)
now = datetime.now().strftime('_%Y%m%d_%H%M%S')
@ -623,12 +631,10 @@ def _zip_embed(source, files):
copyfile(source, path_source)
target = source
with zipfile.PyZipFile(EASYMACRO + 'zip', mode='w') as zf:
zf.writepy(EASYMACRO + 'py')
py_compile.compile(EASYMACRO, FILE_PYC)
xml = LiboXML()
path_easymacro = PATH + EASYMACRO + 'zip'
path_easymacro = PATH + FILE_PYC
names = [f[1] for f in files] + [path_easymacro]
nodes = []
with zipfile.ZipFile(target, 'w', compression=zipfile.ZIP_DEFLATED) as zt:
@ -647,14 +653,14 @@ def _zip_embed(source, files):
data.append(name)
zt.write(path, name)
zt.write(EASYMACRO + 'zip', path_easymacro)
zt.write(FILE_PYC, path_easymacro)
data.append(path_easymacro)
xml.parse_manifest(xml_manifest)
xml_manifest = xml.add_data_manifest(data)
zt.writestr(path_manifest, xml_manifest)
os.unlink(EASYMACRO + 'zip')
os.unlink(FILE_PYC)
return
@ -692,8 +698,6 @@ def _embed(args):
def _locales(args):
EASYMACRO = 'easymacro.py'
if args.files:
files = args.files.split(',')
else:
@ -725,8 +729,39 @@ def _update():
return
def _new(args):
if not args.target:
msg = 'Add argument target: -t PATH_TARGET'
log.error(msg)
return
if not args.name:
msg = 'Add argument name: -n name-new-extension'
log.error(msg)
return
path = _join(args.target, args.name)
_mkdir(path)
_mkdir(_join(path, 'files'))
_mkdir(_join(path, 'images'))
path_logo = 'images/pymacros.png'
copyfile(path_logo, _join(path, 'images/logo.png'))
copyfile('zaz.py', _join(path, 'zaz.py'))
copyfile(EASYMACRO_TMP, _join(path, 'easymacro.py'))
copyfile('conf.py.example', _join(path, 'conf.py'))
msg = 'Folders and files copy successfully for new extension.'
log.info(msg)
msg = f'Change to folder: {path}'
log.info(msg)
return
def main(args):
if args.new:
_new(args)
return
if args.update:
_update()
return
@ -739,14 +774,16 @@ def main(args):
_embed(args)
return
if args.new:
_new()
if args.create:
_create()
return
if not _validate_update():
return
_update_files()
if not args.only_compress:
_update_files()
_compress_oxt()
if args.install:
@ -759,9 +796,13 @@ def main(args):
def _process_command_line_arguments():
parser = argparse.ArgumentParser(
description='Make LibreOffice extensions')
parser.add_argument('-i', '--install', dest='install', action='store_true',
parser.add_argument('-new', '--new', dest='new', action='store_true',
default=False, required=False)
parser.add_argument('-n', '--new', dest='new', action='store_true',
parser.add_argument('-t', '--target', dest='target', default='')
parser.add_argument('-n', '--name', dest='name', default='', required=False)
parser.add_argument('-c', '--create', dest='create', action='store_true',
default=False, required=False)
parser.add_argument('-i', '--install', dest='install', action='store_true',
default=False, required=False)
parser.add_argument('-e', '--embed', dest='embed', action='store_true',
default=False, required=False)
@ -771,6 +812,8 @@ def _process_command_line_arguments():
default=False, required=False)
parser.add_argument('-u', '--update', dest='update', action='store_true',
default=False, required=False)
parser.add_argument('-oc', '--only_compress', dest='only_compress',
action='store_true', default=False, required=False)
return parser.parse_args()