[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/designer/src base/tools/DataSourceEditor.p...
From: |
Jason Cater |
Subject: |
gnue/designer/src base/tools/DataSourceEditor.p... |
Date: |
Wed, 04 Jun 2003 19:24:12 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Jason Cater <address@hidden> 03/06/04 19:24:12
Modified files:
designer/src/base/tools: DataSourceEditor.py SchemaNavigator.py
SchemaViewer.py
designer/src/forms/LayoutEditor: DisplayDropTarget.py
WidgetHandler.py
Log message:
mostly working drag-and-drop support for the schema navigator; several
typos/bug fixes
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/base/tools/DataSourceEditor.py.diff?tr1=1.36&tr2=1.37&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/base/tools/SchemaNavigator.py.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/base/tools/SchemaViewer.py.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/DisplayDropTarget.py.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/designer/src/forms/LayoutEditor/WidgetHandler.py.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
Patches:
Index: gnue/designer/src/base/tools/DataSourceEditor.py
diff -c gnue/designer/src/base/tools/DataSourceEditor.py:1.36
gnue/designer/src/base/tools/DataSourceEditor.py:1.37
*** gnue/designer/src/base/tools/DataSourceEditor.py:1.36 Fri May 23
20:02:31 2003
--- gnue/designer/src/base/tools/DataSourceEditor.py Wed Jun 4 19:24:12 2003
***************
*** 660,666 ****
"Label": label})
! do = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
do.SetData(cPickle.dumps(data,1))
dropSource = wxDropSource(self)
--- 660,666 ----
"Label": label})
! do = wxCustomDataObject(wxCustomDataFormat("application/x-gnue-designer"))
do.SetData(cPickle.dumps(data,1))
dropSource = wxDropSource(self)
Index: gnue/designer/src/base/tools/SchemaNavigator.py
diff -c gnue/designer/src/base/tools/SchemaNavigator.py:1.3
gnue/designer/src/base/tools/SchemaNavigator.py:1.4
*** gnue/designer/src/base/tools/SchemaNavigator.py:1.3 Mon Jun 2 19:33:26 2003
--- gnue/designer/src/base/tools/SchemaNavigator.py Wed Jun 4 19:24:12 2003
***************
*** 103,108 ****
--- 103,109 ----
self.expanded = 1
EVT_TREE_BEGIN_DRAG(self, self.tree.GetId(), self.OnBeginDrag)
EVT_TREE_BEGIN_RDRAG(self, self.tree.GetId(), self.OnBeginRDrag)
+ EVT_TREE_BEGIN_RDRAG(self, self.tree.GetId(), self.OnBeginRDrag)
for connection in self.connectionNames:
ConnectionNode(self, tree, root, connection=connection)
***************
*** 126,138 ****
return ""
def OnBeginDrag(self, event, right=0):
! do = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
#"application/x-gnue-designer-schema"))
do.SetData(cPickle.dumps(self.buildDataObject(right),1))
dropSource = wxDropSource(self)
dropSource.SetData(do)
result = dropSource.DoDragDrop(false)
- print "result=%s" % result
def OnBeginRDrag(self, event):
self.OnBeginDrag(event, right=1)
--- 127,138 ----
return ""
def OnBeginDrag(self, event, right=0):
! do =
wxCustomDataObject(wxCustomDataFormat("application/x-gnue-designer"))
#"application/x-gnue-designer-schema"))
do.SetData(cPickle.dumps(self.buildDataObject(right),1))
dropSource = wxDropSource(self)
dropSource.SetData(do)
result = dropSource.DoDragDrop(false)
def OnBeginRDrag(self, event):
self.OnBeginDrag(event, right=1)
***************
*** 144,153 ****
while not isinstance(parent, ConnectionNode):
parent = self.tree.GetPyData(self.tree.GetItemParent(parent.node))
! connection = parent.connection
! return { 'connection': connection,
! 'name': object.schema.name }
def __addField(self, object):
--- 144,156 ----
while not isinstance(parent, ConnectionNode):
parent = self.tree.GetPyData(self.tree.GetItemParent(parent.node))
! rs = {}
! for attr, val in object.schema.__dict__.items():
! if attr[0] != '_' and type(val) != types.MethodType:
! rs[attr] = val
! rs['connection'] = parent.connection
! return rs
def __addField(self, object):
***************
*** 188,194 ****
cookie = 0
child, cookie = self.tree.GetFirstChild(table.node, cookie)
while child.IsOk():
! fields.append(child)
child, cookie = self.tree.GetNextChild(table.node, cookie)
return [{'Type': 'SchemaDrop', 'Data': rs, 'ShowMenu': right}]
--- 191,197 ----
cookie = 0
child, cookie = self.tree.GetFirstChild(table.node, cookie)
while child.IsOk():
! fields.append(self.__addField(self.tree.GetPyData(child)))
child, cookie = self.tree.GetNextChild(table.node, cookie)
return [{'Type': 'SchemaDrop', 'Data': rs, 'ShowMenu': right}]
***************
*** 211,217 ****
node = self.GetPyData(parent)
if node and not node.expanded:
- node.expanded = 1
node.expand()
event.Skip()
--- 214,219 ----
***************
*** 262,272 ****
--- 264,278 ----
class ConnectionNode(Node):
def expand(self):
+ self.expanded = 1
connections = self.navigator.connections
dataObject = connections.getDataObject(self.connection, "object")
connections.requestConnection(dataObject, self.connection)
schemaTypes = dataObject.getSchemaTypes()
+ if not schemaTypes:
+ return
+
schemaTypes.sort()
for schema, name, keep in schemaTypes:
if keep:
***************
*** 292,299 ****
--- 298,308 ----
def getColumn(self, i=0):
return ""
def expand(self):
+ self.expanded = 1
tree = self.tree
schemas = self.dataObject.getSchemaList(self.type)
+ if not schemas:
+ return
schemas.sort()
for schema in schemas:
TableNode(self.navigator, self.tree, self.node,
***************
*** 306,311 ****
--- 315,321 ----
def getColumn(self, i=0):
return ""
def expand(self):
+ self.expanded = 1
for field in self.schema.getChildSchema(self.schema):
FieldNode(self.navigator, self.tree, self.node, field=field)
***************
*** 336,342 ****
return rv
def expand(self):
! return
--- 346,352 ----
return rv
def expand(self):
! self.expanded = 1
Index: gnue/designer/src/base/tools/SchemaViewer.py
diff -c gnue/designer/src/base/tools/SchemaViewer.py:1.15
gnue/designer/src/base/tools/SchemaViewer.py:1.16
*** gnue/designer/src/base/tools/SchemaViewer.py:1.15 Mon Jun 2 19:33:26 2003
--- gnue/designer/src/base/tools/SchemaViewer.py Wed Jun 4 19:24:12 2003
***************
*** 269,275 ****
object = self.connectionCache[self.connectionName][1]\
[self.list.HitTest(event.GetPoint())[0]]
! do = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
do.SetData(cPickle.dumps(self.buildDataObject(object),1))
dropSource = wxDropSource(self)
--- 269,275 ----
object = self.connectionCache[self.connectionName][1]\
[self.list.HitTest(event.GetPoint())[0]]
! do = wxCustomDataObject(wxCustomDataFormat("application/x-gnue-designer"))
do.SetData(cPickle.dumps(self.buildDataObject(object),1))
dropSource = wxDropSource(self)
***************
*** 459,465 ****
"DefaultInfo": defaultval
} )
! do = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
do.SetData(cPickle.dumps(data,1))
dropSource = wxDropSource(self)
--- 459,465 ----
"DefaultInfo": defaultval
} )
! do = wxCustomDataObject(wxCustomDataFormat("application/x-gnue-designer"))
do.SetData(cPickle.dumps(data,1))
dropSource = wxDropSource(self)
Index: gnue/designer/src/forms/LayoutEditor/DisplayDropTarget.py
diff -c gnue/designer/src/forms/LayoutEditor/DisplayDropTarget.py:1.18
gnue/designer/src/forms/LayoutEditor/DisplayDropTarget.py:1.19
*** gnue/designer/src/forms/LayoutEditor/DisplayDropTarget.py:1.18 Wed Jun
4 16:00:52 2003
--- gnue/designer/src/forms/LayoutEditor/DisplayDropTarget.py Wed Jun 4
19:24:12 2003
***************
*** 41,47 ****
wxPyDropTarget.__init__(self)
self.editor = editor
! self.data = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
self.SetDataObject(self.data)
def OnEnter(self, x, y, d):
--- 41,47 ----
wxPyDropTarget.__init__(self)
self.editor = editor
! self.data =
wxCustomDataObject(wxCustomDataFormat("application/x-gnue-designer"))
self.SetDataObject(self.data)
def OnEnter(self, x, y, d):
***************
*** 58,64 ****
# Called when OnDrop returns true. We need to get the data and
# do something with it.
! def OnData(self, x, y, d):
instance = self.editor.instance
--- 58,64 ----
# Called when OnDrop returns true. We need to get the data and
# do something with it.
! def OnData(self, bx, by, d):
instance = self.editor.instance
***************
*** 69,84 ****
unpickled = cPickle.loads(data)
! nextY = int(y / self.editor.gridHeight)
!
for params in unpickled:
- x = int(x / self.editor.gridWidth)
y = nextY
if params['Type'] == 'SchemaDrop':
! self.schemaDrop(params, x, y)
continue
attributes = params['Attributes']
# Entry types require a "block".. find or create one
--- 69,86 ----
unpickled = cPickle.loads(data)
! nextY = int(by / self.editor.gridHeight)
! x = int(bx / self.editor.gridWidth)
for params in unpickled:
y = nextY
if params['Type'] == 'SchemaDrop':
! self.schemaDrop(params, bx, by)
continue
+ # TODO: Most of this crap can be purged out of here
+ # TODO: schemaDrop replaced most of it
+
attributes = params['Attributes']
# Entry types require a "block".. find or create one
***************
*** 239,282 ****
# case we just return the suggested value given to us.
# This handles dropping from the Schema Navigator
def schemaDrop(self, params, x, y):
instance = self.editor.instance
# TODO: if params['ShowMenu'], give user options
! for table, fields in params['Data']:
! block = None
! for set in ((self.editor.block,),instance.blocks):
! for test in set:
! try:
! datasource = instance.datasources[block.name]
! if datasource.connection == table['connection'] and \
! datasource.table == table['name']:
! block = test
! break
! except (KeyError, AttributeError):
! pass
! if not block:
! datasource = instance.incubator.createObject(
! instance.rootObject,
! 'datasource',
! instance.rootObject,
! attributes={'name': instance.getUniqueName('dts%s'%table['name']),
! 'connection':table['connection'],
! 'table': table['name']},
! select=0)
! block = instance.incubator.createObject(
instance.rootObject,
'block',
instance.rootObject._logic,
! attributes={'name': instance.getUniqueName('blk%s'%table['name']),
'datasource':datasource.name},
select=0)
! page = self.editor.page
--- 241,520 ----
# case we just return the suggested value given to us.
+ #
# This handles dropping from the Schema Navigator
+ #
def schemaDrop(self, params, x, y):
+ try:
+ table, fields = params['Data'][0]
+ except:
+ return
+
instance = self.editor.instance
# TODO: if params['ShowMenu'], give user options
! blocks = []
! for set in ((self.editor.block,),instance.blocks):
! for test in set:
! try:
! datasource = instance.datasources[test.datasource]
! if datasource.connection.lower() == table['connection'].lower() and
\
! datasource.table.lower() == table['name'].lower():
! blocks.append(test)
! except (KeyError, AttributeError):
! pass
!
! if not params['ShowMenu']:
! # User left-click-dragged, so do the default action
! if blocks:
! self.schemaDrop_Add(table, fields, blocks[0], x, y)
! else:
! self.schemaDrop_Create(table, fields, x, y)
! else:
! # Present a menu of options
! menu = wxMenu()
! current = 0
! if blocks and blocks[0] == self.editor.block:
! wid = wxNewId()
! menu.Append(wid, _('Add Fields to Current Block'))
! current = 1
! EVT_MENU(menu, wid,
! lambda event, s=self, t=table, f=fields, x=x, y=y,
! b=blocks[0]: s.schemaDrop_Add(t, f, b, x, y) )
! wid = wxNewId()
! menu.Append(wid, _('Add Fields to New Block'))
! EVT_MENU(menu, wid, lambda event, s=self, t=table, x=x, y=y,
! f=fields: s.schemaDrop_Create(t, f, x, y) )
! if len(blocks) > 1 + current:
! smenu = wxMenu()
! menu.AppendMenu(wxNewId(), _("Add Fields to Block"), smenu)
! for block in blocks[1:]:
! wid = wxNewId()
! smenu.Append(wid, block.name)
! EVT_MENU(smenu, wid,
! lambda event, s=self, t=table, f=fields, x=x, y=y,
! b=block: s.schemaDrop_Add(t, f, b, x, y) )
!
! ## TODO: Finish schemaDrop_Dropdown
! ## menu.AppendSeparator()
! ## wid = wxNewId()
! ## menu.Append(wid, _("Add as a dropdown to current block"))
! ## EVT_MENU(menu, wid,
! ## lambda event, s=self, t=table, x=x, y=y,
! ## f=fields: s.schemaDrop_Dropdown(t, f, x, y) )
!
! menu.AppendSeparator()
! wid = wxNewId()
! menu.Append(wid, _("Create Block (no fields)"))
! EVT_MENU(menu, wid, lambda event, s=self, t=table,
! f=fields: s.schemaDrop_Block(t, f, select=1) )
! wid = wxNewId()
! menu.Append(wid, _("Create Data Source (no bound block)"))
! EVT_MENU(menu, wid, lambda event, s=self, t=table,
! f=fields: s.schemaDrop_Datasource(t, f,
select=1) )
!
! # Show the popup menu
! self.editor.panel.PopupMenuXY(menu, x, y)
!
!
! #
! # User requested we add fields to current block
! #
! def schemaDrop_Add(self, table, fields, block, x, y):
! y = int(y / self.editor.gridHeight)
! x = int(x / self.editor.gridWidth)
! maxWidth = x
! page = self.editor.page
! instance = self.editor.instance
! for f in fields:
! try:
! label=f['label'] + ':'
! except KeyError:
! label=f['name'].replace('_',' ').capitalize()+':'
!
! # Create the field
! try:
! width = min(f['length'],30)
! except KeyError:
! width = 10
!
! fattr = {'name': instance.getUniqueName('fld' + f['name'].capitalize()),
! 'field':f['name'],
! 'typecast':f['datatype']}
!
! try:
! fattr['required'] = f['required']
! except KeyError:
! pass
!
! try:
! defaulttype = fattr['defaulttype']
! defaultval = fattr['defaultval']
! except KeyError:
! defaulttype = None
!
! if defaulttype == 'constant':
! fattr['default'] = defaultval
!
! field = instance.incubator.createObject(
! instance.rootObject,
! 'field',
! block,
! attributes=fattr,
! select=0)
!
! # Create any pre-insert triggers
! triggertext = ""
! if defaulttype == 'sequence':
! triggertext = "\n# Set default value\n" \
! + "if self.isEmpty():\n" \
! + " self.autofillBySequence('%s')\n" % defaultval
! elif defaulttype == 'system' and defaultval == 'timestamp':
! triggertext = "\n# Set default value\n" \
! + "if self.isEmpty():\n" \
! + " self.value = %s.extensions.getTimeStamp()\n" \
! % block.datasource
! if triggertext:
! instance.incubator.createObject(
! instance.rootObject,
! 'trigger',
! field,
! attributes = {
! '_content_': triggertext,
! 'type': 'PRE-INSERT',
! 'name': '%s_PreInsert' % field.name },
! select=0)
!
!
!
! # Create the labels
! instance.incubator.createObject(
! instance.rootObject,
! 'label',
! page,
! attributes={'name': instance.getUniqueName('lbl%s' %
f['name'].capitalize()),
! 'text': label,
! 'Char:x': x,
! 'Char:y': y,
! 'Char:width': len(label)},
! select=0)
!
! # Create the entry
! instance.incubator.createObject(
! instance.rootObject,
! 'entry',
! page,
! attributes={'name': instance.getUniqueName('ntry%s' %
f['name'].capitalize()),
! 'field': field.name,
! 'block': block.name,
! 'Char:x': x + len(label) + 1,
! 'Char:y': y,
! 'Char:width': width},
! select=0)
!
! maxWidth = max(maxWidth, x + len(label) + width + 2)
! y += 1
!
! # Adjust form height if necessary
! if y > instance.rootObject._layout.Char__height or \
! maxWidth > instance.rootObject._layout.Char__width:
! instance.dispatchEvent('ObjectModified',
! object=instance.rootObject._layout,
! old={'Char:height': instance.rootObject._layout.Char__height,
! 'Char:width': instance.rootObject._layout.Char__width},
! new={'Char:height': y,
! 'Char:width': maxWidth},
! originator=__name__)
!
! # Select the new block
! instance.dispatchEvent('ObjectSelected', object=block,
originator=__name__)
!
! #
! # User requested we create a new block and add fields
! #
! def schemaDrop_Create(self, table, fields, x, y):
! block = self.schemaDrop_Block(table, fields)
! self.schemaDrop_Add(table, fields, block, x, y)
!
!
! #
! # user requested we only create a new block
! #
! def schemaDrop_Block(self, table, fields, select=0):
! instance = self.editor.instance
! datasource = self.schemaDrop_Datasource(table, fields)
! o = instance.incubator.createObject(
instance.rootObject,
'block',
instance.rootObject._logic,
! attributes={'name':
instance.getUniqueName('blk%s'%table['name'].capitalize()),
'datasource':datasource.name},
select=0)
! # Select the new block
! if select:
! instance.dispatchEvent('ObjectSelected', object=o, originator=__name__)
!
! return o
!
! #
! # User requested we only create a new datasource
! #
! def schemaDrop_Datasource(self, table, fields, attrs={}, select=0):
! instance = self.editor.instance
! attrs.update({'name':
instance.getUniqueName('dts%s'%table['name'].capitalize()),
! 'connection':table['connection'],
! 'table': table['name']})
!
! # Add the primary key(s) if applicable
! try:
! if table['primarykey']:
! attrs['primarykey'] = string.join(table['primarykey'],',')
! except KeyError:
! pass
!
! o = instance.incubator.createObject(
! instance.rootObject,
! 'datasource',
! instance.rootObject,
! attributes=attrs,
! select=0)
!
! # Select the new datasource
! if select:
! instance.dispatchEvent('ObjectSelected', object=o, originator=__name__)
!
! return o
!
!
! #
! # User requested we create a dropdown
! #
! def schemaDrop_Dropdown(self, table, fields, x, y):
! if not self.editor.block:
! print "No blocks in form" # TODO: Better feedback
! return
!
! datasource = self.schemaDrop_Datasource(table, fields, {'prequery': 1})
! block = self.editor.block
!
! fkid = None
! fkdescr = None
! try:
! pk = table['primarykey'] or []
! except KeyError:
! pk = []
!
! for field in fields:
! if field['name'] in pk:
! fkid = field
! break
!
! # TODO: Finish me!
!
Index: gnue/designer/src/forms/LayoutEditor/WidgetHandler.py
diff -c gnue/designer/src/forms/LayoutEditor/WidgetHandler.py:1.12
gnue/designer/src/forms/LayoutEditor/WidgetHandler.py:1.13
*** gnue/designer/src/forms/LayoutEditor/WidgetHandler.py:1.12 Mon Jun 2
19:33:26 2003
--- gnue/designer/src/forms/LayoutEditor/WidgetHandler.py Wed Jun 4
19:24:12 2003
***************
*** 151,157 ****
# "database": self.connectionName } }
#
#
! do = wxCustomDataObject(wxCustomDataFormat("GNUeDesVisualElement"))
do.SetData(cPickle.dumps(data,1))
## icon = FeedbackBitmap(10,10).icon()
--- 151,157 ----
# "database": self.connectionName } }
#
#
! do = wxCustomDataObject(wxCustomDataFormat("application/x-gnue-designer"))
do.SetData(cPickle.dumps(data,1))
## icon = FeedbackBitmap(10,10).icon()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/designer/src base/tools/DataSourceEditor.p...,
Jason Cater <=