tk_logger.py 1.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
"""
    Creates a log on bottom of window using a Tkinter.Text.
    
    Name: tk_logger.py
    Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""

import sys
if sys.version_info[0] < 3:
    import Tkinter as Tk
else:
    import tkinter as Tk

class Log(object):
    
    
    def __init__(self, parent):
        self.parent = parent
        self._body = Tk.Text(self.parent, width=0, height=10, bg="white", fg="black", padx=5, pady=5)
        self._body.insert(Tk.INSERT, "$ Pynovisao is ready to use!\n")
        self._body.config(state=Tk.DISABLED)
        self._body.pack(side=Tk.BOTTOM, fill=Tk.X, expand=False)
        
        
    def write_logger(self, fmt, *args):
        self.clear_logger()
        self.append_logger(fmt % args)
        
    def append_logger(self, fmt, *args):
        self._body.config(state=Tk.NORMAL)
        self._body.insert(Tk.END, fmt % args)
        self._body.insert(Tk.END, '\n')
        self._body.config(state=Tk.DISABLED)
        
    def clear_logger(self):
        self._body.config(state=Tk.NORMAL)
        self._body.delete('1.0', Tk.END)
        self._body.insert('1.0', '$ ')
        self._body.config(state=Tk.DISABLED)
        
    def destroy_logger(self):
        self._body.pack_forget();
        self._body.destroy();