Add examples for calc, writer, base
This commit is contained in:
parent
ed7ad9e7d7
commit
72e175cdeb
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
rsync -ravz build/ elmau.net:/opt/www/doc/zaz/
|
|
@ -2,10 +2,99 @@
|
||||||
For Base
|
For Base
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
You need install ``peewee``
|
||||||
|
|
||||||
|
``pip install -U peewee``
|
||||||
|
|
||||||
Create table
|
Create table
|
||||||
^^^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
import easymacro as app
|
||||||
|
from peewee import *
|
||||||
|
|
||||||
|
database_proxy = DatabaseProxy()
|
||||||
|
|
||||||
|
class BaseModel(Model):
|
||||||
|
class Meta:
|
||||||
|
database = database_proxy
|
||||||
|
legacy_table_names = False
|
||||||
|
|
||||||
|
|
||||||
|
class Contacts(BaseModel):
|
||||||
|
id = IdentityField()
|
||||||
|
name = CharField()
|
||||||
|
born = app.BaseDateField(null=True)
|
||||||
|
|
||||||
|
|
||||||
def create_table():
|
def create_table():
|
||||||
|
path = '/home/mau/test.odb'
|
||||||
|
if app.paths.exists(path):
|
||||||
|
db = app.docs.connect(path)
|
||||||
|
else:
|
||||||
|
db = app.docs.new('base', {'path': path})
|
||||||
|
|
||||||
|
tables = [Contacts]
|
||||||
|
db.initialize(database_proxy, tables)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
Insert data
|
||||||
|
^^^^^^^^^^^
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
def base_insert_data():
|
||||||
|
path = '/home/mau/test.odb'
|
||||||
|
db = app.docs.connect(path)
|
||||||
|
db.initialize(database_proxy)
|
||||||
|
|
||||||
|
rows = (
|
||||||
|
dict(name = 'Ingrid Bergman', born=app.dates.date(2001, 1, 1)),
|
||||||
|
dict(name = 'Sofia Loren', born=app.dates.date(2002, 2, 2)),
|
||||||
|
dict(name = 'Kim Novak', born=app.dates.date(2003, 3, 3)),
|
||||||
|
dict(name = 'Jane Fonda', born=app.dates.date(2004, 4, 4)),
|
||||||
|
dict(name = 'Marion Cotillar', born=app.dates.date(2005, 5, 5)),
|
||||||
|
)
|
||||||
|
for row in rows:
|
||||||
|
Contactos.insert(**row).execute()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
Select data
|
||||||
|
^^^^^^^^^^^
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
def base_select_data():
|
||||||
|
path = '/home/mau/test.odb'
|
||||||
|
db = app.docs.connect(path)
|
||||||
|
db.initialize(database_proxy)
|
||||||
|
|
||||||
|
query = Contactos.select()
|
||||||
|
rows = db.get_query(query).tuples
|
||||||
|
for row in rows:
|
||||||
|
print(row)
|
||||||
|
|
||||||
|
rows = db.get_query(query).dicts
|
||||||
|
for row in rows:
|
||||||
|
print(row)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
You can get tuples or dict::
|
||||||
|
|
||||||
|
(1, 'Ingrid Bergman', datetime.date(2001, 1, 1))
|
||||||
|
(2, 'Sofia Loren', datetime.date(2002, 2, 2))
|
||||||
|
(3, 'Kim Novak', datetime.date(2003, 3, 3))
|
||||||
|
(4, 'Jane Fonda', datetime.date(2004, 4, 4))
|
||||||
|
(5, 'Marion Cotillar', datetime.date(2005, 5, 5))
|
||||||
|
|
||||||
|
{'id': 1, 'name': 'Ingrid Bergman', 'born': datetime.date(2001, 1, 1)}
|
||||||
|
{'id': 2, 'name': 'Sofia Loren', 'born': datetime.date(2002, 2, 2)}
|
||||||
|
{'id': 3, 'name': 'Kim Novak', 'born': datetime.date(2003, 3, 3)}
|
||||||
|
{'id': 4, 'name': 'Jane Fonda', 'born': datetime.date(2004, 4, 4)}
|
||||||
|
{'id': 5, 'name': 'Marion Cotillar', 'born': datetime.date(2005, 5, 5)}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,23 @@
|
||||||
|
|
||||||
Examples for Calc
|
For Calc
|
||||||
-----------------
|
--------
|
||||||
|
|
||||||
First
|
Data to cell
|
||||||
^^^^^^^^^^
|
^^^^^^^^^^^^
|
||||||
|
|
||||||
|
Automatic calculate size range.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
def _():
|
def calc_data_to_cell():
|
||||||
|
sheet = app.active_sheet
|
||||||
|
data = (
|
||||||
|
('Month', 'Total'),
|
||||||
|
('January', 100),
|
||||||
|
('February', 200),
|
||||||
|
('March', 300),
|
||||||
|
('April', 400),
|
||||||
|
('May', 500),
|
||||||
|
)
|
||||||
|
sheet['A1'].data = data
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
Examples for Draw
|
For Draw
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
Save image from clipboard
|
Save image from clipboard
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
|
|
||||||
Examples for Writer
|
For Writer
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
First
|
Set autostyle in table
|
||||||
^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
def _():
|
def writer_table_set_style():
|
||||||
|
doc = app.active
|
||||||
|
table = doc.tables[0]
|
||||||
|
table.style = 'Academic'
|
||||||
return
|
return
|
||||||
|
|
|
@ -3665,15 +3665,19 @@ class BaseRow:
|
||||||
|
|
||||||
class BaseQuery(object):
|
class BaseQuery(object):
|
||||||
PY_TYPES = {
|
PY_TYPES = {
|
||||||
'SQL_LONG': 'getLong',
|
'VARCHAR': 'getString',
|
||||||
'SQL_VARYING': 'getString',
|
'INTEGER': 'getLong',
|
||||||
'SQL_FLOAT': 'getFloat',
|
'DATE': 'getDate',
|
||||||
'SQL_BOOLEAN': 'getBoolean',
|
# ~ 'SQL_LONG': 'getLong',
|
||||||
'SQL_TYPE_DATE': 'getDate',
|
# ~ 'SQL_VARYING': 'getString',
|
||||||
'SQL_TYPE_TIME': 'getTime',
|
# ~ 'SQL_FLOAT': 'getFloat',
|
||||||
'SQL_TIMESTAMP': 'getTimestamp',
|
# ~ 'SQL_BOOLEAN': 'getBoolean',
|
||||||
|
# ~ 'SQL_TYPE_DATE': 'getDate',
|
||||||
|
# ~ 'SQL_TYPE_TIME': 'getTime',
|
||||||
|
# ~ 'SQL_TIMESTAMP': 'getTimestamp',
|
||||||
}
|
}
|
||||||
TYPES_DATE = ('SQL_TYPE_DATE', 'SQL_TYPE_TIME', 'SQL_TIMESTAMP')
|
# ~ TYPES_DATE = ('SQL_TYPE_DATE', 'SQL_TYPE_TIME', 'SQL_TIMESTAMP')
|
||||||
|
TYPES_DATE = ('DATE', 'SQL_TYPE_TIME', 'SQL_TIMESTAMP')
|
||||||
|
|
||||||
def __init__(self, query):
|
def __init__(self, query):
|
||||||
self._query = query
|
self._query = query
|
||||||
|
@ -3699,6 +3703,7 @@ class BaseQuery(object):
|
||||||
|
|
||||||
def _to_python(self, index):
|
def _to_python(self, index):
|
||||||
type_field = self._meta.getColumnTypeName(index)
|
type_field = self._meta.getColumnTypeName(index)
|
||||||
|
# ~ print('TF', type_field)
|
||||||
value = getattr(self._query, self.PY_TYPES[type_field])(index)
|
value = getattr(self._query, self.PY_TYPES[type_field])(index)
|
||||||
if type_field in self.TYPES_DATE:
|
if type_field in self.TYPES_DATE:
|
||||||
value = _struct_to_date(value)
|
value = _struct_to_date(value)
|
||||||
|
@ -3824,10 +3829,11 @@ class LOBase(object):
|
||||||
self._con.getTables().refresh()
|
self._con.getTables().refresh()
|
||||||
return
|
return
|
||||||
|
|
||||||
def initialize(self, database_proxy, tables):
|
def initialize(self, database_proxy, tables=[]):
|
||||||
db = FirebirdDatabase(self)
|
db = FirebirdDatabase(self)
|
||||||
database_proxy.initialize(db)
|
database_proxy.initialize(db)
|
||||||
db.create_tables(tables)
|
if tables:
|
||||||
|
db.create_tables(tables)
|
||||||
return
|
return
|
||||||
|
|
||||||
def _validate_sql(self, sql, params):
|
def _validate_sql(self, sql, params):
|
||||||
|
@ -6482,6 +6488,14 @@ class Paths(object):
|
||||||
_P = Paths
|
_P = Paths
|
||||||
|
|
||||||
|
|
||||||
|
class Dates(object):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def date(cls, year, month, day):
|
||||||
|
d = datetime.date(year, month, day)
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
class SpellChecker(object):
|
class SpellChecker(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -6543,6 +6557,8 @@ def __getattr__(name):
|
||||||
return LOShortCuts()
|
return LOShortCuts()
|
||||||
if name == 'clipboard':
|
if name == 'clipboard':
|
||||||
return ClipBoard
|
return ClipBoard
|
||||||
|
if name == 'dates':
|
||||||
|
return Dates
|
||||||
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue