#! /usr/bin/python

#############################################################################################
#  GReal Bookmarks Manager v.0.2b
#  Copyright March 2002
#  ['PhrozenSmoke (PhrozenSmoke@yahoo.com)'], '
#  
#  A BASIC, (and experimental!) bookmark manager for RealPlayer.  Written with Python/PyGTK. This program
#  was created to satisfy my own personal needs, since RealPlayer 8 for Linux does not seem to have the nice 
#  bookmark system available in Windows versions of RealPlayer.  I guess the designers of RealPlayer assumed 
#  that Linux users would memorize all their favorite \'net station links. This program is very new, and should 
#  be considered VERY experimental (expect bugs!).  The program requires a recent version of Python, particularly 
#  with XML (xml.dom.minidom) support. Some features are definitely missing, including Drag and Drop support 
#  and prettier buttons.  Nevertheless, its already very usable and very functional.  The bookmark data is saved 
#  and read in XML format (the default location is  /greal-bookmarks.xml  - the root directory of your file system.)  
#  
#  Written: March 2002 
#  By: PhrozenSmoke@yahoo.com  
#  
#  This software comes with NO WARRANTY whatsoever.  
#  
#  License: Open Source, free for non-commercial use.  Please leave these credits intact.    
#  
#  
#  This program and its source may be freely modified and redistributed for non-commercial,  non-profit use only.   
#  
#  This program requires Python, PyGTK, and PyGnome. Tested only on: Mandrake 8.1, Kernel 2.4.8, Glibc 2.2, 
#  Python 2.2, PyGTK 0.6.9, PyGnome 1.4.2, Gtk 1.2.8.-4
#############################################################################################

import sys, os, types, string
from _gtk import *
from GDK import *
from GTK import *
from gtk import *
import GtkExtra
import GTK,GDK
import xml.dom.minidom
import threading
from gnome.ui import *

global win
win=None
global thetree
thetree=None
global notebook
notebook=None
global treedata
treedata={}
global current_file
current_file="/greal_bookmarks.xml"
global real_command
real_command="/usr/X11R6/bin/realplay"
global entry1
entry1=None
global OKbutton
OKbutton=None
global inputcmd
inputcmd=None
global doSave
doSave=1
global filesel
filesel=None
global nametext
global urltext
nametext=None
urltext=None
global treematch
treematch={}
global diawin
global diamesg
global dia
dia=None


if __name__ == "__main__" :
    __file__ = sys.argv[0]
HostingDir = os.path.dirname (__file__)

class Context :
    def __init__ (self, tooltips=None, accelgroup=None, imagedirs=None,
    window=None, context=None) :
        if isinstance (context, Context) :
            self._tooltips = context._tooltips
            self._accelgroup = context._accelgroup
            self._imagedirs = context._imagedirs
            self._top = context._top
        else :
            if tooltips is None :
                self._tooltips = gtk_tooltips_new ()
            if accelgroup is None :
                self._accelgroup = gtk_accel_group_new ()
            if imagedirs is None :
                base = HostingDir
                self._imagedirs = [base, os.path.join (base, "pixmaps")]
            if window is None :
                self._top = None
        if tooltips is not None :
            self._tooltips = tooltips
        if accelgroup is not None :
            self._accelgroup = accelgroup
        if type (imagedirs) is types.StringType :
            self._imagedirs = string.split (imagedirs, os.pathsep)
        elif imagedirs is not None :
            self._imagedirs = list (imagedirs)
        if window is not None :
            self._top = window
        self._root = None
    def setTip (self, w, msg) :
        gtk_tooltips_set_tip (self._tooltips, w, msg, None)
    def addAccel (self, w, sigName, keyVal, modVal, flagVal) :
        gtk_widget_add_accelerator (w, sigName, self._accelgroup,
            keyVal, modVal, flagVal)
    def setContainerLabelWithAccel (self, item, text,
    accel=None, mask=0, sig="activate_item") :
        label = gtk_container_children (item)[0]
        key = gtk_label_parse_uline (label, text)
        if accel is None :
            accel = self._accelgroup
            mask = GDK.MOD1_MASK
        gtk_widget_add_accelerator (item, sig, accel, key, mask, 0)
    def findPixmapPath (self, pixName) :
        for i in self._imagedirs :
            pixPath = os.path.join (i, pixName)
            if os.path.exists (pixPath) :
                return pixPath
        raise IOError (None, "pixmap '%s' not found" % pixName)
    def show (self) :
	if self._root is not None :
	    gtk_widget_show_all (self._root)
    def destroy (self) :
	if self._root is not None :
            gtk_widget_destroy (self._root)
    def giveNames (self, nameList) :
        for i in nameList :
            w = getattr (self, i)
            gtk_widget_set_name (w, i)
    controllerClass = None
    def setupController (self) :
        if self.controllerClass is not None :
            ctrl = self.controllerClass ()
            self._controller = ctrl
            self.connect (ctrl)


##BEGIN I18N SUPPORT
from locale import setlocale, LC_MESSAGES, LC_ALL
setlocale (LC_ALL, "")

def grabFile(*args):   
        global current_file
        global filesel
        global doSave
 	current_file=filesel.get_filename()
	filesel.hide()
	if doSave:
          saveXML(current_file)
        else:
          loadXML(current_file)

def doFileSelHide(*args):
       global filesel
       filesel.hide()

def createFileSel(*args):
        global filesel
        filesel = GtkFileSelection()
        filesel.set_title('Open a GReal Bookmarks file...')
        filesel.connect('destroy', doFileSelHide)
        filesel.connect('delete_event', doFileSelHide)
        filesellabel = filesel.ok_button.children()[0]
        filesellabel.set_text('OK')
        filesel.ok_button.connect('clicked', grabFile)
        filesellabel = filesel.cancel_button.children()[0]
        filesellabel.set_text('Cancel')
        filesel.cancel_button.connect('clicked', doFileSelHide)

def do_file_open(*args):
       global filesel
       global doSave
       if args[1]:
           doSave=1
       else:
           doSave=0
       if doSave:
           filesel.set_title("Save the GReal Bookmarks file as...")
       else:
           filesel.set_title('Open a GReal Bookmarks file...')
       filesel.show()


def loadXML(filename):
   global treedata
   global real_command
   global treematch
   try:
     dom=xml.dom.minidom
     doc=dom.parse(filename)
     treedata.clear()
     treematch.clear()
     try:
       real_command=str(doc.getElementsByTagName("greal-command")[0].attributes.get("cmd").value).strip()
     except:
       real_command="/usr/X11R6/bin/realplay"

     cats=doc.getElementsByTagName("greal-category")
     for i in cats:
       cname=str(i.attributes.get("catname").value).strip()
       cdata={}
       bookmarks=i.getElementsByTagName("greal-bookmark")
       for y in bookmarks:
           site=str(y.attributes.get("bname").value).strip()
           url=str(y.attributes.get("bURL").value).strip()
           cdata[site]=url
       treedata[cname]=cdata

     #adding tabs for each category
     names = treedata.keys()
     names.sort()
     counter=0
     while getCurrentTabNumber() > -1:
       try:
         removeCurrentTab()
         counter=counter+1
         #if counter > 28: break
       except:
         break
     for n in names:
       addTab(n,treedata[n],1)     
   except:
     showMessage("An error occurred opening or parsing the file '"+getCurrentFile()+"'.\nPlease ensure that the file exists, is accessible, and is in GReal-compatible XML format.")

def saveXML(filename):
   global current_file
   global treedata
   try:
     f=open(current_file,"w")
     f.write("<?xml version=\"1.0\" ?>\n\t<GREAL-BOOKMARKS>\n\t\t<greal-command cmd=\""+getCommand()+"\" />\n")
     f.flush()
     names=treedata.keys()
     names.sort()
     for catname in names:
       f.write("\t\t\t<greal-category catname=\""+catname+"\">\n")
       d=treedata[catname]
       sites=d.keys()
       sites.sort()
       for i in sites:
          f.write("\t\t\t\t<greal-bookmark bname=\""+i+"\" bURL=\""+d[i]+"\" />\n")
       f.write("\t\t\t</greal-category>\n")
     f.write("\t</GREAL-BOOKMARKS>")
     f.flush()
     f.close()
   except:
     showMessage("Error saving XML bookmark data")



def getCurrentTabNumber():
   global notebook
   return gtk_notebook_get_current_page(notebook)

def getCurrentTabName():
   global notebook
   return str(gtk_label_get(gtk_notebook_get_tab_label(notebook,gtk_notebook_get_nth_page(notebook,gtk_notebook_get_current_page(notebook)))) )

def tabNameExists(tbname):
    global treedata
    if treedata.has_key(str(tbname)):
       return 1
    return 0

def getCommand():
   global real_command
   return real_command

def setCommand(realcmd):
   global real_command
   real_command=realcmd

def getCurrentFile():
   global current_file
   return current_file

def setCurrentFile(filename):
   global current_file
   current_file=str(filename)

def removeCurrentTab(*args):
   global treedata
   global notebook
   global treematch
   hidediac()
   try:
        del treedata[str(getCurrentTabName())]
        del treematch[getCurrentTabName()]
   except:
        pass
   gtk_notebook_remove_page(notebook,getCurrentTabNumber())
   saveXML(getCurrentFile())

def getSelectedName():
    global thetree
    if len(gtk_clist_get_selection(thetree)):
      return str(gtk_clist_get_text(thetree,gtk_clist_get_selection(thetree)[0],0))
    return None

def getSelectedURL():
    global thetree
    if len(gtk_clist_get_selection(thetree)):
      return str(gtk_clist_get_text(thetree,gtk_clist_get_selection(thetree)[0],1))
    return None

def getSelectedIndex():
    global thetree
    if len(gtk_clist_get_selection(thetree)):
      return gtk_clist_get_selection(thetree)[0]
    else:
      return -1

def deleteCurrentBookmark(*args):
    global thetree
    global current_file
    global thetree
    global treedata
    if not getSelectedIndex() == -1:
      ok=1  # create some kinda confirmation here
      if ok:
        ddict=treedata[getCurrentTabName()]
        del ddict[getSelectedName()]
        treedata[getCurrentTabName()]=ddict
        gtk_clist_remove(thetree,getSelectedIndex())
        saveXML(current_file)

def playSelectedURL(*args):
    if not getSelectedURL():
      return
    ll=[getSelectedURL()," &"]
    try:
      #os.spawnvp(os.P_NOWAIT,getCommand()+" http://www.test.com/",ll)
      threading._start_new_thread(os.popen,(getCommand()+" "+getSelectedURL(),))
    except:
      showMessage("Unknown error launching the RealPlayer application!")

def doEdit(*args):
   global nametext
   global urltext
   if not getSelectedIndex() == -1:
     gtk_entry_set_text(nametext,getSelectedName())
     gtk_entry_set_text(urltext,getSelectedURL())
     deleteCurrentBookmark()

def addBookmark(*args):
   global nametext
   global urltext
   global treedata
   global thetree
   global treematch
   thetree=treematch[getCurrentTabName()]
   sname=gtk_entry_get_text(nametext).strip()
   surl=gtk_entry_get_text(urltext).strip()
   if sname and surl:
     d=treedata[getCurrentTabName()]
     if not d.has_key(sname):
       d[sname]=surl
       treedata[getCurrentTabName()]=d
       saveXML(getCurrentFile())
       gtk_clist_append(thetree,(sname,surl))
       gtk_clist_sort(thetree)
       gtk_entry_set_text(nametext,"")
       gtk_entry_set_text(urltext,"")
     else:
       showMessage("A bookmark by this name already exists in this category!\nPlease select another name, or edit/delete the existing copy.")


def setTree(tr, *args):
    global thetree
    thetree=tr
   

def addTab(tabname,data_dict={},refresh=0,*args):
           global notebook
           global thetree
           global treedata
           global treematch

           if not data_dict:
              data_dict={}
           treedata[tabname]=data_dict.copy()
	   buffer = tabname
	   frame = gtk_frame_new(buffer)
	   gtk_frame_set_shadow_type(frame,SHADOW_ETCHED_OUT)

	   scrolledwindow1 = gtk_scrolled_window_new ()
	   viewport1 = gtk_viewport_new ()
	   gtk_viewport_set_shadow_type (viewport1, GTK.SHADOW_ETCHED_OUT)
        
	   thetree=gtk_clist_new_with_titles(2,["Site Name","URL"]) 
           treematch[tabname]=thetree
           nlist=data_dict.keys()
           nlist.sort()
           for x in nlist:
	      gtk_clist_append(thetree,[str(x),str(data_dict[x])])


	   gtk_container_add (viewport1, thetree)
	   gtk_container_add (scrolledwindow1, viewport1)

	   gtk_container_add (frame, scrolledwindow1) 
	   gtk_clist_set_column_width(thetree,0,200)   

	   label = gtk_label_new(tabname)
	   gtk_notebook_append_page(notebook,frame, label)
           gtk_signal_connect(thetree,"select_row",setTree,(thetree,))
           gtk_signal_connect(thetree,"unselect_row",setTree,(thetree,))
           gtk_signal_connect(thetree,"click_column",setTree,(thetree,))
           saveXML(current_file)
           if refresh:
              gtk_widget_show_all(notebook)
              try:
                gtk_notebook_set_page(len(treedata)-1)
              except:
                pass

class window1 (Context) :
    def __init__ (self, context=None) :
        global win
        global thetree
        global notebook
        global nametext
        global urltext
	Context.__init__ (self, context=context)
	window1 = gtk_window_new (GTK.WINDOW_TOPLEVEL)
	self._root = window1
	if context is None :
	    self._top = window1
	    gtk_widget_realize (window1)
	gtk_window_set_title (window1, "GReal Bookmarks")
	gtk_window_set_position (window1, GTK.WIN_POS_CENTER)
	gtk_container_set_border_width (window1, 2)
	gtk_window_add_accel_group (window1, self._accelgroup)
	self.window1 = window1
	frame1 = gtk_frame_new (None)
	self.frame1 = frame1
	vbox1 = gtk_vbox_new (0, 0)
	self.vbox1 = vbox1
        thetoolbar=gtk_hbox_new(0,0)

	opbutton = gtk_button_new_with_label ("Open...")
	self.setTip (opbutton, "Load a GReal Bookmarks-compatible file.")
	self.opbutton = opbutton
	gtk_box_pack_start (thetoolbar, opbutton, 1, 1, 10)

	savebutton = gtk_button_new_with_label ("Save")
	self.setTip (savebutton, "Save the currently loaded GReal Bookmarks file.")
	self.savebutton = savebutton
	gtk_box_pack_start (thetoolbar, savebutton, 1, 1, 10)

	saveasbutton = gtk_button_new_with_label ("Save As...")
	self.setTip (saveasbutton, "Save the currently loaded GReal Bookmarks file to another file.")
	self.saveasbutton = saveasbutton
	gtk_box_pack_start (thetoolbar, saveasbutton, 1, 1, 10)

	vseparator1 = gtk_vseparator_new ()
	self.vseparator1 = vseparator1
	gtk_box_pack_start (thetoolbar, vseparator1, 1, 1, 5)

	aboutbutton = gtk_button_new_with_label ("About")
	self.setTip (aboutbutton, "About GReal Bookmarks Manager.")
	self.aboutbutton = aboutbutton
	gtk_box_pack_start (thetoolbar, aboutbutton, 1, 1, 10)

	exitbutton = gtk_button_new_with_label ("Exit")
	self.setTip (exitbutton, "Exit GReal Bookmarks Manager.")
	self.exitbutton = exitbutton
	gtk_box_pack_start (thetoolbar, exitbutton, 1, 1, 10)

        #p=gdk_pixmap_create_from_xpm(window1,None,"/usr/share/icons/aol.xpm")
	self.thetoolbar = thetoolbar
	gtk_box_pack_start (vbox1, thetoolbar, 1, 1, 10)

       	hseparator0 = gtk_hseparator_new ()
	self.hseparator0 = hseparator0
	gtk_box_pack_start (vbox1, hseparator0, 1, 1, 3)

	treebox = gtk_hbox_new (0, 0)
	gtk_widget_set_usize (treebox, 119, 245)
	self.treebox = treebox

	notebook = gtk_notebook_new()
	gtk_notebook_set_tab_pos(notebook,POS_TOP)
	gtk_box_pack_start(treebox,notebook)
	gtk_notebook_set_scrollable(notebook,TRUE)

        global current_file
        loadXML(current_file)

	gtk_box_pack_start (treebox, notebook, 1, 1, 3)

	sidebar = gtk_vbox_new (1, 0)
	gtk_widget_set_usize (sidebar, 88, -2)
	self.sidebar = sidebar
	playbutt = gtk_button_new_with_label ("Play")
	self.setTip (playbutt, "Play the selected URL with RealPlayer.")
	self.playbutt = playbutt
	gtk_box_pack_start (sidebar, playbutt, 0, 0, 2)
	editbutt = gtk_button_new_with_label ("Edit")
	self.setTip (editbutt, "Edit the selected bookmark.")
	self.editbutt = editbutt
	gtk_box_pack_start (sidebar, editbutt, 0, 0, 2)
	delbutton = gtk_button_new_with_label ("Delete")
	self.setTip (delbutton, "Delete the selected bookmark.")
	self.delbutton = delbutton
	gtk_box_pack_start (sidebar, delbutton, 0, 0, 2)

	newcat = gtk_button_new_with_label ("Add Category")
	self.setTip (newcat, "Add a new category (tab).")
	self.newcat = newcat
	gtk_box_pack_start (sidebar, newcat, 0, 0, 2)

	delcat = gtk_button_new_with_label ("Del Category")
	self.setTip (delcat, "Delete the selected category and tab.")
	self.delcat = delcat
	gtk_box_pack_start (sidebar, delcat, 0, 0, 2)

	editcmd = gtk_button_new_with_label ("Edit Command")
	self.setTip (editcmd, "Edit the command run to launch RealPlayer.")
	self.editcmd = editcmd
	gtk_box_pack_start (sidebar, editcmd, 0, 0, 2)

	gtk_box_pack_start (treebox, sidebar, 0, 0, 6)
	gtk_box_pack_start (vbox1, treebox, 0, 0, 10)

       	hseparator1 = gtk_hseparator_new ()
	self.hseparator1 = hseparator1
	gtk_box_pack_start (vbox1, hseparator1, 1, 1, 3)

	addbox = gtk_hbox_new (0, 0)
	self.addbox = addbox
	addtextbox = gtk_vbox_new (0, 0)
	self.addtextbox = addtextbox
	hbox3 = gtk_hbox_new (0, 0)
	self.hbox3 = hbox3
	bname = gtk_label_new ("Name:")
	gtk_widget_set_usize (bname, 68, -2)
	self.bname = bname
	gtk_box_pack_start (hbox3, bname, 0, 0, 0)
	nametext = gtk_entry_new ()
	self.nametext = nametext
	gtk_box_pack_start (hbox3, nametext, 1, 1, 0)
	gtk_box_pack_start (addtextbox, hbox3, 1, 1, 0)
	hbox4 = gtk_hbox_new (0, 0)
	self.hbox4 = hbox4
	burl = gtk_label_new ("URL:")
	gtk_widget_set_usize (burl, 68, -2)
	self.burl = burl
	gtk_box_pack_start (hbox4, burl, 0, 0, 0)
	urltext = gtk_entry_new ()
	self.urltext = urltext
	gtk_box_pack_start (hbox4, urltext, 1, 1, 0)
	gtk_box_pack_start (addtextbox, hbox4, 1, 1, 0)
	gtk_box_pack_start (addbox, addtextbox, 1, 1, 0)
	addbutt = gtk_button_new_with_label ("ADD / Edit")
	gtk_widget_set_usize (addbutt, 84, -2)
	self.setTip (addbutt, "Add or Edit this bookmark")
	self.addbutt = addbutt
	gtk_box_pack_start (addbox, addbutt, 0, 0, 6)
	gtk_box_pack_start (vbox1, addbox, 1, 1, 5)

       	hseparator2 = gtk_hseparator_new ()
	self.hseparator2 = hseparator2
	gtk_box_pack_start (vbox1, hseparator2, 1, 1, 3)

	progtitle = gtk_label_new ("GReal Bookmarks Manager.  Copyright 2002, PhrozenSmoke@yahoo.com")
	gtk_widget_set_usize (progtitle, -2, 36)
	self.progtitle = progtitle
	gtk_box_pack_start (vbox1, progtitle, 0, 0, 0)
	gtk_container_add (frame1, vbox1)
	gtk_container_add (window1, frame1)
	self.setupController ()
	gtk_window_set_default_size (window1, 590,340)
	gtk_widget_show_all (window1)

    def connect (self, listener, extra=None) :
	if extra is None: extra = self



######### INPUT DIALOG ###################

wins = {}

def addcat(*args):
  global entry1
  global current_file
  hideit()
  if entry1.get_text():
    cat=str(entry1.get_text()).strip()
    if cat:
      if tabNameExists(cat):
         showMessage("Category  '"+cat+"' already exists. Select another name.")
      else:
         cat.replace("\"","")
         addTab(cat,{},1)
         saveXML(current_file)
         entry1.set_text("")
         #showMessage("Category  '"+cat+"' has been added.")


def editCmd(*args):
    hideit()
    if entry1.get_text():
      cat=str(entry1.get_text()).strip()
      if cat:
        setCommand(cat)
        entry1.set_text("")
        saveXML(current_file)
     

def hideit(*args):
  global win
  win.hide()
  return TRUE

def hidedia(*args):
  global diawin
  diawin.hide()
  return TRUE

def hidediac(*args):
  global dia
  dia.hide()
  return TRUE

def askRemoveCurrentTab(*args):
    global dia
    dia.show()
    return TRUE

def useAnswer(*args):
   global inputcmd
   inputcmd()

def showit(*args):
    global win
    global OKbutton
    global inputcmd
    inputcmd=args[1]
    win.show()
    return TRUE

def showedit(*args):
   global entry1
   entry1.set_text(getCommand())
   showit("",args[1])

def restoreit(*args):    
    myinput()
    mydialog()
    myconfirm()

def showMessage(mess=""):
    global diamesg
    global diawin
    diamesg.set_text(str(mess))
    diawin.show()
    return TRUE
   

def myinput():
	        global win
                global entry1
                global OKbutton
		win = GtkDialog()
		wins["progress_bar"] = win
		win.set_title("GReal")
                win.connect('destroy', restoreit)
		vbox = GtkVBox(spacing=5)
		vbox.set_border_width(10)
		win.vbox.pack_start(vbox)
		vbox.show()

		label1 = GtkLabel("Enter your selection:")
		label1.set_alignment(0, 0.5)
		vbox.pack_start(label1, expand=FALSE)
		label1.show()

		entry1 = GtkEntry()
		entry1.set_usize(200, 20)
		vbox.pack_start(entry1)
		entry1.show()

		button = GtkButton("OK")
		button.connect("clicked", useAnswer)
		win.action_area.pack_start(button)
		button.set_flags(CAN_DEFAULT)
		button.grab_default()
		button.show()
                OKbutton=button

		button2 = GtkButton("Cancel")
		button2.connect("clicked", hideit)
		win.action_area.pack_start(button2)
		button2.set_flags(CAN_DEFAULT)
		button2.grab_default()
		button2.show()
	        #win.show()



def mydialog():
	        global diawin
                global diamesg
		diawin = GtkDialog()
		wins["dia"] = diawin
		diawin.set_title("GReal")
                diawin.connect('destroy', restoreit)
		vbox = GtkVBox(spacing=5)
		vbox.set_border_width(10)
		diawin.vbox.pack_start(vbox)
		vbox.show()

		diamesg = GtkLabel("GReal")
		diamesg.set_alignment(0, 0.5)
		diamesg.set_usize(450, 60)
		vbox.pack_start(diamesg, expand=TRUE)
		diamesg.show()

		button = GtkButton("OK")
		button.connect("clicked", hidedia)
		diawin.action_area.pack_start(button)
		button.set_flags(CAN_DEFAULT)
		button.grab_default()
		button.show()


def myconfirm():
                global dia
		dia = GtkDialog()
		wins["diac"] = dia
		dia.set_title("GReal")
                dia.connect('destroy', restoreit)
		vbox = GtkVBox(spacing=5)
		vbox.set_border_width(10)
		dia.vbox.pack_start(vbox)
		vbox.show()

		mesg = GtkLabel("Are you sure you want to DELETE this category?\nCAUTION: All bookmarks on this tab will be DELETED!")
		mesg.set_alignment(0, 0.5)
		mesg.set_usize(370, 65)
		vbox.pack_start(mesg, expand=TRUE)
		mesg.show()

		button = GtkButton("DELETE")
		button.connect("clicked", removeCurrentTab)
		dia.action_area.pack_start(button)
		button.set_flags(CAN_DEFAULT)
		button.grab_default()
		button.show()

		button2 = GtkButton("Cancel")
		button2.connect("clicked", hidediac)
		dia.action_area.pack_start(button2)
		button2.set_flags(CAN_DEFAULT)
		button2.grab_default()
		button2.show()
	        #win.show()


########### ABOUT #################
def do_about(self,argy=None):
        about = GnomeAbout('GReal Bookmarks Manager', '0.2b', 'Copyright March 2002', ['PhrozenSmoke (PhrozenSmoke@yahoo.com)'], 'GReal Bookmarks Manager","GReal Bookmarks Manager v.0.2b\nA BASIC, (and experimental!) bookmark manager for RealPlayer.\n\nWritten with Python/PyGTK.\nThis program was created to satisfy my own personal needs, since RealPlayer 8 for Linux does not seem to have the nice bookmark system available in Windows versions of RealPlayer.  I guess the designers of RealPlayer assumed that Linux users would memorize all their favorite \'net station links. This program is very new, and should be considered VERY experimental (expect bugs!).  The program requires a recent version of Python, particularly with XML (xml.dom.minidom) support. Some features are definitely missing, including Drag and Drop support and prettier buttons.  Nevertheless, its already very usable and very functional.  The bookmark data is saved and read in XML format (the default location is  /greal-bookmarks.xml  - the root directory of your file system.)\n\nWritten: March 2002\nBy: PhrozenSmoke@yahoo.com\n\nThis software comes with NO WARRANTY whatsoever.\n\nLicense: Open Source, free for non-commercial use.  Please leave these credits intact. \n\nThis program and its source may be freely modified and redistributed for non-commercial,  non-profit use only. \n\nThis program requires Python, PyGTK, and PyGnome. Tested only on: Mandrake 8.1, Kernel 2.4.8, Glibc 2.2, Python 2.2, PyGTK 0.6.9, PyGnome 1.4.2, Gtk 1.2.8.-4')

        about.set_default_size(300,200)
        about.connect('destroy', about.destroy)
        about.show()
########## START/STOP METHODS ##################

def quit (*args) :
    saveXML(getCurrentFile())
    gtk_main_quit ()


def run () :
    gtk_init ()
    gtk_set_locale ()
    w=window1 ()
    myinput()
    mydialog()
    myconfirm()
    createFileSel()
    gtk_signal_connect (w.window1, "destroy", quit)
    gtk_signal_connect (w.exitbutton, "clicked", quit)
    gtk_signal_connect (w.newcat, "clicked", showit,(addcat,))
    gtk_signal_connect (w.editcmd, "clicked", showedit,(editCmd,))
    gtk_signal_connect (w.editbutt, "clicked", doEdit)
    gtk_signal_connect (w.delcat, "clicked", askRemoveCurrentTab)
    gtk_signal_connect (w.playbutt, "clicked", playSelectedURL)
    gtk_signal_connect (w.delbutton, "clicked", doEdit)
    gtk_signal_connect (w.savebutton, "clicked", saveXML)
    gtk_signal_connect (w.opbutton, "clicked",do_file_open,(0,) )
    gtk_signal_connect (w.saveasbutton, "clicked",do_file_open,(1,) )
    gtk_signal_connect (w.addbutt, "clicked", addBookmark)
    gtk_signal_connect (w.aboutbutton, "clicked", do_about)
    gtk_main ()

if __name__ == "__main__" :
    run ()
