class CheckingWindow(wx.Frame): def __init__(self, parent, title, processed_payments, output_file_loc): wx.Frame.__init__(self, parent, title=title, size=GUIUtils.calculate_window_size()) self.margin_to_frame_edge = 25 self.column_width = len( self.get_object_attrs_not_abstract(processed_payments)) self.processed_payments = processed_payments self.attr_column_mapping = {} self.output_file_loc = output_file_loc self.title_sizer = wx.BoxSizer(wx.HORIZONTAL) self.title = wx.StaticText( self, -1, style=wx.ALIGN_CENTER ) self.title.SetLabelMarkup( "<span size=\"xx-large\" weight=\"bold\">" "Checking Window</span>") self.title_sizer.Add(self.title, 1, wx.EXPAND, self.margin_to_frame_edge) self.title_sizer.SetMinSize(100, 50) # Build up the grid to display the data self.grid_sizer = wx.BoxSizer(wx.HORIZONTAL) self.grid = Grid(self, -1) self.grid.CreateGrid(len(processed_payments), self.column_width) self.grid_sizer.Add(self.grid, wx.EXPAND) for col_id, attribute in enumerate(self.get_object_attrs_not_abstract( processed_payments)): self.grid.SetColLabelValue(col_id, processed_payments[0].__dict__[attribute].name) self.attr_column_mapping[attribute] = \ (col_id, processed_payments[0].__dict__[attribute].name) for row_id, payment in enumerate(processed_payments): for col_id, attribute in enumerate(self.get_object_attrs_not_abstract( processed_payments)): if isinstance(payment.__dict__[attribute].value, datetime): self.grid.SetCellValue( row_id, col_id, payment.__dict__[attribute].value.strftime("%d/%m/%Y")) else: self.grid.SetCellValue( row_id, col_id, payment.__dict__[attribute].value) if isinstance(payment.__dict__[attribute].value, str) and \ re.match(r"X{6,14}", payment.__dict__[attribute].value): for col_col_id, _ in enumerate(self.get_object_attrs_not_abstract( processed_payments)): self.grid.SetCellBackgroundColour( row_id, col_col_id, wx.Colour(238, 210, 2, wx.ALPHA_OPAQUE)) elif not payment.__dict__[attribute].user_editable: self.grid.SetReadOnly(row_id, col_id) self.grid.AutoSize() # Create a Confirm Button self.confirm_sizer = wx.BoxSizer(wx.HORIZONTAL) self.confirm_button = wx.Button(self, label="Confirm") self.confirm_button.Bind(wx.EVT_BUTTON, self.confirm) self.confirm_sizer.Add(self.confirm_button, 1, wx.EXPAND|wx.ALL, self.margin_to_frame_edge) self.confirm_sizer.SetMinSize(100, 50) # Set up the base sizers self.base_sizer = wx.BoxSizer(wx.VERTICAL) self.base_sizer.Add(self.title_sizer, 1, wx.EXPAND|wx.ALL, self.margin_to_frame_edge) self.base_sizer.Add(self.grid_sizer, 5, wx.EXPAND|wx.LEFT|wx.RIGHT, self.margin_to_frame_edge) self.base_sizer.Add(self.confirm_sizer, 0.5 , wx.EXPAND|wx.ALL, self.margin_to_frame_edge) # Layout sizers self.SetSizer(self.base_sizer) self.SetAutoLayout(1) self.base_sizer.Fit(self) self.Show() @staticmethod def get_object_attrs_not_abstract(processed_payments): return sorted([x for x in dir(processed_payments[0]) if not x.startswith("_") and x in processed_payments[0].__dict__ and hasattr(processed_payments[0].__dict__[x], "value") and processed_payments[0].__dict__[x].value != ""], key=lambda x: processed_payments[0].__dict__[x].ordinal) def confirm(self, _): # Go over all the rows and run the validator methods. If one of them fails throw up an error message flagging # where the error is for row_id, processed_payment in enumerate(self.processed_payments): for user_editable_attr in [y for y in self.get_object_attrs_not_abstract(self.processed_payments) if self.processed_payments[0].__dict__[y].user_editable]: column_id, _ = \ self.attr_column_mapping[user_editable_attr] if(not processed_payment.__dict__[user_editable_attr].validator( self.grid.GetCellValue(row_id, column_id))): error_dialog = \ MessageDialog(self, "Data Entered in Column '{}' on Row '{}' - '{}' " "does not match what was expected. \n" "Please alter the data and click confirm again.\n\n" "No data has been altered and no files have been created.".format( self.attr_column_mapping[user_editable_attr][1], row_id, self.grid.GetCellValue(row_id, column_id) ), "Data Error - Please Recheck the Table", wx.OK|wx.ICON_ERROR|wx.CENTRE) error_dialog.ShowModal() return # After the validity of the data is assured, set the values to the new values and begin the conversion process for row_id, processed_payment in enumerate(self.processed_payments): for user_editable_attr in [y for y in self.get_object_attrs_not_abstract(self.processed_payments) if self.processed_payments[0].__dict__[y].user_editable]: column_id, _ = \ self.attr_column_mapping[user_editable_attr] if isinstance(processed_payment.__dict__[user_editable_attr].value, datetime): processed_payment.__dict__[user_editable_attr].value = datetime.strptime( self.grid.GetCellValue(row_id, column_id), "%d/%m/%Y") else: processed_payment.__dict__[user_editable_attr].value = \ self.grid.GetCellValue(row_id, column_id) converter = Converter() converter.write_output_file(self.output_file_loc, self.processed_payments) self.Close()
class MyFrame(wx.Frame): def __init__(self, parent, id, title): self.dao = self.init_db() self.read_records = 0 constraint = Constraints() constraint.offset = 0 constraint.limit = 100 # First, call the base class' __init__ method to create the frame wx.Frame.__init__(self, parent, id, title, wx.Point(100, 100), wx.Size(300, 200)) # Associate some events with methods of this class wx.EVT_SIZE(self, self.OnSize) #wx.EVT_SCROLLWIN_BOTTOM(self, self.OnEndScroll) # Add a panel and some controls to display the size and position panel = wx.Panel(self, -1) panel.SetBackgroundColour('#FDDF99') self.grid = Grid(panel) self.grid.CreateGrid(0, 12) wx.grid.EVT_GRID_CELL_LEFT_CLICK(self, self.OnGridLeftClick) #wx.EVT_SCROLLWIN_BOTTOM(self.grid, self.OnEndScroll) self.grid.Bind(wx.EVT_SCROLLWIN, self.OnEndScroll) #self.grid.SetCellBackgroundColour(2, 2, wx.CYAN) #self.grid.SetCellEditor(5, 0, wx.grid.GridCellNumberEditor(1,1000)) #self.grid.SetCellValue(5, 0, "123") #self.grid.SetCellAlignment(9, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) #self.grid.SetCellValue(9, 1, "This cell is set to span 3 rows and 3 columns") sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.grid, 1, wx.EXPAND) panel.SetSizer(sizer) #self.grid.ClearGrid() ##self.grid.AppendRows(20) #self.grid.SetColLabelValue(0,"test") #self.grid.SetCellValue(21, 1, "This cell is set to span 3 rows and 3 columns") rows = self.dao.fetch_records(constraint, raw_answers=True, record_type_classname=AutosModel) self.read_records = len(rows) print(rows[0]) #print(rows[7]["marca"]) #print(rows[7]["modelo"]) #print(rows[7]["version"]) self.printRows(rows) def printRows(self, rows): self.grid.SetColLabelValue(0, rows[0][0][0]) self.grid.SetColLabelValue(1, rows[0][1][0]) self.grid.SetColLabelValue(2, rows[0][2][0]) self.grid.AppendRows(self.read_records) i = -1 for row in rows: #print(i) #print(row[0]) #print(row[1]) #print(row[2]) if i > -1: self.grid.SetCellValue(i, 0, row[0]) self.grid.SetCellValue(i, 1, row[1]) self.grid.SetCellValue(i, 2, str(row[2])) i = i + 1 self.grid.AutoSize() # This method is called automatically when the CLOSE event is # sent to this window def OnCloseWindow(self, event): # tell the window to kill itself self.Destroy() def OnEndScroll(self, event): # tell the window to kill itself print("Llegue al final") print(event.GetPosition()) print(event.GetOrientation()) #print(event.__dict__) #print(event.commandType) event.Skip() # This method is called by the system when the window is resized, # because of the association above. def OnSize(self, event): # tell the event system to continue looking for an event handler, # so the default handler will get called. event.Skip() def OnGridLeftClick(self, evt): print("OnCellLeftClick: (%d,%d) %s\n" % (evt.GetRow(), evt.GetCol(), evt.GetPosition())) evt.Skip() def init_db(self): trx = TransactionManager( 'mssql', { 'dsn': 'MSSQLServer', 'host': '192.168.0.7', 'port': '1433', 'user': '******', 'password': '******', 'database': 'veritrade' }) daoDelegate = DAODelegateTest() return DatabasePersistence(trx, daoDelegate)