~wxbanker-devs/wxbanker/trunk

« back to all changes in this revision

Viewing changes to wxbanker/tagtransactiondialog.py

  • Committer: Michael Rooney
  • Date: 2010-08-09 09:07:04 UTC
  • Revision ID: mrooney@ubuntu.com-20100809090704-kg1tmkd5wth02rbw
implement the final bit of tagging, adding a tag via the context menu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#    https://launchpad.net/wxbanker
 
2
#    tagtransactiondialog.py: Copyright 2007-2010 Mike Rooney <mrooney@ubuntu.com>
 
3
#
 
4
#    This file is part of wxBanker.
 
5
#
 
6
#    wxBanker is free software: you can redistribute it and/or modify
 
7
#    it under the terms of the GNU General Public License as published by
 
8
#    the Free Software Foundation, either version 3 of the License, or
 
9
#    (at your option) any later version.
 
10
#
 
11
#    wxBanker is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU General Public License
 
17
#    along with wxBanker.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
import wx
 
20
from wxbanker.bankobjects.tag import Tag, EmptyTagException
 
21
 
 
22
class TagTransactionsPanel(wx.Panel):
 
23
    def __init__(self, parent, transactions):
 
24
        wx.Panel.__init__(self, parent)
 
25
        self.Transactions = transactions
 
26
        self.Sizer = wx.BoxSizer(wx.VERTICAL)
 
27
        self.Sizer.AddSpacer(6)
 
28
        
 
29
        introText = wx.StaticText(self, label=_("You can also tag a transaction by putting #tagname anywhere in the description."))
 
30
        textCtrlText = wx.StaticText(self, label=_("Tag:"))
 
31
        self.textCtrl = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
 
32
        removalText = wx.StaticText(self, label=_("To remove this tag later, simply remove it from the description or right-click on the transaction."))
 
33
        
 
34
        textCtrlSizer = wx.BoxSizer()
 
35
        textCtrlSizer.Add(textCtrlText, flag=wx.ALIGN_CENTER_VERTICAL)
 
36
        textCtrlSizer.AddSpacer(9)
 
37
        textCtrlSizer.Add(wx.StaticText(self, label=Tag.TAG_CHAR), flag=wx.ALIGN_CENTER_VERTICAL)
 
38
        textCtrlSizer.Add(self.textCtrl)
 
39
        
 
40
        # Button sizer
 
41
        self.buttonSizer = wx.BoxSizer()
 
42
        tagButton = wx.Button(self, label=_("Add Tag"), id=wx.ID_OK)
 
43
        cancelButton = wx.Button(self, label=_("Cancel"), id=wx.ID_CANCEL)
 
44
        self.buttonSizer.AddStretchSpacer()
 
45
        self.buttonSizer.Add(tagButton)
 
46
        self.buttonSizer.AddSpacer(6)
 
47
        self.buttonSizer.Add(cancelButton)
 
48
        self.buttonSizer.AddSpacer(6)
 
49
        
 
50
         # Main sizer
 
51
        self.Sizer.AddSpacer(12)
 
52
        self.Sizer.Add(introText)
 
53
        self.Sizer.AddSpacer(12)
 
54
        self.Sizer.Add(textCtrlSizer)
 
55
        self.Sizer.AddSpacer(24)
 
56
        self.Sizer.Add(removalText)
 
57
        self.Sizer.AddSpacer(12)
 
58
        self.Sizer.Add(self.buttonSizer, flag=wx.ALIGN_RIGHT|wx.EXPAND)
 
59
        self.Sizer.AddSpacer(6)
 
60
        
 
61
        for text in (introText, removalText):
 
62
            text.Wrap(400)
 
63
        
 
64
        # Focus the textctrl so the user can just start typing.
 
65
        self.textCtrl.SetFocus()
 
66
        
 
67
        self.textCtrl.Bind(wx.EVT_TEXT_ENTER, self.onTagEnter)
 
68
        self.Bind(wx.EVT_BUTTON, self.onButton)
 
69
        
 
70
    def onTagEnter(self, event):
 
71
        self.applyTag()
 
72
        # Dialogs auto-close on certain IDs but a text entry is not one of them.
 
73
        self.Parent.Destroy()
 
74
        
 
75
    def onButton(self, event):
 
76
        """If the tag button was clicked tag the transactions, and close the dialog in any case (Cancel)."""
 
77
        assert event.Id in (wx.ID_OK, wx.ID_CANCEL)
 
78
        
 
79
        if event.Id == wx.ID_OK:
 
80
            self.applyTag()
 
81
               
 
82
        #self.Parent.Destroy()
 
83
        event.Skip()
 
84
        
 
85
    def applyTag(self):
 
86
         # Strip the tag character in case the user was unclear about needing to use it.
 
87
        tag = self.textCtrl.Value.strip(Tag.TAG_CHAR)
 
88
        
 
89
        # If there's no tag, there's no tagging to do.
 
90
        if not tag:
 
91
            return
 
92
        
 
93
        # Apply the tag to each transaction selected.
 
94
        for transaction in self.Transactions:
 
95
            transaction.AddTag(tag)
 
96
        
 
97
            
 
98
class TagTransactionsDialog(wx.Dialog):
 
99
    def __init__(self, parent, transactions):
 
100
        wx.Dialog.__init__(self, parent, title=_("Add a tag"))
 
101
        self.Sizer = wx.BoxSizer()
 
102
        tagPanel = TagTransactionsPanel(self, transactions)
 
103
        self.Sizer.AddSpacer(6)
 
104
        self.Sizer.Add(tagPanel, 1, wx.EXPAND)
 
105
        self.Sizer.AddSpacer(6)
 
106
        self.Fit()
 
107
        
 
 
b'\\ No newline at end of file'