root/branches/0.3/src/log_window.py

Revision 527, 2.5 kB (checked in by nicfit, 2 years ago)

#232, #263

Line 
1 ################################################################################
2 #  Copyright (C) 2006  Travis Shirk <travis@pobox.com>
3 #
4 #  This program is free software; you can redistribute it and/or modify
5 #  it under the terms of the GNU General Public License as published by
6 #  the Free Software Foundation; either version 2 of the License, or
7 #  (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 #
18 #  $Id$
19 ################################################################################
20 import os
21 import gtk
22 import logging
23 import mesk, mesk.window
24 _ = mesk.i18n._
25
26 class LogWindow(mesk.window.Window):
27     def __init__(self):
28         mesk.window.Window.__init__(self, 'log_window', 'main_window.glade')
29
30         self._levels = mesk.log.LEVEL2STRINGS.keys()
31         self._levels.sort()
32
33         level_combobox = self.xml.get_widget('level_combobox')
34         curr = mesk.log.get_logging_level()
35         level_combobox.set_active(self._levels.index(curr))
36         self.log_textview = self.xml.get_widget('log_textview')
37
38     def _on_level_combobox_changed(self, combo):
39         active = combo.get_active_text()
40         mesk.log.set_logging_level(mesk.log.string_to_level(active))
41
42     def _on_close_button_clicked(self, button):
43         self.hide()
44
45     def _on_save_button_clicked(self, button):
46         buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
47                  gtk.STOCK_SAVE, gtk.RESPONSE_OK)
48         d = gtk.FileChooserDialog(title=_('Save Log File'), parent=self.window,
49                                   action=gtk.FILE_CHOOSER_ACTION_SAVE,
50                                   buttons=buttons)
51         d.set_current_folder(os.path.expandvars("$HOME"))
52         resp = d.run()
53         if resp == gtk.RESPONSE_OK:
54             filename = d.get_filename()
55             fp = file(filename, 'w')
56             buf = self.log_textview.get_buffer()
57             log_txt = buf.get_text(buf.get_start_iter(), buf.get_end_iter())
58             fp.write(log_txt)
59             fp.close()
60         d.destroy()
61
62     def _on_clear_button_clicked(self, button):
63         self.log_textview.get_buffer().set_text('')
Note: See TracBrowser for help on using the browser.