def add_item(self, path): # Generate item inp_choices, inp_sel = self.set_type_choices(path) type_choice = ct.DataTypeChoice(self.ctr, choices=inp_choices) item = ct.InputListItem(path=path, type=type_choice, buttons=ct.MiniButtonBoxInput(self.ctr)) self.Bind(wx.EVT_CHOICE, self.onTypeChoice, item.type.type) item.buttons.btn_mag.Bind(wx.EVT_BUTTON, self.onMagButton) item.buttons.btn_delete.Bind(wx.EVT_BUTTON, self.onDelButton) item.buttons.btn_info.Bind(wx.EVT_BUTTON, self.onInfoButton) # Insert list item idx = self.ctr.InsertStringItem(self.ctr.GetItemCount() + 1, item.path) self.ctr.SetItemWindow(idx, 1, item.type, expand=True) self.ctr.SetItemWindow(idx, 2, item.buttons, expand=True) # Set drop-down selection, check it for data and open other tabs item.type.type.SetSelection(inp_sel) if item.type.type.GetString(inp_sel) in [ 'processed pickle', 'processed pickle list', 'processed pickle folder' ]: self.main_window.toolbar.EnableTool( self.main_window.tb_btn_run.GetId(), True) elif item.type.type.GetString(inp_sel) == 'reference MTZ': self.input_window.opt_chk_useref.Enable() elif item.type.type.GetString(inp_sel) == 'sequence': pass else: warn_bmp = bitmaps.fetch_icon_bitmap('actions', 'status_unknown', size=16) item.buttons.btn_info.SetBitmapLabel(warn_bmp) item.warning = True # Record index in all relevant places item.id = idx item.buttons.index = idx item.type.index = idx item.type_selection = inp_sel # Resize columns to fit content col1_width = max([ self.ctr.GetItemWindow(s, col=1).type.GetSize()[0] for s in range(self.ctr.GetItemCount()) ]) + 5 col2_width = item.buttons.GetSize()[0] + 15 col0_width = self.ctr.GetSize()[0] - col1_width - col2_width self.ctr.SetColumnWidth(0, col0_width) self.ctr.SetColumnWidth(1, col1_width) self.ctr.SetColumnWidth(2, col2_width) # Make sure all the choice lists are the same size if item.type.type.GetSize()[0] < col1_width - 5: item.type.type.SetSize((col1_width - 5, -1)) # Attach data object to item self.ctr.SetItemData(item.id, item)
def add_item(self, path): # Generate item inputs, inp_choices, inp_sel = self.set_type_choices(path) type_choice = ct.DataTypeChoice(self.ctr, choices=inp_choices) item = ct.InputListItem(path=path, type=type_choice, buttons=ct.MiniButtonBoxInput(self.ctr)) self.Bind(wx.EVT_CHOICE, self.onTypeChoice, item.type.type) # item.buttons.btn_mag.Bind(wx.EVT_BUTTON, self.onMagButton) # item.buttons.btn_delete.Bind(wx.EVT_BUTTON, self.onDelButton) # item.buttons.btn_info.Bind(wx.EVT_BUTTON, self.onInfoButton) self.Bind(wx.EVT_BUTTON, self.onMagButton, item.buttons.btn_mag) self.Bind(wx.EVT_BUTTON, self.onDelButton, item.buttons.btn_delete) self.Bind(wx.EVT_BUTTON, self.onInfoButton, item.buttons.btn_info) # Insert list item idx = self.ctr.InsertStringItem(self.ctr.GetItemCount() + 1, item.path) self.ctr.SetItemWindow(idx, 1, item.type, expand=True) self.ctr.SetItemWindow(idx, 2, item.buttons, expand=True) # Set drop-down selection, check it for data and open other tabs item.type.type.SetSelection(inp_sel) if item.type.type.GetString(inp_sel) in ('coordinates', 'structure factors', 'background', 'raw image file'): if "image" in item.type.type.GetString(inp_sel): view_bmp = bitmaps.fetch_custom_icon_bitmap('image_viewer16') item.buttons.btn_mag.SetBitmapLabel(view_bmp) else: warn_bmp = bitmaps.fetch_icon_bitmap('actions', 'status_unknown', size=16) item.buttons.btn_info.SetBitmapLabel(warn_bmp) item.warning = True # Record index in all relevant places item.id = idx item.buttons.index = idx item.type.index = idx item.type_selection = inp_sel # Resize columns to fit content self.ctr.SetColumnWidth(1, width=-1) self.ctr.SetColumnWidth(2, width=-1) self.ctr.SetColumnWidth(0, width=-3) # Make sure all the choice lists are the same size if item.type.type.GetSize()[0] < self.ctr.GetColumnWidth(2) - 5: item.type.type.SetSize((self.ctr.GetColumnWidth(2) - 5, -1)) # Attach data object to item self.ctr.SetItemData(item.id, item) self.Layout()