def __init__(self, parent, curSelected=(0, 1)):
        iTradeSizedDialog.__init__(self,parent,-1,message('converter_title'),
                                   size=(420, 420),style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)

        # container
        container = self.GetContentsPane()
        container.SetSizerType("vertical")

        # resizable pane
        pane = sc.SizedPanel(container, -1)
        pane.SetSizerType("form")
        pane.SetSizerProps(expand=True)

        # Row 1 : Org Currency Value
        self.wxOrgVal = masked.Ctrl(pane, integerWidth=9, fractionWidth=2, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupDigits = True, groupChar=getGroupChar(), decimalChar=getDecimalChar(), selectOnEntry=True )
        self.wxOrgVal.SetValue(1)
        masked.EVT_NUM(self, self.wxOrgVal.GetId(), self.OnValueChange)

        self.wxOrgCur = wx.ComboBox(pane,-1, "", size=wx.Size(80,-1), style=wx.CB_DROPDOWN|wx.CB_READONLY)

        list = list_of_currencies()
        (curFrom, curTo) = curSelected

        for c in list:
            self.wxOrgCur.Append(c,c)

        self.wxOrgCur.SetSelection(curFrom)
        self.m_orgcur = list[curFrom]
        wx.EVT_COMBOBOX(self,self.wxOrgCur.GetId(),self.OnOrgCurrency)

        # Row 2 : Dest Currency Value
        self.wxDestVal = wx.StaticText(pane, -1, "", size=(100,-1), style = wx.ALIGN_RIGHT | wx.ST_NO_AUTORESIZE)
        self.wxDestVal.SetLabel('')
        self.wxDestVal.SetSizerProps(valign='center')
        self.wxDestCur = wx.ComboBox(pane,-1, "", size=wx.Size(80,-1), style=wx.CB_DROPDOWN|wx.CB_READONLY)

        for c in list:
            self.wxDestCur.Append(c,c)

        self.wxDestCur.SetSelection(curTo)
        self.m_destcur = list[curTo]
        wx.EVT_COMBOBOX(self,self.wxDestCur.GetId(),self.OnDestCurrency)

        # Last Row : OK and Cancel
        btnpane = sc.SizedPanel(container, -1)
        btnpane.SetSizerType("horizontal")
        btnpane.SetSizerProps(expand=True)

        # context help
        if wx.Platform != "__WXMSW__":
            btn = wx.ContextHelpButton(self)

        # CLOSE
        btn = wx.Button(btnpane, wx.ID_CANCEL, message('close'))
        btn.SetHelpText(message('close_desc'))

        # a little trick to make sure that you can't resize the dialog to
        # less screen space than the controls need
        self.Fit()
        self.SetMinSize(self.GetSize())

        EVT_UPDATE_CONVERT(self, self.OnUpdateConvert)

        # convert now
        self.convertValue()
Example #2
0
    def __init__(self, parent, curSelected=(0, 1)):
        iTradeSizedDialog.__init__(self,
                                   parent,
                                   -1,
                                   message('converter_title'),
                                   size=(420, 420),
                                   style=wx.DEFAULT_DIALOG_STYLE
                                   | wx.RESIZE_BORDER)

        # container
        container = self.GetContentsPane()
        container.SetSizerType("vertical")

        # resizable pane
        pane = sc.SizedPanel(container, -1)
        pane.SetSizerType("form")
        pane.SetSizerProps(expand=True)

        # Row 1 : Org Currency Value
        self.wxOrgVal = masked.Ctrl(pane,
                                    integerWidth=9,
                                    fractionWidth=2,
                                    controlType=masked.controlTypes.NUMBER,
                                    allowNegative=False,
                                    groupDigits=True,
                                    groupChar=getGroupChar(),
                                    decimalChar=getDecimalChar(),
                                    selectOnEntry=True)
        self.wxOrgVal.SetValue(1)
        masked.EVT_NUM(self, self.wxOrgVal.GetId(), self.OnValueChange)

        self.wxOrgCur = wx.ComboBox(pane,
                                    -1,
                                    "",
                                    size=wx.Size(80, -1),
                                    style=wx.CB_DROPDOWN | wx.CB_READONLY)

        list = list_of_currencies()
        (curFrom, curTo) = curSelected

        for c in list:
            self.wxOrgCur.Append(c, c)

        self.wxOrgCur.SetSelection(curFrom)
        self.m_orgcur = list[curFrom]
        wx.EVT_COMBOBOX(self, self.wxOrgCur.GetId(), self.OnOrgCurrency)

        # Row 2 : Dest Currency Value
        self.wxDestVal = wx.StaticText(pane,
                                       -1,
                                       "",
                                       size=(100, -1),
                                       style=wx.ALIGN_RIGHT
                                       | wx.ST_NO_AUTORESIZE)
        self.wxDestVal.SetLabel('')
        self.wxDestVal.SetSizerProps(valign='center')
        self.wxDestCur = wx.ComboBox(pane,
                                     -1,
                                     "",
                                     size=wx.Size(80, -1),
                                     style=wx.CB_DROPDOWN | wx.CB_READONLY)

        for c in list:
            self.wxDestCur.Append(c, c)

        self.wxDestCur.SetSelection(curTo)
        self.m_destcur = list[curTo]
        wx.EVT_COMBOBOX(self, self.wxDestCur.GetId(), self.OnDestCurrency)

        # Last Row : OK and Cancel
        btnpane = sc.SizedPanel(container, -1)
        btnpane.SetSizerType("horizontal")
        btnpane.SetSizerProps(expand=True)

        # context help
        if wx.Platform != "__WXMSW__":
            btn = wx.ContextHelpButton(self)

        # CLOSE
        btn = wx.Button(btnpane, wx.ID_CANCEL, message('close'))
        btn.SetHelpText(message('close_desc'))

        # a little trick to make sure that you can't resize the dialog to
        # less screen space than the controls need
        self.Fit()
        self.SetMinSize(self.GetSize())

        EVT_UPDATE_CONVERT(self, self.OnUpdateConvert)

        # convert now
        self.convertValue()
    def __init__(self, parent, quote, bAdd = True):
        # context help
        pre = wx.PreDialog()
        pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
        if bAdd:
            title = message('stops_add_caption') % quote.name()
        else:
            title = message('stops_edit_caption') % quote.name()
        pre.Create(parent, -1, title, size=(420, 420))
        self.PostCreate(pre)

        # init
        self.m_add = bAdd
        self.m_quote = quote
        self.m_parent = parent

        # sizers
        sizer = wx.BoxSizer(wx.VERTICAL)

        # current quote
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, quote.name())
        box.Add(label, 0, wx.ALIGN_LEFT|wx.ALL, 5)

        label = wx.StaticText(self, -1, message('stops_last'))
        box.Add(label, 0, wx.ALIGN_LEFT|wx.ALL, 5)

        label = wx.StaticText(self, -1, quote.sv_close(bDispCurrency=True))
        box.Add(label, 0, wx.ALIGN_LEFT|wx.ALL, 5)

        sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

        # Thresholds
        if quote.nv_number()==0:
            msgb = message('stops_noshares_loss')
            msgh = message('stops_noshares_win')
        else:
            msgb = message('stops_shares_loss')
            msgh = message('stops_shares_win')

            box = wx.BoxSizer(wx.HORIZONTAL)

            label = wx.StaticText(self, -1, message('stops_portfolio') % (quote.nv_number(),quote.sv_pr(bDispCurrency=True)) )
            box.Add(label, 0, wx.ALIGN_LEFT|wx.ALL, 5)

            sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)


        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, msgb)
        box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5)

        self.wxLoss = masked.Ctrl( self, integerWidth=6, fractionWidth=2, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupChar=getGroupChar(), decimalChar=getDecimalChar() )
        box.Add(self.wxLoss, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5)
        if quote.hasStops(): self.wxLoss.SetValue(quote.nv_stoploss())

        label = wx.StaticText(self, -1, quote.currency_symbol())
        box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5)

        sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, msgh)
        box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5)

        self.wxWin = masked.Ctrl( self, integerWidth=6, fractionWidth=2, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupChar=getGroupChar(), decimalChar=getDecimalChar() )
        box.Add(self.wxWin, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5)
        if quote.hasStops(): self.wxWin.SetValue(quote.nv_stopwin())

        label = wx.StaticText(self, -1, quote.currency_symbol())
        box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_LEFT|wx.ALL, 5)

        sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

        # Commands (OK / CANCEL / Help)
        box = wx.BoxSizer(wx.HORIZONTAL)

        # context help
        if wx.Platform != "__WXMSW__":
            btn = wx.ContextHelpButton(self)
            box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        # OK
        if bAdd:
            msg = message('stops_add')
            msgdesc = message('stops_add_desc')
        else:
            msg = message('stops_edit')
            msgdesc = message('stops_edit_desc')

        btn = wx.Button(self, wx.ID_OK, msg)
        btn.SetDefault()
        btn.SetHelpText(msgdesc)
        box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
        wx.EVT_BUTTON(self, wx.ID_OK, self.OnValid)

        # CANCEL
        btn = wx.Button(self, wx.ID_CANCEL, message('cancel'))
        btn.SetHelpText(message('cancel_desc'))
        box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)

        sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)

        self.SetAutoLayout(True)
        self.SetSizerAndFit(sizer)
Example #4
0
    def __init__(self, parent, quote, bAdd=True):
        # context help
        pre = wx.PreDialog()
        pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
        if bAdd:
            title = message('stops_add_caption') % quote.name()
        else:
            title = message('stops_edit_caption') % quote.name()
        pre.Create(parent, -1, title, size=(420, 420))
        self.PostCreate(pre)

        # init
        self.m_add = bAdd
        self.m_quote = quote
        self.m_parent = parent

        # sizers
        sizer = wx.BoxSizer(wx.VERTICAL)

        # current quote
        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, quote.name())
        box.Add(label, 0, wx.ALIGN_LEFT | wx.ALL, 5)

        label = wx.StaticText(self, -1, message('stops_last'))
        box.Add(label, 0, wx.ALIGN_LEFT | wx.ALL, 5)

        label = wx.StaticText(self, -1, quote.sv_close(bDispCurrency=True))
        box.Add(label, 0, wx.ALIGN_LEFT | wx.ALL, 5)

        sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

        # Thresholds
        if quote.nv_number() == 0:
            msgb = message('stops_noshares_loss')
            msgh = message('stops_noshares_win')
        else:
            msgb = message('stops_shares_loss')
            msgh = message('stops_shares_win')

            box = wx.BoxSizer(wx.HORIZONTAL)

            label = wx.StaticText(
                self, -1,
                message('stops_portfolio') %
                (quote.nv_number(), quote.sv_pr(bDispCurrency=True)))
            box.Add(label, 0, wx.ALIGN_LEFT | wx.ALL, 5)

            sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, msgb)
        box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, 5)

        self.wxLoss = masked.Ctrl(self,
                                  integerWidth=6,
                                  fractionWidth=2,
                                  controlType=masked.controlTypes.NUMBER,
                                  allowNegative=False,
                                  groupChar=getGroupChar(),
                                  decimalChar=getDecimalChar())
        box.Add(self.wxLoss, 0,
                wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, 5)
        if quote.hasStops(): self.wxLoss.SetValue(quote.nv_stoploss())

        label = wx.StaticText(self, -1, quote.currency_symbol())
        box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, 5)

        sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

        box = wx.BoxSizer(wx.HORIZONTAL)

        label = wx.StaticText(self, -1, msgh)
        box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, 5)

        self.wxWin = masked.Ctrl(self,
                                 integerWidth=6,
                                 fractionWidth=2,
                                 controlType=masked.controlTypes.NUMBER,
                                 allowNegative=False,
                                 groupChar=getGroupChar(),
                                 decimalChar=getDecimalChar())
        box.Add(self.wxWin, 0,
                wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, 5)
        if quote.hasStops(): self.wxWin.SetValue(quote.nv_stopwin())

        label = wx.StaticText(self, -1, quote.currency_symbol())
        box.Add(label, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.ALL, 5)

        sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

        # Commands (OK / CANCEL / Help)
        box = wx.BoxSizer(wx.HORIZONTAL)

        # context help
        if wx.Platform != "__WXMSW__":
            btn = wx.ContextHelpButton(self)
            box.Add(btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        # OK
        if bAdd:
            msg = message('stops_add')
            msgdesc = message('stops_add_desc')
        else:
            msg = message('stops_edit')
            msgdesc = message('stops_edit_desc')

        btn = wx.Button(self, wx.ID_OK, msg)
        btn.SetDefault()
        btn.SetHelpText(msgdesc)
        box.Add(btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5)
        wx.EVT_BUTTON(self, wx.ID_OK, self.OnValid)

        # CANCEL
        btn = wx.Button(self, wx.ID_CANCEL, message('cancel'))
        btn.SetHelpText(message('cancel_desc'))
        box.Add(btn, 0, wx.ALIGN_CENTRE | wx.ALL, 5)

        sizer.AddSizer(box, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5)

        self.SetAutoLayout(True)
        self.SetSizerAndFit(sizer)
    def __init__(self, parent, portfolio, operation):
        iTradeSizedDialog.__init__(self, None, -1, message('portfolio_properties_%s'% operation),
                        style=wx.DEFAULT_DIALOG_STYLE , size=(420, 420) )

        if portfolio:
            self.m_filename = portfolio.filename()
            self.m_name = portfolio.name()
            self.m_accountref = portfolio.accountref()
            self.m_market = portfolio.market()
            self.m_currency = portfolio.currency()
            self.m_vat = portfolio.vat()
            self.m_term = portfolio.term()
            self.m_risk = portfolio.risk()
            self.m_indice = portfolio.indice()
        else:
            self.m_filename = 'noname'
            self.m_name = ''
            self.m_accountref = ''
            self.m_market = 'EURONEXT'
            self.m_currency = 'EUR'
            self.m_vat = 1.196
            self.m_term = 3
            self.m_risk = 5
            self.m_indice = getDefaultIndice(self.m_market)
        self.m_operation = operation

        # container
        container = self.GetContentsPane()
        container.SetSizerType("vertical")

        # resizable pane
        pane = sc.SizedPanel(container, -1)
        pane.SetSizerType("form")
        pane.SetSizerProps(expand=True)

        # row1 : filename
        label = wx.StaticText(pane, -1, message('portfolio_filename'))
        label.SetSizerProps(valign='center')
        self.wxFilenameCtrl = wx.TextCtrl(pane, -1, self.m_filename, size=(120,-1))
        self.wxFilenameCtrl.SetSizerProps(expand=True)

        # row2 : name
        label = wx.StaticText(pane, -1, message('portfolio_name'))
        label.SetSizerProps(valign='center')
        self.wxNameCtrl = wx.TextCtrl(pane, -1, self.m_name, size=(180,-1))
        self.wxNameCtrl.SetSizerProps(expand=True)

        # row3 : accountref
        label = wx.StaticText(pane, -1, message('portfolio_accountref'))
        label.SetSizerProps(valign='center')

        self.wxAccountRefCtrl = wx.TextCtrl(pane, -1, self.m_accountref, size=(80,-1))
        self.wxAccountRefCtrl.SetSizerProps(expand=True)

        # row4 : market
        label = wx.StaticText(pane, -1, message('portfolio_market'))
        label.SetSizerProps(valign='center')

        self.wxMarketCtrl = wx.ComboBox(pane,-1, "", size=wx.Size(160,-1), style=wx.CB_DROPDOWN|wx.CB_READONLY)
        wx.EVT_COMBOBOX(self,self.wxMarketCtrl.GetId(),self.OnMarket)

        count = 0
        for eachCtrl in list_of_markets():
            self.wxMarketCtrl.Append(eachCtrl,eachCtrl)
            if eachCtrl==self.m_market:
                idx = count
            count = count + 1

        self.wxMarketCtrl.SetSelection(idx)

        # row5 : main indice
        label = wx.StaticText(pane, -1, message('portfolio_indicator'))
        label.SetSizerProps(valign='center')

        self.wxIndicatorCtrl = wx.ComboBox(pane,-1, "", size=wx.Size(160,-1), style=wx.CB_DROPDOWN|wx.CB_READONLY)
        wx.EVT_COMBOBOX(self,self.wxIndicatorCtrl.GetId(),self.OnIndicator)

        count = 0
        for eachCtrl in quotes.list():
            if eachCtrl.list()==QLIST_INDICES:
                self.wxIndicatorCtrl.Append(eachCtrl.name(),eachCtrl.isin())
                if eachCtrl.isin()==self.m_indice:
                    idx = count
                count = count + 1

        self.wxIndicatorCtrl.SetSelection(idx)

        # row6 : currency
        label = wx.StaticText(pane, -1, message('portfolio_currency'))
        label.SetSizerProps(valign='center')

        self.wxCurrencyCtrl = wx.ComboBox(pane,-1, "", size=wx.Size(80,-1), style=wx.CB_DROPDOWN|wx.CB_READONLY)
        wx.EVT_COMBOBOX(self,self.wxCurrencyCtrl.GetId(),self.OnCurrency)

        count = 0
        for eachCtrl in list_of_currencies():
            #print eachCtrl
            self.wxCurrencyCtrl.Append(eachCtrl,eachCtrl)
            if eachCtrl==self.m_currency:
                idx = count
            count = count + 1

        self.wxCurrencyCtrl.SetSelection(idx)

        # row7 : default vat
        label = wx.StaticText(pane, -1, message('portfolio_vat'))
        label.SetSizerProps(valign='center')

        self.wxVATCtrl = masked.Ctrl(pane, integerWidth=5, fractionWidth=3, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupChar=getGroupChar(), decimalChar=getDecimalChar() )
        self.wxVATCtrl.SetValue((self.m_vat-1)*100)

        # Row8 : trading style
        label = wx.StaticText(container, -1, message('prop_tradingstyle'))

        btnpane = sc.SizedPanel(container, -1, style = wx.RAISED_BORDER | wx.CAPTION | wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE)
        btnpane.SetSizerType("form")
        btnpane.SetSizerProps(expand=True)

        label = wx.StaticText(btnpane, -1, message('prop_term'))
        label.SetSizerProps(valign='center')

        self.wxTermCtrl = masked.Ctrl(btnpane, integerWidth=3, fractionWidth=0, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupChar=getGroupChar(), decimalChar=getDecimalChar() )
        self.wxTermCtrl.SetValue(self.m_term)

        label = wx.StaticText(btnpane, -1, message('prop_risk'))
        label.SetSizerProps(valign='center')

        self.wxRiskCtrl = masked.Ctrl(btnpane, integerWidth=3, fractionWidth=0, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupChar=getGroupChar(), decimalChar=getDecimalChar() )
        self.wxRiskCtrl.SetValue(self.m_risk)

        # row 9 : separator
        line = wx.StaticLine(container, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
        line.SetSizerProps(expand=True)

        # Last Row : OK and Cancel
        btnpane = sc.SizedPanel(container, -1)
        btnpane.SetSizerType("horizontal")
        btnpane.SetSizerProps(expand=True)

        if operation=='create':
            msg = message('portfolio_properties_btncreate')
            msgdesc = message('portfolio_properties_btncreatedesc')
            fnt = self.OnValid
        elif operation=='delete':
            msg = message('portfolio_properties_btndelete')
            msgdesc = message('portfolio_properties_btndeletedesc')
            fnt = self.OnValid
        elif operation=='edit':
            msg = message('portfolio_properties_btnedit')
            msgdesc = message('portfolio_properties_btneditdesc')
            fnt = self.OnValid
        elif operation=='rename':
            msg = message('portfolio_properties_btnrename')
            msgdesc = message('portfolio_properties_btnrenamedesc')
            fnt = self.OnValid
        else:
            msg = message('valid')
            msgdesc = message('valid_desc')
            fnt = self.OnValid

        # context help
        if wx.Platform != "__WXMSW__":
            btn = wx.ContextHelpButton(btnpane)

        # OK
        btn = wx.Button(btnpane, wx.ID_OK, msg)
        btn.SetDefault()
        btn.SetHelpText(msgdesc)
        wx.EVT_BUTTON(self, wx.ID_OK, fnt)

        # CANCEL
        btn = wx.Button(btnpane, wx.ID_CANCEL, message('cancel'))
        btn.SetHelpText(message('cancel_desc'))

        # enable some fields based on the operation
        if operation=='edit':
            # edit: filename, market and currency can't be changed
            self.wxFilenameCtrl.Enable(False)
            self.wxMarketCtrl.Enable(False)
            self.wxCurrencyCtrl.Enable(False)
            #self.wxNameCtrl.SetFocus()
        elif operation=='delete':
            # display only
            self.wxFilenameCtrl.Enable(False)
            self.wxNameCtrl.Enable(False)
            self.wxAccountRefCtrl.Enable(False)
            self.wxMarketCtrl.Enable(False)
            self.wxCurrencyCtrl.Enable(False)
            self.wxVATCtrl.Enable(False)
            self.wxTermCtrl.Enable(False)
            self.wxRiskCtrl.Enable(False)
            self.wxIndicatorCtrl.Enable(False)
            #self.btn.SetFocus()
        elif operation=='rename':
            # filename only
            self.wxNameCtrl.Enable(False)
            self.wxAccountRefCtrl.Enable(False)
            self.wxMarketCtrl.Enable(False)
            self.wxCurrencyCtrl.Enable(False)
            self.wxVATCtrl.Enable(False)
            self.wxTermCtrl.Enable(False)
            self.wxRiskCtrl.Enable(False)
            self.wxIndicatorCtrl.Enable(False)
            #self.btn.SetFocus()
        else:
            # everything is editable
            pass

        # a little trick to make sure that you can't resize the dialog to
        # less screen space than the controls need
        self.Fit()
        self.SetMinSize(self.GetSize())
    def __init__(self, parent, op, opmode, market=None, currency='EUR'):
        # pre-init
        self.opmode = opmode

        self.m_market = market

        if op:
            self.m_type = op.type()
            self.m_value = op.nv_value()
            self.m_expenses = op.nv_expenses()
            self.m_number = op.nv_number()
            if op.quote():
                if op.isQuote():
                    self.m_name = op.quote().key()
                    self.m_market = op.quote().market()
                else:
                    self.m_name = ""
            else:
                self.m_name = op.name()
            self.m_date = op.date()
            self.m_ref = op.ref()
        else:
            self.m_type = OPERATION_SELL
            self.m_value = 0.0
            self.m_expenses = 0.0
            self.m_number = 0
            self.m_name = ""
            self.m_date = date.today()
            self.m_ref = -1

        self.m_parent = parent

        if opmode == OPERATION_MODIFY:
            tb = message('portfolio_modify')
        elif opmode == OPERATION_ADD:
            tb = message('portfolio_new')
        elif opmode == OPERATION_DELETE:
            tb = message('portfolio_delete')
        else:
            tb = '??'
        tt = tb + ' %s - %s %s'
        if op:
            self.tt = tt % (op.date().strftime('%x'),op.operation(),op.description())
        else:
            self.tt = tb

        # init
        iTradeSizedDialog.__init__(self,parent, -1, self.tt, style=wx.DEFAULT_DIALOG_STYLE, size=(420, 480))

        # container
        container = self.GetContentsPane()
        container.SetSizerType("vertical")

        # resizable pane
        pane = sc.SizedPanel(container, -1)
        pane.SetSizerType("form")
        pane.SetSizerProps(expand=True)

        # Row1 : date
        label = wx.StaticText(pane, -1, message('portfolio_date'))
        label.SetSizerProps(valign='center')

        ssdatetime = wx.DateTimeFromDMY(self.m_date.day,self.m_date.month-1,self.m_date.year)
        self.wxDateCtrl = wx.DatePickerCtrl(pane, -1, ssdatetime , size = (120,-1), style = wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
        wx.EVT_DATE_CHANGED(self, self.wxDateCtrl.GetId(), self.OnDate)

        # Row 2 : kind of operation
        label = wx.StaticText(pane, -1, message('portfolio_operation'))
        label.SetSizerProps(valign='center')

        self.wxTypeCtrl = wx.ComboBox(pane,-1, "", size=wx.Size(160,-1), style=wx.CB_DROPDOWN|wx.CB_READONLY)
        wx.EVT_COMBOBOX(self,self.wxTypeCtrl.GetId(),self.OnType)

        count = 0
        for k,v in operation_ctrl:
            #print '***',message(v),k
            self.wxTypeCtrl.Append(message(v),k)
            if k==self.m_type:
                idx = count
            count = count + 1

        self.wxTypeCtrl.SetSelection(idx)

        # Row 3 : quote
        btnpane = sc.SizedPanel(container, -1)
        btnpane.SetSizerType("horizontal")
        btnpane.SetSizerProps(expand=True)

        self.wxNameLabel = wx.StaticText(btnpane, -1, message('portfolio_description'))
        self.wxNameLabel.SetSizerProps(valign='center')

        bmp = wx.Bitmap(os.path.join(itrade_config.dirRes, 'quotes.png'))
        self.wxNameButton = wx.BitmapButton(btnpane, -1, bmp, size=wx.Size(bmp.GetWidth()+5, bmp.GetHeight()+5))
        wx.EVT_BUTTON(self, self.wxNameButton.GetId(), self.OnQuote)

        #print 'creating ctrl:',self.m_name
        self.wxNameCtrl = wx.TextCtrl(btnpane, -1, self.m_name, size=wx.Size(240,-1), style = wx.TE_LEFT)
        wx.EVT_TEXT( self, self.wxNameCtrl.GetId(), self.OnDescChange )
        self.wxNameCtrl.SetSizerProps(expand=True)

        # Row 4 : value
        btnpane = sc.SizedPanel(container, -1)
        btnpane.SetSizerType("horizontal")
        btnpane.SetSizerProps(expand=True)

        self.wxValueLabel = wx.StaticText(btnpane, -1, message('portfolio_field_credit'))
        self.wxValueLabel.SetSizerProps(valign='center')

        self.wxValueCtrl = masked.Ctrl(btnpane, integerWidth=9, fractionWidth=2, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupDigits = True, groupChar=getGroupChar(), decimalChar=getDecimalChar(), selectOnEntry=True )
        wx.EVT_TEXT( self, self.wxValueCtrl.GetId(), self.OnValueChange )

        self.wxValueTxt = wx.StaticText(btnpane, -1, currency2symbol(currency))
        self.wxValueTxt.SetSizerProps(valign='center')

        self.wxExpPreTxt = wx.StaticText(btnpane, -1, '')
        self.wxExpPreTxt.SetSizerProps(valign='center')

        self.wxExpensesCtrl = masked.Ctrl(btnpane, integerWidth=4, fractionWidth=2, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupDigits = True, groupChar=getGroupChar(), decimalChar=getDecimalChar(), selectOnEntry=True )
        wx.EVT_TEXT( self, self.wxExpensesCtrl.GetId(), self.OnExpensesChange )

        self.wxExpPostTxt = wx.StaticText(btnpane, -1, "%s %s" % (currency2symbol(currency),message('portfolio_post_expenses')))
        self.wxExpPostTxt.SetSizerProps(valign='center')

        # resizable pane
        pane = sc.SizedPanel(container, -1)
        pane.SetSizerType("form")
        pane.SetSizerProps(expand=True)

        # number
        label = wx.StaticText(pane, -1, message('portfolio_quantity'))
        label.SetSizerProps(valign='center')

        self.wxNumberCtrl = masked.Ctrl(pane, integerWidth=9, fractionWidth=0, controlType=masked.controlTypes.NUMBER, allowNegative = False, groupChar=getGroupChar(), decimalChar=getDecimalChar() )
        wx.EVT_TEXT( self, self.wxNumberCtrl.GetId(), self.OnNumberChange )

        # separator
        line = wx.StaticLine(container, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
        line.SetSizerProps(expand=True)

        # Last Row : OK and Cancel
        btnpane = sc.SizedPanel(container, -1)
        btnpane.SetSizerType("horizontal")
        btnpane.SetSizerProps(expand=True)

        # context help
        if wx.Platform != "__WXMSW__":
            btn = wx.ContextHelpButton(btnpane)

        # OK
        btn = wx.Button(btnpane, wx.ID_OK, tb)
        btn.SetDefault()
        btn.SetHelpText(message('ok_desc'))
        wx.EVT_BUTTON(self, wx.ID_OK, self.OnValid)

        # CANCEL
        btn = wx.Button(btnpane, wx.ID_CANCEL, message('cancel'))
        btn.SetHelpText(message('cancel_desc'))
        wx.EVT_BUTTON(self, wx.ID_CANCEL, self.OnCancel)

        self.refreshPage()
Example #7
0
    def __init__(self, parent, portfolio, operation):
        iTradeSizedDialog.__init__(self,
                                   None,
                                   -1,
                                   message('portfolio_properties_%s' %
                                           operation),
                                   style=wx.DEFAULT_DIALOG_STYLE,
                                   size=(420, 420))

        if portfolio:
            self.m_filename = portfolio.filename()
            self.m_name = portfolio.name()
            self.m_accountref = portfolio.accountref()
            self.m_market = portfolio.market()
            self.m_currency = portfolio.currency()
            self.m_vat = portfolio.vat()
            self.m_term = portfolio.term()
            self.m_risk = portfolio.risk()
            self.m_indice = portfolio.indice()
        else:
            self.m_filename = 'noname'
            self.m_name = ''
            self.m_accountref = ''
            self.m_market = 'EURONEXT'
            self.m_currency = 'EUR'
            self.m_vat = 1.196
            self.m_term = 3
            self.m_risk = 5
            self.m_indice = getDefaultIndice(self.m_market)
        self.m_operation = operation

        # container
        container = self.GetContentsPane()
        container.SetSizerType("vertical")

        # resizable pane
        pane = sc.SizedPanel(container, -1)
        pane.SetSizerType("form")
        pane.SetSizerProps(expand=True)

        # row1 : filename
        label = wx.StaticText(pane, -1, message('portfolio_filename'))
        label.SetSizerProps(valign='center')
        self.wxFilenameCtrl = wx.TextCtrl(pane,
                                          -1,
                                          self.m_filename,
                                          size=(120, -1))
        self.wxFilenameCtrl.SetSizerProps(expand=True)

        # row2 : name
        label = wx.StaticText(pane, -1, message('portfolio_name'))
        label.SetSizerProps(valign='center')
        self.wxNameCtrl = wx.TextCtrl(pane, -1, self.m_name, size=(180, -1))
        self.wxNameCtrl.SetSizerProps(expand=True)

        # row3 : accountref
        label = wx.StaticText(pane, -1, message('portfolio_accountref'))
        label.SetSizerProps(valign='center')

        self.wxAccountRefCtrl = wx.TextCtrl(pane,
                                            -1,
                                            self.m_accountref,
                                            size=(80, -1))
        self.wxAccountRefCtrl.SetSizerProps(expand=True)

        # row4 : market
        label = wx.StaticText(pane, -1, message('portfolio_market'))
        label.SetSizerProps(valign='center')

        self.wxMarketCtrl = wx.ComboBox(pane,
                                        -1,
                                        "",
                                        size=wx.Size(160, -1),
                                        style=wx.CB_DROPDOWN | wx.CB_READONLY)
        wx.EVT_COMBOBOX(self, self.wxMarketCtrl.GetId(), self.OnMarket)

        count = 0
        for eachCtrl in list_of_markets():
            self.wxMarketCtrl.Append(eachCtrl, eachCtrl)
            if eachCtrl == self.m_market:
                idx = count
            count = count + 1

        self.wxMarketCtrl.SetSelection(idx)

        # row5 : main indice
        label = wx.StaticText(pane, -1, message('portfolio_indicator'))
        label.SetSizerProps(valign='center')

        self.wxIndicatorCtrl = wx.ComboBox(pane,
                                           -1,
                                           "",
                                           size=wx.Size(160, -1),
                                           style=wx.CB_DROPDOWN
                                           | wx.CB_READONLY)
        wx.EVT_COMBOBOX(self, self.wxIndicatorCtrl.GetId(), self.OnIndicator)

        count = 0
        for eachCtrl in quotes.list():
            if eachCtrl.list() == QLIST_INDICES:
                #self.wxIndicatorCtrl.Append(eachCtrl.name(),eachCtrl.isin())
                try:
                    self.wxIndicatorCtrl.Append(eachCtrl.name(),
                                                eachCtrl.isin())
                except:
                    print 'eachCtrl:', eachCtrl
                if eachCtrl.isin() == self.m_indice:
                    idx = count
                count = count + 1

        self.wxIndicatorCtrl.SetSelection(idx)

        # row6 : currency
        label = wx.StaticText(pane, -1, message('portfolio_currency'))
        label.SetSizerProps(valign='center')

        self.wxCurrencyCtrl = wx.ComboBox(pane,
                                          -1,
                                          "",
                                          size=wx.Size(80, -1),
                                          style=wx.CB_DROPDOWN
                                          | wx.CB_READONLY)
        wx.EVT_COMBOBOX(self, self.wxCurrencyCtrl.GetId(), self.OnCurrency)

        count = 0
        for eachCtrl in list_of_currencies():
            #print eachCtrl
            self.wxCurrencyCtrl.Append(eachCtrl, eachCtrl)
            if eachCtrl == self.m_currency:
                idx = count
            count = count + 1

        self.wxCurrencyCtrl.SetSelection(idx)

        # row7 : default vat
        label = wx.StaticText(pane, -1, message('portfolio_vat'))
        label.SetSizerProps(valign='center')

        self.wxVATCtrl = masked.Ctrl(pane,
                                     integerWidth=5,
                                     fractionWidth=3,
                                     controlType=masked.controlTypes.NUMBER,
                                     allowNegative=False,
                                     groupChar=getGroupChar(),
                                     decimalChar=getDecimalChar())
        self.wxVATCtrl.SetValue((self.m_vat - 1) * 100)

        # Row8 : trading style
        label = wx.StaticText(container, -1, message('prop_tradingstyle'))

        btnpane = sc.SizedPanel(container,
                                -1,
                                style=wx.RAISED_BORDER | wx.CAPTION
                                | wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN
                                | wx.NO_FULL_REPAINT_ON_RESIZE)
        btnpane.SetSizerType("form")
        btnpane.SetSizerProps(expand=True)

        label = wx.StaticText(btnpane, -1, message('prop_term'))
        label.SetSizerProps(valign='center')

        self.wxTermCtrl = masked.Ctrl(btnpane,
                                      integerWidth=3,
                                      fractionWidth=0,
                                      controlType=masked.controlTypes.NUMBER,
                                      allowNegative=False,
                                      groupChar=getGroupChar(),
                                      decimalChar=getDecimalChar())
        self.wxTermCtrl.SetValue(self.m_term)

        label = wx.StaticText(btnpane, -1, message('prop_risk'))
        label.SetSizerProps(valign='center')

        self.wxRiskCtrl = masked.Ctrl(btnpane,
                                      integerWidth=3,
                                      fractionWidth=0,
                                      controlType=masked.controlTypes.NUMBER,
                                      allowNegative=False,
                                      groupChar=getGroupChar(),
                                      decimalChar=getDecimalChar())
        self.wxRiskCtrl.SetValue(self.m_risk)

        # row 9 : separator
        line = wx.StaticLine(container,
                             -1,
                             size=(20, -1),
                             style=wx.LI_HORIZONTAL)
        line.SetSizerProps(expand=True)

        # Last Row : OK and Cancel
        btnpane = sc.SizedPanel(container, -1)
        btnpane.SetSizerType("horizontal")
        btnpane.SetSizerProps(expand=True)

        if operation == 'create':
            msg = message('portfolio_properties_btncreate')
            msgdesc = message('portfolio_properties_btncreatedesc')
            fnt = self.OnValid
        elif operation == 'delete':
            msg = message('portfolio_properties_btndelete')
            msgdesc = message('portfolio_properties_btndeletedesc')
            fnt = self.OnValid
        elif operation == 'edit':
            msg = message('portfolio_properties_btnedit')
            msgdesc = message('portfolio_properties_btneditdesc')
            fnt = self.OnValid
        elif operation == 'rename':
            msg = message('portfolio_properties_btnrename')
            msgdesc = message('portfolio_properties_btnrenamedesc')
            fnt = self.OnValid
        else:
            msg = message('valid')
            msgdesc = message('valid_desc')
            fnt = self.OnValid

        # context help
        if wx.Platform != "__WXMSW__":
            btn = wx.ContextHelpButton(btnpane)

        # OK
        btn = wx.Button(btnpane, wx.ID_OK, msg)
        btn.SetDefault()
        btn.SetHelpText(msgdesc)
        wx.EVT_BUTTON(self, wx.ID_OK, fnt)

        # CANCEL
        btn = wx.Button(btnpane, wx.ID_CANCEL, message('cancel'))
        btn.SetHelpText(message('cancel_desc'))

        # enable some fields based on the operation
        if operation == 'edit':
            # edit: filename, market and currency can't be changed
            self.wxFilenameCtrl.Enable(False)
            self.wxMarketCtrl.Enable(False)
            self.wxCurrencyCtrl.Enable(False)
            #self.wxNameCtrl.SetFocus()
        elif operation == 'delete':
            # display only
            self.wxFilenameCtrl.Enable(False)
            self.wxNameCtrl.Enable(False)
            self.wxAccountRefCtrl.Enable(False)
            self.wxMarketCtrl.Enable(False)
            self.wxCurrencyCtrl.Enable(False)
            self.wxVATCtrl.Enable(False)
            self.wxTermCtrl.Enable(False)
            self.wxRiskCtrl.Enable(False)
            self.wxIndicatorCtrl.Enable(False)
            #self.btn.SetFocus()
        elif operation == 'rename':
            # filename only
            self.wxNameCtrl.Enable(False)
            self.wxAccountRefCtrl.Enable(False)
            self.wxMarketCtrl.Enable(False)
            self.wxCurrencyCtrl.Enable(False)
            self.wxVATCtrl.Enable(False)
            self.wxTermCtrl.Enable(False)
            self.wxRiskCtrl.Enable(False)
            self.wxIndicatorCtrl.Enable(False)
            #self.btn.SetFocus()
        else:
            # everything is editable
            pass

        # a little trick to make sure that you can't resize the dialog to
        # less screen space than the controls need
        self.Fit()
        self.SetMinSize(self.GetSize())