controls/IDBrowser.py
changeset 2458 2a70d5240300
parent 2428 e0f16317668e
child 2492 7dd551ac2fa0
equal deleted inserted replaced
2430:65ff9a309ff3 2458:2a70d5240300
    35         return len(self.data[0]) if self.data else self.columncount
    35         return len(self.data[0]) if self.data else self.columncount
    36 
    36 
    37     def GetCount(self):
    37     def GetCount(self):
    38         return len(self.data)
    38         return len(self.data)
    39     
    39     
    40     def GetAttrByRow(self, row, col, attr):
       
    41         if col == 3:
       
    42             attr.SetColour('blue')
       
    43             attr.SetBold(True)
       
    44             return True
       
    45         return False
       
    46 
       
    47 
       
    48     def Compare(self, item1, item2, col, ascending):
    40     def Compare(self, item1, item2, col, ascending):
    49         if not ascending: # swap sort order?
    41         if not ascending: # swap sort order?
    50             item2, item1 = item1, item2
    42             item2, item1 = item1, item2
    51         row1 = self.GetRow(item1)
    43         row1 = self.GetRow(item1)
    52         row2 = self.GetRow(item2)
    44         row2 = self.GetRow(item2)
    82 colflags = dv.DATAVIEW_COL_RESIZABLE|dv.DATAVIEW_COL_SORTABLE
    74 colflags = dv.DATAVIEW_COL_RESIZABLE|dv.DATAVIEW_COL_SORTABLE
    83 
    75 
    84 class IDBrowser(wx.Panel):
    76 class IDBrowser(wx.Panel):
    85     def __init__(self, parent, ctr, SelectURICallBack=None, SelectIDCallBack=None, **kwargs):
    77     def __init__(self, parent, ctr, SelectURICallBack=None, SelectIDCallBack=None, **kwargs):
    86         big = self.isManager = SelectURICallBack is None and SelectIDCallBack is None 
    78         big = self.isManager = SelectURICallBack is None and SelectIDCallBack is None 
    87         wx.Panel.__init__(self, parent, -1, size=(800 if big else 400,
    79         wx.Panel.__init__(self, parent, -1, size=(800 if big else 450,
    88                                                   600 if big else 200))
    80                                                   600 if big else 200))
    89 
    81 
    90         self.SelectURICallBack = SelectURICallBack
    82         self.SelectURICallBack = SelectURICallBack
    91         self.SelectIDCallBack = SelectIDCallBack
    83         self.SelectIDCallBack = SelectIDCallBack
    92 
    84 
    97         self.dvc = dv.DataViewCtrl(self, style = dvStyle)
    89         self.dvc = dv.DataViewCtrl(self, style = dvStyle)
    98                     
    90                     
    99         args = lambda *a,**k:(a,k)
    91         args = lambda *a,**k:(a,k)
   100 
    92 
   101         ColumnsDesc = [
    93         ColumnsDesc = [
   102             args(_("ID"), COL_ID, width = 100),
    94             args(_("ID"), COL_ID, width = 70),
   103             args(_("Last URI"), COL_URI, width = 160 if big else 80),
    95             args(_("Last URI"), COL_URI, width = 300 if big else 80),
   104             args(_("Description"), COL_DESC, width = 200, 
    96             args(_("Description"), COL_DESC, width = 300 if big else 200, 
   105                 mode = dv.DATAVIEW_CELL_EDITABLE 
    97                 mode = dv.DATAVIEW_CELL_EDITABLE 
   106                        if self.isManager 
    98                        if self.isManager 
   107                        else dv.DATAVIEW_CELL_INERT),
    99                        else dv.DATAVIEW_CELL_INERT),
   108             args(_("Last connection"),  COL_LAST, width = 120),
   100             args(_("Last connection"),  COL_LAST, width = 120),
   109         ]
   101         ]
   110 
   102 
   111         self.model = IDBrowserModel(ctr.ProjectPath, len(ColumnsDesc))
   103         self.model = IDBrowserModel(ctr.ProjectPath, len(ColumnsDesc))
   112         self.dvc.AssociateModel(self.model)
   104         self.dvc.AssociateModel(self.model)
   113 
   105 
       
   106         col_list = []
   114         for a,k in ColumnsDesc:
   107         for a,k in ColumnsDesc:
   115             self.dvc.AppendTextColumn(*a,**dict(k, flags = colflags))
   108             col_list.append(
   116 
   109                 self.dvc.AppendTextColumn(*a,**dict(k, flags = colflags)))
   117         # TODO : when select,
   110         col_list[COL_LAST].SetSortOrder(False)
   118         #  - update ID field of scheme editor
   111 
   119         #  - enable use URI button
   112         # TODO : sort by last bvisit by default
   120 
   113 
   121         self.Sizer = wx.BoxSizer(wx.VERTICAL) 
   114         self.Sizer = wx.BoxSizer(wx.VERTICAL) 
   122         self.Sizer.Add(self.dvc, 1, wx.EXPAND)
   115         self.Sizer.Add(self.dvc, 1, wx.EXPAND)
   123 
   116 
   124         btnbox = wx.BoxSizer(wx.HORIZONTAL)
   117         btnbox = wx.BoxSizer(wx.HORIZONTAL)
   139             self.Bind(wx.EVT_BUTTON, self.OnImportButton, importButton)
   132             self.Bind(wx.EVT_BUTTON, self.OnImportButton, importButton)
   140             btnbox.Add(importButton, 0, wx.LEFT|wx.RIGHT, 5)
   133             btnbox.Add(importButton, 0, wx.LEFT|wx.RIGHT, 5)
   141 
   134 
   142         else :
   135         else :
   143             # selector mode
   136             # selector mode
   144             # use last known URI button
       
   145             # TODO : disable use URI button until something selected
       
   146             self.useURIButton = wx.Button(self, label=_("Use last URI"))
   137             self.useURIButton = wx.Button(self, label=_("Use last URI"))
   147             self.Bind(wx.EVT_BUTTON, self.OnUseURIButton, self.useURIButton)
   138             self.Bind(wx.EVT_BUTTON, self.OnUseURIButton, self.useURIButton)
   148             self.useURIButton.Disable()
   139             self.useURIButton.Disable()
   149             btnbox.Add(self.useURIButton, 0, wx.LEFT|wx.RIGHT, 5)
   140             btnbox.Add(self.useURIButton, 0, wx.LEFT|wx.RIGHT, 5)
   150 
   141