zaz/doc/source/main/tools.rst

347 lines
4.9 KiB
ReStructuredText

Tools
-----
Remember, always import library.
.. code-block:: python
import easymacro as app
Info from PC
^^^^^^^^^^^^
* Operate system
.. code-block:: python
app.msgbox(app.OS)
* Current user
.. code-block:: python
app.msgbox(app.USER)
* Name PC
.. code-block:: python
app.msgbox(app.PC)
* Name desktop, only GNU/Linux
.. code-block:: python
app.msgbox(app.DESKTOP)
* Language
.. code-block:: python
app.msgbox(app.LANG)
* Language with variant
.. code-block:: python
app.msgbox(app.LANGUAGE)
* Application name
.. code-block:: python
app.msgbox(app.NAME)
* Application version
.. code-block:: python
app.msgbox(app.VERSION)
* In Windows
.. code-block:: python
app.msgbox(app.IS_WIN)
* In Mac
.. code-block:: python
app.msgbox(app.IS_MAC)
Message Box
^^^^^^^^^^^
.. code-block:: python
app.msgbox(app.IS_WIN, 'My Macro')
Show warning
^^^^^^^^^^^^
.. code-block:: python
message = 'Caution, this action is dangerous'
title = 'My App'
app.warning(message, title)
Show error box
^^^^^^^^^^^^^^
.. code-block:: python
message = 'ERROR: Contact technical support'
title = 'My App'
app.errorbox(message, title)
Make question
^^^^^^^^^^^^^
.. code-block:: python
message = 'Is easy Python?'
title = 'My App'
result = app.question(message, title)
app.msgbox(result)
InputBox
^^^^^^^^
* Normal data
.. code-block:: python
message = 'Type your name'
default = ''
title = 'My App'
result = app.inputbox(message, default, title)
app.msgbox(result)
* Private data
.. code-block:: python
message = 'Type your password'
default = ''
title = 'My App'
echochar = "*"
result = app.inputbox(message, default, title, echochar)
app.msgbox(result)
Paths and files
^^^^^^^^^^^^^^^
* Get info path
.. code-block:: python
path = '/home/mau/myfile.ods'
p = app.paths(path)
app.debug(p.path)
app.debug(p.file_name)
app.debug(p.name)
app.debug(p.ext)
app.debug(p.url)
Or get information in a tuple
.. code-block:: python
path = '/home/mau/myfile.ods'
p = app.paths(path)
app.debug(p.info)
* Get path home
.. code-block:: python
path = app.paths.home
app.debug(path)
* Get path documents
.. code-block:: python
path = app.paths.documents
app.debug(path)
* Get path temp
.. code-block:: python
path = app.paths.temp_dir
app.debug(path)
Date and times
^^^^^^^^^^^^^^
* Get today
.. code-block:: python
app.msgbox(app.today())
* Get now
.. code-block:: python
app.msgbox(app.now())
* Get now only time
.. code-block:: python
app.msgbox(app.now(True))
Thread
^^^^^^
You can execute any macro in thread
* Normal execution
.. code-block:: python
def show_time(seconds):
app.sleep(seconds)
app.msgbox(app.NAME)
return
def main(args=None):
show_time(5)
app.msgbox('Finish...')
return
* Run in thread
.. code-block:: python
@app.run_in_thread
def show_time(seconds):
app.sleep(seconds)
app.msgbox(app.NAME)
return
def main(args=None):
show_time(5)
app.msgbox('Finish...')
return
Dictionary <-> properties
^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
args = {
'Hidden': True,
'Password': 'letmein',
}
properties = app.dict_to_property(args)
app.msgbox(properties)
data = app.data_to_dict(properties)
app.msgbox(data)
Tuples or lists to dictionary
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
tuple_of_tuples = (
('Hidden', True),
('Password', 'letmein'),
)
data = app.data_to_dict(tuple_of_tuples)
app.msgbox(data)
list_of_lists = [
['Hidden', True],
['Password', 'letmein'],
]
data = app.data_to_dict(list_of_lists)
app.msgbox(data)
Json
^^^^
.. code-block:: python
data = {
'Hidden': True,
'Password': 'letmein',
}
json = app.json_dumps(data)
app.msgbox(json)
data = app.json_loads(json)
app.msgbox(data)
Call Macros
^^^^^^^^^^^
You can any macro, for default call macros Python.
.. code-block:: python
def show_message():
app.msgbox(app.INFO_DEBUG)
return
def main(args=None):
args = {
'library': 'test',
'name': 'show_message',
}
app.call_macro(args)
return
Of course is better call directly if both macros are the same languaje, but, you can call macro in Basic too.
.. code-block:: vbnet
Sub show_message()
MsgBox "Basic from Python"
End Sub
Call from Python with.
.. code-block:: python
args = {
'language': 'Basic',
'library': 'Standard',
'module': 'Module1',
'name': 'show_message',
}
app.call_macro(args)
Execute macro in other thread
.. code-block:: python
app.call_macro(args, True)