create gui option to view the log

This commit is contained in:
sqlcoder 2009-12-05 15:54:49 +00:00
parent c9b9927315
commit 6826d0157a
3 changed files with 172 additions and 2 deletions

129
pyfpdb/GuiLogView.py Executable file
View File

@ -0,0 +1,129 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Copyright 2008 Carl Gherardi
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, version 3 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU Affero General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#In the "official" distribution you can find the license in
#agpl-3.0.txt in the docs folder of the package.
import xml.dom.minidom
from xml.dom.minidom import Node
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import pango
import Configuration
log = Configuration.get_logger("logging.conf", "logview")
class GuiLogView:
def __init__(self, config, mainwin, vbox):
self.config = config
self.main_window = mainwin
self.vbox = vbox
gtk.Widget.set_size_request(self.vbox, 700, 400);
self.liststore = gtk.ListStore(str, str, str, str) # date, module, level, text
self.listview = gtk.TreeView(model=self.liststore)
self.listview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
scrolledwindow = gtk.ScrolledWindow()
scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.vbox.pack_start(scrolledwindow, expand=True, fill=True, padding=0)
scrolledwindow.add(self.listview)
self.listview.show()
scrolledwindow.show()
self.vbox.show()
self.loadLog()
self.vbox.show_all()
def loadLog(self):
#self.configStore = gtk.TreeStore(gobject.TYPE_PYOBJECT, gobject.TYPE_STRING, gobject.TYPE_STRING)
#self.configView = gtk.TreeView(self.configStore)
#self.configView.set_enable_tree_lines(True)
self.liststore.clear()
col = gtk.TreeViewColumn("Date/Time")
self.listview.append_column(col)
cRender = gtk.CellRendererText()
cRender.set_property("wrap-mode", pango.WRAP_WORD_CHAR)
col.pack_start(cRender, True)
col.add_attribute(cRender, 'text', 0)
col.set_max_width(1000)
col = gtk.TreeViewColumn("Module")
self.listview.append_column(col)
cRender = gtk.CellRendererText()
cRender.set_property("wrap-mode", pango.WRAP_WORD_CHAR)
col.pack_start(cRender, True)
col.add_attribute(cRender, 'text', 1)
col.set_max_width(1000)
col = gtk.TreeViewColumn("Level")
self.listview.append_column(col)
cRender = gtk.CellRendererText()
cRender.set_property("wrap-mode", pango.WRAP_WORD_CHAR)
col.pack_start(cRender, True)
col.add_attribute(cRender, 'text', 2)
col.set_max_width(1000)
col = gtk.TreeViewColumn("Text")
self.listview.append_column(col)
cRender = gtk.CellRendererText()
cRender.set_property("wrap-mode", pango.WRAP_WORD_CHAR)
col.pack_start(cRender, True)
col.add_attribute(cRender, 'text', 3)
col.set_max_width(1000)
l = 0
for line in open('logging.out', 'r'):
#self.addLogText(line)
iter = self.liststore.append([line.strip(), "", "", ""])
l = l + 1
if l >= 100:
break
if __name__=="__main__":
config = Configuration.Config()
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
win.set_title("Test Log Viewer")
win.set_border_width(1)
win.set_default_size(600, 500)
win.set_resizable(True)
dia = gtk.Dialog("Log Viewer",
win,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_CLOSE, gtk.RESPONSE_OK))
dia.set_default_size(500, 500)
log = GuiLogView(config, win, dia.vbox)
response = dia.run()
if response == gtk.RESPONSE_ACCEPT:
pass
dia.destroy()

View File

@ -60,7 +60,8 @@ if not options.errorsToConsole:
errorFile = open('fpdb-error-log.txt', 'w', 0)
sys.stderr = errorFile
import logging
#import logging
import logging, logging.config
import pygtk
pygtk.require('2.0')
@ -70,6 +71,7 @@ import interlocks
import GuiPrefs
import GuiLogView
import GuiBulkImport
import GuiPlayerStats
import GuiPositionalStats
@ -85,6 +87,8 @@ import Exceptions
VERSION = "0.12"
log = Configuration.get_logger("logging.conf", "fpdb")
class fpdb:
def tab_clicked(self, widget, tab_name):
"""called when a tab button is clicked to activate that tab"""
@ -413,6 +417,29 @@ class fpdb:
self.release_global_lock()
def dia_logs(self, widget, data=None):
lock_set = False
if self.obtain_global_lock():
lock_set = True
dia = gtk.Dialog(title="Log Messages"
,parent=None
,flags=0
,buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_OK))
logviewer = GuiLogView.GuiLogView(self.config, self.window, dia.vbox)
response = dia.run()
if response == gtk.RESPONSE_ACCEPT:
pass
dia.destroy()
if lock_set:
self.release_global_lock()
def addLogText(self, text):
end_iter = self.logbuffer.get_end_iter()
self.logbuffer.insert(end_iter, text)
self.logview.scroll_to_mark(self.logbuffer.get_insert(), 0)
def __calendar_dialog(self, widget, entry):
self.dia_confirm.set_modal(False)
d = gtk.Window(gtk.WINDOW_TOPLEVEL)
@ -515,6 +542,7 @@ class fpdb:
</menu>
<menu action="help">
<menuitem action="Abbrev"/>
<menuitem action="Logs"/>
<separator/>
<menuitem action="About"/>
<menuitem action="License"/>
@ -556,6 +584,7 @@ class fpdb:
('stats', None, '_Statistics (todo)', None, 'View Database Statistics', self.dia_database_stats),
('help', None, '_Help'),
('Abbrev', None, '_Abbrevations (todo)', None, 'List of Abbrevations', self.tab_abbreviations),
('Logs', None, '_Log Messages', None, 'Log and Debug Messages', self.dia_logs),
('About', None, 'A_bout', None, 'About the program', self.dia_about),
('License', None, '_License and Copying (todo)', None, 'License and Copying', self.dia_licensing),
])

View File

@ -11,6 +11,18 @@ keys=fileFormatter,stderrFormatter
level=INFO
handlers=consoleHandler,fileHandler
[logger_fpdb]
level=INFO
handlers=consoleHandler,fileHandler
qualname=fpdb
propagate=0
[logger_logview]
level=INFO
handlers=consoleHandler,fileHandler
qualname=logview
propagate=0
[logger_parser]
level=INFO
handlers=consoleHandler,fileHandler
@ -24,7 +36,7 @@ qualname=importer
propagate=0
[logger_config]
level=DEBUG
level=INFO
handlers=consoleHandler,fileHandler
qualname=config
propagate=0