From: Alex T. <ale...@us...> - 2004-08-12 23:55:58
|
Update of /cvsroot/pythoncard/PythonCard/tools/resourceEditor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3227 Modified Files: resourceEditor.py Log Message: Add a dialog to give new name and, if appropriate, label/text when creating a component via (Edit/Duplicate, Copy/Paste or Component/<comp>). Provide offset checkboxes to allow easy default positioning. Index: resourceEditor.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/tools/resourceEditor/resourceEditor.py,v retrieving revision 1.204 retrieving revision 1.205 diff -C2 -d -r1.204 -r1.205 *** resourceEditor.py 12 Aug 2004 19:14:22 -0000 1.204 --- resourceEditor.py 12 Aug 2004 23:55:48 -0000 1.205 *************** *** 21,24 **** --- 21,25 ---- from modules import stackInfoDialog from modules import menuDialog + from modules.newComponentDialog import NewComponentDialog from modules import stringDialog from modules.dialogInfoDialog import DialogInfoDialog *************** *** 1022,1082 **** ##self.propertyEditorWindow.Thaw() def on_componentDuplicate_command(self, event): if self.startName in self.components: aWidget = self.components[self.startName] - result = dialog.textEntryDialog(self, 'Duplicate ' + self.startName, - 'Name for copy:', - self.startName + 'Copy') - if result.accepted: - name = result.text - if name in self.components: - dialog.alertDialog(self, name + " already exists", 'Error: Unable to duplicate widget') - else: - # now loop through the original widget and build a dictionary suitable - # for making a copy - d = {} - d['type'] = aWidget.__class__.__name__ - #for key in aWidget._getAttributeNames(): - attributes = aWidget._spec.getAttributes().keys() - attributes.sort() - for key in attributes: - # I'm not exactly sure why I have to special-case these tuples - if key == 'bitmap': - # this should get recreated from the file attribute - pass - elif key in ['position', 'size']: - d[key] = getattr(aWidget, key) - elif getattr(aWidget, key) is not None: - d[key] = getattr(aWidget, key) - d['name'] = name - #d['toolTip'] = '' - #print d - - # a lot of this is common to add widget below - # so refactor so the common code is in a method - self.components[name] = d - # offset the widget so that it isn't underneath - # the original - x, y = self.components[name].position - x += 10 - y += 10 - self.components[name].position = (x, y) - - self.components.order.remove(name) - self.components.order.insert(NUM_SIZING_HANDLES, name) - self.fixComponentOrder(name) - - self.startName = name - self.startPosition = self.components[self.startName].position - self.startSize = self.components[self.startName].size - self.offset = (0, 0) - self.showSizingHandles(name) - self.documentChanged = True ! c = self.components[name] ! wx.EVT_LEFT_DOWN(c, self.on_mouseDown) ! wx.EVT_LEFT_UP(c, self.on_mouseUp) ! wx.EVT_MOTION(c, self.on_mouseDrag) def on_componentDelete_command(self, event): --- 1023,1104 ---- ##self.propertyEditorWindow.Thaw() + def create_component(self, desc, offsets, promptString, errString): + dlg = NewComponentDialog(self, desc, offsets, promptString) + result = dlg.showModal() + if result.accepted: + name = dlg.components.fldName.text + if name in self.components: + dialog.alertDialog(self, name + " already exists", 'Error: Unable to '+errString+' widget') + return + if 'label' in desc.keys(): + desc['label'] = dlg.components.fldLabelOrText.text + elif 'text' in desc.keys(): + desc['text'] = dlg.components.fldLabelOrText.text + + desc['name'] = name + self.components[name] = desc + if offsets: + # offset the widget so that it isn't underneath the original + x, y = self.components[name].position + dx, dy = self.components[name].size + #rint x, y, dx, dy + if dlg.components.chkHorizontal.checked: + x += dx+30 + if dlg.components.chkVertical.checked: + y += dy+30 + else: + if dlg.components.chkVertical.checked: + y += dy+30 + else: + x += 10 + y += 10 + #rint " => ", x, y + self.components[name].position = (x, y) + + # KEA 2001-12-20 + # hack to insert component so that it is the first one + # in the list + # a similar trick will be needed for re-ordering widgets + self.components.order.remove(name) + self.components.order.insert(NUM_SIZING_HANDLES, name) + self.fixComponentOrder(name) + + self.startName = name + self.startPosition = self.components[self.startName].position + self.startSize = self.components[self.startName].size + self.offset = (0, 0) + self.showSizingHandles(name) + self.documentChanged = True + + c = self.components[self.startName] + wx.EVT_LEFT_DOWN(c, self.on_mouseDown) + wx.EVT_LEFT_UP(c, self.on_mouseUp) + wx.EVT_MOTION(c, self.on_mouseDrag) + def on_componentDuplicate_command(self, event): if self.startName in self.components: aWidget = self.components[self.startName] ! # now loop through the original widget and build a dictionary suitable ! # for making a copy ! d = {} ! d['type'] = aWidget.__class__.__name__ ! #for key in aWidget._getAttributeNames(): ! attributes = aWidget._spec.getAttributes().keys() ! attributes.sort() ! for key in attributes: ! # I'm not exactly sure why I have to special-case these tuples ! if key == 'bitmap': ! # this should get recreated from the file attribute ! pass ! elif key == "id": ! # must avoid duplicate IDs ! pass ! elif key in ['position', 'size']: ! d[key] = getattr(aWidget, key) ! elif getattr(aWidget, key) is not None: ! d[key] = getattr(aWidget, key) + self.create_component(d, True, 'Duplicate ' + d['type'], "duplicate") def on_componentDelete_command(self, event): *************** *** 1104,1130 **** i += 1 desc['position'] = (10, 10) ! ! name = desc['name'] ! self.components[name] = desc ! ! # KEA 2001-12-20 ! # hack to insert component so that it is the first one ! # in the list ! # a similar trick will be needed for re-ordering widgets ! self.components.order.remove(name) ! self.components.order.insert(NUM_SIZING_HANDLES, name) ! self.fixComponentOrder(name) ! ! self.startName = name ! self.startPosition = self.components[self.startName].position ! self.startSize = self.components[self.startName].size ! self.offset = (0, 0) ! self.showSizingHandles(name) ! self.documentChanged = True ! ! c = self.components[self.startName] ! wx.EVT_LEFT_DOWN(c, self.on_mouseDown) ! wx.EVT_LEFT_UP(c, self.on_mouseUp) ! wx.EVT_MOTION(c, self.on_mouseDrag) def on_componentSendBack_command(self, event): --- 1126,1131 ---- i += 1 desc['position'] = (10, 10) ! self.create_component(desc, False, "New"+className, "create") ! def on_componentSendBack_command(self, event): *************** *** 1537,1568 **** desc = eval(desc) name = desc['name'] ! if name in self.components: ! aWidget = self.components[name] ! result = dialog.textEntryDialog(self, 'New name', ! name + ' component already exists\nEnter a new name:', ! name + 'Copy') ! if result.accepted: ! name = result.text ! if name in self.components: ! dialog.alertDialog(self, name + " already exists", 'Error: Unable to duplicate component') ! return ! else: ! return ! #print name, desc ! desc['name'] = name ! self.components[name] = desc ! ! # this is common to duplicate, need to refactor ! self.components.order.remove(name) ! self.components.order.insert(NUM_SIZING_HANDLES, name) ! self.fixComponentOrder(name) ! ! self.startName = name ! self.startPosition = self.components[self.startName].position ! self.startSize = self.components[self.startName].size ! self.offset = (0, 0) ! self.showSizingHandles(name) ! self.documentChanged = True ! def loadConfig(self): --- 1538,1544 ---- desc = eval(desc) name = desc['name'] ! # AGT 2004-07-08 ! # give dialog to set name ! self.create_component(desc, True, 'Paste ' + desc['type'], "paste") def loadConfig(self): |