Commit e40ac88d authored by eric pellegrini's avatar eric pellegrini
Browse files

Improved the UserDefinition viewer dialog

Modified a bit the behaviour of UserDefinitionDialog when clicking on
apply/save buttons
parent 52f19699
......@@ -144,7 +144,7 @@ class IPlugin(wx.Panel):
return
window = event.GetPane().window
# Call the 'close' method the plugin to be closed
window.close()
......
......@@ -66,54 +66,29 @@ class UserDefinitionPlugin(ComponentPlugin):
self._mainPanel.GetSizer().Add(udPanel,0,wx.EXPAND|wx.ALL,5)
self.Bind(wx.EVT_BUTTON, self.on_apply, applyButton)
self.Bind(wx.EVT_BUTTON, self.on_save, saveButton)
def on_save(self, event):
self.Bind(wx.EVT_BUTTON, lambda evt : self.on_apply(evt,True), saveButton)
def on_apply(self, event, save=False):
name = str(self._udName.GetValue().strip())
if not name:
LOGGER('Empty user definition name.','error',['console'])
LOGGER('Empty user definition name.','error',['dialog'])
return
value = self.validate()
if value is None:
return
udType = getattr(self,'udType','type')
if UD_STORE.has_definition(self._target,self.type,name):
LOGGER('There is already a user-definition that matches %s,%s,%s' % (self._target,udType,name),'error',['console'])
LOGGER('There is already a user-definition with that name.','error',['dialog'])
return
UD_STORE.set_definition(self._target,self.type,name,value)
pub.sendMessage("msg_set_ud")
UD_STORE.save()
LOGGER('User definition %r successfully set.' % name,'info',['console'])
def on_apply(self, event):
name = str(self._udName.GetValue().strip())
if not name:
LOGGER('Empty user definition name.','error',['console'])
return
value = self.validate()
if value is None:
return
udType = getattr(self,'udType','type')
if UD_STORE.has_definition(self._target,self.type,name):
LOGGER('There is already a user-definition that matches %s,%s,%s' % (self._target,udType,name),'error',['console'])
return
UD_STORE.set_definition(self._target,self.type,name,value)
pub.sendMessage("msg_set_ud")
LOGGER('User definition %r successfully set.' % name,'info',['console'])
if save:
UD_STORE.save()
......@@ -152,7 +152,7 @@ if __name__ == "__main__":
app = wx.App(False)
p = UserDefinitionDialog(None,t,'atoms_list')
p = UserDefinitionDialog(None,t,'atom_selection')
p.SetSize((800,800))
......
......@@ -136,15 +136,23 @@ class UserDefinitionViewer(wx.Dialog):
self._tree.Expand(item)
def on_show_info(self, event=None):
currentItem = self._tree.GetSelection()
itemData = self._tree.GetItemData(currentItem)
ItemData = self._tree.GetItemData(self._tree.GetSelection())
if ItemData is None:
if itemData is None:
return
containerStr = str(ItemData.GetData())
self._info.SetValue(containerStr)
data = itemData.GetData()
level = self.get_item_level(currentItem)
if level <= 3:
self._info.SetValue("Contains the followings definitions: %s" % data.keys())
return
self._info.SetValue(str(itemData.GetData()))
def on_delete(self, event):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment