#!/usr/bin/env python2.5 # -*- coding: UTF-8 -*- #***************************************************************************\ #* Copyright (C) 2007 by Nicolai Spohrer, * #* nicolai@xeve.de * #* * #* 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 3 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, see * #* or write to the * #* Free Software Foundation, Inc., * #* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * #***************************************************************************/ import gtk import httplib import re from time import sleep import threading count_reconnected=0 class get_ip(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.status=-1 def run(self): try: con=httplib.HTTPConnection("checkip.dyndns.org") con.request("GET", "/") data=con.getresponse().read() except: print "Error while getting response, trying again" self.status=1 else: self.IP=re.match(".*Current IP Address: (.*).*", data).group(1) self.status=0 class reconnect(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.status=-1 def run(self): try: SITE="192.168.2.1" FILENAME="/cgi-bin/disconnect.exe" con=httplib.HTTPConnection(SITE) con.request("GET", FILENAME) con_info=con.getresponse() except: self.status=1 print "Couldn't reconnect... strange." else: print "Reconnected." self.status=0 def callback(widget): widget.set_blinking(True) fgip=get_ip() fgip.start() while fgip.status == -1: sleep(0.1) gtk.main_iteration_do(False) gtk.main_iteration_do(True) IP_before=fgip.IP global count_reconnected reco=reconnect() reco.start() while reco.status == -1: sleep(0.1) gtk.main_iteration_do(False) gtk.main_iteration_do(True) n=0 while n < 501: gtk.main_iteration_do(False) sleep(0.01) n=n+1 gtk.main_iteration_do(True) IP=None gip=get_ip() gip.start() while gip.status == -1: sleep(0.1) gtk.main_iteration_do(False) gtk.main_iteration_do(True) IP=gip.IP while IP == IP_before: gip=get_ip() gip.start() while gip.status == -1: sleep(0.1) gtk.main_iteration_do(False) IP=gip.IP gtk.main_iteration_do(True) widget.set_blinking(False) count_reconnected+=1 widget.set_tooltip("IP: %s, reconnected %i times" % (IP, count_reconnected)) r_icon_name="/home/nicolai/files/gbutton.png" r_ic=gtk.StatusIcon() r_ic.set_from_file(r_icon_name) r_ic.set_visible(True) r_ic.connect("activate", callback) clicked=0 def click_callback(widget): global clicked clicked+=1 widget.set_tooltip("Button was pressed %i times" % (clicked)) print "%i times clicked" % (clicked) c_icon_name="/home/nicolai/files/pbutton.png" c_ic=gtk.StatusIcon() c_ic.set_from_file(c_icon_name) c_ic.set_visible(True) c_ic.connect("activate", click_callback) gtk.main()