# -*- mode: python; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
#
#    Copyright (c) 2001 Internet Discovery Incorporated.
#
#	$Id$

import Tix, Tixinspect, os, sys, traceback, string
import tkMessageBox

class Tk(Tixinspect.Tk):
    """Toplevel widget of Tix which represents mostly the main window
    of an application. It has an associated Tcl interpreter.

    A Tide instance of Tk is inspectable by the tk send mechanism.
    It has also been set up to autoload any Tix tcl procredures,
    and to autoload any Tide tcl procredures or Python classes.
    """

    def __init__(self, screenName=None, baseName=None, className='Tide'):
        r"""Intinialize Tixinspect and add to sys.path and auto_path. """

        Tixinspect.Tk.__init__(self, screenName, baseName, className)
        self.tk.eval('lappend auto_path $env(TIXAPPS_SRC)')
        self.tk.eval('lappend auto_path [file join $env(TIXAPPS_SRC) idledev]')
        self.tk.eval('lappend auto_path [file join $env(TIXAPPS_SRC) ObjTcl]')
        self.tk.eval('lappend auto_path [file join $env(TIXAPPS_SRC) Utils]')

        sys.path.append(os.path.join(os.environ['TIXAPPS_SRC'], 'Widgets'))
        self.tk.eval('lappend auto_path [file join $env(TIXAPPS_SRC) Widgets]')

    def start(self):
        self.tk.eval('''
        if {[catch {package require Tixapps} err]} {
        global errorInfo auto_path
        error "$errorInfo\nauto_path is: $auto_path"
        }''')
        self.tk.eval('tixapps::init')

    def register(self, name, quiet=0):
	# quiet == -1 : wont be using send
	# quiet == 1  : don't ask questions just disable send
	# quiet == 0  : Ask questions before you enable send
        self.tk.eval('tixapps::register %s %d' % (name, quiet))
