Skip to content

Instantly share code, notes, and snippets.

@TamasBarta
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save TamasBarta/8968204 to your computer and use it in GitHub Desktop.

Select an option

Save TamasBarta/8968204 to your computer and use it in GitHub Desktop.

Revisions

  1. TamasBarta revised this gist Apr 10, 2015. No changes.
  2. TamasBarta revised this gist Apr 10, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion netcheck.py
    Original file line number Diff line number Diff line change
    @@ -55,4 +55,4 @@ def main(self):
    gtk.main()

    checker = Checker()
    checker.main()
    checker.main()
  3. TamasBarta revised this gist Feb 13, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions netcheck.py
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ class Checker:

    def internet_on(self):
    try:
    response=urllib2.urlopen('http://74.125.228.100',timeout=1)
    response=urllib2.urlopen('http://74.125.228.100',timeout=2)
    return True
    except urllib2.URLError as err: pass
    except socket.timeout as err: pass
    @@ -36,9 +36,9 @@ def check(self):
    self.a.set_icon('ubuntuone-client-error')
    n = pynotify.Notification('Internetkapcsolat ellenőrző',
    body,
    'notification-message-im')
    'network')
    n.show()
    gtk.timeout_add(1000, self.check)
    gtk.timeout_add(3000, self.check)

    def main(self):
    # print what
    @@ -51,7 +51,7 @@ def main(self):
    m.append(mQuit)
    self.a.set_menu(m)

    gtk.timeout_add(1000, self.check)
    gtk.timeout_add(3000, self.check)
    gtk.main()

    checker = Checker()
  4. TamasBarta created this gist Feb 13, 2014.
    58 changes: 58 additions & 0 deletions netcheck.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    import urllib2
    import appindicator
    import pynotify
    import gtk
    from concurrent import futures
    import socket

    class Checker:

    last_check = True
    a = None

    def internet_on(self):
    try:
    response=urllib2.urlopen('http://74.125.228.100',timeout=1)
    return True
    except urllib2.URLError as err: pass
    except socket.timeout as err: pass
    return False

    def quit(self, item):
    gtk.main_quit();

    def check(self):
    current_check = self.internet_on()
    if self.last_check != current_check:
    self.last_check = current_check
    pynotify.init('netcheckindicator')
    if current_check:
    body = 'Van internetkapcsolat'
    self.a.set_icon('ubuntuone-client-idle')
    else:
    body = 'Nincs internetkapcsolat'
    self.a.set_icon('ubuntuone-client-error')
    n = pynotify.Notification('Internetkapcsolat ellenőrző',
    body,
    'notification-message-im')
    n.show()
    gtk.timeout_add(1000, self.check)

    def main(self):
    # print what
    self.a = appindicator.Indicator('netcheckindicator', 'ubuntuone-client-idle', appindicator.CATEGORY_APPLICATION_STATUS)
    self.a.set_status( appindicator.STATUS_ACTIVE )
    m = gtk.Menu()
    mQuit = gtk.MenuItem('Kilépés')
    mQuit.show()
    mQuit.connect('activate', self.quit)
    m.append(mQuit)
    self.a.set_menu(m)

    gtk.timeout_add(1000, self.check)
    gtk.main()

    checker = Checker()
    checker.main()