Add support for ODBC
This commit is contained in:
parent
55df1aa1bc
commit
ac4aac9b89
|
@ -85,6 +85,7 @@ from com.sun.star.awt import XWindowListener
|
||||||
from com.sun.star.awt import XMenuListener
|
from com.sun.star.awt import XMenuListener
|
||||||
from com.sun.star.awt import XKeyListener
|
from com.sun.star.awt import XKeyListener
|
||||||
from com.sun.star.awt import XItemListener
|
from com.sun.star.awt import XItemListener
|
||||||
|
from com.sun.star.awt import XFocusListener
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -570,10 +571,10 @@ class LODocument(object):
|
||||||
|
|
||||||
def _init_values(self):
|
def _init_values(self):
|
||||||
self._type_doc = get_type_doc(self.obj)
|
self._type_doc = get_type_doc(self.obj)
|
||||||
if self._type_doc == 'base':
|
# ~ if self._type_doc == 'base':
|
||||||
self._cc = self.obj.DatabaseDocument.getCurrentController()
|
# ~ self._cc = self.obj.DatabaseDocument.getCurrentController()
|
||||||
else:
|
# ~ else:
|
||||||
self._cc = self.obj.getCurrentController()
|
self._cc = self.obj.getCurrentController()
|
||||||
return
|
return
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -1158,6 +1159,10 @@ class LOWriter(LODocument):
|
||||||
def cursor(self):
|
def cursor(self):
|
||||||
return self.text.createTextCursor()
|
return self.text.createTextCursor()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def paragraphs(self):
|
||||||
|
return [LOTextRange(p) for p in self.text]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def selection(self):
|
def selection(self):
|
||||||
sel = self.obj.getCurrentSelection()
|
sel = self.obj.getCurrentSelection()
|
||||||
|
@ -1209,16 +1214,40 @@ class LOWriter(LODocument):
|
||||||
self.insert_content(cursor, image)
|
self.insert_content(cursor, image)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def go_start(self):
|
||||||
|
cursor = self._cc.getViewCursor()
|
||||||
|
cursor.gotoStart(False)
|
||||||
|
return cursor
|
||||||
|
|
||||||
|
def go_end(self):
|
||||||
|
cursor = self._cc.getViewCursor()
|
||||||
|
cursor.gotoEnd(False)
|
||||||
|
return cursor
|
||||||
|
|
||||||
|
def select(self, text):
|
||||||
|
self._cc.select(text)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
class LOTextRange(object):
|
class LOTextRange(object):
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
self._obj = obj
|
self._obj = obj
|
||||||
|
self._is_paragraph = self.obj.ImplementationName == 'SwXParagraph'
|
||||||
|
self._is_table = self.obj.ImplementationName == 'SwXTextTable'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def obj(self):
|
def obj(self):
|
||||||
return self._obj
|
return self._obj
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_paragraph(self):
|
||||||
|
return self._is_paragraph
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_table(self):
|
||||||
|
return self._is_table
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def string(self):
|
def string(self):
|
||||||
return self.obj.String
|
return self.obj.String
|
||||||
|
@ -1232,7 +1261,7 @@ class LOTextRange(object):
|
||||||
return self.text.createTextCursorByRange(self.obj)
|
return self.text.createTextCursorByRange(self.obj)
|
||||||
|
|
||||||
|
|
||||||
class LOBase(LODocument):
|
class LOBase(object):
|
||||||
TYPES = {
|
TYPES = {
|
||||||
str: 'setString',
|
str: 'setString',
|
||||||
int: 'setInt',
|
int: 'setInt',
|
||||||
|
@ -1267,13 +1296,33 @@ class LOBase(LODocument):
|
||||||
if not self.exists:
|
if not self.exists:
|
||||||
self._dbc.registerDatabaseLocation(name, path_url)
|
self._dbc.registerDatabaseLocation(name, path_url)
|
||||||
else:
|
else:
|
||||||
db = self._dbc.getByName(name)
|
if name.startswith('odbc:'):
|
||||||
self.path = _path_system(self._dbc.getDatabaseLocation(name))
|
self._con = self._odbc(name, kwargs)
|
||||||
super().__init__(db)
|
else:
|
||||||
self._con = db.getConnection('', '')
|
db = self._dbc.getByName(name)
|
||||||
msg = 'Connected to: {}'.format(name)
|
self.path = _path_system(self._dbc.getDatabaseLocation(name))
|
||||||
|
self._con = db.getConnection('', '')
|
||||||
|
|
||||||
|
if self._con is None:
|
||||||
|
msg = 'Not connected to: {}'.format(name)
|
||||||
|
else:
|
||||||
|
msg = 'Connected to: {}'.format(name)
|
||||||
debug(msg)
|
debug(msg)
|
||||||
|
|
||||||
|
def _odbc(self, name, kwargs):
|
||||||
|
dm = create_instance('com.sun.star.sdbc.DriverManager')
|
||||||
|
args = dict_to_property(kwargs)
|
||||||
|
try:
|
||||||
|
con = dm.getConnectionWithInfo('sdbc:{}'.format(name), args)
|
||||||
|
return con
|
||||||
|
except Exception as e:
|
||||||
|
error(str(e))
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def obj(self):
|
||||||
|
return self._obj
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._name
|
return self._name
|
||||||
|
@ -1299,6 +1348,10 @@ class LOBase(LODocument):
|
||||||
self._dbc.registerDatabaseLocation(name, _path_url(path))
|
self._dbc.registerDatabaseLocation(name, _path_url(path))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def revoke(self, name):
|
||||||
|
self._dbc.revokeDatabaseLocation(name)
|
||||||
|
return True
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
# ~ self._db.connection.commit()
|
# ~ self._db.connection.commit()
|
||||||
# ~ self._db.connection.getTables().refresh()
|
# ~ self._db.connection.getTables().refresh()
|
||||||
|
@ -1337,8 +1390,8 @@ class LOBase(LODocument):
|
||||||
else:
|
else:
|
||||||
cursor = self._con.createStatement()
|
cursor = self._con.createStatement()
|
||||||
cursor.execute(sql)
|
cursor.execute(sql)
|
||||||
# ~ executeQuery
|
# ~ resulset = cursor.executeQuery(sql)
|
||||||
# ~ executeUpdate
|
# ~ rows = cursor.executeUpdate(sql)
|
||||||
self.save()
|
self.save()
|
||||||
return cursor
|
return cursor
|
||||||
|
|
||||||
|
@ -1639,6 +1692,17 @@ class LOCellRange(object):
|
||||||
img.setSize(Size(w, h))
|
img.setSize(Size(w, h))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def insert_shape(self, tipo, **kwargs):
|
||||||
|
s = self.obj.Size
|
||||||
|
w = kwargs.get('width', s.Width)
|
||||||
|
h = kwargs.get('Height', s.Height)
|
||||||
|
img = self.doc.create_instance('com.sun.star.drawing.{}Shape'.format(tipo))
|
||||||
|
set_properties(img, kwargs)
|
||||||
|
self.draw_page.add(img)
|
||||||
|
img.Anchor = self.obj
|
||||||
|
img.setSize(Size(w, h))
|
||||||
|
return
|
||||||
|
|
||||||
def select(self):
|
def select(self):
|
||||||
self.doc._cc.select(self.obj)
|
self.doc._cc.select(self.obj)
|
||||||
return
|
return
|
||||||
|
@ -1837,6 +1901,20 @@ class EventsItemRoadmap(EventsItem):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class EventsFocus(EventsListenerBase, XFocusListener):
|
||||||
|
|
||||||
|
def __init__(self, controller, name):
|
||||||
|
super().__init__(controller, name)
|
||||||
|
|
||||||
|
def focusGained(self, event):
|
||||||
|
obj = event.Source.Model
|
||||||
|
obj.BackgroundColor = COLOR_ON_FOCUS
|
||||||
|
|
||||||
|
def focusLost(self, event):
|
||||||
|
obj = event.Source.Model
|
||||||
|
obj.BackgroundColor = -1
|
||||||
|
|
||||||
|
|
||||||
class EventsKey(EventsListenerBase, XKeyListener):
|
class EventsKey(EventsListenerBase, XKeyListener):
|
||||||
"""
|
"""
|
||||||
event.KeyChar
|
event.KeyChar
|
||||||
|
@ -2044,6 +2122,13 @@ class UnoBaseObject(object):
|
||||||
def step(self, value):
|
def step(self, value):
|
||||||
self.model.Step = value
|
self.model.Step = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def back_color(self):
|
||||||
|
return self.model.BackgroundColor
|
||||||
|
@back_color.setter
|
||||||
|
def back_color(self, value):
|
||||||
|
self.model.BackgroundColor = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rules(self):
|
def rules(self):
|
||||||
return self._rules
|
return self._rules
|
||||||
|
@ -2301,6 +2386,10 @@ class UnoRoadmap(UnoBaseObject):
|
||||||
self.model.insertByIndex(i, opt)
|
self.model.insertByIndex(i, opt)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def set_enabled(self, index, value):
|
||||||
|
self.model.getByIndex(index).Enabled = value
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_custom_class(tipo, obj):
|
def get_custom_class(tipo, obj):
|
||||||
classes = {
|
classes = {
|
||||||
|
@ -2325,6 +2414,7 @@ def add_listeners(events, control, name=''):
|
||||||
'addActionListener': EventsButton,
|
'addActionListener': EventsButton,
|
||||||
'addMouseListener': EventsMouse,
|
'addMouseListener': EventsMouse,
|
||||||
'addItemListener': EventsItem,
|
'addItemListener': EventsItem,
|
||||||
|
'addFocusListener': EventsFocus,
|
||||||
}
|
}
|
||||||
if hasattr(control, 'obj'):
|
if hasattr(control, 'obj'):
|
||||||
control = contro.obj
|
control = contro.obj
|
||||||
|
@ -2795,6 +2885,7 @@ class LODialog(object):
|
||||||
self._model = self._obj.Model
|
self._model = self._obj.Model
|
||||||
self._init_controls()
|
self._init_controls()
|
||||||
self._events = None
|
self._events = None
|
||||||
|
self._color_on_focus = -1
|
||||||
return
|
return
|
||||||
|
|
||||||
def _create(self, properties):
|
def _create(self, properties):
|
||||||
|
@ -2833,6 +2924,7 @@ class LODialog(object):
|
||||||
'stardiv.Toolkit.UnoButtonControl': 'button',
|
'stardiv.Toolkit.UnoButtonControl': 'button',
|
||||||
'stardiv.Toolkit.UnoEditControl': 'text',
|
'stardiv.Toolkit.UnoEditControl': 'text',
|
||||||
'stardiv.Toolkit.UnoRoadmapControl': 'roadmap',
|
'stardiv.Toolkit.UnoRoadmapControl': 'roadmap',
|
||||||
|
'stardiv.Toolkit.UnoFixedHyperlinkControl': 'link',
|
||||||
}
|
}
|
||||||
return types[name]
|
return types[name]
|
||||||
|
|
||||||
|
@ -2859,6 +2951,15 @@ class LODialog(object):
|
||||||
def height(self, value):
|
def height(self, value):
|
||||||
self.model.Height = value
|
self.model.Height = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_on_focus(self):
|
||||||
|
return self._color_on_focus
|
||||||
|
@color_on_focus.setter
|
||||||
|
def color_on_focus(self, value):
|
||||||
|
global COLOR_ON_FOCUS
|
||||||
|
COLOR_ON_FOCUS = get_color(value)
|
||||||
|
self._color_on_focus = COLOR_ON_FOCUS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def step(self):
|
def step(self):
|
||||||
return self.model.Step
|
return self.model.Step
|
||||||
|
@ -2880,7 +2981,6 @@ class LODialog(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
# ~ self.model.Step = self.step
|
|
||||||
return self.obj.execute()
|
return self.obj.execute()
|
||||||
|
|
||||||
def close(self, value=0):
|
def close(self, value=0):
|
||||||
|
@ -3888,6 +3988,11 @@ def end():
|
||||||
# ~ Export ok
|
# ~ Export ok
|
||||||
# ~ https://en.wikipedia.org/wiki/Web_colors
|
# ~ https://en.wikipedia.org/wiki/Web_colors
|
||||||
def get_color(*value):
|
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 = {
|
COLORS = {
|
||||||
'aliceblue': 15792383,
|
'aliceblue': 15792383,
|
||||||
'antiquewhite': 16444375,
|
'antiquewhite': 16444375,
|
||||||
|
@ -4047,10 +4152,12 @@ def get_color(*value):
|
||||||
color = (r << 16) + (g << 8) + b
|
color = (r << 16) + (g << 8) + b
|
||||||
else:
|
else:
|
||||||
color = COLORS.get(value.lower(), -1)
|
color = COLORS.get(value.lower(), -1)
|
||||||
|
|
||||||
return color
|
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)
|
||||||
|
@ -4431,3 +4538,28 @@ class LIBOServer(object):
|
||||||
else:
|
else:
|
||||||
instance = self._sm.createInstance(name)
|
instance = self._sm.createInstance(name)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ~ controls = {
|
||||||
|
# ~ 'CheckBox': 'com.sun.star.awt.UnoControlCheckBoxModel',
|
||||||
|
# ~ 'ComboBox': 'com.sun.star.awt.UnoControlComboBoxModel',
|
||||||
|
# ~ 'CurrencyField': 'com.sun.star.awt.UnoControlCurrencyFieldModel',
|
||||||
|
# ~ 'DateField': 'com.sun.star.awt.UnoControlDateFieldModel',
|
||||||
|
# ~ 'FileControl': 'com.sun.star.awt.UnoControlFileControlModel',
|
||||||
|
# ~ 'FixedLine': 'com.sun.star.awt.UnoControlFixedLineModel',
|
||||||
|
# ~ 'FixedText': 'com.sun.star.awt.UnoControlFixedTextModel',
|
||||||
|
# ~ 'FormattedField': 'com.sun.star.awt.UnoControlFormattedFieldModel',
|
||||||
|
# ~ 'GroupBox': 'com.sun.star.awt.UnoControlGroupBoxModel',
|
||||||
|
# ~ 'ImageControl': 'com.sun.star.awt.UnoControlImageControlModel',
|
||||||
|
# ~ 'ListBox': 'com.sun.star.awt.UnoControlListBoxModel',
|
||||||
|
# ~ 'NumericField': 'com.sun.star.awt.UnoControlNumericFieldModel',
|
||||||
|
# ~ 'PatternField': 'com.sun.star.awt.UnoControlPatternFieldModel',
|
||||||
|
# ~ 'ProgressBar': 'com.sun.star.awt.UnoControlProgressBarModel',
|
||||||
|
# ~ 'ScrollBar': 'com.sun.star.awt.UnoControlScrollBarModel',
|
||||||
|
# ~ 'SimpleAnimation': 'com.sun.star.awt.UnoControlSimpleAnimationModel',
|
||||||
|
# ~ 'SpinButton': 'com.sun.star.awt.UnoControlSpinButtonModel',
|
||||||
|
# ~ 'Throbber': 'com.sun.star.awt.UnoControlThrobberModel',
|
||||||
|
# ~ 'TimeField': 'com.sun.star.awt.UnoControlTimeFieldModel',
|
||||||
|
# ~ }
|
||||||
|
|
Loading…
Reference in New Issue