editors/ConfTreeNodeEditor.py
changeset 1768 691083b5682a
parent 1758 845ca626db09
child 1846 14b40afccd69
equal deleted inserted replaced
1767:c74815729afd 1768:691083b5682a
   120         bitmap = GetBitmap(bitmapname)
   120         bitmap = GetBitmap(bitmapname)
   121         if bitmap is None:
   121         if bitmap is None:
   122             bitmap = wx.EmptyBitmap(0, 0)
   122             bitmap = wx.EmptyBitmap(0, 0)
   123 
   123 
   124         wx.StaticBitmap.__init__(self, parent, ID,
   124         wx.StaticBitmap.__init__(self, parent, ID,
   125                  bitmap,
   125                                  bitmap,
   126                  pos, size,
   126                                  pos, size,
   127                  style,
   127                                  style,
   128                  name)
   128                                  name)
   129 
   129 
   130 
   130 
   131 class ConfTreeNodeEditor(EditorPanel):
   131 class ConfTreeNodeEditor(EditorPanel):
   132 
   132 
   133     SHOW_BASE_PARAMS = True
   133     SHOW_BASE_PARAMS = True
   139         if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0:
   139         if self.SHOW_PARAMS and len(self.Controler.GetParamsAttributes()) > 0:
   140             tabs_num += 1
   140             tabs_num += 1
   141 
   141 
   142         if tabs_num > 1 or self.SHOW_BASE_PARAMS:
   142         if tabs_num > 1 or self.SHOW_BASE_PARAMS:
   143             self.Editor = wx.Panel(parent,
   143             self.Editor = wx.Panel(parent,
   144                 style=wx.SUNKEN_BORDER | wx.SP_3D)
   144                                    style=wx.SUNKEN_BORDER | wx.SP_3D)
   145 
   145 
   146             self.MainSizer = wx.BoxSizer(wx.VERTICAL)
   146             self.MainSizer = wx.BoxSizer(wx.VERTICAL)
   147 
   147 
   148             if self.SHOW_BASE_PARAMS:
   148             if self.SHOW_BASE_PARAMS:
   149                 baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL)
   149                 baseparamseditor_sizer = wx.BoxSizer(wx.HORIZONTAL)
   150                 self.MainSizer.AddSizer(baseparamseditor_sizer, border=5,
   150                 self.MainSizer.AddSizer(baseparamseditor_sizer, border=5,
   151                       flag=wx.GROW | wx.ALL)
   151                                         flag=wx.GROW | wx.ALL)
   152 
   152 
   153                 self.FullIECChannel = wx.StaticText(self.Editor, -1)
   153                 self.FullIECChannel = wx.StaticText(self.Editor, -1)
   154                 self.FullIECChannel.SetFont(
   154                 self.FullIECChannel.SetFont(
   155                     wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL,
   155                     wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL,
   156                             wx.BOLD, faceName=faces["helv"]))
   156                             wx.BOLD, faceName=faces["helv"]))
   157                 baseparamseditor_sizer.AddWindow(self.FullIECChannel,
   157                 baseparamseditor_sizer.AddWindow(self.FullIECChannel,
   158                       flag=wx.ALIGN_CENTER_VERTICAL)
   158                                                  flag=wx.ALIGN_CENTER_VERTICAL)
   159 
   159 
   160                 updownsizer = wx.BoxSizer(wx.VERTICAL)
   160                 updownsizer = wx.BoxSizer(wx.VERTICAL)
   161                 baseparamseditor_sizer.AddSizer(updownsizer, border=5,
   161                 baseparamseditor_sizer.AddSizer(updownsizer, border=5,
   162                       flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL)
   162                                                 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL)
   163 
   163 
   164                 self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(self.Editor,
   164                 self.IECCUpButton = wx.lib.buttons.GenBitmapTextButton(
   165                       bitmap=GetBitmap('IECCDown'), size=wx.Size(16, 16), style=wx.NO_BORDER)
   165                     self.Editor,
       
   166                     bitmap=GetBitmap('IECCDown'),
       
   167                     size=wx.Size(16, 16),
       
   168                     style=wx.NO_BORDER)
   166                 self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1),
   169                 self.IECCUpButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(1),
   167                       self.IECCUpButton)
   170                                        self.IECCUpButton)
   168                 updownsizer.AddWindow(self.IECCUpButton, flag=wx.ALIGN_LEFT)
   171                 updownsizer.AddWindow(self.IECCUpButton, flag=wx.ALIGN_LEFT)
   169 
   172 
   170                 self.IECCDownButton = wx.lib.buttons.GenBitmapButton(self.Editor,
   173                 self.IECCDownButton = wx.lib.buttons.GenBitmapButton(
   171                       bitmap=GetBitmap('IECCUp'), size=wx.Size(16, 16), style=wx.NO_BORDER)
   174                     self.Editor, bitmap=GetBitmap('IECCUp'),
       
   175                     size=wx.Size(16, 16), style=wx.NO_BORDER)
   172                 self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1),
   176                 self.IECCDownButton.Bind(wx.EVT_BUTTON, self.GetItemChannelChangedFunction(-1),
   173                       self.IECCDownButton)
   177                                          self.IECCDownButton)
   174                 updownsizer.AddWindow(self.IECCDownButton, flag=wx.ALIGN_LEFT)
   178                 updownsizer.AddWindow(self.IECCDownButton, flag=wx.ALIGN_LEFT)
   175 
   179 
   176                 self.ConfNodeName = wx.TextCtrl(self.Editor,
   180                 self.ConfNodeName = wx.TextCtrl(self.Editor,
   177                       size=wx.Size(150, 25))
   181                                                 size=wx.Size(150, 25))
   178                 self.ConfNodeName.SetFont(
   182                 self.ConfNodeName.SetFont(
   179                     wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL,
   183                     wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL,
   180                             wx.BOLD, faceName=faces["helv"]))
   184                             wx.BOLD, faceName=faces["helv"]))
   181                 self.ConfNodeName.Bind(wx.EVT_TEXT,
   185                 self.ConfNodeName.Bind(
   182                       self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True),
   186                     wx.EVT_TEXT,
   183                       self.ConfNodeName)
   187                     self.GetTextCtrlCallBackFunction(self.ConfNodeName, "BaseParams.Name", True),
   184                 baseparamseditor_sizer.AddWindow(self.ConfNodeName, border=5,
   188                     self.ConfNodeName)
   185                       flag=wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
   189                 baseparamseditor_sizer.AddWindow(
       
   190                     self.ConfNodeName, border=5,
       
   191                     flag=wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER_VERTICAL)
   186 
   192 
   187                 buttons_sizer = self.GenerateMethodButtonSizer()
   193                 buttons_sizer = self.GenerateMethodButtonSizer()
   188                 baseparamseditor_sizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER)
   194                 baseparamseditor_sizer.AddSizer(buttons_sizer, flag=wx.ALIGN_CENTER)
   189 
   195 
   190             if tabs_num > 1:
   196             if tabs_num > 1:
   213 
   219 
   214             panel_style = wx.TAB_TRAVERSAL | wx.HSCROLL | wx.VSCROLL
   220             panel_style = wx.TAB_TRAVERSAL | wx.HSCROLL | wx.VSCROLL
   215             if self.ConfNodeNoteBook is None and parent != self.Editor:
   221             if self.ConfNodeNoteBook is None and parent != self.Editor:
   216                 panel_style |= wx.SUNKEN_BORDER
   222                 panel_style |= wx.SUNKEN_BORDER
   217             self.ParamsEditor = wx.ScrolledWindow(parent,
   223             self.ParamsEditor = wx.ScrolledWindow(parent,
   218                   style=panel_style)
   224                                                   style=panel_style)
   219             self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnParamsEditorResize)
   225             self.ParamsEditor.Bind(wx.EVT_SIZE, self.OnParamsEditorResize)
   220             self.ParamsEditor.Bind(wx.EVT_SCROLLWIN, self.OnParamsEditorScroll)
   226             self.ParamsEditor.Bind(wx.EVT_SCROLLWIN, self.OnParamsEditorScroll)
   221 
   227 
   222             self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=5)
   228             self.ParamsEditorSizer = wx.FlexGridSizer(cols=1, hgap=0, rows=1, vgap=5)
   223             self.ParamsEditorSizer.AddGrowableCol(0)
   229             self.ParamsEditorSizer.AddGrowableCol(0)
   224             self.ParamsEditorSizer.AddGrowableRow(0)
   230             self.ParamsEditorSizer.AddGrowableRow(0)
   225             self.ParamsEditor.SetSizer(self.ParamsEditorSizer)
   231             self.ParamsEditor.SetSizer(self.ParamsEditorSizer)
   226 
   232 
   227             self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
   233             self.ConfNodeParamsSizer = wx.BoxSizer(wx.VERTICAL)
   228             self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, border=5,
   234             self.ParamsEditorSizer.AddSizer(self.ConfNodeParamsSizer, border=5,
   229                   flag=wx.LEFT | wx.RIGHT | wx.BOTTOM)
   235                                             flag=wx.LEFT | wx.RIGHT | wx.BOTTOM)
   230 
   236 
   231             self.RefreshConfNodeParamsSizer()
   237             self.RefreshConfNodeParamsSizer()
   232 
   238 
   233             if self.ConfNodeNoteBook is not None:
   239             if self.ConfNodeNoteBook is not None:
   234                 self.ConfNodeNoteBook.AddPage(self.ParamsEditor, _("Config"))
   240                 self.ConfNodeNoteBook.AddPage(self.ParamsEditor, _("Config"))
   304         msizer = wx.BoxSizer(wx.HORIZONTAL)
   310         msizer = wx.BoxSizer(wx.HORIZONTAL)
   305 
   311 
   306         for confnode_method in self.Controler.ConfNodeMethods:
   312         for confnode_method in self.Controler.ConfNodeMethods:
   307             if "method" in confnode_method and confnode_method.get("shown", True):
   313             if "method" in confnode_method and confnode_method.get("shown", True):
   308                 button = GenBitmapTextButton(self.Editor,
   314                 button = GenBitmapTextButton(self.Editor,
   309                     bitmap=GetBitmap(confnode_method.get("bitmap", "Unknown")),
   315                                              bitmap=GetBitmap(confnode_method.get("bitmap", "Unknown")),
   310                     label=confnode_method["name"], style=wx.NO_BORDER)
   316                                              label=confnode_method["name"],
       
   317                                              style=wx.NO_BORDER)
   311                 button.SetFont(normal_bt_font)
   318                 button.SetFont(normal_bt_font)
   312                 button.SetToolTipString(confnode_method["tooltip"])
   319                 button.SetToolTipString(confnode_method["tooltip"])
   313                 if confnode_method.get("push", False):
   320                 if confnode_method.get("push", False):
   314                     button.Bind(wx.EVT_LEFT_DOWN, self.GetButtonCallBackFunction(confnode_method["method"], True))
   321                     button.Bind(wx.EVT_LEFT_DOWN, self.GetButtonCallBackFunction(confnode_method["method"], True))
   315                 else:
   322                 else:
   344                 value = element_infos["value"]
   351                 value = element_infos["value"]
   345                 label = _(name)
   352                 label = _(name)
   346                 if value is not None:
   353                 if value is not None:
   347                     label += " - %s" % _(value)
   354                     label += " - %s" % _(value)
   348                 staticbox = wx.StaticBox(self.ParamsEditor,
   355                 staticbox = wx.StaticBox(self.ParamsEditor,
   349                       label=_(label), size=wx.Size(10, 0))
   356                                          label=_(label), size=wx.Size(10, 0))
   350                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   357                 staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   351                 flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
   358                 flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
   352                 if first:
   359                 if first:
   353                     flags |= wx.TOP
   360                     flags |= wx.TOP
   354                 sizer.AddSizer(staticboxsizer, border=5, flag=flags)
   361                 sizer.AddSizer(staticboxsizer, border=5, flag=flags)
   360                 boxsizer.AddGrowableCol(1)
   367                 boxsizer.AddGrowableCol(1)
   361                 flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
   368                 flags = (wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
   362                 if first:
   369                 if first:
   363                     flags |= wx.TOP
   370                     flags |= wx.TOP
   364                 sizer.AddSizer(boxsizer, border=5, flag=flags)
   371                 sizer.AddSizer(boxsizer, border=5, flag=flags)
   365                 staticbitmap = GenStaticBitmap(ID=-1, bitmapname=element_infos["name"],
   372                 staticbitmap = GenStaticBitmap(
       
   373                     ID=-1, bitmapname=element_infos["name"],
   366                     name="%s_bitmap" % element_infos["name"], parent=self.ParamsEditor,
   374                     name="%s_bitmap" % element_infos["name"], parent=self.ParamsEditor,
   367                     pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
   375                     pos=wx.Point(0, 0), size=wx.Size(24, 24), style=0)
   368                 boxsizer.AddWindow(staticbitmap, border=5, flag=wx.RIGHT)
   376                 boxsizer.AddWindow(staticbitmap, border=5, flag=wx.RIGHT)
   369 
   377 
   370                 statictext = wx.StaticText(self.ParamsEditor,
   378                 statictext = wx.StaticText(self.ParamsEditor,
   371                       label="%s:" % _(element_infos["name"]))
   379                                            label="%s:" % _(element_infos["name"]))
   372                 boxsizer.AddWindow(statictext, border=5,
   380                 boxsizer.AddWindow(statictext, border=5,
   373                       flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT)
   381                                    flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT)
   374 
   382 
   375                 if isinstance(element_infos["type"], types.ListType):
   383                 if isinstance(element_infos["type"], types.ListType):
   376                     if isinstance(element_infos["value"], types.TupleType):
   384                     if isinstance(element_infos["value"], types.TupleType):
   377                         browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   385                         browse_boxsizer = wx.BoxSizer(wx.HORIZONTAL)
   378                         boxsizer.AddSizer(browse_boxsizer)
   386                         boxsizer.AddSizer(browse_boxsizer)
   379 
   387 
   380                         textctrl = wx.TextCtrl(self.ParamsEditor,
   388                         textctrl = wx.TextCtrl(self.ParamsEditor,
   381                               size=wx.Size(275, -1), style=wx.TE_READONLY)
   389                                                size=wx.Size(275, -1), style=wx.TE_READONLY)
   382                         if element_infos["value"] is not None:
   390                         if element_infos["value"] is not None:
   383                             textctrl.SetValue(element_infos["value"][0])
   391                             textctrl.SetValue(element_infos["value"][0])
   384                             value_infos = element_infos["value"][1]
   392                             value_infos = element_infos["value"][1]
   385                         else:
   393                         else:
   386                             value_infos = None
   394                             value_infos = None
   392                                     self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"],
   400                                     self.GetBrowseCallBackFunction(element_infos["name"], textctrl, element_infos["type"],
   393                                                                    value_infos, element_path),
   401                                                                    value_infos, element_path),
   394                                     button)
   402                                     button)
   395                     else:
   403                     else:
   396                         combobox = wx.ComboBox(self.ParamsEditor,
   404                         combobox = wx.ComboBox(self.ParamsEditor,
   397                               size=wx.Size(300, -1), style=wx.CB_READONLY)
   405                                                size=wx.Size(300, -1), style=wx.CB_READONLY)
   398                         boxsizer.AddWindow(combobox)
   406                         boxsizer.AddWindow(combobox)
   399 
   407 
   400                         if element_infos["use"] == "optional":
   408                         if element_infos["use"] == "optional":
   401                             combobox.Append("")
   409                             combobox.Append("")
   402                         if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
   410                         if len(element_infos["type"]) > 0 and isinstance(element_infos["type"][0], types.TupleType):
   404                                 combobox.Append(choice)
   412                                 combobox.Append(choice)
   405                             name = element_infos["name"]
   413                             name = element_infos["name"]
   406                             value = element_infos["value"]
   414                             value = element_infos["value"]
   407 
   415 
   408                             staticbox = wx.StaticBox(self.ParamsEditor,
   416                             staticbox = wx.StaticBox(self.ParamsEditor,
   409                                   label="%s - %s" % (_(name), _(value)), size=wx.Size(10, 0))
   417                                                      label="%s - %s" % (_(name), _(value)),
       
   418                                                      size=wx.Size(10, 0))
   410                             staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   419                             staticboxsizer = wx.StaticBoxSizer(staticbox, wx.VERTICAL)
   411                             sizer.AddSizer(staticboxsizer, border=5, flag=wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
   420                             sizer.AddSizer(staticboxsizer, border=5, flag=wx.GROW | wx.BOTTOM | wx.LEFT | wx.RIGHT)
   412                             self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path)
   421                             self.GenerateSizerElements(staticboxsizer, element_infos["children"], element_path)
   413                             callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path)
   422                             callback = self.GetChoiceContentCallBackFunction(combobox, staticboxsizer, element_path)
   414                         else:
   423                         else:
   427                     if "min" in element_infos["type"]:
   436                     if "min" in element_infos["type"]:
   428                         scmin = element_infos["type"]["min"]
   437                         scmin = element_infos["type"]["min"]
   429                     if "max" in element_infos["type"]:
   438                     if "max" in element_infos["type"]:
   430                         scmax = element_infos["type"]["max"]
   439                         scmax = element_infos["type"]["max"]
   431                     spinctrl = wx.SpinCtrl(self.ParamsEditor,
   440                     spinctrl = wx.SpinCtrl(self.ParamsEditor,
   432                           size=wx.Size(300, -1), style=wx.SP_ARROW_KEYS | wx.ALIGN_RIGHT)
   441                                            size=wx.Size(300, -1),
       
   442                                            style=wx.SP_ARROW_KEYS | wx.ALIGN_RIGHT)
   433                     spinctrl.SetRange(scmin, scmax)
   443                     spinctrl.SetRange(scmin, scmax)
   434                     boxsizer.AddWindow(spinctrl)
   444                     boxsizer.AddWindow(spinctrl)
   435                     if element_infos["value"] is not None:
   445                     if element_infos["value"] is not None:
   436                         spinctrl.SetValue(element_infos["value"])
   446                         spinctrl.SetValue(element_infos["value"])
   437                     spinctrl.Bind(wx.EVT_SPINCTRL,
   447                     spinctrl.Bind(wx.EVT_SPINCTRL,
   453                             scmin = 0
   463                             scmin = 0
   454                         else:
   464                         else:
   455                             scmin = -(2**31)
   465                             scmin = -(2**31)
   456                         scmax = 2**31-1
   466                         scmax = 2**31-1
   457                         spinctrl = wx.SpinCtrl(self.ParamsEditor,
   467                         spinctrl = wx.SpinCtrl(self.ParamsEditor,
   458                               size=wx.Size(300, -1), style=wx.SP_ARROW_KEYS | wx.ALIGN_RIGHT)
   468                                                size=wx.Size(300, -1),
       
   469                                                style=wx.SP_ARROW_KEYS | wx.ALIGN_RIGHT)
   459                         spinctrl.SetRange(scmin, scmax)
   470                         spinctrl.SetRange(scmin, scmax)
   460                         boxsizer.AddWindow(spinctrl)
   471                         boxsizer.AddWindow(spinctrl)
   461                         if element_infos["value"] is not None:
   472                         if element_infos["value"] is not None:
   462                             spinctrl.SetValue(element_infos["value"])
   473                             spinctrl.SetValue(element_infos["value"])
   463                         spinctrl.Bind(wx.EVT_SPINCTRL,
   474                         spinctrl.Bind(wx.EVT_SPINCTRL,
   569         maxx, maxy = self.ParamsEditorSizer.GetMinSize()
   580         maxx, maxy = self.ParamsEditorSizer.GetMinSize()
   570         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
   581         posx = max(0, min(xstart, (maxx - window_size[0]) / SCROLLBAR_UNIT))
   571         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
   582         posy = max(0, min(ystart, (maxy - window_size[1]) / SCROLLBAR_UNIT))
   572         self.ParamsEditor.Scroll(posx, posy)
   583         self.ParamsEditor.Scroll(posx, posy)
   573         self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
   584         self.ParamsEditor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
   574                 maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT, posx, posy)
   585                                         maxx / SCROLLBAR_UNIT, maxy / SCROLLBAR_UNIT,
       
   586                                         posx, posy)
   575 
   587 
   576     def OnParamsEditorResize(self, event):
   588     def OnParamsEditorResize(self, event):
   577         self.RefreshScrollbars()
   589         self.RefreshScrollbars()
   578         event.Skip()
   590         event.Skip()
   579 
   591