示例#1
0
 def init_grid(panel):
     grid_box = wx.BoxSizer(wx.VERTICAL)
     title = wx.StaticText(panel, -1, "Grid")
     data_grid = Grid(panel, -1, size=(700, -1))
     data_grid.SetTable(GlobalVariable.grid_data)
     data_grid.AdjustScrollbars()
     data_grid.EnableEditing(False)  # 设置数据无法修改
     data_grid.SetRowLabelSize(40)
     data_grid.SetColLabelSize(20)
     data_grid.DisableDragRowSize()  # 设置无法拖动修改行高
     data_grid.SetSelectionMode(Grid.wxGridSelectRows)  # 设置整行选取模式
     data_grid.Refresh()
     data_grid.Bind(grid.EVT_GRID_CELL_RIGHT_DCLICK, self.copy_line)
     button_box = wx.BoxSizer(wx.HORIZONTAL)
     previous_button = wx.Button(panel, -1, '<', size=(-1, -1))
     next_button = wx.Button(panel, -1, '>', size=(-1, -1))
     self.Bind(wx.EVT_BUTTON, self.__on_previous, previous_button)
     self.Bind(wx.EVT_BUTTON, self.__on_next, next_button)
     button_box.Add(previous_button)
     button_box.Add(next_button)
     grid_box.Add(title, 0)
     grid_box.Add(data_grid, 1,
                  wx.EXPAND | wx.TOP | wx.RIGHT | wx.BOTTOM, 5)
     grid_box.Add(button_box, 0, wx.EXPAND | wx.BOTTOM, 5)
     return data_grid, grid_box
示例#2
0
    def run_as_data_tool(self, workspace):
        m = workspace.measurements
        assert isinstance(m, cpmeas.Measurements)
        m.is_first_image = True
        image_set_count = m.image_set_count
        for i in range(image_set_count):
            self.run(workspace)
            img_stats = workspace.display_data.statistics
            if i == 0:
                header = ["Image set"]
                for flag_name, object_name, feature, value, pf in img_stats:
                    header.append(flag_name)
                header.append("Pass/Fail")
                statistics = [header]
            row = [str(i + 1)]
            ok = True
            for flag_name, object_name, feature, value, pf in img_stats:
                ok = ok and (pf == "Pass")
                row.append(str(value))
            row.append("Pass" if ok else "Fail")
            statistics.append(row)
            if i < image_set_count - 1:
                m.next_image_set()
        self.show_window = False
        if image_set_count > 0:
            import wx
            from wx.grid import Grid, PyGridTableBase, EVT_GRID_LABEL_LEFT_CLICK
            from cellprofiler.gui import get_cp_icon

            frame = wx.Frame(workspace.frame, -1, "Flag image results")
            sizer = wx.BoxSizer(wx.VERTICAL)
            frame.SetSizer(sizer)
            grid = Grid(frame, -1)
            sizer.Add(grid, 1, wx.EXPAND)
            #
            # The flag table supplies the statistics to the grid
            # using the grid table interface
            #
            sort_order = np.arange(len(statistics) - 1)
            sort_col = [None]
            sort_ascending = [None]

            def on_label_clicked(event):
                col = event.GetCol()
                if sort_col[0] == col:
                    sort_ascending[0] = not sort_ascending[0]
                else:
                    sort_ascending[0] = True
                sort_col[0] = col
                data = [x[col] for x in statistics[1:]]
                try:
                    data = np.array(data, float)
                except ValueError:
                    data = np.array(data)
                if sort_ascending[0]:
                    sort_order[:] = np.lexsort((data, ))
                else:
                    sort_order[::-1] = np.lexsort((data, ))
                grid.ForceRefresh()

            grid.Bind(EVT_GRID_LABEL_LEFT_CLICK, on_label_clicked)

            class FlagTable(PyGridTableBase):
                def __init__(self):
                    PyGridTableBase.__init__(self)

                def GetColLabelValue(self, col):
                    if col == sort_col[0]:
                        if sort_ascending[0]:

                            return statistics[0][col] + " v"
                        else:
                            return statistics[0][col] + " ^"
                    return statistics[0][col]

                def GetNumberRows(self):
                    return len(statistics) - 1

                def GetNumberCols(self):
                    return len(statistics[0])

                def GetValue(self, row, col):
                    return statistics[sort_order[row] + 1][col]

            grid.SetTable(FlagTable())
            frame.Fit()
            max_size = int(
                wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y) * 3 / 4)
            if frame.Size[1] > max_size:
                frame.SetSize((frame.Size[0], max_size))
            frame.SetIcon(get_cp_icon())
            frame.Show()
示例#3
0
class StatisticalAnalysisDialog(wx.Dialog):
    rel_cov = None

    def __init__(self, parent, model):
        wx.Dialog.__init__(self,
                           parent,
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
                           | wx.MAXIMIZE_BOX)
        vbox = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(vbox)
        self.SetTitle('Statistical Analysis of Parameters')

        dpi_scale_factor = wx.GetApp().dpi_scale_factor

        self.ptxt = wx.StaticText(self, label="...")
        self.pbar = wx.Gauge(self, range=1000)

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        vbox.Add(hbox, proportion=1, flag=wx.EXPAND)

        lpanel = wx.Panel(self)
        gpanel = wx.Panel(self)
        gbox = wx.BoxSizer(wx.VERTICAL)
        gpanel.SetSizer(gbox)
        self.grid = Grid(gpanel)
        gbox.Add(wx.StaticText(gpanel, label='Estimated covariance matrix:'),
                 proportion=0,
                 flag=wx.FIXED_MINSIZE)
        gbox.Add(self.grid, proportion=1, flag=wx.EXPAND)
        self.normalize_checkbox = wx.CheckBox(
            gpanel, label='Normalize value (σ_ij/σ_i/σ_j)')
        self.normalize_checkbox.SetValue(True)
        self.normalize_checkbox.Bind(wx.EVT_CHECKBOX, self.OnToggleNormalize)
        gbox.Add(self.normalize_checkbox, proportion=0, flag=wx.FIXED_MINSIZE)

        nfparams = len([pi for pi in model.parameters if pi.fit])
        self.grid.CreateGrid(nfparams + 1, nfparams)
        self.grid.SetColLabelTextOrientation(wx.VERTICAL)
        self.grid.SetColLabelSize(int(dpi_scale_factor * 80))
        for i in range(nfparams):
            self.grid.SetRowSize(i, int(dpi_scale_factor * 80))
            self.grid.SetColSize(i, int(dpi_scale_factor * 80))
            self.grid.SetColLabelValue(i, '%i' % i)
            self.grid.SetRowLabelValue(i + 1, '%i' % i)
        self.grid.SetRowSize(nfparams, int(dpi_scale_factor * 80))
        self.grid.DisableCellEditControl()
        self.grid.SetMinSize(
            (int(dpi_scale_factor * 200), int(dpi_scale_factor * 200)))
        self.grid.Bind(EVT_GRID_CELL_LEFT_DCLICK, self.OnSelectCell)
        rpanel = PlotPanel(self)
        rpanel.SetMinSize(
            (int(dpi_scale_factor * 200), int(dpi_scale_factor * 200)))
        self.plot_panel = rpanel
        self.ax = rpanel.figure.add_subplot(111)

        hbox.Add(lpanel, proportion=0, flag=wx.EXPAND | wx.ALIGN_TOP)
        hbox.Add(gpanel, proportion=1, flag=wx.EXPAND)
        hbox.Add(rpanel, proportion=1, flag=wx.EXPAND)

        lsizer = wx.GridSizer(vgap=1, hgap=2, cols=2)
        lpanel.SetSizer(lsizer)
        self.entries = {}
        for key, emin, emax, val in [('pop', 1, 20 * nfparams, 2 * nfparams),
                                     ('samples', 1000, 10000000, 10000),
                                     ('burn', 0, 10000, 200)]:
            lsizer.Add(wx.StaticText(lpanel, label='%s:' % key),
                       flag=wx.FIXED_MINSIZE)
            self.entries[key] = wx.SpinCtrl(lpanel,
                                            wx.ID_ANY,
                                            min=emin,
                                            max=emax,
                                            value=str(val))
            lsizer.Add(self.entries[key], flag=wx.FIXED_MINSIZE)

        lsizer.AddStretchSpacer(10)
        but = wx.Button(self, label='Run Analysis...')
        vbox.Add(but)
        vbox.Add(self.ptxt, proportion=0, flag=wx.EXPAND)
        vbox.Add(self.pbar, proportion=0, flag=wx.EXPAND)

        self.Bind(wx.EVT_BUTTON, self.OnRunAnalysis, but)
        self.Bind(wx.EVT_CLOSE, self.OnClose)

        self.model = model
        self.thread = None

        psize = parent.GetSize()
        self.SetSize(int(psize.GetWidth() * 0.75),
                     int(psize.GetHeight() * 0.75))

    def OnRunAnalysis(self, event):
        if self.thread is not None:
            return
        self.thread = threading.Thread(target=self.run_bumps)
        self.thread.start()

    def run_bumps(self):
        self.bproblem = self.model.bumps_problem()
        mon = ProgressMonitor(self.bproblem, self.pbar, self.ptxt)
        pop = self.entries['pop'].GetValue()
        burn = self.entries['burn'].GetValue()
        samples = self.entries['samples'].GetValue()
        self.pbar.SetRange(
            int(samples / (len(self.bproblem.model_parameters()) * pop)) +
            burn)

        res = self.model.bumps_fit(method='dream',
                                   pop=pop,
                                   samples=samples,
                                   burn=burn,
                                   thin=1,
                                   alpha=0,
                                   outliers='none',
                                   trim=False,
                                   monitors=[mon],
                                   problem=self.bproblem)
        self._res = res
        wx.CallAfter(self.display_bumps)

    def display_bumps(self):
        self.thread.join(timeout=5.0)
        self.thread = None
        self.pbar.SetValue(0)

        res = self._res
        self.draw = res.state.draw()
        self.abs_cov = res.cov
        self.rel_cov = res.cov / res.dx[:, newaxis] / res.dx[newaxis, :]
        rel_max = [0, 1, abs(self.rel_cov[0, 1])]
        if self.normalize_checkbox.IsChecked():
            display_cov = self.rel_cov
            fmt = "%.6f"
        else:
            display_cov = self.abs_cov
            fmt = "%.4g"
        self.grid.SetRowLabelValue(0, 'Value/Error:')
        for i, ci in enumerate(self.rel_cov):
            self.grid.SetColLabelValue(i, self.draw.labels[i])
            self.grid.SetRowLabelValue(i + 1, self.draw.labels[i])
            self.grid.SetCellValue(0, i, "%.8g\n%.4g" % (res.x[i], res.dx[i]))
            self.grid.SetCellAlignment(0, i, wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
            self.grid.SetReadOnly(0, i)
            self.grid.SetCellBackgroundColour(0, i, "#cccccc")
            for j, cj in enumerate(ci):
                self.grid.SetCellValue(i + 1, j, fmt % display_cov[i, j])
                self.grid.SetReadOnly(i + 1, j)
                self.grid.SetCellAlignment(i + 1, j, wx.ALIGN_CENTRE,
                                           wx.ALIGN_CENTRE)
                if i == j:
                    self.grid.SetCellBackgroundColour(i + 1, j, "#888888")
                elif abs(cj) > 0.4:
                    self.grid.SetCellBackgroundColour(i + 1, j, "#ffcccc")
                elif abs(cj) > 0.3:
                    self.grid.SetCellBackgroundColour(i + 1, j, "#ffdddd")
                elif abs(cj) > 0.2:
                    self.grid.SetCellBackgroundColour(i + 1, j, "#ffeeee")
                if i != j and abs(cj) > rel_max[2]:
                    rel_max = [min(i, j), max(i, j), abs(cj)]
        self.hists = _hists(self.draw.points.T, bins=50)

        fig = self.plot_panel.figure
        fig.clear()
        ax = fig.add_subplot(111)
        data, x, y = self.hists[(rel_max[0], rel_max[1])]
        vmin, vmax = data[data > 0].min(), data.max()
        ax.pcolorfast(y,
                      x,
                      maximum(vmin, data),
                      norm=LogNorm(vmin, vmax),
                      cmap='inferno')
        ax.set_xlabel(self.draw.labels[rel_max[1]])
        ax.set_ylabel(self.draw.labels[rel_max[0]])
        self.plot_panel.flush_plot()

        # add analysis data do model for later storange in export header
        exdict = {}
        exdict['library'] = 'bumps'
        exdict['version'] = bumps_version
        exdict['settings'] = dict(pop=self.entries['pop'].GetValue(),
                                  burn=self.entries['burn'].GetValue(),
                                  samples=self.entries['samples'].GetValue())
        exdict['parameters'] = [
            dict(name=li,
                 value=float(xi),
                 error=float(dxi),
                 cross_correlations=dict(
                     (self.draw.labels[j], float(res.cov[i, j]))
                     for j in range(len(res.x))))
            for i, (li, xi,
                    dxi) in enumerate(zip(self.draw.labels, res.x, res.dx))
        ]
        self.model.extra_analysis['statistics_mcmc'] = exdict

    def OnToggleNormalize(self, evt):
        if self.rel_cov is None:
            evt.Skip()
            return
        if self.normalize_checkbox.IsChecked():
            display_cov = self.rel_cov
            fmt = "%.6f"
        else:
            display_cov = self.abs_cov
            fmt = "%.4g"
        for i, ci in enumerate(self.rel_cov):
            for j, cj in enumerate(ci):
                self.grid.SetCellValue(i + 1, j, fmt % display_cov[i, j])

    def OnSelectCell(self, evt):
        i, j = evt.GetCol(), evt.GetRow() - 1
        if i == j or j == -1:
            return
        elif i > j:
            itmp = i
            i = j
            j = itmp

        fig = self.plot_panel.figure
        fig.clear()
        ax = fig.add_subplot(111)
        data, x, y = self.hists[(i, j)]
        vmin, vmax = data[data > 0].min(), data.max()
        ax.pcolorfast(y,
                      x,
                      maximum(vmin, data),
                      norm=LogNorm(vmin, vmax),
                      cmap='inferno')
        ax.set_xlabel(self.draw.labels[j])
        ax.set_ylabel(self.draw.labels[i])
        self.plot_panel.flush_plot()

    def OnClose(self, event):
        if self.thread is not None and self.thread.is_alive():
            # a running bumps simulation can't be interrupted from other thread, stop window from closing
            self.ptxt.SetLabel("Simulation running")
            event.Veto()
            return
        event.Skip()
示例#4
0
    def __init__(self, parent):
        Panel.__init__(self, parent)

        grid = Grid(self)

        grid.CreateGrid(0, _TOTAL_COLS)

        grid.HideRowLabels()  # Hide the index column
        grid.EnableGridLines(False)  # Hide grid lines
        grid.DisableDragGridSize(
        )  # Disable resizing of rows/columns by dragging
        grid.DisableDragColMove()  # Disable reordering of columns by dragging
        grid.SetCellHighlightPenWidth(
            0)  # Disable the highlight around the "current" cell
        grid.SetCellHighlightROPenWidth(
            0)  # Disable the highlight around the "current" read-only cell
        grid.SetSelectionMode(wx.grid.Grid.SelectRows)  # Select the entire row

        grid.SetColLabelValue(_SHIP_COL, "Ship")
        grid.SetColLabelValue(_FIT_COL, "Fit")
        grid.SetColLabelValue(_POINTS_COL, "Points")
        grid.SetColLabelValue(_EHP_COL, "EHP")
        grid.SetColLabelValue(_DPS_COL, "DPS")
        grid.SetColLabelValue(_TANK_COL, "Tank")
        grid.SetColLabelValue(_ACTIVE_COL, "Active?")

        grid.SetColFormatBool(_ACTIVE_COL)

        grid.Bind(wx.grid.EVT_GRID_CELL_CHANGING, self._onCellChanging)
        grid.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK, self._showContextMenu)
        grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_CLICK, self._onCellLeftClick)
        grid.Bind(wx.grid.EVT_GRID_CELL_LEFT_DCLICK,
                  self._onCellDoubleLeftClick)
        gui.mainFrame.MainFrame.getInstance().Bind(GE.FIT_CHANGED,
                                                   self._onFitChanged)

        shipCountLabel = wx.StaticText(self)
        pointCountLabel = wx.StaticText(self)
        dpsLabel = wx.StaticText(self)
        ehpLabel = wx.StaticText(self)

        infoPanelSizer = wx.FlexGridSizer(4, 0, 16)
        infoPanelSizer.Add(wx.StaticText(self, label="Ships"),
                           flag=wx.ALIGN_CENTER)
        infoPanelSizer.Add(wx.StaticText(self, label="Points"),
                           flag=wx.ALIGN_CENTER)
        infoPanelSizer.Add(wx.StaticText(self, label="Total DPS"),
                           flag=wx.ALIGN_CENTER)
        infoPanelSizer.Add(wx.StaticText(self, label="Total EHP"),
                           flag=wx.ALIGN_CENTER)
        infoPanelSizer.Add(shipCountLabel, flag=wx.ALIGN_CENTER)
        infoPanelSizer.Add(pointCountLabel, flag=wx.ALIGN_CENTER)
        infoPanelSizer.Add(dpsLabel, flag=wx.ALIGN_CENTER)
        infoPanelSizer.Add(ehpLabel, flag=wx.ALIGN_CENTER)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(grid, 1, wx.EXPAND)
        sizer.Add(infoPanelSizer, 0, wx.EXPAND | wx.ALL, border=8)
        self.SetSizer(sizer)

        self._grid = grid
        self.shipCountLabel = shipCountLabel
        self.pointCountLabel = pointCountLabel
        self.dpsLabel = dpsLabel
        self.ehpLabel = ehpLabel
        self._setup: Setup = None
示例#5
0
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)
示例#6
0
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)