Add config proxy
This commit is contained in:
parent
4eb0b51a6d
commit
a49a1ad4d8
|
@ -1,4 +1,4 @@
|
|||
v 0.8.0 [06-jun-2021]
|
||||
v 0.8.0 [13-jun-2021]
|
||||
- Update easymacro.py
|
||||
- Add proxy config
|
||||
|
||||
|
|
72
easymacro.py
72
easymacro.py
|
@ -2881,6 +2881,23 @@ class LOCalcRange(object):
|
|||
self.obj.fillAuto(0, source)
|
||||
return
|
||||
|
||||
def _cast(self, t, v):
|
||||
if not t:
|
||||
return v
|
||||
|
||||
if t == datetime.date:
|
||||
nv = datetime.date.fromordinal(int(v) + DATE_OFFSET)
|
||||
else:
|
||||
nv = t(v)
|
||||
return nv
|
||||
|
||||
def get_data(self, types):
|
||||
values = [
|
||||
[self._cast(types[i], v) for i, v in enumerate(row)]
|
||||
for row in self.data
|
||||
]
|
||||
return values
|
||||
|
||||
|
||||
class LOWriterStyles(object):
|
||||
|
||||
|
@ -3944,6 +3961,7 @@ class LODocs(object):
|
|||
return doc
|
||||
|
||||
def __len__(self):
|
||||
# ~ len(self._desktop.Components)
|
||||
for i, _ in enumerate(self._desktop.Components):
|
||||
pass
|
||||
return i + 1
|
||||
|
@ -4713,6 +4731,13 @@ class UnoText(UnoBaseObject):
|
|||
def value(self, value):
|
||||
self.model.Text = value
|
||||
|
||||
@property
|
||||
def echochar(self):
|
||||
return chr(self.model.EchoChar)
|
||||
@echochar.setter
|
||||
def echochar(self, value):
|
||||
self.model.EchoChar = ord(value[0])
|
||||
|
||||
def validate(self):
|
||||
return
|
||||
|
||||
|
@ -5553,6 +5578,11 @@ class LODialog(object):
|
|||
self.obj.dispose()
|
||||
return value
|
||||
|
||||
def set_values(self, data):
|
||||
for k, v in data.items():
|
||||
self._controls[k].value = v
|
||||
return
|
||||
|
||||
|
||||
class LOSheets(object):
|
||||
|
||||
|
@ -6645,48 +6675,6 @@ def get_fonts():
|
|||
return device.FontDescriptors
|
||||
|
||||
|
||||
# ~ From request
|
||||
# ~ https://github.com/psf/requests/blob/master/requests/structures.py#L15
|
||||
class CaseInsensitiveDict(MutableMapping):
|
||||
|
||||
def __init__(self, data=None, **kwargs):
|
||||
self._store = OrderedDict()
|
||||
if data is None:
|
||||
data = {}
|
||||
self.update(data, **kwargs)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
# Use the lowercased key for lookups, but store the actual
|
||||
# key alongside the value.
|
||||
self._store[key.lower()] = (key, value)
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._store[key.lower()][1]
|
||||
|
||||
def __delitem__(self, key):
|
||||
del self._store[key.lower()]
|
||||
|
||||
def __iter__(self):
|
||||
return (casedkey for casedkey, mappedvalue in self._store.values())
|
||||
|
||||
def __len__(self):
|
||||
return len(self._store)
|
||||
|
||||
def lower_items(self):
|
||||
"""Like iteritems(), but with all lowercase keys."""
|
||||
values = (
|
||||
(lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items()
|
||||
)
|
||||
return values
|
||||
|
||||
# Copy is required
|
||||
def copy(self):
|
||||
return CaseInsensitiveDict(self._store.values())
|
||||
|
||||
def __repr__(self):
|
||||
return str(dict(self.items()))
|
||||
|
||||
|
||||
# ~ https://en.wikipedia.org/wiki/Web_colors
|
||||
def get_color(value):
|
||||
COLORS = {
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
|||
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M9.17218 14.8284L12.0006 12M14.829 9.17157L12.0006 12M12.0006 12L9.17218 9.17157M12.0006 12L14.829 14.8284" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
After Width: | Height: | Size: 505 B |
|
@ -0,0 +1,8 @@
|
|||
<svg width="24" height="24" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M3 7.5V5C3 3.89543 3.89543 3 5 3H16.1716C16.702 3 17.2107 3.21071 17.5858 3.58579L20.4142 6.41421C20.7893 6.78929 21 7.29799 21 7.82843V19C21 20.1046 20.1046 21 19 21H5C3.89543 21 3 20.1046 3 19V16.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M6 21V17" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M18 21V13.6C18 13.2686 17.7314 13 17.4 13H15" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M16 3V8.4C16 8.73137 15.7314 9 15.4 9H13.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M8 3V6" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M1 12H12M12 12L9 9M12 12L9 15" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
After Width: | Height: | Size: 942 B |
|
@ -2881,6 +2881,23 @@ class LOCalcRange(object):
|
|||
self.obj.fillAuto(0, source)
|
||||
return
|
||||
|
||||
def _cast(self, t, v):
|
||||
if not t:
|
||||
return v
|
||||
|
||||
if t == datetime.date:
|
||||
nv = datetime.date.fromordinal(int(v) + DATE_OFFSET)
|
||||
else:
|
||||
nv = t(v)
|
||||
return nv
|
||||
|
||||
def get_data(self, types):
|
||||
values = [
|
||||
[self._cast(types[i], v) for i, v in enumerate(row)]
|
||||
for row in self.data
|
||||
]
|
||||
return values
|
||||
|
||||
|
||||
class LOWriterStyles(object):
|
||||
|
||||
|
@ -3944,6 +3961,7 @@ class LODocs(object):
|
|||
return doc
|
||||
|
||||
def __len__(self):
|
||||
# ~ len(self._desktop.Components)
|
||||
for i, _ in enumerate(self._desktop.Components):
|
||||
pass
|
||||
return i + 1
|
||||
|
@ -4713,6 +4731,13 @@ class UnoText(UnoBaseObject):
|
|||
def value(self, value):
|
||||
self.model.Text = value
|
||||
|
||||
@property
|
||||
def echochar(self):
|
||||
return chr(self.model.EchoChar)
|
||||
@echochar.setter
|
||||
def echochar(self, value):
|
||||
self.model.EchoChar = ord(value[0])
|
||||
|
||||
def validate(self):
|
||||
return
|
||||
|
||||
|
@ -5553,6 +5578,11 @@ class LODialog(object):
|
|||
self.obj.dispose()
|
||||
return value
|
||||
|
||||
def set_values(self, data):
|
||||
for k, v in data.items():
|
||||
self._controls[k].value = v
|
||||
return
|
||||
|
||||
|
||||
class LOSheets(object):
|
||||
|
||||
|
@ -6645,48 +6675,6 @@ def get_fonts():
|
|||
return device.FontDescriptors
|
||||
|
||||
|
||||
# ~ From request
|
||||
# ~ https://github.com/psf/requests/blob/master/requests/structures.py#L15
|
||||
class CaseInsensitiveDict(MutableMapping):
|
||||
|
||||
def __init__(self, data=None, **kwargs):
|
||||
self._store = OrderedDict()
|
||||
if data is None:
|
||||
data = {}
|
||||
self.update(data, **kwargs)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
# Use the lowercased key for lookups, but store the actual
|
||||
# key alongside the value.
|
||||
self._store[key.lower()] = (key, value)
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._store[key.lower()][1]
|
||||
|
||||
def __delitem__(self, key):
|
||||
del self._store[key.lower()]
|
||||
|
||||
def __iter__(self):
|
||||
return (casedkey for casedkey, mappedvalue in self._store.values())
|
||||
|
||||
def __len__(self):
|
||||
return len(self._store)
|
||||
|
||||
def lower_items(self):
|
||||
"""Like iteritems(), but with all lowercase keys."""
|
||||
values = (
|
||||
(lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items()
|
||||
)
|
||||
return values
|
||||
|
||||
# Copy is required
|
||||
def copy(self):
|
||||
return CaseInsensitiveDict(self._store.values())
|
||||
|
||||
def __repr__(self):
|
||||
return str(dict(self.items()))
|
||||
|
||||
|
||||
# ~ https://en.wikipedia.org/wiki/Web_colors
|
||||
def get_color(value):
|
||||
COLORS = {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import easymacro as app
|
||||
|
||||
|
||||
|
@ -32,6 +33,17 @@ PACKAGES = {
|
|||
|
||||
def open_dialog_pip():
|
||||
dialog = _create_dialog()
|
||||
|
||||
proxy = app.get_config('proxy', {}, TITLE)
|
||||
if proxy:
|
||||
app.debug(proxy)
|
||||
HOST = proxy['txt_proxy_host']
|
||||
PORT = proxy['txt_proxy_port']
|
||||
USER = proxy['txt_proxy_user']
|
||||
PASS = proxy['txt_proxy_pass']
|
||||
os.environ['http_proxy'] = f'http://{USER}:{PASS}@{HOST}:{PORT}'
|
||||
os.environ['https_proxy'] = f'http://{USER}:{PASS}@{HOST}:{PORT}'
|
||||
|
||||
dialog.open()
|
||||
return
|
||||
|
||||
|
@ -300,7 +312,46 @@ class Controllers(object):
|
|||
return
|
||||
|
||||
def cmd_proxy_action(self, event):
|
||||
app.msgbox('Config Proxy')
|
||||
dialog = _create_dialog_proxy()
|
||||
data = app.get_config('proxy', {}, TITLE)
|
||||
dialog.set_values(data)
|
||||
dialog.open()
|
||||
return
|
||||
|
||||
|
||||
class ControllersProxy(object):
|
||||
|
||||
def __init__(self, dialog):
|
||||
self.d = dialog
|
||||
|
||||
def cmd_proxy_save_action(self, event):
|
||||
data = dict(
|
||||
txt_proxy_host = self.d.txt_proxy_host.value,
|
||||
txt_proxy_port = self.d.txt_proxy_port.value,
|
||||
txt_proxy_user = self.d.txt_proxy_user.value,
|
||||
txt_proxy_pass = self.d.txt_proxy_pass.value,
|
||||
)
|
||||
msg = _('Are you shure save data?')
|
||||
if not app.question(msg):
|
||||
return
|
||||
|
||||
app.set_config('proxy', data, TITLE)
|
||||
|
||||
msg = _('Save data sucesfully')
|
||||
app.msgbox(msg)
|
||||
self.d.close()
|
||||
return
|
||||
|
||||
def cmd_proxy_delete_action(self, event):
|
||||
msg = _("Are you shure delete data?")
|
||||
if not app.question(msg):
|
||||
return
|
||||
|
||||
app.set_config('proxy', {}, TITLE)
|
||||
|
||||
msg = _('Delete data sucesfully')
|
||||
app.msgbox(msg)
|
||||
self.d.close()
|
||||
return
|
||||
|
||||
|
||||
|
@ -573,3 +624,141 @@ def _create_dialog():
|
|||
dialog.lst_log.visible = False
|
||||
|
||||
return dialog
|
||||
|
||||
|
||||
def _create_dialog_proxy():
|
||||
args= {
|
||||
'Name': 'dlg_proxy',
|
||||
'Title': 'Zaz-Pip - Config Proxy',
|
||||
'Width': 150,
|
||||
'Height': 100,
|
||||
}
|
||||
dialog = app.create_dialog(args)
|
||||
dialog.id = ID_EXTENSION
|
||||
dialog.events = ControllersProxy
|
||||
|
||||
args = {
|
||||
'Type': 'Label',
|
||||
'Name': 'lbl_proxy_host',
|
||||
'Label': 'Host: ',
|
||||
'Width': 40,
|
||||
'Height': 12,
|
||||
'Border': 1,
|
||||
'Align': 2,
|
||||
'VerticalAlign': 1,
|
||||
'X': 5,
|
||||
'Y': 5,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
args = {
|
||||
'Type': 'Text',
|
||||
'Name': 'txt_proxy_host',
|
||||
'Width': 95,
|
||||
'Height': 12,
|
||||
'Border': 0,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
args = {
|
||||
'Type': 'Label',
|
||||
'Name': 'lbl_proxy_port',
|
||||
'Label': 'Port: ',
|
||||
'Width': 40,
|
||||
'Height': 12,
|
||||
'Border': 1,
|
||||
'Align': 2,
|
||||
'VerticalAlign': 1,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
args = {
|
||||
'Type': 'Text',
|
||||
'Name': 'txt_proxy_port',
|
||||
'Width': 95,
|
||||
'Height': 12,
|
||||
'Border': 0,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
args = {
|
||||
'Type': 'Label',
|
||||
'Name': 'lbl_proxy_user',
|
||||
'Label': 'User: ',
|
||||
'Width': 40,
|
||||
'Height': 12,
|
||||
'Border': 1,
|
||||
'Align': 2,
|
||||
'VerticalAlign': 1,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
args = {
|
||||
'Type': 'Text',
|
||||
'Name': 'txt_proxy_user',
|
||||
'Width': 95,
|
||||
'Height': 12,
|
||||
'Border': 0,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
args = {
|
||||
'Type': 'Label',
|
||||
'Name': 'lbl_proxy_pass',
|
||||
'Label': 'Password: ',
|
||||
'Width': 40,
|
||||
'Height': 12,
|
||||
'Border': 1,
|
||||
'Align': 2,
|
||||
'VerticalAlign': 1,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
args = {
|
||||
'Type': 'Text',
|
||||
'Name': 'txt_proxy_pass',
|
||||
'Width': 95,
|
||||
'Height': 12,
|
||||
'Border': 0,
|
||||
}
|
||||
txt = dialog.add_control(args)
|
||||
txt.echochar = '*'
|
||||
|
||||
args = {
|
||||
'Type': 'Button',
|
||||
'Name': 'cmd_proxy_save',
|
||||
'Label': _('Save'),
|
||||
'Width': 50,
|
||||
'Height': 15,
|
||||
'ImageURL': 'save.svg',
|
||||
'ImagePosition': 1,
|
||||
'FocusOnClick': False,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
args = {
|
||||
'Type': 'Button',
|
||||
'Name': 'cmd_proxy_delete',
|
||||
'Label': _('Delete'),
|
||||
'Width': 50,
|
||||
'Height': 15,
|
||||
'ImageURL': 'delete.svg',
|
||||
'ImagePosition': 1,
|
||||
'FocusOnClick': False,
|
||||
}
|
||||
dialog.add_control(args)
|
||||
|
||||
dialog.txt_proxy_host.move(dialog.lbl_proxy_host, x=5, y=0)
|
||||
dialog.lbl_proxy_port.move(dialog.lbl_proxy_host)
|
||||
dialog.txt_proxy_port.move(dialog.lbl_proxy_port, x=5, y=0)
|
||||
dialog.lbl_proxy_user.move(dialog.lbl_proxy_port)
|
||||
dialog.txt_proxy_user.move(dialog.lbl_proxy_user, x=5, y=0)
|
||||
dialog.lbl_proxy_pass.move(dialog.lbl_proxy_user)
|
||||
dialog.txt_proxy_pass.move(dialog.lbl_proxy_pass, x=5, y=0)
|
||||
|
||||
dialog.cmd_proxy_save.move(dialog.lbl_proxy_pass, y=10)
|
||||
dialog.cmd_proxy_delete.move(dialog.lbl_proxy_pass, y=10)
|
||||
controls = (dialog.cmd_proxy_save, dialog.cmd_proxy_delete)
|
||||
dialog.center(controls)
|
||||
|
||||
return dialog
|
||||
|
|
Loading…
Reference in New Issue