class myPanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) # Top Sizer topSizer = wx.BoxSizer(wx.VERTICAL) # Input Label labelSizer = wx.BoxSizer(wx.HORIZONTAL) self.inputLabel = wx.StaticText(self, -1, data.enterPadyamLabel, wx.Point(40, 20), wx.Size(720, 20)) self.increaseFontSize(self.inputLabel, 1.5) labelSizer.Add(self.inputLabel, 1, wx.EXPAND | wx.ALL, 5) topSizer.Add(labelSizer, 0, wx.ALIGN_LEFT) # Input Multiline TextCtrl self.input = wx.TextCtrl(self, 5, '', wx.Point(40, 50), wx.Size(720, 140), wx.TE_MULTILINE | wx.TE_DONTWRAP) self.increaseFontSize(self.input, 1.5) topSizer.Add(self.input, 1, wx.EXPAND | wx.ALL, 5) # Output Label labelSizer1 = wx.BoxSizer(wx.HORIZONTAL) self.outputLabel = wx.StaticText(self, -1, data.seeResultsHereLabel, wx.Point(40, 20), wx.Size(720, 20)) self.increaseFontSize(self.outputLabel, 1.5) labelSizer1.Add(self.outputLabel, 1, wx.EXPAND | wx.ALL, 5) topSizer.Add(labelSizer1, 0, wx.ALIGN_LEFT) # Output Multiline Grid self.output = Grid(self, 6, wx.Point(40, 210), wx.Size(790, 140), wx.TE_MULTILINE | wx.TE_READONLY) self.output.SetDefaultRowSize(25) self.output.SetDefaultColSize(50) self.output.SetRowLabelSize(0) self.output.SetColLabelSize(0) self.output.CreateGrid(10, 30) self.output.Bind(wx.grid.EVT_GRID_SELECT_CELL, self.evtOnCellSelected) topSizer.Add(self.output, 1, wx.EXPAND | wx.ALL, 5) # Control Sizer controlSizer = wx.BoxSizer(wx.HORIZONTAL) # Radio Box self.radioList = [data.findVruthamLabel, data.checkVruthamLabel] self.rb = wx.RadioBox(self, 50, data.whatToDoLabel, wx.Point(40, 375), wx.Size(250, 90), self.radioList, 3, wx.RA_SPECIFY_ROWS) self.increaseFontSize(self.rb, 1.5) controlSizer.Add(self.rb, 0, wx.ALL, 10) wx.EVT_RADIOBOX(self, 50, self.evtRadioBox) # Combobox self.vruthamList = data.vruthamNameList() self.vruthamCombo = wx.ComboBox(self, 30, data.selectVruthamLabel, wx.Point(420, 390), wx.Size(250, -1), self.vruthamList, wx.CB_DROPDOWN | wx.CB_READONLY) self.increaseFontSize(self.vruthamCombo, 1.5) controlSizer.Add(self.vruthamCombo, 0, wx.ALIGN_CENTER) wx.EVT_COMBOBOX(self, 30, self.evtComboBox) self.vruthamCombo.Enable(0) # Status TextCtrl self.status = wx.TextCtrl(self, 5, '', wx.DefaultPosition, wx.Size(250, 80), wx.TE_MULTILINE | wx.TE_READONLY) self.increaseFontSize(self.status, 1.5) self.status.SetBackgroundColour( wx.SystemSettings.GetColour(wx.SYS_COLOUR_SCROLLBAR)) controlSizer.Add(self.status, 0, wx.EXPAND | wx.ALL, 15) topSizer.Add(controlSizer, 0, wx.ALIGN_CENTER) # Button Sizer buttonSizer = wx.BoxSizer(wx.HORIZONTAL) # Buttons self.goButton = wx.Button(self, 10, data.findLabel, wx.Point(379, 470), wx.Size(117, 35)) self.increaseFontSize(self.goButton, 1.5) self.increaseFontWeight(self.goButton) wx.EVT_BUTTON(self, 10, self.goClick) buttonSizer.Add(self.goButton, 0, wx.ALL, 10) self.clearButton = wx.Button(self, 11, data.clearLabel, wx.Point(506, 470), wx.Size(117, 35)) self.increaseFontSize(self.clearButton, 1.5) self.increaseFontWeight(self.clearButton) wx.EVT_BUTTON(self, 11, self.clearClick) buttonSizer.Add(self.clearButton, 0, wx.ALL, 10) self.closeButton = wx.Button(self, 12, data.closeLabel, wx.Point(633, 470), wx.Size(117, 35)) self.increaseFontSize(self.closeButton, 1.5) self.increaseFontWeight(self.closeButton) wx.EVT_BUTTON(self, 12, self.closeClick) buttonSizer.Add(self.closeButton, 0, wx.ALL, 10) topSizer.Add(buttonSizer, 0, wx.ALIGN_CENTER) self.SetSizer(topSizer) topSizer.SetSizeHints(self) # Initialize Variables self.inVruthamName = '' self.checkVruthamFlg = 0 self.checkFlgSet = 0 self.dictErrors = {} def displayStatus(self, row, col): self.status.Clear() if self.output.GetNumberRows() <= 0: return if self.output.GetNumberCols() <= 0: return if self.output.GetCellValue(row, col) == '': return if self.checkFlgSet == 1: if self.dictErrors.has_key((row, col)): self.status.AppendText(self.dictErrors[(row, col)]) elif self.output.GetCellValue(row, col) == data.rightLabel: self.status.AppendText(data.thisLineIsCorrectLabel) elif self.output.GetCellValue(row, col) == data.wrongLabel: self.status.AppendText(data.thisLineIsWrongLabel) else: if row == 0: self.status.AppendText(data.syllableCountLabel + ' ' + self.output.GetCellValue(row, col)) else: self.status.AppendText(data.thisIsCorrectLabel) else: if row == 0: self.status.AppendText(self.output.GetCellValue(row, col)) else: if col == 0: self.status.AppendText(data.slokamLabel + ' ' + self.output.GetCellValue(row, col)) elif col == 1: self.status.AppendText(data.lineLabel + ' ' + self.output.GetCellValue(row, col)) elif col == 2: if self.output.GetCellValue(row, col) != data.iDontKnowLabel: if self.dictErrors.has_key((row, col)): self.status.AppendText( data.lineVruthamGanangalLabel + ' ' + self.output.GetCellValue(row, col) + ', ' + data.yathiBhangamLabel) else: self.status.AppendText( data.lineVruthamGanangalLabel + ' ' + self.output.GetCellValue(row, col)) else: self.status.AppendText(data.dontKnowVruthamLabel) else: if self.output.GetCellValue(row, col) != data.iDontKnowLabel: if self.dictErrors.has_key((row, col)): self.status.AppendText( data.slokamsVruthamLabel + ' ' + self.output.GetCellValue(row, col) + ', ' + data.yathiBhangamLabel) else: self.status.AppendText( data.slokamsVruthamLabel + ' ' + self.output.GetCellValue(row, col)) else: self.status.AppendText(data.dontKnowVruthamLabel) def evtOnCellSelected(self, event): eventObject = event.GetEventObject() row = event.GetRow() col = event.GetCol() self.displayStatus(row, col) event.Skip() def evtRadioBox(self, event): if (event.GetInt() == 1): self.vruthamCombo.Enable(1) self.goButton.SetLabel(data.checkLabel) self.checkVruthamFlg = 1 else: self.vruthamCombo.Enable(0) self.goButton.SetLabel(data.findLabel) self.checkVruthamFlg = 0 def giveCell(self, row=0, col=0): if self.output.GetNumberCols() < col + 1: self.output.AppendCols(col + 1 - self.output.GetNumberCols()) if self.output.GetNumberRows() < row + 1: self.output.AppendRows(row + 1 - self.output.GetNumberRows()) def increaseFontSize(self, text, size): Font = text.GetFont() Font.SetPointSize(Font.GetPointSize() * size) text.SetFont(Font) def increaseFontWeight(self, text): Font = text.GetFont() Font.SetWeight(wx.FONTWEIGHT_BOLD) text.SetFont(Font) def increaseCellFontSize(self, row, col): Font = self.output.GetDefaultCellFont() Font.SetPointSize(Font.GetPointSize() * 1.5) self.output.SetCellFont(row, col, Font) def increaseCellFontWeight(self, row, col): Font = self.output.GetCellFont(row, col) Font.SetWeight(wx.FONTWEIGHT_BOLD) self.output.SetCellFont(row, col, Font) def evtComboBox(self, event): self.inVruthamName = event.GetString() def splitIntoLines(self, errLocs): errLocLines = [] lineList = [] for i in errLocs: if i[0] == (-1, -1): lineList.append(i) errLocLines.append(lineList) lineList = [] else: lineList.append(i) errLocLines.append([((-1, -1), 'y')]) return errLocLines def highLightErrors(self): # Print Syllable numbers and Lakshanam lakshanamStr = data.getVruthamLakshanam(self.inVruthamName) incrRow = 0 incrCol = 1 self.ardhaVishamaVrutham = 'n' lakshanamLines = lakshanamStr.split('|') if lakshanamLines[0] == 'ANUSHTUP': lakshanamLines = ' ' anushtupVrutham = 'y' for i in lakshanamLines: self.giveCell(incrRow, incrCol) self.output.SetCellValue(0, incrCol, str(incrCol)) self.increaseCellFontWeight(0, incrCol) self.output.SetCellAlignment(0, incrCol, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.output.SetCellBackgroundColour( 0, incrCol, wx.TheColourDatabase.Find('LIGHT BLUE')) incrCol = incrCol + 1 # Display Ganam Grouping incrRow += 1 incrCol = 1 self.giveCell(incrRow, incrCol) ganamColour1 = wx.Colour(166, 166, 166) ganamColour2 = wx.Colour(200, 200, 200) self.output.SetCellBackgroundColour(incrRow, incrCol, ganamColour1) self.output.SetCellBackgroundColour(incrRow, incrCol + 1, ganamColour2) self.output.SetCellBackgroundColour(incrRow, incrCol + 2, ganamColour2) self.output.SetCellBackgroundColour(incrRow, incrCol + 3, ganamColour2) self.output.SetCellBackgroundColour(incrRow, incrCol + 4, ganamColour1) self.output.SetCellBackgroundColour(incrRow, incrCol + 5, ganamColour1) self.output.SetCellBackgroundColour(incrRow, incrCol + 6, ganamColour1) self.output.SetCellBackgroundColour(incrRow, incrCol + 7, ganamColour2) else: if lakshanamLines[0] == 'AV': self.ardhaVishamaVrutham = 'y' lakshanamLines = lakshanamLines[1:len(lakshanamLines)] for lakshanam in lakshanamLines: incrRow = incrRow + 1 ganamCount = 1 ganamStr = '' ganam = '' ganamColour1 = wx.Colour(166, 166, 166) ganamColour2 = wx.Colour(200, 200, 200) curGanamColour = ganamColour1 for i in lakshanam: self.giveCell(incrRow, incrCol) self.output.SetCellValue(0, incrCol, str(incrCol)) self.increaseCellFontWeight(0, incrCol) self.output.SetCellAlignment(0, incrCol, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.output.SetCellBackgroundColour( 0, incrCol, wx.TheColourDatabase.Find('LIGHT BLUE')) self.output.SetCellValue(incrRow, incrCol, i) self.increaseCellFontWeight(incrRow, incrCol) self.output.SetCellAlignment(incrRow, incrCol, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.output.SetCellBackgroundColour( incrRow, incrCol, wx.TheColourDatabase.Find('LIGHT BLUE')) # Display Ganam Grouping ganamStr += i if incrCol % 3 == 0: if data.ganamDict.has_key(ganamStr): ganam = data.ganamDict[ganamStr] self.dictErrors[( incrRow, incrCol - 2)] = ganam + ' ' + data.ganamLabel self.dictErrors[( incrRow, incrCol - 1)] = ganam + ' ' + data.ganamLabel self.dictErrors[( incrRow, incrCol)] = ganam + ' ' + data.ganamLabel ganamStr = '' self.output.SetCellBackgroundColour( incrRow, incrCol - 2, curGanamColour) self.output.SetCellBackgroundColour( incrRow, incrCol - 1, curGanamColour) self.output.SetCellBackgroundColour( incrRow, incrCol, curGanamColour) if curGanamColour == ganamColour1: curGanamColour = ganamColour2 else: curGanamColour = ganamColour1 ganamCount += 1 elif ganamCount > len(lakshanam) / 3: if ganamStr == '-': self.dictErrors[(incrRow, incrCol)] = data.guruLabel else: self.dictErrors[(incrRow, incrCol)] = data.laghuLabel ganamStr = '' self.output.SetCellBackgroundColour( incrRow, incrCol, curGanamColour) if curGanamColour == ganamColour1: curGanamColour = ganamColour2 else: curGanamColour = ganamColour1 ganamCount += 1 incrCol = incrCol + 1 incrCol = 1 gridRow = incrRow + 1 gridCol = 1 # Print Padyam lineNum = 0 lakshanam = '' bgColour = wx.Colour(255, 212, 160) errLocLines = self.splitIntoLines(self.errLocs) for oneErrLocLine in errLocLines: if oneErrLocLine == [((-1, -1), 'y')]: if self.ardhaVishamaVrutham == 'y': if lineNum != 0: for i in range(0, 4 - lineNum): gridCol = 1 self.giveCell(gridRow, gridCol) self.output.SetCellValue(gridRow, 0, data.wrongLabel) self.increaseCellFontSize(gridRow, 0) self.increaseCellFontWeight(gridRow, 0) self.output.SetCellBackgroundColour( gridRow, 0, wx.RED) lakshanam = lakshanamLines[lineNum + i] while gridCol <= len(lakshanam): self.output.SetCellBackgroundColour( gridRow, gridCol, wx.RED) self.dictErrors[(gridRow, gridCol)] = data.emptySylLabel gridCol = gridCol + 1 gridRow = gridRow + 1 lineNum = 0 gridCol = 1 if self.output.GetCellValue(gridRow - 1, 0) != '': gridRow = gridRow + 1 self.giveCell(gridRow, gridCol) continue if self.ardhaVishamaVrutham == 'y': lakshanam = lakshanamLines[lineNum % 4] else: lakshanam = lakshanamStr if lineNum == 4: lineNum = 1 gridRow = gridRow + 1 self.giveCell(gridRow, gridCol) else: lineNum = lineNum + 1 if lineNum == 1: if bgColour.Green() == 212: bgColour = wx.Colour(255, 255, 160) else: bgColour = wx.Colour(255, 212, 160) yathiInPrevChar = 0 for i in oneErrLocLine: if i[0] == (-1, -1): yathiInPrevChar = 0 while gridCol > 1 and gridCol <= len(lakshanam): self.output.SetCellValue(gridRow, 0, data.wrongLabel) self.increaseCellFontSize(gridRow, 0) self.increaseCellFontWeight(gridRow, 0) self.output.SetCellBackgroundColour(gridRow, 0, wx.RED) self.output.SetCellBackgroundColour( gridRow, gridCol, wx.RED) self.dictErrors[(gridRow, gridCol)] = data.emptySylLabel gridCol = gridCol + 1 if gridCol == 1: self.giveCell(gridRow, gridCol) self.output.SetCellValue(gridRow, 0, '') self.output.SetCellBackgroundColour( gridRow, 0, wx.WHITE) gridRow = gridRow + 1 gridCol = 1 continue if gridCol == 1: self.giveCell(gridRow, gridCol) self.output.SetCellValue(gridRow, 0, data.rightLabel) self.increaseCellFontSize(gridRow, 0) self.increaseCellFontWeight(gridRow, 0) self.output.SetCellBackgroundColour(gridRow, 0, wx.GREEN) self.giveCell(gridRow, gridCol) if i[1] == 'n': yathiInPrevChar = 0 self.output.SetCellValue( gridRow, gridCol, self.input.GetValue()[i[0][0]:i[0][1] + 1]) self.output.SetCellBackgroundColour( gridRow, gridCol, wx.RED) if gridCol - 1 < len(lakshanam): if lakshanam[gridCol - 1] == '-': self.dictErrors[( gridRow, gridCol)] = data.wronglyPlacedLaghuLabel else: self.dictErrors[( gridRow, gridCol)] = data.wronglyPlacedGuruLabel else: self.dictErrors[(gridRow, gridCol)] = data.extraSylLabel self.output.SetCellValue(gridRow, 0, data.wrongLabel) self.increaseCellFontSize(gridRow, 0) self.increaseCellFontWeight(gridRow, 0) self.output.SetCellBackgroundColour(gridRow, 0, wx.RED) elif i[1] == 'g': self.output.SetCellValue( gridRow, gridCol, self.input.GetValue()[i[0][0]:i[0][1] + 1]) self.output.SetCellBackgroundColour( gridRow, gridCol, wx.RED) self.dictErrors[(gridRow, gridCol)] = data.wrongGanamLabel self.output.SetCellValue(gridRow, 0, data.wrongLabel) self.increaseCellFontSize(gridRow, 0) self.increaseCellFontWeight(gridRow, 0) self.output.SetCellBackgroundColour(gridRow, 0, wx.RED) else: self.output.SetCellValue( gridRow, gridCol, self.input.GetValue()[i[0][0]:i[0][1] + 1]) self.output.SetCellBackgroundColour( gridRow, gridCol, bgColour) if yathiInPrevChar == 1: yathiInPrevChar = 0 if ' ' not in self.input.GetValue()[yathiStartPos:i[0][0]] and \ '/' not in self.input.GetValue()[yathiStartPos:i[0][0]]: self.output.SetCellValue(gridRow, 0, data.wrongLabel) self.increaseCellFontSize(gridRow, 0) self.increaseCellFontWeight(gridRow, 0) self.output.SetCellBackgroundColour( gridRow, 0, wx.RED) self.output.SetCellBackgroundColour( gridRow, gridCol, wx.RED) self.dictErrors[( gridRow, gridCol)] = data.yathiRequiredLabel if i[1] == 't': yathiInPrevChar = 1 yathiStartPos = i[0][1] + 1 self.increaseCellFontSize(gridRow, gridCol) gridCol = gridCol + 1 while self.output.GetCellValue(gridRow, 0) == '': self.output.DeleteRows(gridRow, 1) gridRow -= 1 self.output.SetGridCursor(0, 0) def printVruthamNames(self, vruthamNames): gRows, gCols = 0, 0 # Print Header self.giveCell(gRows, 3) self.output.SetCellValue(0, 0, data.slokamLabel) self.increaseCellFontSize(0, 0) self.increaseCellFontWeight(0, 0) self.output.SetCellAlignment(0, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.output.SetCellBackgroundColour( 0, 0, wx.TheColourDatabase.Find('LIGHT BLUE')) self.output.SetCellValue(0, 1, data.lineLabel) self.increaseCellFontSize(0, 1) self.increaseCellFontWeight(0, 1) self.output.SetCellAlignment(0, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.output.SetCellBackgroundColour( 0, 1, wx.TheColourDatabase.Find('LIGHT BLUE')) self.output.SetCellValue(0, 2, data.lineVruthamGanangalLabel) self.increaseCellFontSize(0, 2) self.increaseCellFontWeight(0, 2) self.output.SetCellAlignment(0, 2, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.output.SetCellBackgroundColour( 0, 2, wx.TheColourDatabase.Find('LIGHT BLUE')) self.output.SetCellValue(0, 3, data.slokaVruthamLabel) self.increaseCellFontSize(0, 3) self.increaseCellFontWeight(0, 3) self.output.SetCellAlignment(0, 3, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.output.SetCellBackgroundColour( 0, 3, wx.TheColourDatabase.Find('LIGHT BLUE')) gRows = gRows + 1 yathiBhangamSlokam = -1 for i in vruthamNames: yathiBhangam = 'n' self.giveCell(gRows, 1) self.output.SetDefaultColSize(190, 1) self.output.SetCellValue(gRows, 0, i[0]) self.increaseCellFontWeight(gRows, 0) self.output.SetCellAlignment(gRows, 0, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.output.SetCellValue(gRows, 1, i[1]) self.increaseCellFontWeight(gRows, 1) self.output.SetCellAlignment(gRows, 1, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) if i[2] != -1: self.output.SetCellValue(gRows, 2, data.vruthamTable[i[2]][1]) else: self.output.SetCellValue(gRows, 2, data.iDontKnowLabel) self.increaseCellFontSize(gRows, 2) self.increaseCellFontWeight(gRows, 2) self.output.SetCellAlignment(gRows, 2, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) if i[3] == -1: self.output.SetCellValue(gRows, 3, data.iDontKnowLabel) elif i[3] == -2: self.output.SetCellValue(gRows, 3, '') else: self.output.SetCellValue(gRows, 3, data.vruthamTable[i[3]][1]) self.increaseCellFontSize(gRows, 3) self.increaseCellFontWeight(gRows, 3) self.output.SetCellAlignment(gRows, 3, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) if int(i[0]) % 2 != 0: bgColour = wx.Colour(255, 255, 160) # HTML value ffffa0 else: bgColour = wx.Colour(255, 212, 160) # HTML value ffd4a0 self.output.SetCellBackgroundColour(gRows, 0, bgColour) self.output.SetCellBackgroundColour(gRows, 1, bgColour) if i[2] != -1: self.output.SetCellBackgroundColour(gRows, 2, bgColour) if i[4] == 'n': self.output.SetCellBackgroundColour(gRows, 2, wx.RED) self.dictErrors[(gRows, 2)] = data.yathiBhangamLabel yathiBhangamSlokam = i[0] if i[0] == yathiBhangamSlokam: yathiBhangam = 'y' else: self.output.SetCellBackgroundColour(gRows, 2, wx.RED) if i[3] != -1: self.output.SetCellBackgroundColour(gRows, 3, bgColour) if yathiBhangam == 'y': curSlokam = self.output.GetCellValue(gRows, 0) for i in range(0, 4): if self.output.GetCellValue(gRows - i, 0) != curSlokam: break self.output.SetCellBackgroundColour( gRows - i, 3, wx.RED) self.dictErrors[(gRows - i, 3)] = data.yathiBhangamLabel else: curSlokam = self.output.GetCellValue(gRows, 0) for i in range(0, 4): if self.output.GetCellValue(gRows - i, 0) != curSlokam: break self.output.SetCellBackgroundColour(gRows - i, 3, wx.RED) gRows = gRows + 1 self.output.AutoSizeColumns() def goClick(self, event): self.checkFlgSet = 0 if self.output.GetNumberRows() != 0: self.dictErrors = {} self.output.DeleteRows(0, self.output.GetNumberRows()) self.output.DeleteCols(0, self.output.GetNumberCols()) self.output.SetDefaultRowSize(25, 1) self.output.SetDefaultColSize(50, 1) if self.input.GetValue() == '': self.output.SetDefaultColSize(790, 1) self.giveCell() self.output.SetCellValue(0, 0, data.noPadyamGivenLabel) self.increaseCellFontSize(0, 0) return if filter(lambda x: x > u'\u0d00' and x < u'\u0d65', self.input.GetValue()) == '': self.output.SetDefaultColSize(790, 1) self.giveCell() self.output.SetCellValue(0, 0, data.givePadyamInMalLabel) self.increaseCellFontSize(0, 0) return if self.checkVruthamFlg == 1: if self.inVruthamName == '': self.output.SetDefaultColSize(790, 1) self.giveCell() self.output.SetCellValue(0, 0, data.noVruthamGivenLabel) self.increaseCellFontSize(0, 0) return self.checkFlgSet = 1 self.outVruthamName, self.errLocs = getVrutham( self.input.GetValue(), self.inVruthamName) self.highLightErrors() else: self.checkFlgSet = 0 self.outVruthamName, self.errLocs = getVrutham( self.input.GetValue(), '') self.printVruthamNames(self.outVruthamName) def clearClick(self, event): self.status.Clear() if self.output.GetNumberRows() != 0: self.dictErrors = {} self.output.DeleteRows(0, self.output.GetNumberRows()) self.output.DeleteCols(0, self.output.GetNumberCols()) self.output.SetDefaultRowSize(25, 1) self.output.SetDefaultColSize(50, 1) if self.input.GetValue() != '': diag = wx.MessageDialog( self, data.clearAreYouSureLabel, data.pleaseConfirmLabel, wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if diag.ShowModal() == wx.ID_YES: self.input.Clear() def closeClick(self, event): dlg = wx.MessageDialog(self, data.quitAreYouSureLabel, data.pleaseConfirmLabel, wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if dlg.ShowModal() == wx.ID_YES: self.GetParent().Close(True)
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)