Skip to content

Commit

Permalink
add blinking icon when connecting to vpn
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon2fly committed Aug 21, 2016
1 parent 95e3a34 commit 28d4cc3
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 16 deletions.
91 changes: 91 additions & 0 deletions connecting1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions connecting2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions connecting3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 21 additions & 6 deletions vpn_indicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ def __init__(self, q_info, sender):
self.APPINDICATOR_ID = 'myappindicator'
self.icon1 = os.path.abspath('connected.svg')
self.icon2 = os.path.abspath('connectnot.svg')
self.icon3 = os.path.abspath('connecting.gif')
self.icon345 = [os.path.abspath(icon) for icon in ['connecting1.svg','connecting2.svg','connecting3.svg']]
self.hang = False
self.is_connecting = False
self.icon_th = 0

self.last_recv = ['']
self.indicator = appindicator.Indicator.new(self.APPINDICATOR_ID, self.icon2,
Expand All @@ -203,14 +205,29 @@ def __init__(self, q_info, sender):
notify.init(self.APPINDICATOR_ID)

def run(self, *args):
GLib.timeout_add(2000, self.callback, *args)
GLib.timeout_add(1000, self.callback, *args)
GLib.timeout_add(700, self.blinking)
Gtk.main()

def blinking(self):
if self.is_connecting:
if self.icon_th == 3:
self.icon_th = 0
self.indicator.set_icon(self.icon345[self.icon_th])
self.icon_th += 1
return True

def reload(self, data_in):
if data_in:
print data_in[:12]

self.last_recv = data_in.split(';')
if 'connecting' in data_in:
print 'set blinking'
self.is_connecting = True
else:
self.is_connecting = False

if 'connected' in data_in:
self.hang = False
self.status('', self.last_recv)
Expand All @@ -227,7 +244,7 @@ def reload(self, data_in):
elif 'main exit' in data_in:
self.quit()

return True
# return True

def build_menu(self):
menu = Gtk.Menu()
Expand Down Expand Up @@ -302,7 +319,6 @@ def status(self, menu_obj, messages=''):
{:<22}{:<15}
{:<21}{:<15}
'''.format(*msg)

elif 'terminate' in messages[0]:
summary = 'VPN tunnel has broken'
body = 'Please choose a different server and try again'
Expand All @@ -313,7 +329,7 @@ def status(self, menu_obj, messages=''):
summary = 'Status unknown'
body = "Waiting for connection from main program"

self.notifier.update(summary, '<span foreground="blue" size="100" font_family="monospace">'+body+'</span>', icon=None)
self.notifier.update(summary, body, icon=None)
self.notifier.show()

def handler(self, signal_num, frame):
Expand All @@ -325,7 +341,6 @@ def send_cmd(self, menu_obj, arg):
self.send(arg)

def callback(self):

try:
data = self.q_info.get_nowait()
self.reload(data)
Expand Down
Loading

0 comments on commit 28d4cc3

Please sign in to comment.