Example #1
0
    def addCtrls(self, type=REL_LABEL[OTHER_REL], label="", primary=False):
        pa = wx.StaticText(self, -1, AMI.getLabel("PA"))
        self.pa = wx.TextCtrl(self, -1, size=(200, -1), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER) 
        self.pa.SetToolTipString(AMI.getHelp("PA"))
        self.pa.SetFocus()

        ty = wx.StaticText(self, -1, AMI.getLabel("TY"))
        self.ty = wx.Choice(self, -1, (-1, -1), choices = self.types)
        self.ty.SetToolTipString(AMI.getHelp("TY"))

        pr = wx.StaticText(self, -1, AMI.getLabel("PR"))
        self.pr = wx.CheckBox(self, -1 )
        self.pr.SetToolTipString(AMI.getHelp("PR"))

        ag = wx.StaticText(self, -1, AMI.getLabel("AG"))
        self.ag = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.ag.SetToolTipString(AMI.getHelp("AG"))

        st = wx.StaticText(self, -1, AMI.getLabel("ST"))
        self.st = wx.TextCtrl(self, -1, "", size=(-1, -1))
        self.st.SetToolTipString(AMI.getHelp("ST"))

        po = wx.StaticText(self, -1, AMI.getLabel("PO"))
        self.po = wx.TextCtrl(self, -1, "", size=(-1, -1))
        self.po.SetToolTipString(AMI.getHelp("PO"))

        mc = wx.StaticText(self, -1, AMI.getLabel("MC"))
        self.mc = wx.Choice(self, -1, (-1, -1), choices = self.mailClasses)
        self.mc.SetToolTipString(AMI.getHelp("MC"))

        hn = wx.StaticText(self, -1, AMI.getLabel("HN"))
        self.hn = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.hn.SetToolTipString(AMI.getHelp("HN"))

        nh = wx.StaticText(self, -1, AMI.getLabel("NH"))
        self.nh = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.nh.SetToolTipString(AMI.getHelp("NH"))

        re = wx.StaticText(self, -1, AMI.getLabel("RE"))
        self.re = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.re.SetToolTipString(AMI.getHelp("RE"))

        pc = wx.StaticText(self, -1, AMI.getLabel("PC"))
        self.pc = wx.TextCtrl(self, -1, "", size=(-1, -1))
        self.pc.SetToolTipString(AMI.getHelp("PC"))

        ci = wx.StaticText(self, -1, AMI.getLabel("CI"))
        self.ci = wx.TextCtrl(self, -1, "", size=(-1, -1))
        self.ci.SetToolTipString(AMI.getHelp("CI"))

        sr = wx.StaticText(self, -1, AMI.getLabel("SR"))
        self.sr = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.sr.SetToolTipString(AMI.getHelp("SR"))

        co = wx.StaticText(self, -1, AMI.getLabel("CO"))
        self.co = CountryChoice(self)
        self.co.SetToolTipString(AMI.getHelp("CO"))

        la = wx.StaticText(self, -1, AMI.getLabel("LA"))
        self.la = wx.TextCtrl(self, -1, "", size=(200, -1))
        self.la.SetToolTipString(AMI.getHelp("LA"))

        us = wx.StaticText(self, -1, AMI.getLabel("US"))
        self.us = wx.Choice(self, -1, (-1, -1), choices = self.mailUsage)
        self.us.SetToolTipString(AMI.getHelp("US"))

        self.updateB = wx.Button(self, 10, self.updateLabel["add"], (50, -1))
        self.deleteB = wx.Button(self, 20, "Delete", (50, -1))
        self.disableDeleteButton()

        # On my system the GridBagSizer did not run stable so I switched to 
        # the RowColSizer.
        formSizer = rcsizer.RowColSizer()

        formSizer.Add(pa,        row=0, col=1, flag=wx.ALIGN_LEFT)
        formSizer.Add(la,        row=4, col=1, flag=wx.ALIGN_LEFT )

        formSizer.AddSpacer(6,6, row=1, col=2)

        formSizer.Add(self.pa,   row=0, col=3, rowspan=4, flag=wx.EXPAND)
        formSizer.Add(self.la,   row=4, col=3, flag=wx.ALL)

        formSizer.AddSpacer(6,6, row=2, col=4)

        formSizer.Add(st,        row=0, col=5, flag=wx.ALIGN_LEFT)
        formSizer.Add(pc,        row=1, col=5, flag=wx.ALIGN_LEFT)
        formSizer.Add(po,        row=2, col=5, flag=wx.ALIGN_LEFT)
        formSizer.Add(ty,        row=3, col=5, flag=wx.ALIGN_LEFT)
        formSizer.Add(mc,        row=4, col=5, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=2, col=6)

        formSizer.Add(self.st,   row=0, col=7, colspan=5, flag=wx.EXPAND)
        formSizer.Add(self.pc,   row=1, col=7, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.po,   row=2, col=7, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.ty,   row=3, col=7, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.mc,   row=4, col=7, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=2, col=8)

        formSizer.Add(ci,        row=1, col=9, flag=wx.ALIGN_LEFT)
        formSizer.Add(co,        row=2, col=9, flag=wx.ALIGN_LEFT)
        formSizer.Add(us,        row=3, col=9, flag=wx.ALIGN_LEFT)
        formSizer.Add(pr,        row=4, col=9, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=2, col=10)

        formSizer.Add(self.ci,   row=1, col=11, flag=wx.EXPAND)
        formSizer.Add(self.co,   row=2, col=11, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.us,   row=3, col=11, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.pr,   row=4, col=11, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=1, col=12)

        formSizer.Add(hn,        row=0, col=13, flag=wx.ALIGN_LEFT)
        formSizer.Add(nh,        row=1, col=13, flag=wx.ALIGN_LEFT)
        formSizer.Add(re,        row=2, col=13, flag=wx.ALIGN_LEFT)
        formSizer.Add(sr,        row=3, col=13, flag=wx.ALIGN_LEFT)
        formSizer.Add(ag,        row=4, col=13, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=1, col=14)

        formSizer.Add(self.hn,   row=0, col=15, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.nh,   row=1, col=15, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.re,   row=2, col=15, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.sr,   row=3, col=15, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.ag,   row=4, col=15, flag=wx.ALIGN_LEFT)

        bBox = wx.BoxSizer(wx.HORIZONTAL)
        bBox.Add(self.deleteB)
        bBox.Add(self.updateB)

        formSizer.Add(bBox, row=5, col=15, flag=wx.ALL | wx.ALIGN_RIGHT)
        self.SetSizer(formSizer)
Example #2
0
class AddressForm(wx.Panel):
    def __init__(self, *args, **kwargs):

        wx.Panel.__init__(self, *args, **kwargs)

        self.types = REL_LABEL.values()
        self.mailClasses = MAIL_CLASS.values()
        self.mailUsage = MAIL_USAGE.values()
        self.updateLabel = {"add":"Add", "update":"Update"}

        self.addCtrls()


    def addCtrls(self, type=REL_LABEL[OTHER_REL], label="", primary=False):
        pa = wx.StaticText(self, -1, AMI.getLabel("PA"))
        self.pa = wx.TextCtrl(self, -1, size=(200, -1), style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER) 
        self.pa.SetToolTipString(AMI.getHelp("PA"))
        self.pa.SetFocus()

        ty = wx.StaticText(self, -1, AMI.getLabel("TY"))
        self.ty = wx.Choice(self, -1, (-1, -1), choices = self.types)
        self.ty.SetToolTipString(AMI.getHelp("TY"))

        pr = wx.StaticText(self, -1, AMI.getLabel("PR"))
        self.pr = wx.CheckBox(self, -1 )
        self.pr.SetToolTipString(AMI.getHelp("PR"))

        ag = wx.StaticText(self, -1, AMI.getLabel("AG"))
        self.ag = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.ag.SetToolTipString(AMI.getHelp("AG"))

        st = wx.StaticText(self, -1, AMI.getLabel("ST"))
        self.st = wx.TextCtrl(self, -1, "", size=(-1, -1))
        self.st.SetToolTipString(AMI.getHelp("ST"))

        po = wx.StaticText(self, -1, AMI.getLabel("PO"))
        self.po = wx.TextCtrl(self, -1, "", size=(-1, -1))
        self.po.SetToolTipString(AMI.getHelp("PO"))

        mc = wx.StaticText(self, -1, AMI.getLabel("MC"))
        self.mc = wx.Choice(self, -1, (-1, -1), choices = self.mailClasses)
        self.mc.SetToolTipString(AMI.getHelp("MC"))

        hn = wx.StaticText(self, -1, AMI.getLabel("HN"))
        self.hn = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.hn.SetToolTipString(AMI.getHelp("HN"))

        nh = wx.StaticText(self, -1, AMI.getLabel("NH"))
        self.nh = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.nh.SetToolTipString(AMI.getHelp("NH"))

        re = wx.StaticText(self, -1, AMI.getLabel("RE"))
        self.re = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.re.SetToolTipString(AMI.getHelp("RE"))

        pc = wx.StaticText(self, -1, AMI.getLabel("PC"))
        self.pc = wx.TextCtrl(self, -1, "", size=(-1, -1))
        self.pc.SetToolTipString(AMI.getHelp("PC"))

        ci = wx.StaticText(self, -1, AMI.getLabel("CI"))
        self.ci = wx.TextCtrl(self, -1, "", size=(-1, -1))
        self.ci.SetToolTipString(AMI.getHelp("CI"))

        sr = wx.StaticText(self, -1, AMI.getLabel("SR"))
        self.sr = wx.TextCtrl(self, -1, "", size=(170, -1))
        self.sr.SetToolTipString(AMI.getHelp("SR"))

        co = wx.StaticText(self, -1, AMI.getLabel("CO"))
        self.co = CountryChoice(self)
        self.co.SetToolTipString(AMI.getHelp("CO"))

        la = wx.StaticText(self, -1, AMI.getLabel("LA"))
        self.la = wx.TextCtrl(self, -1, "", size=(200, -1))
        self.la.SetToolTipString(AMI.getHelp("LA"))

        us = wx.StaticText(self, -1, AMI.getLabel("US"))
        self.us = wx.Choice(self, -1, (-1, -1), choices = self.mailUsage)
        self.us.SetToolTipString(AMI.getHelp("US"))

        self.updateB = wx.Button(self, 10, self.updateLabel["add"], (50, -1))
        self.deleteB = wx.Button(self, 20, "Delete", (50, -1))
        self.disableDeleteButton()

        # On my system the GridBagSizer did not run stable so I switched to 
        # the RowColSizer.
        formSizer = rcsizer.RowColSizer()

        formSizer.Add(pa,        row=0, col=1, flag=wx.ALIGN_LEFT)
        formSizer.Add(la,        row=4, col=1, flag=wx.ALIGN_LEFT )

        formSizer.AddSpacer(6,6, row=1, col=2)

        formSizer.Add(self.pa,   row=0, col=3, rowspan=4, flag=wx.EXPAND)
        formSizer.Add(self.la,   row=4, col=3, flag=wx.ALL)

        formSizer.AddSpacer(6,6, row=2, col=4)

        formSizer.Add(st,        row=0, col=5, flag=wx.ALIGN_LEFT)
        formSizer.Add(pc,        row=1, col=5, flag=wx.ALIGN_LEFT)
        formSizer.Add(po,        row=2, col=5, flag=wx.ALIGN_LEFT)
        formSizer.Add(ty,        row=3, col=5, flag=wx.ALIGN_LEFT)
        formSizer.Add(mc,        row=4, col=5, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=2, col=6)

        formSizer.Add(self.st,   row=0, col=7, colspan=5, flag=wx.EXPAND)
        formSizer.Add(self.pc,   row=1, col=7, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.po,   row=2, col=7, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.ty,   row=3, col=7, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.mc,   row=4, col=7, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=2, col=8)

        formSizer.Add(ci,        row=1, col=9, flag=wx.ALIGN_LEFT)
        formSizer.Add(co,        row=2, col=9, flag=wx.ALIGN_LEFT)
        formSizer.Add(us,        row=3, col=9, flag=wx.ALIGN_LEFT)
        formSizer.Add(pr,        row=4, col=9, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=2, col=10)

        formSizer.Add(self.ci,   row=1, col=11, flag=wx.EXPAND)
        formSizer.Add(self.co,   row=2, col=11, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.us,   row=3, col=11, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.pr,   row=4, col=11, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=1, col=12)

        formSizer.Add(hn,        row=0, col=13, flag=wx.ALIGN_LEFT)
        formSizer.Add(nh,        row=1, col=13, flag=wx.ALIGN_LEFT)
        formSizer.Add(re,        row=2, col=13, flag=wx.ALIGN_LEFT)
        formSizer.Add(sr,        row=3, col=13, flag=wx.ALIGN_LEFT)
        formSizer.Add(ag,        row=4, col=13, flag=wx.ALIGN_LEFT)

        formSizer.AddSpacer(6,6, row=1, col=14)

        formSizer.Add(self.hn,   row=0, col=15, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.nh,   row=1, col=15, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.re,   row=2, col=15, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.sr,   row=3, col=15, flag=wx.ALIGN_LEFT)
        formSizer.Add(self.ag,   row=4, col=15, flag=wx.ALIGN_LEFT)

        bBox = wx.BoxSizer(wx.HORIZONTAL)
        bBox.Add(self.deleteB)
        bBox.Add(self.updateB)

        formSizer.Add(bBox, row=5, col=15, flag=wx.ALL | wx.ALIGN_RIGHT)
        self.SetSizer(formSizer)


    def setValue(self, id, v):
        """Sets the gui control identified by id (metadata.AddressMeta.id)
        to the passed value v.
        """
        if id == "PA": self.pa.SetValue(unicode(v))
        elif id == "ST": self.st.SetValue(unicode(v))
        elif id == "PC": self.pc.SetValue(unicode(v))
        elif id == "CI": self.ci.SetValue(unicode(v))
        elif id == "LA": self.la.SetValue(unicode(v))
        elif id == "AG": self.ag.SetValue(unicode(v))
        elif id == "HN": self.hn.SetValue(unicode(v))
        elif id == "NH": self.nh.SetValue(unicode(v))
        elif id == "PO": self.po.SetValue(unicode(v))
        elif id == "RE": self.re.SetValue(unicode(v))
        elif id == "SR": self.sr.SetValue(unicode(v))
        elif id == "CO": self.co.setValue(v)
        elif id == "PR":
            if (v and (v == "true" or v == "yes") ):
                self.pr.SetValue(True)
            else:
                self.pr.SetValue(False)
        elif id == "TY": 
            try:
                self.ty.SetSelection(self.types.index(v))
            except:
                self.ty.SetSelection(-1)
        elif id == "MC":
            try:
                self.mc.SetSelection(self.mailClasses.index(v))
            except:
                self.mc.SetSelection(-1)
        elif id == "US": 
            try:
                self.us.SetSelection(self.mailUsage.index(v))
            except:
                self.us.SetSelection(-1)
        else: 
            raise BaseException("Id %s unknown!" % id)

    def getValues(self):
        """Returns its values as dict {ID:VAL, ...}. Unset Values will not be 
        included in the dictionary"""
        d = {}
        d["PA"] = self.pa.GetValue()
        d["ST"] = self.st.GetValue()
        d["PC"] = self.pc.GetValue()
        d["CI"] = self.ci.GetValue()
        d["LA"] = self.la.GetValue()
        d["AG"] = self.ag.GetValue()
        d["HN"] = self.hn.GetValue()
        d["NH"] = self.nh.GetValue()
        d["PO"] = self.po.GetValue()
        d["RE"] = self.re.GetValue()
        d["SR"] = self.sr.GetValue()
        if self.co.GetCurrentSelection() >= 0:
            d["CO"] = self.co.getValue(self.co.GetCurrentSelection())
        if self.ty.GetCurrentSelection() >= 0:
            d["TY"] = self.types[self.ty.GetCurrentSelection()]
        if self.pr.GetValue():
            d["PR"] = "yes"
        else:
            d["PR"] = ""
        if self.mc.GetCurrentSelection() >= 0:
            d["MC"] = self.mailClasses[self.mc.GetCurrentSelection()]
        if self.us.GetCurrentSelection() >= 0:
            d["US"] = self.mailUsage[self.us.GetCurrentSelection()]
        return d

    def setButtonLabelAdd(self):
        """Sets the label if idx refers to an existing entry or not
        """
        self.updateB.SetLabel(self.updateLabel["add"])

    def setButtonLabelUpdate(self):
        """Sets the label if idx refers to an existing entry or not
        """
        self.updateB.SetLabel(self.updateLabel["update"])

    def enableDeleteButton(self):
        self.deleteB.Enable()

    def disableDeleteButton(self):
        self.deleteB.Disable()

    def getTypeString(self, idx):
        if idx < 0:
            return unicode("")
        else:
            return unicode(self.types[idx])

    def reset(self):
        """Just to make it more readable or understandable
        """
        for id in AMI.getIDs():
            self.setValue(id, "")