repos/MysteryMachine

changeset 290:fdd982891520

Add Append button to list value widget (and make worK!)
- Code alternate write methods to new attribute widget
- Append method tested and works,
- insert method stubbed in.
author Roger Gammans <rgammans@computer-surgery.co.uk>
date Wed Mar 16 21:43:52 2011 +0000 (14 months ago)
parents 00a95670a101
children caccbbf32d05
files MysteryMachine/Ui/wx/attribute_controls.py MysteryMachine/Ui/wx/dialogs/newattribute.py
line diff
     1.1 --- a/MysteryMachine/Ui/wx/attribute_controls.py	Wed Mar 16 21:23:57 2011 +0000
     1.2 +++ b/MysteryMachine/Ui/wx/attribute_controls.py	Wed Mar 16 21:43:52 2011 +0000
     1.3 @@ -21,7 +21,6 @@
     1.4  import wx
     1.5  import functools
     1.6  
     1.7 -from dialogs.objectpicker import ObjectPicker, EVT_OBJECTPICKED_EVENT
     1.8  
     1.9  _Factory = {}
    1.10  
    1.11 @@ -104,11 +103,21 @@
    1.12  
    1.13  
    1.14  class _list_wx_widget(wx.PyPanel):
    1.15 +    ID_APPENDBUTTON = NewUI_ID()
    1.16      def __init__(self,parent,attribute):
    1.17          super(_list_wx_widget,self).__init__(parent,-1)
    1.18 +        self.attribute = attribute
    1.19          self.SetExtraStyle(wx.WS_EX_VALIDATE_RECURSIVELY)
    1.20 -        sizer = wx.FlexGridSizer(wx.VERTICAL,3,len(attribute))
    1.21 +        sizer = wx.FlexGridSizer(wx.VERTICAL,5,len(attribute))
    1.22          self.SetSizer(sizer) 
    1.23 +        self.newbutton = wx.Button(self,self.__class__.ID_APPENDBUTTON,label="Append")
    1.24 +        sizer.Add(self.newbutton)
    1.25 +        wx.EVT_BUTTON(self,self.__class__.ID_APPENDBUTTON,self.onAppend)
    1.26 +        sizer.Add(wx.Panel(self,wx.ID_ANY))
    1.27 +        sizer.Add(wx.Panel(self,wx.ID_ANY))
    1.28 +        sizer.Add(wx.Panel(self,wx.ID_ANY))
    1.29 +        sizer.Add(wx.Panel(self,wx.ID_ANY))
    1.30 +
    1.31          i = 0
    1.32          for element in attribute:
    1.33              index_label = wx.StaticText(self,ID_LABEL)
    1.34 @@ -120,8 +129,16 @@
    1.35              sizer.Add(index_label)
    1.36              sizer.Add(stable_idx)
    1.37              sizer.Add(data)
    1.38 +            sizer.Add(wx.Button(self,wx.ID_ANY,label="Insert After"))
    1.39 +            sizer.Add(wx.Button(self,wx.ID_ANY,label="Delete"))
    1.40              i += 1
    1.41  
    1.42 +    def onAppend(self,evt):
    1.43 +       from dialogs.newattribute import NewAttributeDialog
    1.44 +       dlg = NewAttributeDialog(self,-1,owner = self.attribute ,title ="Enter initial value",
    1.45 +                                write = "append")
    1.46 +       dlg.Show()
    1.47 +
    1.48  _Factory["list"]      = _list_wx_widget
    1.49  
    1.50  
    1.51 @@ -170,6 +187,7 @@
    1.52          wx.EVT_BUTTON(self,self.__class__.ID_OPENBUTTON,self.onOpenTarget)
    1.53      
    1.54      def onChangeTarget(self,evt): 
    1.55 +        from dialogs.objectpicker import ObjectPicker
    1.56          dlg = ObjectPicker(self,-1,title ="Chose new target",system = self.attribute.get_root(),
    1.57                              action = self.GetValidator().UpdateValue)
    1.58          dlg.Show()
     2.1 --- a/MysteryMachine/Ui/wx/dialogs/newattribute.py	Wed Mar 16 21:23:57 2011 +0000
     2.2 +++ b/MysteryMachine/Ui/wx/dialogs/newattribute.py	Wed Mar 16 21:43:52 2011 +0000
     2.3 @@ -44,6 +44,11 @@
     2.4  def _apply_default(name,default,kwargs):
     2.5      if name not in kwargs: kwargs[name] = default
     2.6  
     2.7 +def _get_arg(args,name,default = None):
     2.8 +    rv = args.get(name,default)
     2.9 +    if name in args:
    2.10 +        del args[name]
    2.11 +    return rv
    2.12  
    2.13  class NewAttributeDialog(wx.Dialog):
    2.14      """This dialog get the initial values for a new attribute.
    2.15 @@ -55,8 +60,11 @@
    2.16  
    2.17      def __init__(self,parent,id,*args,**kwargs):
    2.18          _apply_default('size',(400,400),kwargs)
    2.19 -        self.parent_node = kwargs.get("owner")
    2.20 -        del kwargs["owner"]
    2.21 +        self.parent_node   = _get_arg(kwargs,"owner")
    2.22 +        self.writemethod   = _get_arg(kwargs,"write",default = "set_value")
    2.23 +        if self.writemethod not in ("set_value","insert","append"):
    2.24 +            raise ValueError("write value `%s' not known"%self.writemethod)
    2.25 +
    2.26          super(NewAttributeDialog,self).__init__(parent,id,**kwargs)
    2.27          self.typepanels = {}
    2.28          self.current_type = None
    2.29 @@ -71,6 +79,8 @@
    2.30          self.namefield =wx.TextCtrl(self,wx.ID_ANY)       
    2.31          self.sizer.Add(self.namefield,0,wx.EXPAND)
    2.32  
    2.33 +        self.namefield.Show(self.writemethod == "set_value")
    2.34 +
    2.35          self.typechoice = wx.Choice(self,self.__class__.ID_CHOICE,choices =sorted(GetAttributeTypeList()) )
    2.36          self.sizer.Add(self.typechoice,0,wx.EXPAND)
    2.37  
    2.38 @@ -116,7 +126,11 @@
    2.39      def onOK(self,event):
    2.40          attribute , currentpanel = self.typepanels[self.current_type]
    2.41          attribute_name = self.namefield.GetValue()
    2.42 -        self.parent_node[attribute_name] = attribute
    2.43 +        if self.writemethod == "set_value": self.parent_node[attribute_name] = attribute
    2.44 +        if self.writemethod == "append": self.parent_node.append(attribute)
    2.45 +        #TODO
    2.46 +        #if self.writemethod == "insert": self.parent_node.insert(XXX,attribute)
    2.47 +
    2.48          self.Close()
    2.49          self.Destroy()
    2.50