Adding import/export capability
[multilist] / src / libbottombar.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 """
5 This file is part of Multilist.
6
7 Multilist is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 Multilist is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Multilist.  If not, see <http://www.gnu.org/licenses/>.
19
20 Copyright (C) 2008 Christoph Würstle
21 """
22
23
24 import logging
25
26 import gtk
27
28 import gtk_toolbox
29
30 try:
31         _
32 except NameError:
33         _ = lambda x: x
34
35
36 _moduleLogger = logging.getLogger(__name__)
37
38
39 class Bottombar(gtk.VBox):
40
41         __gsignals__ = {
42         }
43
44         def __init__(self, db, view, isHildon):
45                 gtk.VBox.__init__(self, homogeneous = False, spacing = 3)
46
47                 self.db = db
48                 self.isHildon = isHildon
49                 self.view = view
50
51                 _moduleLogger.info("libBottomBar, init")
52
53                 buttonHBox = gtk.HBox()
54                 self.pack_start(buttonHBox, expand = False, fill = True, padding = 3)
55
56                 button = gtk.Button(stock = gtk.STOCK_ADD)
57                 button.connect("clicked", self.new_item, None)
58                 buttonHBox.pack_start(button, expand = True, fill = True, padding = 3)
59
60                 button = gtk.Button(stock = gtk.STOCK_DELETE)
61                 button.connect("clicked", self.del_item, None)
62                 buttonHBox.pack_start(button, expand = True, fill = True, padding = 3)
63
64         def set_orientation(self, orientation):
65                 if orientation == gtk.ORIENTATION_HORIZONTAL:
66                         pass
67                 elif orientation == gtk.ORIENTATION_VERTICAL:
68                         pass
69                 else:
70                         raise NotImplementedError(orientation)
71
72         @gtk_toolbox.log_exception(_moduleLogger)
73         def new_item(self, widget = None, data1 = None, data2 = None):
74                 window = gtk_toolbox.find_parent_window(self)
75                 dialog = gtk.Dialog(
76                         _("New item name:"),
77                         window,
78                         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
79                         (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
80                 )
81
82                 entryKlasse = gtk.Entry()
83                 entryKlasse.set_text("")
84                 dialog.vbox.pack_start(entryKlasse, True, True, 0)
85
86                 dialog.vbox.show_all()
87                 if dialog.run() == gtk.RESPONSE_ACCEPT:
88                         self.view.liststorehandler.add_row(entryKlasse.get_text())
89                 dialog.destroy()
90
91         @gtk_toolbox.log_exception(_moduleLogger)
92         def del_item(self, widget = None, data1 = None, data2 = None):
93                 window = gtk_toolbox.find_parent_window(self)
94                 path, col = self.view.treeview.get_cursor()
95                 if path is None:
96                         mbox = gtk.MessageDialog(window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("No item selected!"))
97                         response = mbox.run()
98                         mbox.hide()
99                         mbox.destroy()
100                         return
101
102                 mbox = gtk.MessageDialog(window, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Delete current item?"))
103                 response = mbox.run()
104                 mbox.hide()
105                 mbox.destroy()
106                 if response == gtk.RESPONSE_YES:
107                         self.view.del_active_row()
108
109         def rename_category(self, widget = None, data1 = None, data2 = None):
110                 window = gtk_toolbox.find_parent_window(self)
111                 dialog = gtk.Dialog(
112                         _("New category name:"),
113                         window,
114                         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
115                         (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
116                 )
117
118                 entryKlasse = gtk.Entry()
119                 entryKlasse.set_text(self.view.liststorehandler.selection.get_category())
120                 dialog.vbox.pack_start(entryKlasse, True, True, 0)
121
122                 dialog.vbox.show_all()
123                 if dialog.run() == gtk.RESPONSE_ACCEPT:
124                         _moduleLogger.info("new category name "+entryKlasse.get_text())
125                         self.view.liststorehandler.rename_category(entryKlasse.get_text())
126                 else:
127                         pass
128                 dialog.destroy()
129
130         def rename_list(self, widget = None, data1 = None, data2 = None):
131                 window = gtk_toolbox.find_parent_window(self)
132                 dialog = gtk.Dialog(
133                         _("New list name:"),
134                         window,
135                         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
136                         (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT)
137                 )
138
139                 entryKlasse = gtk.Entry()
140                 entryKlasse.set_text(self.view.liststorehandler.selection.get_list())
141                 dialog.vbox.pack_start(entryKlasse, True, True, 0)
142
143                 dialog.vbox.show_all()
144                 if dialog.run() == gtk.RESPONSE_ACCEPT:
145                         _moduleLogger.info("new list name "+entryKlasse.get_text())
146                         self.view.liststorehandler.rename_list(entryKlasse.get_text())
147                 else:
148                         pass
149                 dialog.destroy()