1
# https://launchpad.net/wxbanker
2
# tagtransactiondialog.py: Copyright 2007-2010 Mike Rooney <mrooney@ubuntu.com>
4
# This file is part of wxBanker.
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.
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.
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/>.
20
from wxbanker.bankobjects.tag import Tag, EmptyTagException
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)
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."))
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)
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)
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)
61
for text in (introText, removalText):
64
# Focus the textctrl so the user can just start typing.
65
self.textCtrl.SetFocus()
67
self.textCtrl.Bind(wx.EVT_TEXT_ENTER, self.onTagEnter)
68
self.Bind(wx.EVT_BUTTON, self.onButton)
70
def onTagEnter(self, event):
72
# Dialogs auto-close on certain IDs but a text entry is not one of them.
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)
79
if event.Id == wx.ID_OK:
82
#self.Parent.Destroy()
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)
89
# If there's no tag, there's no tagging to do.
93
# Apply the tag to each transaction selected.
94
for transaction in self.Transactions:
95
transaction.AddTag(tag)
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)
b'\\ No newline at end of file'