2005-06-11 13:47:30 +00:00
#!/usr/bin/python
2004-11-11 00:43:16 +00:00
from wxPython . wx import *
2004-11-11 03:14:56 +00:00
from os import system
2005-06-11 13:47:30 +00:00
from re import sub
2004-11-11 03:14:56 +00:00
SMSLEN = 160
2004-11-11 00:43:16 +00:00
2004-11-13 17:33:33 +00:00
#class FloatValidator(wxValidator):
# def Clone (self):
# return self.__class__()
# def Validate(self, window):
# ctrl =wxPyTypeCast(self.GetWindow(), "wxTextCtrl")
# try:
# value = float( ctrl.GetValue())
# return true
# except ValueError:
# wx.MessageBox("A text object must contain some text!", "Error")
# return false
# def TransferToWindow(self):
# return true
# def TransferFromWindow(self):
# return true
2004-11-11 00:43:16 +00:00
class SmsToolFrame ( wxFrame ) :
def __init__ ( self , parent , id , title ) :
wxFrame . __init__ ( self , parent , id , title ,
wxPoint ( 100 , 100 ) , wxSize ( 450 , 70 ) )
panel = wxPanel ( self , - 1 )
self . panel = panel
wxStaticText ( panel , - 1 , " Text: " ,
wxDLG_PNT ( panel , wxPoint ( 4 , 4 ) ) , wxDefaultSize )
wxStaticText ( panel , - 1 , " Nummer: " ,
wxDLG_PNT ( panel , wxPoint ( 4 , 20 ) ) , wxDefaultSize )
2004-11-11 03:14:56 +00:00
self . textCtrl = wxTextCtrl ( panel , 20 , " " ,
2004-11-11 00:43:16 +00:00
wxDLG_PNT ( panel , wxPoint ( 30 , 4 ) ) ,
wxDLG_SZE ( panel , wxSize ( 160 , - 1 ) ) )
2004-11-13 17:33:33 +00:00
self . textCtrl . SetMaxLength ( SMSLEN ) ;
2005-06-11 13:47:30 +00:00
self . textCtrl . SetFocus ( )
2004-11-11 00:43:16 +00:00
self . nrCtrl = wxTextCtrl ( panel , - 1 , " " ,
wxDLG_PNT ( panel , wxPoint ( 30 , 20 ) ) ,
2005-06-11 13:47:30 +00:00
wxDLG_SZE ( panel , wxSize ( 60 , - 1 ) ) )
2004-11-11 00:43:16 +00:00
self . fooCtrl = wxButton ( panel , 10 , " Senden " ,
2005-06-11 13:47:30 +00:00
wxDLG_PNT ( panel , wxPoint ( 100 , 20 ) ) ,
2004-11-11 00:43:16 +00:00
wxDLG_SZE ( panel , wxSize ( 30 , - 1 ) ) )
EVT_BUTTON ( self , 10 , self . OnFooClick )
2004-11-11 03:14:56 +00:00
self . zaehler = wxStaticText ( panel , - 1 , str ( SMSLEN ) ,
2005-06-11 13:47:30 +00:00
wxDLG_PNT ( panel , wxPoint ( 150 , 20 ) ) , wxDefaultSize )
2004-11-11 03:14:56 +00:00
EVT_TEXT ( self , 20 , self . OnChange )
2004-11-11 00:43:16 +00:00
def OnCloseWindow ( self , event ) :
self . Destroy ( )
def OnFooClick ( self , event ) :
2004-11-11 03:14:56 +00:00
text = self . textCtrl . GetValue ( )
nr = self . nrCtrl . GetValue ( )
2005-06-11 13:47:30 +00:00
# Quote text
text = sub ( " ' " , " ' ' " , text )
nr = sub ( " ' " , " ' ' " , nr )
rc = system ( " echo ' " + text + " ' | gsmsendsms ' " + nr + " ' " )
if ( rc == 0 ) :
self . foodialog = wxMessageDialog ( self . panel ,
" Message sent " ,
" Success " , wxOK , wxPoint ( 100 , 100 ) )
else :
self . foodialog = wxMessageDialog ( self . panel ,
" gsmsendsms returned error code: " + str ( rc >> 8 ) ,
" Error " , wxOK , wxPoint ( 100 , 100 ) )
2004-11-11 03:14:56 +00:00
self . foodialog . Show ( true )
def OnChange ( self , event ) :
self . zaehler . SetLabel ( str ( SMSLEN - len ( self . textCtrl . GetValue ( ) ) ) )
2004-11-11 00:43:16 +00:00
class SmsTool ( wxApp ) :
def OnInit ( self ) :
frame = SmsToolFrame ( NULL , - 1 , " SmsTool " )
frame . Show ( true )
self . SetTopWindow ( frame )
return true
smstool = SmsTool ( 0 )
smstool . MainLoop ( )