Clean some functions
This commit is contained in:
parent
fed6a01a51
commit
bb3a3c8bf7
356
source/diff.py
356
source/diff.py
|
@ -3645,77 +3645,6 @@ class LOWindow(object):
|
||||||
# ~ def __getattr__(name):
|
# ~ def __getattr__(name):
|
||||||
|
|
||||||
|
|
||||||
def _get_class_doc(obj):
|
|
||||||
classes = {
|
|
||||||
'calc': LOCalc,
|
|
||||||
'writer': LOWriter,
|
|
||||||
'base': LOBase,
|
|
||||||
'impress': LOImpress,
|
|
||||||
'draw': LODraw,
|
|
||||||
'math': LOMath,
|
|
||||||
'basic': LOBasicIde,
|
|
||||||
}
|
|
||||||
type_doc = get_type_doc(obj)
|
|
||||||
return classes[type_doc](obj)
|
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
|
||||||
def get_document(title=''):
|
|
||||||
doc = None
|
|
||||||
desktop = get_desktop()
|
|
||||||
if not title:
|
|
||||||
doc = _get_class_doc(desktop.getCurrentComponent())
|
|
||||||
return doc
|
|
||||||
|
|
||||||
for d in desktop.getComponents():
|
|
||||||
if hasattr(d, 'Title') and d.Title == title:
|
|
||||||
doc = d
|
|
||||||
break
|
|
||||||
|
|
||||||
if doc is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
return _get_class_doc(doc)
|
|
||||||
|
|
||||||
|
|
||||||
def get_documents(custom=True):
|
|
||||||
docs = []
|
|
||||||
desktop = get_desktop()
|
|
||||||
for doc in desktop.getComponents():
|
|
||||||
if custom:
|
|
||||||
docs.append(_get_class_doc(doc))
|
|
||||||
else:
|
|
||||||
docs.append(doc)
|
|
||||||
return docs
|
|
||||||
|
|
||||||
|
|
||||||
def get_selection():
|
|
||||||
return get_document().selection
|
|
||||||
|
|
||||||
|
|
||||||
def get_cell(*args):
|
|
||||||
if args:
|
|
||||||
index = args
|
|
||||||
if len(index) == 1:
|
|
||||||
index = args[0]
|
|
||||||
cell = get_document().get_cell(index)
|
|
||||||
else:
|
|
||||||
cell = get_selection().first
|
|
||||||
return cell
|
|
||||||
|
|
||||||
|
|
||||||
def active_cell():
|
|
||||||
return get_cell()
|
|
||||||
|
|
||||||
|
|
||||||
def active_sheet():
|
|
||||||
return get_document().active
|
|
||||||
|
|
||||||
|
|
||||||
def create_dialog(properties):
|
|
||||||
return LODialog(**properties)
|
|
||||||
|
|
||||||
|
|
||||||
def create_window(kwargs):
|
def create_window(kwargs):
|
||||||
return LOWindow(**kwargs)
|
return LOWindow(**kwargs)
|
||||||
|
|
||||||
|
@ -3978,19 +3907,6 @@ def merge_zip(target, zips):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
|
||||||
def kill(path):
|
|
||||||
p = Path(path)
|
|
||||||
try:
|
|
||||||
if p.is_file():
|
|
||||||
p.unlink()
|
|
||||||
elif p.is_dir():
|
|
||||||
shutil.rmtree(path)
|
|
||||||
except OSError as e:
|
|
||||||
log.error(e)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def get_size_screen():
|
def get_size_screen():
|
||||||
if IS_WIN:
|
if IS_WIN:
|
||||||
user32 = ctypes.windll.user32
|
user32 = ctypes.windll.user32
|
||||||
|
@ -4071,18 +3987,6 @@ def get_epoch():
|
||||||
return int(time.mktime(n.timetuple()))
|
return int(time.mktime(n.timetuple()))
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
|
||||||
def file_copy(source, target='', name=''):
|
|
||||||
p, f, n, e = get_info_path(source)
|
|
||||||
if target:
|
|
||||||
p = target
|
|
||||||
if name:
|
|
||||||
e = ''
|
|
||||||
n = name
|
|
||||||
path_new = join(p, '{}{}'.format(n, e))
|
|
||||||
shutil.copy(source, path_new)
|
|
||||||
return path_new
|
|
||||||
|
|
||||||
|
|
||||||
def _get_menu(type_doc, name_menu):
|
def _get_menu(type_doc, name_menu):
|
||||||
instance = 'com.sun.star.ui.ModuleUIConfigurationManagerSupplier'
|
instance = 'com.sun.star.ui.ModuleUIConfigurationManagerSupplier'
|
||||||
|
@ -4236,179 +4140,6 @@ def end():
|
||||||
return str(e - _start).split('.')[0]
|
return str(e - _start).split('.')[0]
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
|
||||||
# ~ https://en.wikipedia.org/wiki/Web_colors
|
|
||||||
def get_color(*value):
|
|
||||||
if len(value) == 1 and isinstance(value[0], int):
|
|
||||||
return value[0]
|
|
||||||
if len(value) == 1 and isinstance(value[0], tuple):
|
|
||||||
value = value[0]
|
|
||||||
|
|
||||||
COLORS = {
|
|
||||||
'aliceblue': 15792383,
|
|
||||||
'antiquewhite': 16444375,
|
|
||||||
'aqua': 65535,
|
|
||||||
'aquamarine': 8388564,
|
|
||||||
'azure': 15794175,
|
|
||||||
'beige': 16119260,
|
|
||||||
'bisque': 16770244,
|
|
||||||
'black': 0,
|
|
||||||
'blanchedalmond': 16772045,
|
|
||||||
'blue': 255,
|
|
||||||
'blueviolet': 9055202,
|
|
||||||
'brown': 10824234,
|
|
||||||
'burlywood': 14596231,
|
|
||||||
'cadetblue': 6266528,
|
|
||||||
'chartreuse': 8388352,
|
|
||||||
'chocolate': 13789470,
|
|
||||||
'coral': 16744272,
|
|
||||||
'cornflowerblue': 6591981,
|
|
||||||
'cornsilk': 16775388,
|
|
||||||
'crimson': 14423100,
|
|
||||||
'cyan': 65535,
|
|
||||||
'darkblue': 139,
|
|
||||||
'darkcyan': 35723,
|
|
||||||
'darkgoldenrod': 12092939,
|
|
||||||
'darkgray': 11119017,
|
|
||||||
'darkgreen': 25600,
|
|
||||||
'darkgrey': 11119017,
|
|
||||||
'darkkhaki': 12433259,
|
|
||||||
'darkmagenta': 9109643,
|
|
||||||
'darkolivegreen': 5597999,
|
|
||||||
'darkorange': 16747520,
|
|
||||||
'darkorchid': 10040012,
|
|
||||||
'darkred': 9109504,
|
|
||||||
'darksalmon': 15308410,
|
|
||||||
'darkseagreen': 9419919,
|
|
||||||
'darkslateblue': 4734347,
|
|
||||||
'darkslategray': 3100495,
|
|
||||||
'darkslategrey': 3100495,
|
|
||||||
'darkturquoise': 52945,
|
|
||||||
'darkviolet': 9699539,
|
|
||||||
'deeppink': 16716947,
|
|
||||||
'deepskyblue': 49151,
|
|
||||||
'dimgray': 6908265,
|
|
||||||
'dimgrey': 6908265,
|
|
||||||
'dodgerblue': 2003199,
|
|
||||||
'firebrick': 11674146,
|
|
||||||
'floralwhite': 16775920,
|
|
||||||
'forestgreen': 2263842,
|
|
||||||
'fuchsia': 16711935,
|
|
||||||
'gainsboro': 14474460,
|
|
||||||
'ghostwhite': 16316671,
|
|
||||||
'gold': 16766720,
|
|
||||||
'goldenrod': 14329120,
|
|
||||||
'gray': 8421504,
|
|
||||||
'grey': 8421504,
|
|
||||||
'green': 32768,
|
|
||||||
'greenyellow': 11403055,
|
|
||||||
'honeydew': 15794160,
|
|
||||||
'hotpink': 16738740,
|
|
||||||
'indianred': 13458524,
|
|
||||||
'indigo': 4915330,
|
|
||||||
'ivory': 16777200,
|
|
||||||
'khaki': 15787660,
|
|
||||||
'lavender': 15132410,
|
|
||||||
'lavenderblush': 16773365,
|
|
||||||
'lawngreen': 8190976,
|
|
||||||
'lemonchiffon': 16775885,
|
|
||||||
'lightblue': 11393254,
|
|
||||||
'lightcoral': 15761536,
|
|
||||||
'lightcyan': 14745599,
|
|
||||||
'lightgoldenrodyellow': 16448210,
|
|
||||||
'lightgray': 13882323,
|
|
||||||
'lightgreen': 9498256,
|
|
||||||
'lightgrey': 13882323,
|
|
||||||
'lightpink': 16758465,
|
|
||||||
'lightsalmon': 16752762,
|
|
||||||
'lightseagreen': 2142890,
|
|
||||||
'lightskyblue': 8900346,
|
|
||||||
'lightslategray': 7833753,
|
|
||||||
'lightslategrey': 7833753,
|
|
||||||
'lightsteelblue': 11584734,
|
|
||||||
'lightyellow': 16777184,
|
|
||||||
'lime': 65280,
|
|
||||||
'limegreen': 3329330,
|
|
||||||
'linen': 16445670,
|
|
||||||
'magenta': 16711935,
|
|
||||||
'maroon': 8388608,
|
|
||||||
'mediumaquamarine': 6737322,
|
|
||||||
'mediumblue': 205,
|
|
||||||
'mediumorchid': 12211667,
|
|
||||||
'mediumpurple': 9662683,
|
|
||||||
'mediumseagreen': 3978097,
|
|
||||||
'mediumslateblue': 8087790,
|
|
||||||
'mediumspringgreen': 64154,
|
|
||||||
'mediumturquoise': 4772300,
|
|
||||||
'mediumvioletred': 13047173,
|
|
||||||
'midnightblue': 1644912,
|
|
||||||
'mintcream': 16121850,
|
|
||||||
'mistyrose': 16770273,
|
|
||||||
'moccasin': 16770229,
|
|
||||||
'navajowhite': 16768685,
|
|
||||||
'navy': 128,
|
|
||||||
'oldlace': 16643558,
|
|
||||||
'olive': 8421376,
|
|
||||||
'olivedrab': 7048739,
|
|
||||||
'orange': 16753920,
|
|
||||||
'orangered': 16729344,
|
|
||||||
'orchid': 14315734,
|
|
||||||
'palegoldenrod': 15657130,
|
|
||||||
'palegreen': 10025880,
|
|
||||||
'paleturquoise': 11529966,
|
|
||||||
'palevioletred': 14381203,
|
|
||||||
'papayawhip': 16773077,
|
|
||||||
'peachpuff': 16767673,
|
|
||||||
'peru': 13468991,
|
|
||||||
'pink': 16761035,
|
|
||||||
'plum': 14524637,
|
|
||||||
'powderblue': 11591910,
|
|
||||||
'purple': 8388736,
|
|
||||||
'red': 16711680,
|
|
||||||
'rosybrown': 12357519,
|
|
||||||
'royalblue': 4286945,
|
|
||||||
'saddlebrown': 9127187,
|
|
||||||
'salmon': 16416882,
|
|
||||||
'sandybrown': 16032864,
|
|
||||||
'seagreen': 3050327,
|
|
||||||
'seashell': 16774638,
|
|
||||||
'sienna': 10506797,
|
|
||||||
'silver': 12632256,
|
|
||||||
'skyblue': 8900331,
|
|
||||||
'slateblue': 6970061,
|
|
||||||
'slategray': 7372944,
|
|
||||||
'slategrey': 7372944,
|
|
||||||
'snow': 16775930,
|
|
||||||
'springgreen': 65407,
|
|
||||||
'steelblue': 4620980,
|
|
||||||
'tan': 13808780,
|
|
||||||
'teal': 32896,
|
|
||||||
'thistle': 14204888,
|
|
||||||
'tomato': 16737095,
|
|
||||||
'turquoise': 4251856,
|
|
||||||
'violet': 15631086,
|
|
||||||
'wheat': 16113331,
|
|
||||||
'white': 16777215,
|
|
||||||
'whitesmoke': 16119285,
|
|
||||||
'yellow': 16776960,
|
|
||||||
'yellowgreen': 10145074,
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(value) == 3:
|
|
||||||
color = (value[0] << 16) + (value[1] << 8) + value[2]
|
|
||||||
else:
|
|
||||||
value = value[0]
|
|
||||||
if value[0] == '#':
|
|
||||||
r, g, b = bytes.fromhex(value[1:])
|
|
||||||
color = (r << 16) + (g << 8) + b
|
|
||||||
else:
|
|
||||||
color = COLORS.get(value.lower(), -1)
|
|
||||||
return color
|
|
||||||
|
|
||||||
|
|
||||||
COLOR_ON_FOCUS = get_color('LightYellow')
|
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
# ~ Export ok
|
||||||
def render(template, data):
|
def render(template, data):
|
||||||
s = Template(template)
|
s = Template(template)
|
||||||
|
@ -4467,93 +4198,6 @@ def format(template, data):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _get_url_script(macro):
|
|
||||||
macro['language'] = macro.get('language', 'Python')
|
|
||||||
macro['location'] = macro.get('location', 'user')
|
|
||||||
data = macro.copy()
|
|
||||||
if data['language'] == 'Python':
|
|
||||||
data['module'] = '.py$'
|
|
||||||
elif data['language'] == 'Basic':
|
|
||||||
data['module'] = '.{}.'.format(macro['module'])
|
|
||||||
if macro['location'] == 'user':
|
|
||||||
data['location'] = 'application'
|
|
||||||
else:
|
|
||||||
data['module'] = '.'
|
|
||||||
|
|
||||||
url = 'vnd.sun.star.script:{library}{module}{name}?language={language}&location={location}'
|
|
||||||
path = url.format(**data)
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def _call_macro(macro):
|
|
||||||
#~ https://wiki.openoffice.org/wiki/Documentation/DevGuide/Scripting/Scripting_Framework_URI_Specification
|
|
||||||
name = 'com.sun.star.script.provider.MasterScriptProviderFactory'
|
|
||||||
factory = create_instance(name, False)
|
|
||||||
|
|
||||||
macro['language'] = macro.get('language', 'Python')
|
|
||||||
macro['location'] = macro.get('location', 'user')
|
|
||||||
data = macro.copy()
|
|
||||||
if data['language'] == 'Python':
|
|
||||||
data['module'] = '.py$'
|
|
||||||
elif data['language'] == 'Basic':
|
|
||||||
data['module'] = '.{}.'.format(macro['module'])
|
|
||||||
if macro['location'] == 'user':
|
|
||||||
data['location'] = 'application'
|
|
||||||
else:
|
|
||||||
data['module'] = '.'
|
|
||||||
|
|
||||||
args = macro.get('args', ())
|
|
||||||
url = 'vnd.sun.star.script:{library}{module}{name}?language={language}&location={location}'
|
|
||||||
path = url.format(**data)
|
|
||||||
|
|
||||||
script = factory.createScriptProvider('').getScript(path)
|
|
||||||
return script.invoke(args, None, None)[0]
|
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
|
||||||
def call_macro(macro):
|
|
||||||
in_thread = macro.pop('thread')
|
|
||||||
if in_thread:
|
|
||||||
t = threading.Thread(target=_call_macro, args=(macro,))
|
|
||||||
t.start()
|
|
||||||
return
|
|
||||||
|
|
||||||
return _call_macro(macro)
|
|
||||||
|
|
||||||
|
|
||||||
class TimerThread(threading.Thread):
|
|
||||||
|
|
||||||
def __init__(self, event, seconds, macro):
|
|
||||||
threading.Thread.__init__(self)
|
|
||||||
self.stopped = event
|
|
||||||
self.seconds = seconds
|
|
||||||
self.macro = macro
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
info('Timer started... {}'.format(self.macro['name']))
|
|
||||||
while not self.stopped.wait(self.seconds):
|
|
||||||
_call_macro(self.macro)
|
|
||||||
info('Timer stopped... {}'.format(self.macro['name']))
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
|
||||||
def timer(name, seconds, macro):
|
|
||||||
global _stop_thread
|
|
||||||
_stop_thread[name] = threading.Event()
|
|
||||||
thread = TimerThread(_stop_thread[name], seconds, macro)
|
|
||||||
thread.start()
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
# ~ Export ok
|
|
||||||
def stop_timer(name):
|
|
||||||
global _stop_thread
|
|
||||||
_stop_thread[name].set()
|
|
||||||
del _stop_thread[name]
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def _get_key(password):
|
def _get_key(password):
|
||||||
digest = hashlib.sha256(password.encode()).digest()
|
digest = hashlib.sha256(password.encode()).digest()
|
||||||
key = base64.urlsafe_b64encode(digest)
|
key = base64.urlsafe_b64encode(digest)
|
||||||
|
|
Loading…
Reference in New Issue