""" PyPhone.py
 Copyright (C) 1998 Luc Stepniewski

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 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 General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 Ce programme permet de composer des numeros de telephone
 sur un MODEM Voice (testé sur 'USR 56K Pro Message Modem')
"""
import sys
from Gtkinter import *
import pyglade
import modem

DEVICE = 'ttyS1'

def on_composer_clicked(args=None):
    le_numero = numero.get_text()
    
    listitem = GtkListItem(le_numero)
    list.add(listitem)
    listitem.show()
    m.dial(le_numero)

def on_raccrocher_clicked(args=None):
    m.hangup()

def on_repondre_clicked(args=None):
    m.off_hook()

if len(sys.argv) > 1:                                                           
    fname = sys.argv[1]
else:
    fname = 'gui.xml'
        
wtree = pyglade.construct(fname)

try:
    win = wtree.get_widget('window1')
except: pass

try:
    wtree.connect('close_window', mainquit)
except: pass

quitter = wtree.get_widget('quitter')
quitter.connect('clicked', mainquit)

numero = wtree.get_widget('entry5')

composer = wtree.get_widget('composer')
composer.connect('clicked', on_composer_clicked)

raccrocher = wtree.get_widget('raccrocher')
raccrocher.connect('clicked', on_raccrocher_clicked)

repondre= wtree.get_widget('repondre')
repondre.connect('clicked', on_repondre_clicked)

statusbar = wtree.get_widget('statusbar1')
s_id = statusbar.get_context_id('essai')

list = wtree.get_widget('list1')

# Initialisation du Modem
m = modem.Modem(DEVICE)
m.init_device()

statusbar.push(s_id, 'Modem Initialisé correctement sur %s' % DEVICE)

mainloop()