def __init__(self, parent, log, model=None): self.log = log wx.Panel.__init__(self, parent, -1) # Create a dataview control self.dvc = dv.DataViewCtrl( self, style=wx.BORDER_THEME | dv.DV_ROW_LINES # nice alternating bg colors #| dv.DV_HORIZ_RULES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) # Create an instance of our simple model... if model is None: self.model = HoldingsModel(log) else: self.model = model # ...and associate it with the dataview control. Models can # be shared between multiple DataViewCtrls, so this does not # assign ownership like many things in wx do. There is some # internal reference counting happening so you don't really # need to hold a reference to it either, but we do for this # example so we can fiddle with the model from the widget # inspector or whatever. self.dvc.AssociateModel(self.model) # Now we create some columns. The second parameter is the # column number within the model that the DataViewColumn will # fetch the data from. This means that you can have views # using the same model that show different columns of data, or # that they can be in a different order than in the model. self.dvc.AppendTextColumn("Account", _GetColumnIdx("Account"), width=150, mode=dv.DATAVIEW_CELL_EDITABLE) self.dvc.AppendTextColumn("Ticker", _GetColumnIdx("Ticker"), width=70, mode=dv.DATAVIEW_CELL_EDITABLE) self.dvc.AppendTextColumn("Name", _GetColumnIdx("Name"), width=150) self.dvc.AppendTextColumn("Units", _GetColumnIdx("Units"), width=100, align=wx.ALIGN_RIGHT, mode=dv.DATAVIEW_CELL_EDITABLE) self.dvc.AppendTextColumn("Cost Basis", _GetColumnIdx("Cost Basis"), width=100, align=wx.ALIGN_RIGHT, mode=dv.DATAVIEW_CELL_EDITABLE) self.dvc.AppendTextColumn("Purchase Date", _GetColumnIdx("Purchase Date"), width=80, align=wx.ALIGN_RIGHT, mode=dv.DATAVIEW_CELL_EDITABLE) for c in self.dvc.Columns: c.Sortable = False c.Reorderable = False # set the Sizer property (same as SetSizer) self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) # Add some buttons to help out with the tests self.buttonAddRow = wx.Button(self, label="Add Row") self.Bind(wx.EVT_BUTTON, self.OnAddRow, self.buttonAddRow) self.buttonDeleteRows = wx.Button(self, label="Delete Row(s)") self.Bind(wx.EVT_BUTTON, self.OnDeleteRows, self.buttonDeleteRows) self.buttonMoveUp = wx.Button(self, label="Move Up") self.Bind(wx.EVT_BUTTON, self.OnMoveUp, self.buttonMoveUp) self.buttonMoveDown = wx.Button(self, label="Move Down") self.Bind(wx.EVT_BUTTON, self.OnMoveDown, self.buttonMoveDown) btnbox = wx.BoxSizer(wx.HORIZONTAL) btnbox.Add(self.buttonAddRow, 0, wx.LEFT | wx.RIGHT, 5) btnbox.Add(self.buttonDeleteRows, 0, wx.LEFT | wx.RIGHT, 5) btnbox.Add(self.buttonMoveUp, 0, wx.LEFT | wx.RIGHT, 5) btnbox.Add(self.buttonMoveDown, 0, wx.LEFT | wx.RIGHT, 5) self.Sizer.Add(btnbox, 0, wx.TOP | wx.BOTTOM, 5) # Initial state for buttons self.buttonDeleteRows.Disable() self.buttonMoveUp.Disable() self.buttonMoveDown.Disable() # Bind some events so we can see what the DVC sends us self.Bind(dv.EVT_DATAVIEW_ITEM_EDITING_DONE, self.OnEditingDone, self.dvc) self.Bind(dv.EVT_DATAVIEW_ITEM_VALUE_CHANGED, self.OnValueChanged, self.dvc) self.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.OnSelectionChanged, self.dvc)
def __init__(self, parent, log, model=None, data=None): self.log = log wx.Panel.__init__(self, parent, -1) # Create a dataview control self.dvc = dv.DataViewCtrl( self, style=wx.BORDER_THEME | dv.DV_ROW_LINES # nice alternating bg colors #| dv.DV_HORIZ_RULES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) # Create an instance of our simple model... if model is None: self.model = TestModel(data, log) else: self.model = model # ...and associate it with the dataview control. Models can # be shared between multiple DataViewCtrls, so this does not # assign ownership like many things in wx do. There is some # internal reference counting happening so you don't really # need to hold a reference to it either, but we do for this # example so we can fiddle with the model from the widget # inspector or whatever. self.dvc.AssociateModel(self.model) # Now we create some columns. The second parameter is the # column number within the model that the DataViewColumn will # fetch the data from. This means that you can have views # using the same model that show different columns of data, or # that they can be in a different order than in the model. self.dvc.AppendTextColumn("Artist", 1, width=170, mode=dv.DATAVIEW_CELL_EDITABLE) self.dvc.AppendTextColumn("Title", 2, width=260, mode=dv.DATAVIEW_CELL_EDITABLE) self.dvc.AppendTextColumn("Genre", 3, width=80, mode=dv.DATAVIEW_CELL_EDITABLE) # There are Prepend methods too, and also convenience methods # for other data types but we are only using strings in this # example. You can also create a DataViewColumn object # yourself and then just use AppendColumn or PrependColumn. c0 = self.dvc.PrependTextColumn("Id", 0, width=40) # The DataViewColumn object is returned from the Append and # Prepend methods, and we can modify some of it's properties # like this. c0.Alignment = wx.ALIGN_RIGHT c0.Renderer.Alignment = wx.ALIGN_RIGHT c0.MinWidth = 40 # Through the magic of Python we can also access the columns # as a list via the Columns property. Here we'll mark them # all as sortable and reorderable. for c in self.dvc.Columns: c.Sortable = True c.Reorderable = True # Let's change our minds and not let the first col be moved. c0.Reorderable = False # set the Sizer property (same as SetSizer) self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) # Add some buttons to help out with the tests b1 = wx.Button(self, label="New View", name="newView") self.Bind(wx.EVT_BUTTON, self.OnNewView, b1) b2 = wx.Button(self, label="Add Row") self.Bind(wx.EVT_BUTTON, self.OnAddRow, b2) b3 = wx.Button(self, label="Delete Row(s)") self.Bind(wx.EVT_BUTTON, self.OnDeleteRows, b3) btnbox = wx.BoxSizer(wx.HORIZONTAL) btnbox.Add(b1, 0, wx.LEFT | wx.RIGHT, 5) btnbox.Add(b2, 0, wx.LEFT | wx.RIGHT, 5) btnbox.Add(b3, 0, wx.LEFT | wx.RIGHT, 5) self.Sizer.Add(btnbox, 0, wx.TOP | wx.BOTTOM, 5) # Bind some events so we can see what the DVC sends us self.Bind(dv.EVT_DATAVIEW_ITEM_EDITING_DONE, self.OnEditingDone, self.dvc) self.Bind(dv.EVT_DATAVIEW_ITEM_VALUE_CHANGED, self.OnValueChanged, self.dvc)
def __init__(self, parent, log, files_name_text, select_list, input_file_name, model_excel_name, data=None, model=None): self.log = log wx.Panel.__init__(self, parent, -1) self.files_name_text = files_name_text self.input_file_name = input_file_name self.model_excel_name = model_excel_name # Create a dataview control self.dvc = dv.DataViewCtrl( self, style=wx.BORDER_THEME | dv.DV_ROW_LINES # nice alternating bg colors #| dv.DV_HORIZ_RULES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) # Create an instance of our model... if model is None: self.model = MyTreeListModel(data, log) else: self.model = model # Tel the DVC to use the model self.dvc.AssociateModel(self.model) # Define the columns that we want in the view. Notice the # parameter which tells the view which col in the data model to pull # values from for each view column. if 0: self.tr = tr = dv.DataViewTextRenderer() c0 = dv.DataViewColumn( "Genre", # title tr, # renderer 0, # data model column width=80) self.dvc.AppendColumn(c0) else: self.dvc.AppendTextColumn("File name", 0, width=250) #c1 = self.dvc.AppendTextColumn("Artist", 1, width=170, mode=dv.DATAVIEW_CELL_EDITABLE) c2 = self.dvc.AppendTextColumn("Title", 2, width=80, mode=dv.DATAVIEW_CELL_EDITABLE) #c3 = self.dvc.AppendDateColumn('index', 4, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) c4 = self.dvc.AppendToggleColumn('select', 5, width=40, mode=dv.DATAVIEW_CELL_ACTIVATABLE) # Notice how we pull the data from col 3, but this is the 6th col # added to the DVC. The order of the view columns is not dependent on # the order of the model columns at all. c5 = self.dvc.AppendTextColumn("id", 3, width=40, mode=dv.DATAVIEW_CELL_EDITABLE) #c5.Alignment = wx.ALIGN_RIGHT # Set some additional attributes for all the columns for c in self.dvc.Columns: c.Sortable = True c.Reorderable = True self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) #b1 = wx.Button(self, label="Open File", name="openFile") #self.Bind(wx.EVT_BUTTON, self.OnOpen, b1) #b2 = wx.Button(self, label="Del File", name="delFile") #self.Bind(wx.EVT_BUTTON, self.onDel, b2) b3 = wx.Button(self, label="Save File", name="saveFile") self.Bind(wx.EVT_BUTTON, self.OnSave, b3) #b4 = wx.Button(self, label="New View", name="newView") #self.Bind(wx.EVT_BUTTON, self.OnNewView, b4) btnbox = wx.BoxSizer(wx.HORIZONTAL) #btnbox.Add(b1, 0, wx.LEFT|wx.RIGHT, 5) #btnbox.Add(b2, 0, wx.LEFT|wx.RIGHT, 5) btnbox.Add(b3, 0, wx.LEFT | wx.RIGHT, 5) #btnbox.Add(b4, 0, wx.LEFT|wx.RIGHT, 5) self.Sizer.Add(btnbox, 0, wx.TOP | wx.BOTTOM, 5)
def __init__(self, parent, ctr, SelectURICallBack=None, SelectIDCallBack=None, **kwargs): big = self.isManager = SelectURICallBack is None and SelectIDCallBack is None wx.Panel.__init__(self, parent, -1, size=(800 if big else 450, 600 if big else 200)) self.SelectURICallBack = SelectURICallBack self.SelectIDCallBack = SelectIDCallBack dvStyle = wx.BORDER_THEME | dv.DV_ROW_LINES if self.isManager: # no multiple selection in selector mode dvStyle |= dv.DV_MULTIPLE self.dvc = dv.DataViewCtrl(self, style=dvStyle) def args(*a, **k): return (a, k) ColumnsDesc = [ args(_("ID"), COL_ID, width=70), args(_("Last URI"), COL_URI, width=300 if big else 80), args(_("Description"), COL_DESC, width=300 if big else 200, mode=dv.DATAVIEW_CELL_EDITABLE if self.isManager else dv.DATAVIEW_CELL_INERT), args(_("Last connection"), COL_LAST, width=120), ] self.model = IDBrowserModel(ctr.ProjectPath, len(ColumnsDesc)) self.dvc.AssociateModel(self.model) col_list = [] for a, k in ColumnsDesc: col_list.append( self.dvc.AppendTextColumn(*a, **dict(k, flags=colflags))) col_list[COL_LAST].SetSortOrder(False) # TODO : sort by last bvisit by default self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) btnbox = wx.BoxSizer(wx.HORIZONTAL) if self.isManager: # deletion of secret and metadata deleteButton = wx.Button(self, label=_("Delete ID")) self.Bind(wx.EVT_BUTTON, self.OnDeleteButton, deleteButton) btnbox.Add(deleteButton, 0, wx.LEFT | wx.RIGHT, 5) # export all exportButton = wx.Button(self, label=_("Export all")) self.Bind(wx.EVT_BUTTON, self.OnExportButton, exportButton) btnbox.Add(exportButton, 0, wx.LEFT | wx.RIGHT, 5) # import with a merge -> duplicates are asked for importButton = wx.Button(self, label=_("Import")) self.Bind(wx.EVT_BUTTON, self.OnImportButton, importButton) btnbox.Add(importButton, 0, wx.LEFT | wx.RIGHT, 5) else: # selector mode self.useURIButton = wx.Button(self, label=_("Use last URI")) self.Bind(wx.EVT_BUTTON, self.OnUseURIButton, self.useURIButton) self.useURIButton.Disable() btnbox.Add(self.useURIButton, 0, wx.LEFT | wx.RIGHT, 5) self.Sizer.Add(btnbox, 0, wx.TOP | wx.BOTTOM, 5) self.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.OnSelectionChanged, self.dvc)
def __init__(self, parent, log, data=None, model=None): self.log = log wx.Panel.__init__(self, parent, -1) # Create a dataview control self.dvc = dv.DataViewCtrl( self, style=wx.BORDER_THEME | dv.DV_ROW_LINES # nice alternating bg colors #| dv.DV_HORIZ_RULES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) # Create an instance of our model... if model is None: self.model = MyTreeListModel(data, log) else: self.model = model # Tell the DVC to use the model self.dvc.AssociateModel(self.model) # Define the columns that we want in the view. Notice the # parameter which tells the view which column in the data model to pull # values from for each view column. if 1: # here is an example of adding a column with full control over the renderer, etc. tr = dv.DataViewTextRenderer() c0 = dv.DataViewColumn( "Genre", # title tr, # renderer 0, # data model column width=80) self.dvc.AppendColumn(c0) else: # otherwise there are convenience methods for the simple cases self.dvc.AppendTextColumn("Genre", 0, width=80) c1 = self.dvc.AppendTextColumn("Artist", 1, width=170, mode=dv.DATAVIEW_CELL_EDITABLE) c2 = self.dvc.AppendTextColumn("Title", 2, width=260, mode=dv.DATAVIEW_CELL_EDITABLE) c3 = self.dvc.AppendDateColumn('Acquired', 4, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) c4 = self.dvc.AppendToggleColumn('Like', 5, width=40, mode=dv.DATAVIEW_CELL_ACTIVATABLE) # Notice how we pull the data from col 3, but this is the 6th column # added to the DVC. The order of the view columns is not dependent on # the order of the model columns at all. c5 = self.dvc.AppendTextColumn("id", 3, width=40, mode=dv.DATAVIEW_CELL_EDITABLE) c5.Alignment = wx.ALIGN_RIGHT # Set some additional attributes for all the columns for c in self.dvc.Columns: c.Sortable = True c.Reorderable = True self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) b1 = wx.Button(self, label="New View", name="newView") self.Bind(wx.EVT_BUTTON, self.OnNewView, b1) self.Sizer.Add(b1, 0, wx.ALL, 5)
def test_dataviewCtrl1(self): class MyModel(dv.DataViewIndexListModel): def GetCount(self): return 50 def GetColumnCount(self): return 10 def GetValueByRow(self, row, col): return 'value(%d, %d)' % (row, col) def SetValueByRow(self, value, row, col): return True def GetColumnType(self, col): return 'string' dvc = dv.DataViewCtrl(self.frame, style=dv.DV_ROW_LINES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) model = MyModel() count1 = model.GetRefCount() dvc.AssociateModel(model) count2 = model.GetRefCount() # The reference count should still be 1 because the model was # DecRef'ed when it's ownership transferred to C++ in the # AssociateModel call self.assertEqual(count2, 1) self.assertTrue(count2 == count1) # Now try associating it with another view and check counts again dvc2 = dv.DataViewCtrl(self.frame, style=dv.DV_ROW_LINES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) dvc2.AssociateModel(model) self.assertEqual(model.GetRefCount(), 2) # Destroying the 2nd view should drop the refcount again dvc2.Destroy() self.assertEqual(model.GetRefCount(), 1) # And since ownership has been transferred, deleting this reference # to the model should not cause any problems. del model dvc.AppendTextColumn("one", 1, width=80, mode=dv.DATAVIEW_CELL_EDITABLE) dvc.AppendTextColumn("two", 2, width=80, mode=dv.DATAVIEW_CELL_EDITABLE) dvc.AppendTextColumn("three", 3, width=80, mode=dv.DATAVIEW_CELL_EDITABLE) dvc.AppendTextColumn("four", 4, width=80, mode=dv.DATAVIEW_CELL_EDITABLE) dvc.AppendTextColumn("five", 5, width=80, mode=dv.DATAVIEW_CELL_EDITABLE) self.frame.SendSizeEvent() dvc.Refresh() self.myYield()
def __init__(self, *args, **kargs): page = kargs.pop('page', None) parent = kargs.pop('parent', None) title = kargs.pop('title', 'HDF export') path = kargs.pop('path', os.path.join(os.getcwd(), 'data.hdf')) dataset = kargs.pop('dataset', None) metadata = kargs.pop('metadata', OrderedDict()) export_flag = kargs.pop('export_flag', {}) if dataset is None: if page is None: return dataset, metadata, export_flag = build_data( page, verbose=False, metadata=metadata, export_flag=export_flag) style = (wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.RESIZE_BORDER) if parent is not None: style = style | wx.FRAME_FLOAT_ON_PARENT wx.Frame.__init__(self, *args, style=style, title=title, parent=parent, size=(400, 500)) self.SetSizer(wx.BoxSizer(wx.VERTICAL)) hsizer = wx.BoxSizer(wx.HORIZONTAL) self.GetSizer().Add(hsizer, 1, wx.EXPAND, 0) panel = wx.Panel(self) hsizer.Add(panel, 1, wx.EXPAND) panel.SetSizer(wx.BoxSizer(wx.VERTICAL)) sizer = panel.GetSizer() sizer_h = wx.BoxSizer(wx.HORIZONTAL) wildcard = "HDF(hdf)|*.hdf|Any|*.*" self.filepicker = wx.FilePickerCtrl(panel, style=wx.FLP_SAVE | wx.FLP_USE_TEXTCTRL, path=path, wildcard=wildcard) self.sp = wx.SplitterWindow(panel, wx.ID_ANY, style=wx.SP_NOBORDER | wx.SP_LIVE_UPDATE | wx.SP_3DSASH) self.dataviewCtrl = dv.DataViewCtrl(self.sp, style=(wx.BORDER_THEME | dv.DV_ROW_LINES | dv.DV_VERT_RULES)) self.model = HDFDataModel(export_flag=export_flag, dataset=dataset, metadata=metadata) self.dataviewCtrl.AssociateModel(self.model) self.tr = tr = dv.DataViewTextRenderer() c0 = dv.DataViewColumn( "name", # title tr, # renderer 0, # data model column width=200) self.dataviewCtrl.AppendColumn(c0) # self.dataviewCtrl.AppendTextColumn('name', 0, # width = 150, # mode=dv.DATAVIEW_CELL_ACTIVATABLE) c1 = self.dataviewCtrl.AppendToggleColumn( 'export', 1, width=70, mode=dv.DATAVIEW_CELL_ACTIVATABLE) c2 = self.dataviewCtrl.AppendTextColumn( 'value', 2, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) c3 = self.dataviewCtrl.AppendTextColumn( 'shape', 3, mode=dv.DATAVIEW_CELL_ACTIVATABLE) #c4 = self.dataviewCtrl.AppendTextColumn('metadata', 4, # mode=dv.DATAVIEW_CELL_ACTIVATABLE) for c in self.dataviewCtrl.Columns: c.Sortable = True c.Reorderable = True c1.Alignment = wx.ALIGN_CENTER #from ifigure.widgets.var_viewerg2 import _PropertyGrid self.grid = pg.PropertyGrid(self.sp) #self.btn_load = wx.Button(self, label = 'Load') self.choices = [ 'Options...', 'No Property', 'Minimum properties', 'All properties' ] self.cb = wx.ComboBox(panel, wx.ID_ANY, style=wx.TE_PROCESS_ENTER | wx.CB_READONLY, choices=self.choices) self.cb.SetValue(self.choices[0]) self.btn_export = wx.Button(panel, label='Export...') sizer.Add(self.filepicker, 0, wx.EXPAND | wx.ALL, 1) sizer.Add(self.sp, 1, wx.EXPAND | wx.ALL, 5) sizer.Add(sizer_h, 0, wx.EXPAND | wx.ALL, 5) #sizer_h.Add(self.btn_load, 0, wx.EXPAND|wx.ALL, 1) sizer_h.Add(self.cb, 0, wx.EXPAND | wx.ALL, 1) sizer_h.AddStretchSpacer(prop=1) sizer_h.Add(self.btn_export, 0, wx.EXPAND | wx.ALL, 1) self.Layout() self.Show() self.sp.SetMinimumPaneSize(30) self.sp.SplitHorizontally(self.dataviewCtrl, self.grid) self.sp.SetSashPosition(300) # self.Bind(dv.EVT_DATAVIEW_ITEM_VALUE_CHANGED, # self.onDataChanged, self.dataviewCtrl) self.Bind(dv.EVT_DATAVIEW_SELECTION_CHANGED, self.onSelChanged, self.dataviewCtrl) # self.Bind(dv.EVT_DATAVIEW_ITEM_COLLAPSING, # self.onCollapsing, self.dataviewCtrl) self.grid.Bind(pg.EVT_PG_CHANGED, self.onPGChanged, self.grid) self.Bind(wx.EVT_BUTTON, self.onExport, self.btn_export) self.Bind(wx.EVT_COMBOBOX, self.onCBHit, self.cb) self.Bind(wx.EVT_CLOSE, self.onWindowClose) self.page = page wx.GetApp().TopWindow.hdf_export_window = self
def __init__(self): """ wxPython logging window """ #import wx.lib.inspection #wx.lib.inspection.InspectionTool().Show() percentHi = 50 percentWide = 30 try: frame_style = wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER #frame_style = frame_style & ~ (wx.RESIZE_BORDER | wx.MAXIMIZE_BOX) wx.lib.colourdb.updateColourDB() self.wxorange = wx.Colour("ORANGE RED") self.wxdarkgreen = wx.Colour("DARK GREEN") wx.Frame.__init__(self, None, title="Miner panel", style=frame_style) self.Bind(EVT_LOG_MSG, self.on_log_msg) self.Bind(wx.EVT_CLOSE, self.oncloseevt) self.SetIcon(wx.Icon("Miner_on.ico")) (self.display_width_, self.display_height_) = wx.GetDisplaySize() frame_width = self.display_width_ * percentWide / 100 frame_height = self.display_height_ * percentHi / 100 self.SetSize(wx.Size(frame_width, frame_height)) panel_width = self.GetClientSize().GetWidth() - 2 panel_height = self.GetClientSize().GetHeight() - 46 status_width = 500 * percentWide / 100 text_width = panel_width - status_width text_height = panel_height if text_width < 1: text_width = 100 * percentWide / 100 value_width = panel_width - text_width unit_width = value_width / 10 c0_width = int(unit_width * 2) c1_width = int(unit_width * 2) if c0_width < 120: c0_width = 120 if c1_width < 120: c1_width = 120 c2_width = int(unit_width * 6) delta = (c0_width + c1_width + c2_width) - value_width if delta > 10: c2_width = c2_width - delta if c2_width < 260: c2_width = 260 status_width = c0_width + c1_width + c2_width self.dvc = dv.DataViewCtrl( self, style=wx.BORDER_THEME | dv.DV_ROW_LINES # nice alternating bg colors #| dv.DV_HORIZ_RULES | dv.DV_VERT_RULES | dv.DV_MULTIPLE | dv.DV_NO_HEADER, size=(status_width, text_height)) self.model = StatusModel(getpaneldata()) self.dvc.AssociateModel(self.model) c0 = self.dvc.AppendTextColumn("Item " + str(c0_width) + " " + str(value_width), 1, width=c0_width, align=wx.ALIGN_RIGHT, mode=dv.DATAVIEW_CELL_INERT) c1 = self.dvc.AppendTextColumn("Characteristic " + str(c1_width), 2, width=c1_width, align=wx.ALIGN_RIGHT, mode=dv.DATAVIEW_CELL_INERT) c2 = self.dvc.AppendTextColumn("Value " + str(c2_width - 4), 3, width=c2_width - 4, align=wx.ALIGN_LEFT, mode=dv.DATAVIEW_CELL_INERT) for c in self.dvc.Columns: c.Sortable = False c.Reorderable = False log_font = wx.Font(9, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.FONTWEIGHT_NORMAL) panel = wx.Panel(self, wx.ID_ANY) style = wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL | wx.TE_RICH2 self.text = wx.TextCtrl(panel, wx.ID_ANY, size=(text_width, text_height), style=style) self.text.SetFont(log_font) sizer = wx.BoxSizer(wx.VERTICAL) wbox = wx.BoxSizer(wx.HORIZONTAL) hbox = wx.BoxSizer(wx.HORIZONTAL) wbox.Add(self.text, 0, wx.ALL | wx.EXPAND | wx.LEFT, 0) wbox.Add(self.dvc, 0, wx.ALL | wx.EXPAND | wx.RIGHT, 0) self.closebtn = wx.Button(panel, wx.ID_ANY, 'Close') self.closebtn.Bind(wx.EVT_BUTTON, self.onclosebutton) self.Bind(wx.EVT_BUTTON, self.onclosebutton, self.closebtn) self.copybtn = wx.Button(panel, wx.ID_ANY, label="Copy to clipboard") self.copybtn.Bind(wx.EVT_BUTTON, self.oncopybutton) self.Bind(wx.EVT_BUTTON, self.oncopybutton, self.copybtn) self.debugbtn = wx.Button(panel, wx.ID_ANY, label="Miner Debug") self.debugbtn.Bind(wx.EVT_BUTTON, self.ondebugbutton) self.Bind(wx.EVT_BUTTON, self.ondebugbutton, self.debugbtn) self.bsmodebtn = wx.Button(panel, wx.ID_ANY, label="Exclude") self.bsmodebtn.Bind(wx.EVT_BUTTON, self.onbsmodebutton) self.Bind(wx.EVT_BUTTON, self.onbsmodebutton, self.bsmodebtn) self.wakeupbtn = wx.Button(panel, wx.ID_ANY, label="Miner On") self.wakeupbtn.Bind(wx.EVT_BUTTON, self.onwakeupbutton) self.Bind(wx.EVT_BUTTON, self.onwakeupbutton, self.wakeupbtn) self.standbybtn = wx.Button(panel, wx.ID_ANY, label="Miner Off") self.standbybtn.Bind(wx.EVT_BUTTON, self.onstandbybutton) self.Bind(wx.EVT_BUTTON, self.onstandbybutton, self.standbybtn) hbox.Add(self.copybtn, 1, wx.ALL | wx.ALIGN_CENTER, 5) hbox.Add(self.debugbtn, 1, wx.ALL | wx.ALIGN_CENTER, 5) hbox.Add(self.bsmodebtn, 1, wx.ALL | wx.ALIGN_CENTER, 5) hbox.Add(self.standbybtn, 1, wx.ALL | wx.ALIGN_CENTER, 5) hbox.Add(self.wakeupbtn, 1, wx.ALL | wx.ALIGN_CENTER, 5) hbox.Add(self.closebtn, 1, wx.ALL | wx.ALIGN_CENTER, 5) sizer.Add(wbox, flag=wx.ALL | wx.EXPAND) sizer.Add(hbox, 1, flag=wx.ALL | wx.ALIGN_CENTER, border=5) panel.SetSizer(sizer) panel.Layout() panel.Fit() self.CenterOnScreen() self.dataObj = None self.Raise() except Exception as err: toast_err("Status panel error: " + str(err))
def __init__(self, parent, data=None, model=None): wx.Panel.__init__(self, parent, size=(600, 250)) self.anuncio = None self.parent = parent self.dvc = dv.DataViewCtrl(self, style=wx.BORDER_THEME | dv.DV_ROW_LINES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) self.model = None if model is None: if data: self.model = MyTreeListModel(data) else: self.model = model # Tel the DVC to use the model if self.model: self.dvc.AssociateModel(self.model) self.tr = tr = dv.DataViewTextRenderer() c0 = dv.DataViewColumn( "Bloque", # title tr, # renderer 0, # data model column width=250) self.dvc.AppendColumn(c0) # else: # self.dvc.AppendTextColumn("Bloque", 0, width=80) c3 = self.dvc.AppendTextColumn('Inicio', 1, width=200, mode=dv.DATAVIEW_CELL_ACTIVATABLE) c4 = self.dvc.AppendTextColumn('Final', 2, width=200, mode=dv.DATAVIEW_CELL_ACTIVATABLE) c1 = self.dvc.AppendTextColumn("Anuncio", 3, width=300, mode=dv.DATAVIEW_CELL_ACTIVATABLE) c2 = self.dvc.AppendTextColumn("Marca", 4, width=150, mode=dv.DATAVIEW_CELL_ACTIVATABLE) c5 = self.dvc.AppendTextColumn("id", 5, width=40, mode=dv.DATAVIEW_CELL_ACTIVATABLE) # Notice how we pull the data from col 3, but this is the 6th col # added to the DVC. The order of the view columns is not dependent on # the order of the model columns at all. # c5.Alignment = wx.ALIGN_RIGHT # Set some additional attributes for all the columns for i, c in enumerate(self.dvc.Columns): c.Sortable = True c.Reorderable = True self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) self.Bind(dv.EVT_DATAVIEW_ITEM_ACTIVATED, self.OnClick) b1 = wx.Button(self, label="Vista Completa", name="vistacompleta") self.Bind(wx.EVT_BUTTON, self.OnNewView, b1) self.Sizer.Add(b1, 0, wx.ALL, 5)
def _post_init(self): # The native GTK widget used by DataViewCtrl would have an internal # "live" search feature which steals some keyboard shortcuts: Ctrl+n, # Ctrl+p, Ctrl+f, Ctrl+a, Ctrl+Shift+a # https://groups.google.com/d/msg/wxpython-users/1sUPp766uXU/0J22mUrkzoAJ # Ctrl+f can be recovered with by not overriding the Model's # GetColumnType method # See also bug #349 # See bug #260 for generic issues about DataViewCtrl self.treec = dv.DataViewCtrl(self, style=dv.DV_MULTIPLE | dv.DV_NO_HEADER) self.cmenu = ContextMenu(self) self.ctabmenu = TabContextMenu(self.filename) self.logspanel = logs.LogsPanel(self, self.filename) self.dbhistory = logs.DatabaseHistory(self, self.logspanel, self.logspanel.get_panel(), self.filename, self.treec.GetBackgroundColour()) self.properties = Properties(self.treec) self.base_properties = DBProperties(self.properties) self.accelerators = {} creating_tree_event.signal(filename=self.filename) # Initialize the icons only *after* the various plugins have added # their properties self.properties.post_init() # Initialize the tree only *after* instantiating the class (and # initilizing the icons), because actions like the creation of item # images rely on the filename to be in the dictionary for row in core_api.get_all_items(self.filename): self._init_item_data(row["I_id"], row["I_text"]) self.dvmodel = Model(self.data, self.filename) self.treec.AssociateModel(self.dvmodel) # According to DataViewModel's documentation (as of September 2014) # its reference count must be decreased explicitly to avoid memory # leaks; the wxPython demo, however, doesn't do it, and if done here, # the application crashes with a segfault when closing all databases # See also bug #104 #self.dvmodel.DecRef() dvrenderer = Renderer(self, self.treec) dvcolumn = dv.DataViewColumn("Item", dvrenderer, 0, align=wx.ALIGN_LEFT) self.treec.AppendColumn(dvcolumn) self._init_accelerators() self.Initialize(self.treec) # Initialize the logs panel *after* signalling creating_tree_event, # which is used to add plugin logs self.logspanel.initialize() nb_left = wx.GetApp().nb_left nb_left.add_page(self, os.path.basename(self.filename), select=True) # The logs panel must be shown only *after* adding the page to the # notebook, otherwise *for*some*reason* the databases opened # automatically by the sessions manager (those opened manually aren't # affected) will have the sash of the SplitterWindow not correctly # positioned (only if using SetSashGravity) if wx.GetApp().logs_configuration.is_shown(): self.show_logs() self.history_item_update_requests = [] self.history_tree_reset_request = False # Explicitly set focus on the tree, otherwise after opening a database # no window has focus, and this e.g. prevents F10 from showing the menu # if set on autohide, until a window is manually focused (note that # this would happen only when opening a database manually, it wouldn't # happen when a database is opened automatically by the session # manager) self.treec.SetFocus() self.treec.Bind(dv.EVT_DATAVIEW_ITEM_CONTEXT_MENU, self._popup_item_menu) core_api.bind_to_insert_item(self._handle_insert_item) core_api.bind_to_update_item_text(self._handle_update_item_text) core_api.bind_to_deleting_item(self._handle_deleting_item) core_api.bind_to_deleted_item_2(self._handle_deleted_item) core_api.bind_to_history_insert(self._handle_history_insert) core_api.bind_to_history_update_simple( self._handle_history_update_simple) core_api.bind_to_history_update_deep(self._handle_history_update_deep) core_api.bind_to_history_update_text(self._handle_history_update_text) core_api.bind_to_history_remove(self._handle_history_remove) core_api.bind_to_history(self._handle_history)
def __init__(self, parent): wx.Panel.__init__(self, parent, -1) # Create a dataview control self.dvc = dv.DataViewCtrl(self, style=wx.BORDER_THEME | dv.DV_ROW_LINES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) self.model = DataModel([]) self.dvc.AssociateModel(self.model) self.dvc.AppendTextColumn("path", 1, width=170) self.dvc.AppendTextColumn("title", 2, width=300, mode=dv.DATAVIEW_CELL_EDITABLE) self.dvc.AppendProgressColumn("progress", 3, width=130) self.dvc.AppendTextColumn("status", 4, width=300, mode=dv.DATAVIEW_CELL_EDITABLE) # set the Sizer property (same as SetSizer) self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) b2 = wx.Button(self, label="Add files") self.Bind(wx.EVT_BUTTON, self.OnAddRow, b2) self.button_add = b2 b3 = wx.Button(self, label="Delete selected") b3.Enable(False) self.Bind(wx.EVT_BUTTON, self.OnDeleteRows, b3) self.button_delete = b3 b5 = wx.Button(self, label="Start upload") b5.Enable(False) self.Bind(wx.EVT_BUTTON, self.start_upload, b5) self.button_upload_start = b5 b6 = wx.Button(self, label="Stop upload") b6.Enable(False) self.Bind(wx.EVT_BUTTON, self.stop_upload, b6) self.button_upload_stop = b6 self.in_progress = False self.files_in_progress = 0 btnbox = wx.BoxSizer(wx.HORIZONTAL) btnbox.Add(b2, 0, wx.LEFT | wx.RIGHT, 5) btnbox.Add(b3, 0, wx.LEFT | wx.RIGHT, 5) btnbox.Add(b5, 0, wx.LEFT | wx.RIGHT, 5) btnbox.Add(b6, 0, wx.LEFT | wx.RIGHT, 5) self.Sizer.Add(btnbox, 0, wx.TOP | wx.BOTTOM, 5) # Bind some events so we can see what the DVC sends us self.Bind(dv.EVT_DATAVIEW_ITEM_START_EDITING, self.on_before_edit, self.dvc) # self.Bind(dv.EVT_DATAVIEW_ITEM_EDITING_DONE, self.OnEditingDone, self.dvc) # self.Bind(dv.EVT_DATAVIEW_ITEM_VALUE_CHANGED, self.OnValueChanged, self.dvc) self.Bind(dv.EVT_DATAVIEW_ITEM_ACTIVATED, self.RightClick, self.dvc) parent.Bind(wx.EVT_CLOSE, self.OnClose) self.parent = parent # worker stuff self.enclosure_queue = Queue() self.worker = None # drop file_drop_target = MyFileDropTarget(self.on_drop) self.SetDropTarget(file_drop_target) auth = OAuth(self) self.oauth = auth if not auth.ShowModal(): self.parent.Close()
def __init__(self): wx.Frame.__init__(self, None, -1, "New ListCtrl Test") p = wx.Panel(self, -1) box = wx.BoxSizer(wx.VERTICAL) box1 = wx.StaticBoxSizer(wx.StaticBox(p, -1, "MyData"), wx.VERTICAL) self.lista1 = dv.DataViewCtrl( p, size=(500, 150), style=wx.BORDER_THEME #| dv.DV_ROW_LINES # nice alternating bg colors | dv.DV_HORIZ_RULES | dv.DV_VERT_RULES #| dv.DV_MULTIPLE ) self.model1 = MyData1() self.lista1.AssociateModel(self.model1) self.lista1.AppendTextColumn("A", 0, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista1.AppendTextColumn("B", 1, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista1.AppendTextColumn("C", 2, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista1.AppendTextColumn("D", 3, width=150, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista1.Select(self.model1.GetItem(3)) self.lista1.Bind(dv.EVT_DATAVIEW_ITEM_ACTIVATED, self.onDClick1) box1.Add(self.lista1, 1, wx.EXPAND) box.Add(box1, 1, wx.EXPAND | wx.ALL, 5) box2 = wx.StaticBoxSizer(wx.StaticBox(p, -1, "RowDataModel"), wx.VERTICAL) self.lista2 = dv.DataViewCtrl(p, size=(500, 150), style=wx.BORDER_THEME | dv.DV_HORIZ_RULES | dv.DV_VERT_RULES) self.model2 = MyData2() self.lista2.AssociateModel(self.model2) self.lista2.AppendTextColumn("HOLA", 0, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista2.AppendTextColumn("CHAO", 1, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista2.AppendTextColumn("OK", 2, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) for c in self.lista2.Columns: c.Sortable = True c.Reorderable = True self.lista2.Select(self.model2.GetItem(0)) self.lista2.Bind(dv.EVT_DATAVIEW_ITEM_ACTIVATED, self.onDClick2) box2.Add(self.lista2, 1, wx.EXPAND | wx.ALL) box.Add(box2, 1, wx.EXPAND | wx.ALL, 5) box3 = wx.StaticBoxSizer(wx.StaticBox(p, -1, "ObjDataModel"), wx.VERTICAL) self.lista3 = dv.DataViewCtrl(p, size=(500, 150), style=wx.BORDER_THEME | dv.DV_HORIZ_RULES | dv.DV_VERT_RULES) self.model3 = MyData3() self.lista3.AssociateModel(self.model3) self.lista3.AppendTextColumn("A", 0, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista3.AppendTextColumn("B", 1, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista3.AppendTextColumn("C", 2, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) self.lista3.AppendDateColumn("D", 3, width=100, mode=dv.DATAVIEW_CELL_ACTIVATABLE) for c in self.lista3.Columns: c.Sortable = True c.Reorderable = True self.lista3.Select(self.model3.GetItem(1)) self.lista3.Bind(dv.EVT_DATAVIEW_ITEM_ACTIVATED, self.onDClick3) box3.Add(self.lista3, 1, wx.EXPAND | wx.ALL) box.Add(box3, 1, wx.EXPAND | wx.ALL, 5) p.SetAutoLayout(True) p.SetSizer(box) box.Fit(p) self.Fit() #self.lista1.headers[0].text = u"Argentina" self.Bind(wx.EVT_CLOSE, self.onCloseWindow) self.Center(wx.BOTH)
def __init__(self, parent, df, log, model=None): self.df = df self.log = log wx.Panel.__init__(self, parent, -1) # Create a dataview control self.dvc = dv.DataViewCtrl( self, style=wx.BORDER_THEME | dv.DV_ROW_LINES # nice alternating bg colors #| dv.DV_HORIZ_RULES | dv.DV_VERT_RULES | dv.DV_MULTIPLE) # Create an instance of our simple model... if model is None: self.model = Model(self.df, log) else: self.model = model # ...and associate it with the dataview control. Models can # be shared between multiple DataViewCtrls, so this does not # assign ownership like many things in wx do. There is some # internal reference counting happening so you don't really # need to hold a reference to it either, but we do for this # example so we can fiddle with the model from the widget # inspector or whatever. self.dvc.AssociateModel(self.model) # Now we create some columns. The second parameter is the # column number within the model that the DataViewColumn will # fetch the data from. This means that you can have views # using the same model that show different columns of data, or # that they can be in a different order than in the model. idx = 0 header_list = list(self.df.columns) table_name = self.df.index.name if self.df.index.name else "" self.dvc.AppendTextColumn(table_name, 0, width=100) for column in df: self.dvc.AppendTextColumn(header_list[idx], idx + 1, width=100, align=wx.ALIGN_RIGHT) #print(df[column]) idx = idx + 1 # Through the magic of Python we can also access the columns # as a list via the Columns property. Here we'll mark them # all as sortable and reorderable. for c in self.dvc.Columns: c.Sortable = False c.Reorderable = False # set the Sizer property (same as SetSizer) self.Sizer = wx.BoxSizer(wx.VERTICAL) self.Sizer.Add(self.dvc, 1, wx.EXPAND) # Add some buttons to help out with the tests self.buttonNewView = wx.Button(self, label="New View", name="newView") self.Bind(wx.EVT_BUTTON, self.OnNewView, self.buttonNewView) btnbox = wx.BoxSizer(wx.HORIZONTAL) btnbox.Add(self.buttonNewView, 0, wx.LEFT | wx.RIGHT, 5) self.Sizer.Add(btnbox, 0, wx.TOP | wx.BOTTOM, 5)