Ejemplo n.º 1
0
    def __init__(self,
                 parent,
                 title,
                 data,
                 keyEditable=(-1, True),
                 id=wx.ID_ANY,
                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
        """Dialog for inserting/updating table record

        :param data: a list: [(column, value)]
        :param keyEditable: (id, editable?) indicates if textarea for
                            key column is editable(True) or not
        """
        # parent -> VDigitWindow
        wx.Dialog.__init__(self, parent, id, title, style=style)

        self.CenterOnParent()

        self.keyId = keyEditable[0]

        box = StaticBox(parent=self, id=wx.ID_ANY)
        box.Hide()
        self.dataPanel = scrolled.ScrolledPanel(parent=self,
                                                id=wx.ID_ANY,
                                                style=wx.TAB_TRAVERSAL)
        self.dataPanel.SetupScrolling(scroll_x=False)

        # buttons
        self.btnCancel = Button(self, wx.ID_CANCEL)
        self.btnSubmit = Button(self, wx.ID_OK, _("&Submit"))
        self.btnSubmit.SetDefault()

        # data area
        self.widgets = []
        cId = 0
        self.usebox = False
        self.cat = None
        winFocus = False

        for column, ctype, ctypeStr, value in data:
            if self.keyId == cId:
                self.cat = int(value)
                if not keyEditable[1]:
                    self.usebox = True
                    box.SetLabel(" %s %d " % (_("Category"), self.cat))
                    box.Show()
                    self.boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
                    cId += 1
                    continue
                else:
                    valueWin = SpinCtrl(parent=self.dataPanel,
                                        id=wx.ID_ANY,
                                        value=value,
                                        min=-1e9,
                                        max=1e9,
                                        size=(250, -1))
            else:
                valueWin = TextCtrl(parent=self.dataPanel,
                                    id=wx.ID_ANY,
                                    value=value,
                                    size=(250, -1))
                if ctype == int:
                    valueWin.SetValidator(IntegerValidator())
                elif ctype == float:
                    valueWin.SetValidator(FloatValidator())
                if not winFocus:
                    wx.CallAfter(valueWin.SetFocus)
                    winFocus = True

            label = StaticText(parent=self.dataPanel,
                               id=wx.ID_ANY,
                               label=column)
            ctype = StaticText(parent=self.dataPanel,
                               id=wx.ID_ANY,
                               label="[%s]:" % ctypeStr.lower())
            self.widgets.append(
                (label.GetId(), ctype.GetId(), valueWin.GetId()))

            cId += 1

        self._layout()