Create DB Firebird
This commit is contained in:
parent
74a781044c
commit
12c6c5deaf
|
@ -1,6 +1,61 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from .easydoc import LODocument
|
from .easydoc import LODocument
|
||||||
|
from .easymain import BaseObject
|
||||||
|
|
||||||
|
|
||||||
|
class LOBaseSource(BaseObject):
|
||||||
|
_type = 'Base Source'
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self._type}:'
|
||||||
|
|
||||||
|
|
||||||
|
# ~ main_form = frm_container.component.getDrawPage.getforms.getbyindex(0)
|
||||||
|
class LOBaseForm(BaseObject):
|
||||||
|
_type = 'Base Form'
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self._type}: {self.name}'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self.obj.Name
|
||||||
|
|
||||||
|
def open(self):
|
||||||
|
self.obj.open()
|
||||||
|
return
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
return self.obj.close()
|
||||||
|
|
||||||
|
|
||||||
|
class LOBaseForms(BaseObject):
|
||||||
|
_type = 'Base Forms'
|
||||||
|
|
||||||
|
def __init__(self, obj):
|
||||||
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'Base Forms'
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
"""Count forms"""
|
||||||
|
return self.obj.Count
|
||||||
|
|
||||||
|
def __contains__(self, item):
|
||||||
|
"""Contains"""
|
||||||
|
return item in self.obj
|
||||||
|
|
||||||
|
def __getitem__(self, index):
|
||||||
|
"""Index access"""
|
||||||
|
return LOBaseForm(self.obj[index])
|
||||||
|
|
||||||
|
|
||||||
class LOBase(LODocument):
|
class LOBase(LODocument):
|
||||||
|
@ -8,3 +63,10 @@ class LOBase(LODocument):
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
super().__init__(obj)
|
super().__init__(obj)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'Base: {self.title}'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def forms(self):
|
||||||
|
return LOBaseForms(self.obj.FormDocuments)
|
|
@ -7,7 +7,7 @@ from .easywriter import LOWriter
|
||||||
from .easydraw import LODraw
|
from .easydraw import LODraw
|
||||||
from .easyimpress import LOImpress
|
from .easyimpress import LOImpress
|
||||||
from .easymath import LOMath
|
from .easymath import LOMath
|
||||||
from .easybase import LOBase
|
from .easybase import LOBase, LOBaseSource
|
||||||
from .easyide import LOBasicIDE
|
from .easyide import LOBasicIDE
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,9 +85,6 @@ class LODocuments():
|
||||||
return self._classes[main](doc)
|
return self._classes[main](doc)
|
||||||
|
|
||||||
mm = create_instance('com.sun.star.frame.ModuleManager')
|
mm = create_instance('com.sun.star.frame.ModuleManager')
|
||||||
# ~ ??
|
|
||||||
# ~ print(mm.supportsService('com.sun.star.frame.ModuleManager'))
|
|
||||||
|
|
||||||
type_module = mm.identify(doc)
|
type_module = mm.identify(doc)
|
||||||
return self._classes[type_module](doc)
|
return self._classes[type_module](doc)
|
||||||
|
|
||||||
|
@ -98,6 +95,32 @@ class LODocuments():
|
||||||
obj = self._get_class_doc(active)
|
obj = self._get_class_doc(active)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
def is_registered(self, name):
|
||||||
|
dbc = create_instance('com.sun.star.sdb.DatabaseContext')
|
||||||
|
return dbc.hasRegisteredDatabase(name)
|
||||||
|
|
||||||
|
def _new_db(self, args: dict):
|
||||||
|
FIREBIRD = 'sdbc:embedded:firebird'
|
||||||
|
|
||||||
|
path = Paths(args.pop('Path'))
|
||||||
|
register = args.pop('Register', True)
|
||||||
|
name = args.pop('Name', '')
|
||||||
|
open_db = args.pop('Open', False)
|
||||||
|
if register and not name:
|
||||||
|
name = path.name
|
||||||
|
|
||||||
|
dbc = create_instance('com.sun.star.sdb.DatabaseContext')
|
||||||
|
db = dbc.createInstance()
|
||||||
|
db.URL = FIREBIRD
|
||||||
|
db.DatabaseDocument.storeAsURL(path.url, ())
|
||||||
|
if register:
|
||||||
|
dbc.registerDatabaseLocation(name, path.url)
|
||||||
|
|
||||||
|
if open_db:
|
||||||
|
return self.open(path.url, args)
|
||||||
|
|
||||||
|
return LOBaseSource(db)
|
||||||
|
|
||||||
def new(self, type_doc: str='calc', args: dict={}):
|
def new(self, type_doc: str='calc', args: dict={}):
|
||||||
"""Create new document
|
"""Create new document
|
||||||
|
|
||||||
|
@ -108,6 +131,9 @@ class LODocuments():
|
||||||
:return: New document
|
:return: New document
|
||||||
:rtype: Custom class
|
:rtype: Custom class
|
||||||
"""
|
"""
|
||||||
|
if type_doc == 'base':
|
||||||
|
return self._new_db(args)
|
||||||
|
|
||||||
url = f'private:factory/s{type_doc}'
|
url = f'private:factory/s{type_doc}'
|
||||||
opt = dict_to_property(args)
|
opt = dict_to_property(args)
|
||||||
doc = self._desktop.loadComponentFromURL(url, '_default', 0, opt)
|
doc = self._desktop.loadComponentFromURL(url, '_default', 0, opt)
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue