Archived
1
0
Fork 0
This repository has been archived on 2020-10-07. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
smstool/smstool.py
2005-06-11 14:06:13 +00:00

79 lines
2.2 KiB
Python

#!/usr/bin/python
from wxPython.wx import *
from os import system
from re import sub
SMSLEN = 160
class SimserFrame(wxFrame):
def __init__(self, parent, id, title):
# Create GUI
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)
self.textCtrl = wxTextCtrl(panel, 20, "",
wxDLG_PNT(panel, wxPoint(30, 4)),
wxDLG_SZE(panel, wxSize(160, -1)))
self.textCtrl.SetMaxLength(SMSLEN);
self.textCtrl.SetFocus()
self.nrCtrl = wxTextCtrl(panel, -1, "",
wxDLG_PNT(panel, wxPoint(30, 20)),
wxDLG_SZE(panel, wxSize(60, -1)))
self.sendCtrl = wxButton(panel, 10, "Senden",
wxDLG_PNT(panel, wxPoint(100, 20)),
wxDLG_SZE(panel, wxSize(30, -1)))
EVT_BUTTON(self, 10, self.OnSendClick)
self.zaehler = wxStaticText(panel, -1, str(SMSLEN),
wxDLG_PNT(panel, wxPoint(150, 20)), wxDefaultSize)
EVT_TEXT(self, 20, self.OnChange)
def OnCloseWindow(self, event):
self.Destroy()
def OnSendClick(self, event):
text = self.textCtrl.GetValue()
nr = self.nrCtrl.GetValue()
# Quote text
text = sub("'", "''", text)
nr = sub("'", "''", nr)
# Send SMS and report back
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))
self.foodialog.Show(true)
def OnChange(self, event):
self.zaehler.SetLabel(str(SMSLEN-len(self.textCtrl.GetValue())))
class Simser(wxApp):
def OnInit(self):
frame = SimserFrame(NULL, -1, "Simser")
frame.Show(true)
self.SetTopWindow(frame)
return true
smstool=Simser(0)
smstool.MainLoop()