Moving checkout all to menu
[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 gobject
25 import logging
26
27 import gtk
28
29 import gtk_toolbox
30
31 try:
32         _
33 except NameError:
34         _ = lambda x: x
35
36
37 _moduleLogger = logging.getLogger(__name__)
38
39
40 class Bottombar(gtk.HBox):
41
42         __gsignals__ = {
43                 'changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING)),
44                 #'changedCategory': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gobject.TYPE_STRING))
45         }
46
47         def __init__(self, db, view, isHildon):
48                 gtk.HBox.__init__(self, homogeneous = False, spacing = 3)
49
50                 self.db = db
51                 self.isHildon = isHildon
52                 self.view = view
53
54                 _moduleLogger.info("libBottomBar, init")
55
56                 button = gtk.Button(_("New item"))
57                 button.connect("clicked", self.new_item)
58                 self.pack_start(button, expand = False, fill = True, padding = 0)
59
60                 label = gtk.Label("  ")
61                 self.pack_start(label, expand = True, fill = True, padding = 0)
62
63                 button = gtk.Button(_("Del item"))
64                 button.connect("clicked", self.del_item)
65                 self.pack_start(button, expand = False, fill = True, padding = 0)
66
67         @gtk_toolbox.log_exception(_moduleLogger)
68         def new_item(self, widget = None, data1 = None, data2 = None):
69                 dialog = gtk.Dialog(_("New item name:"), None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
70                 dialog.set_position(gtk.WIN_POS_CENTER)
71                 entryKlasse = gtk.Entry()
72                 entryKlasse.set_text("")
73
74                 dialog.vbox.pack_start(entryKlasse, True, True, 0)
75
76                 dialog.vbox.show_all()
77                 #dialog.set_size_request(400, 300)
78
79                 if dialog.run() == gtk.RESPONSE_ACCEPT:
80                         #_moduleLogger.info("new category name "+entryKlasse.get_text())
81                         #self.view.liststorehandler.rename_category(entryKlasse.get_text())
82                         self.view.liststorehandler.add_row(entryKlasse.get_text())
83                 dialog.destroy()
84
85         @gtk_toolbox.log_exception(_moduleLogger)
86         def del_item(self, widget = None, data1 = None, data2 = None):
87                 path, col = self.view.treeview.get_cursor()
88                 if path is not None:
89                         mbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _("Delete current item?"))
90                         response = mbox.run()
91                         mbox.hide()
92                         mbox.destroy()
93                         if response == gtk.RESPONSE_YES:
94                                 self.view.del_active_row()
95                 else:
96                         mbox = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, _("No item selected!"))
97                         response = mbox.run()
98                         mbox.hide()
99                         mbox.destroy()
100
101         def rename_category(self, widget = None, data1 = None, data2 = None):
102                 dialog = gtk.Dialog(_("New category name:"), None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
103
104                 dialog.set_position(gtk.WIN_POS_CENTER)
105                 entryKlasse = gtk.Entry()
106                 entryKlasse.set_text(self.view.liststorehandler.selection.get_category())
107
108                 dialog.vbox.pack_start(entryKlasse, True, True, 0)
109
110                 dialog.vbox.show_all()
111                 #dialog.set_size_request(400, 300)
112
113                 if dialog.run() == gtk.RESPONSE_ACCEPT:
114                         _moduleLogger.info("new category name "+entryKlasse.get_text())
115                         self.view.liststorehandler.rename_category(entryKlasse.get_text())
116                 else:
117                         #print "Cancel", res
118                         pass
119                 dialog.destroy()
120
121         def rename_list(self, widget = None, data1 = None, data2 = None):
122                 dialog = gtk.Dialog(_("New list name:"), None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
123
124                 dialog.set_position(gtk.WIN_POS_CENTER)
125                 entryKlasse = gtk.Entry()
126                 entryKlasse.set_text(self.view.liststorehandler.selection.get_list())
127
128                 dialog.vbox.pack_start(entryKlasse, True, True, 0)
129
130                 dialog.vbox.show_all()
131                 #dialog.set_size_request(400, 300)
132
133                 if dialog.run() == gtk.RESPONSE_ACCEPT:
134                         _moduleLogger.info("new list name "+entryKlasse.get_text())
135                         self.view.liststorehandler.rename_list(entryKlasse.get_text())
136                 else:
137                         #print "Cancel", res
138                         pass
139                 dialog.destroy()