Update all gadgets to API 2

This commit is contained in:
Davide Andreoli 2018-07-14 17:26:32 +02:00
parent 78c6416b09
commit 4a81ad6b47
12 changed files with 208 additions and 303 deletions

View File

@ -11,20 +11,24 @@ from efl import ecore
from efl import evas
from efl import edje
from efl.dbus_mainloop import DBusEcoreMainLoop
from efl.elementary.label import Label
from efl.elementary.layout import Layout
from efl.elementary.slider import Slider
from efl.evas import EXPAND_HORIZ, FILL_HORIZ
from efl import elementary as elm
__gadget_name__ = 'Audio'
__gadget_vers__ = '0.1'
__gadget_vers__ = '0.2'
__gadget_auth__ = 'DaveMDS'
__gadget_mail__ = 'dave@gurumeditation.it'
__gadget_desc__ = 'The complete audio gadget.'
__gadget_vapi__ = 1
__gadget_vapi__ = 2
__gadget_opts__ = { 'popup_on_desktop': True }
# def DBG(msg):
# print("AUDIO: %s" % msg)
# sys.stdout.flush()
_instance = None
@ -43,6 +47,7 @@ class Gadget(e.Gadget):
self.pulse = PulseAudio_Client()
def instance_created(self, obj, site):
# DBG("INSTANCE CREATED")
super().instance_created(obj, site)
obj.signal_callback_add('mouse,down,2', 'over', self.speaker_click_cb)
@ -51,6 +56,7 @@ class Gadget(e.Gadget):
self.speaker_update(obj)
def instance_destroyed(self, obj):
# DBG("INSTANCE DESTROYED")
super().instance_destroyed(obj)
def speaker_click_cb(self, obj, sig, source):
@ -76,54 +82,55 @@ class Gadget(e.Gadget):
return
ch.volume_set(min(max(0, new_vol), 65500))
def popup_created(self, popup):
super().popup_created(popup)
def popup_created(self, elm_parent):
# DBG("POPUP CREATED")
main_box = elm.Box(elm_parent)
main_box.show()
players_box = elm.Box(main_box, size_hint_expand=EXPAND_HORIZ,
size_hint_fill=FILL_HORIZ)
main_box.pack_end(players_box)
players_box.show()
volumes_box = elm.Box(main_box, size_hint_expand=EXPAND_HORIZ,
size_hint_fill=FILL_HORIZ)
main_box.pack_end(volumes_box)
volumes_box.show()
main_box.data['players_box'] = players_box
main_box.data['volumes_box'] = volumes_box
# add all the available players to the popup edje box
for player in self.mpris.players:
self.popup_player_add(popup, player)
self.popup_player_add(main_box, player)
# add all the channel sliders
if self.pulse.conn is not None:
for ch in self.pulse.channels:
self.popup_volume_add(popup, ch)
self.popup_volume_add(main_box, ch)
else:
lb = Label(popup, text='Cannot connect to PulseAudio')
lb = elm.Label(popup, text='Cannot connect to PulseAudio')
volumes_box.pack_start(lb)
lb.show()
popup.part_box_append('volumes.box', lb)
return main_box
def popup_destroyed(self, popup):
super().popup_destroyed(popup)
while True:
# pop an item from the players box
obj = popup.part_box_remove_at('players.box', 0)
if obj is None: break
# remove the obj from our lists
# DBG("POPUP DESTROYED")
# remove the objects from our lists
for obj in popup.data['players_box'].children:
for player, objs in self.player_objs.items():
while obj in objs: objs.remove(obj)
# delete the player layout
obj.delete()
while True:
# pop an item from the players box
obj = popup.part_box_remove_at('volumes.box', 0)
if obj is None: break
# remove the obj from our lists
while obj in objs:
objs.remove(obj)
for obj in popup.data['volumes_box'].children:
for channel, objs in self.channel_objs.items():
while obj in objs: objs.remove(obj)
# delete the slider
obj.delete()
while obj in objs:
objs.remove(obj)
def popup_player_add(self, popup, player):
# create the edje obj for this player from 'e/gadgets/audio/player'
o = Layout(popup)
o = elm.Layout(popup)
e.theme_object_set(o, 'audio', 'player')
o.size_hint_min = o.edje.size_min
o.signal_callback_add('act,play', '', lambda o,sig,src: player.play())
o.signal_callback_add('act,prev', '', lambda o,sig,src: player.prev())
@ -134,8 +141,7 @@ class Gadget(e.Gadget):
o.show()
# insert the player in the popup box
popup.part_box_append('players.box', o)
popup.size_hint_min = popup.size_min
popup.data['players_box'].pack_end(o)
# keep track of this obj in the player_objs dict
if not player in self.player_objs:
@ -158,9 +164,6 @@ class Gadget(e.Gadget):
# remove the player from our list
del self.player_objs[player]
for popup in self._popups:
popup.size_hint_min = popup.size_min
def player_update(self, obj, player):
# player name
obj.part_text_set('player_name', player.label or player.name)
@ -195,8 +198,10 @@ class Gadget(e.Gadget):
pass
def popup_volume_add(self, popup, channel):
sl = Slider(popup, text=channel.name, min_max=(0, 65500),
size_hint_align=(evas.EVAS_HINT_FILL, 0.0))
sl = elm.Slider(popup, text=channel.name, min_max=(0, 65500),
span_size=150,
size_hint_expand=EXPAND_HORIZ,
size_hint_fill=FILL_HORIZ)
sl.value = channel.volume
sl.disabled = True if channel.muted else False
sl.callback_changed_add(self.popup_slider_changed_cb, channel)
@ -207,8 +212,7 @@ class Gadget(e.Gadget):
sl.show()
# insert the slider in the popup box
popup.part_box_prepend('volumes.box', sl)
popup.size_hint_min = popup.size_min
popup.data['volumes_box'].pack_start(sl)
# keep track of this obj in the channel_objs dict
if not channel in self.channel_objs:
@ -257,8 +261,6 @@ class Gadget(e.Gadget):
del self.channel_objs[channel][:]
del self.channel_objs[channel]
for popup in self._popups:
popup.size_hint_min = popup.size_min
class Mpris2_Client(object):
BASE_PATH = 'org.mpris.MediaPlayer2.'
@ -296,6 +298,7 @@ class Mpris2_Client(object):
del player
break
class Mpris2_Player(object):
MAIN_IFACE = 'org.mpris.MediaPlayer2'
PLAYER_IFACE = 'org.mpris.MediaPlayer2.Player'
@ -374,6 +377,7 @@ class AudioChannel(object):
return '[%s]: "%s" volume: %s' % \
(self.iface.split('.')[-1], self.name, self.volume[:])
class PulseAudio_Client(object):
PULSE_OBJ = '/org/pulseaudio/core1'
PULSE_IFACE = 'org.PulseAudio.Core1'

View File

@ -269,41 +269,6 @@ collections {
}
}
/**
* API [e/gadget/popup] This is the group that will be placed inside popups
*/
group { name: "e/gadgets/audio/popup";
min: 310 0;
parts {
part { name: "players.box";
type: BOX;
description { state: "default" 0.0;
rel2.relative: 1.0 0.0;
align: 0.0 0.0;
box {
layout: "vertical";
padding: 0 6;
min: 1 1;
}
}
}
part { name: "volumes.box";
type: BOX;
description { state: "default" 0.0;
rel1.to: "players.box";
rel1.relative: 0.0 1.0;
rel1.offset: 0 6;
align: 0.0 0.0;
box {
layout: "vertical";
padding: 0 6;
min: 1 1;
}
}
}
}
}
group { name: "e/gadgets/audio/player";
min: 310 100;
styles {

View File

@ -4,11 +4,11 @@ import e
__gadget_name__ = 'Calculator'
__gadget_vers__ = '0.1'
__gadget_vers__ = '0.2'
__gadget_auth__ = 'DaveMDS'
__gadget_mail__ = 'dave@gurumeditation.it'
__gadget_desc__ = 'A pure edje calculator.'
__gadget_vapi__ = 1
__gadget_vapi__ = 2
class Gadget(e.Gadget):

View File

@ -9,19 +9,23 @@ from efl import ecore
from efl import evas
from efl import edje
from efl.evas import EXPAND_BOTH, FILL_BOTH
from efl.elementary import Box, Label, Entry, Icon, Genlist, GenlistItemClass, \
ELM_OBJECT_SELECT_MODE_NONE, ELM_LIST_COMPRESS
from efl import elementary as elm
__gadget_name__ = 'CPU Monitor'
__gadget_vers__ = '0.1'
__gadget_vers__ = '0.2'
__gadget_auth__ = 'DaveMDS'
__gadget_mail__ = 'dave@gurumeditation.it'
__gadget_desc__ = 'Multicore CPU monitor'
__gadget_vapi__ = 1
__gadget_vapi__ = 2
__gadget_opts__ = { 'popup_on_desktop': False }
# def DBG(msg):
# print("CPU: %s" % msg)
# sys.stdout.flush()
class Gadget(e.Gadget):
def __init__(self):
@ -31,7 +35,7 @@ class Gadget(e.Gadget):
self.aspect = None
self.main_poller = None
self.popups_poller = None
self.popups_itc = GenlistItemClass(item_style='default',
self.popups_itc = elm.GenlistItemClass(item_style='default',
text_get_func=self.gl_text_get,
content_get_func=self.gl_content_get)
@ -73,37 +77,57 @@ class Gadget(e.Gadget):
return ecore.ECORE_CALLBACK_RENEW
def popup_created(self, popup):
super().popup_created(popup)
def popup_created(self, elm_parent):
table = elm.Table(elm_parent)
table.show()
box = Box(popup)
popup.part_swallow('main.swallow', box)
box.show()
en = Entry(popup, single_line=True, editable=False)
en = elm.Entry(table, single_line=True, editable=False)
en.text_style_user_push("DEFAULT='font_weight=Bold'")
box.pack_end(en)
table.pack(en, 0, 0, 1, 1)
en.show()
popup.data['head'] = en
li = Genlist(popup, homogeneous=True, mode=ELM_LIST_COMPRESS,
select_mode=ELM_OBJECT_SELECT_MODE_NONE,
size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
box.pack_end(li)
li = elm.Genlist(table, homogeneous=True, mode=elm.ELM_LIST_COMPRESS,
select_mode=elm.ELM_OBJECT_SELECT_MODE_NONE,
size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
table.pack(li, 0, 1, 1, 1)
li.show()
popup.data['list'] = li
rect = evas.Rectangle(table.evas, color=(0,0,0,0),
size_hint_min=(300,300))
table.pack(rect, 0, 1, 1, 1)
table.data['head'] = en
table.data['list'] = li
self.popups_poller_cb()
if self.popups_poller is None:
self.popups_poller = ecore.Poller(16, self.popups_poller_cb)
self.popup_update(table)
return table
def popup_destroyed(self, popup):
super().popup_destroyed(popup)
if len(self._popups) < 1 and self.popups_poller is not None:
self.popups_poller.delete()
self.popups_poller = None
def popup_update(self, popup):
li = popup.data['list']
# adjust the size (items count) of the genlist
items_count = li.items_count()
procs_count = len(self.top_procs)
if procs_count > items_count:
for idx in range(items_count, procs_count):
li.item_append(self.popups_itc, idx)
elif procs_count < items_count:
for idx in range(procs_count, items_count):
li.last_item.delete()
# update visible list items and the header text
li.realized_items_update()
popup.data['head'].text = '{} Running processes'.format(procs_count)
def popups_poller_cb(self):
# build an orderd list of all running procs (pid, name, cpu_perc, mun_t)
if psutil.version_info[0] < 2:
@ -118,23 +142,9 @@ class Gadget(e.Gadget):
for p in psutil.process_iter() ]
self.top_procs.sort(key=itemgetter(2), reverse=True)
# update all the visible genlists
# update all the visible popups
for popup in self._popups:
li = popup.data['list']
# adjust the size (items count) of the genlist
items_count = li.items_count()
procs_count = len(self.top_procs)
if procs_count > items_count:
for idx in range(items_count, procs_count):
li.item_append(self.popups_itc, idx)
elif procs_count < items_count:
for idx in range(procs_count, items_count):
li.last_item.delete()
# update visible list items and the header text
li.realized_items_update()
popup.data['head'].text = '{} Running processes'.format(procs_count)
self.popup_update(popup)
return ecore.ECORE_CALLBACK_RENEW
@ -148,9 +158,9 @@ class Gadget(e.Gadget):
def gl_content_get(self, gl, part, idx):
pid, name, cpu, num_t = self.top_procs[idx]
if part == 'elm.swallow.end':
return Label(gl, text='{0:.1f} %'.format(cpu))
return elm.Label(gl, text='{0:.1f} %'.format(cpu))
if part == 'elm.swallow.icon':
try:
return Icon(gl, standard=name)
return elm.Icon(gl, standard=name)
except RuntimeWarning: # icon not found
return None

View File

@ -145,17 +145,4 @@ collections {
// }
}
}
/**
* API [e/gadget/popup] This is the group that will be placed inside popups
*/
group { name: "e/gadgets/cpu/popup";
min: 300 300;
parts {
swallow { "main.swallow";
desc { "default";
}
}
}
}
}

View File

@ -9,23 +9,22 @@ import e
from efl import ecore
from efl import evas
from efl import edje
from efl.elementary.label import Label
from efl import elementary as elm
from efl.elementary.entry import utf8_to_markup
from efl.elementary.button import Button
__gadget_name__ = 'Dropbox'
__gadget_vers__ = '0.1'
__gadget_vers__ = '0.2'
__gadget_auth__ = 'DaveMDS'
__gadget_mail__ = 'dave@gurumeditation.it'
__gadget_desc__ = 'Dropbox info gadget.'
__gadget_vapi__ = 1
__gadget_vapi__ = 2
__gadget_opts__ = { 'popup_on_desktop': False }
#def DBG(msg):
# print("DB: " + msg)
# sys.stdout.flush()
# def DBG(msg):
# print("DROPBOX: %s" % msg)
# sys.stdout.flush()
class Gadget(e.Gadget):
@ -41,22 +40,24 @@ class Gadget(e.Gadget):
def instance_destroyed(self, obj):
super().instance_destroyed(obj)
def popup_created(self, popup):
super().popup_created(popup)
def popup_created(self, elm_parent):
box = elm.Box(elm_parent)
box.show()
popup.data['lb'] = Label(popup)
popup.part_box_append('popup.box', popup.data['lb'])
popup.data['lb'].show()
lb = elm.Label(box)
box.pack_end(lb)
lb.show()
popup.data['bt'] = Button(popup)
popup.data['bt'].callback_clicked_add(self.start_stop_clicked_cb)
popup.part_box_append('popup.box', popup.data['bt'])
popup.data['bt'].show()
bt = elm.Button(box)
bt.callback_clicked_add(self.start_stop_clicked_cb)
box.pack_end(bt)
bt.show()
self.popup_update(popup)
box.data['lb'] = lb
box.data['bt'] = bt
def popup_destroyed(self, popup):
super().popup_destroyed(popup)
self.popup_update(box)
return box
def db_status_changed_cb(self):
for icon in self._instances:
@ -84,9 +85,6 @@ class Gadget(e.Gadget):
popup.data['bt'].text = 'Install Dropbox'
popup.data['bt'].disabled = True
# force the popup to recalculate it's size
popup.size_hint_min = popup.size_min
def start_stop_clicked_cb(self, btn):
if self.db.is_running:
self.db.stop()

View File

@ -77,22 +77,4 @@ collections {
}
}
}
/**
* API [e/gadget/popup] This is the group that will be placed inside popups
*/
group { name: "e/gadgets/dropbox/popup";
// min: 310 0;
parts {
box { "popup.box";
desc { "default";
box {
layout: "vertical";
padding: 0 6;
min: 1 1;
}
}
}
}
}
}

View File

@ -11,11 +11,16 @@ from efl import edje
from efl import ecore
__gadget_name__ = 'Led Clock'
__gadget_vers__ = '0.1'
__gadget_vers__ = '0.2'
__gadget_auth__ = 'DaveMDS'
__gadget_mail__ = 'dave@gurumeditation.it'
__gadget_desc__ = 'The usual led clock.'
__gadget_vapi__ = 1
__gadget_vapi__ = 2
# def DBG(msg):
# print("MEM: %s" % msg)
# sys.stdout.flush()
COLORS = ('off', 'red', 'green', 'blu')

View File

@ -12,23 +12,27 @@ from efl.elementary import Box, Frame, Progressbar
__gadget_name__ = 'Memory Monitor'
__gadget_vers__ = '0.1'
__gadget_vers__ = '0.2'
__gadget_auth__ = 'DaveMDS'
__gadget_mail__ = 'dave@gurumeditation.it'
__gadget_desc__ = 'Ram + Swap monitor'
__gadget_vapi__ = 1
__gadget_vapi__ = 2
__gadget_opts__ = { 'popup_on_desktop': False }
# import sys
# def DBG(msg):
# print("MEM: %s" % msg)
# sys.stdout.flush()
class Gadget(e.Gadget):
def __init__(self):
super().__init__()
self.poller = None
self.mem = 0
self.swp = 0
self.mem = None
self.swp = None
def instance_created(self, obj, site):
super().instance_created(obj, site)
@ -38,7 +42,7 @@ class Gadget(e.Gadget):
int(obj.data_get('aspect_h')))
if self.poller is None:
self.poller = ecore.Poller(8, self.poller_cb, ecore.ECORE_POLLER_CORE)
self.poller = ecore.Poller(16, self.poller_cb, ecore.ECORE_POLLER_CORE)
def instance_destroyed(self, obj):
super().instance_destroyed(obj)
@ -47,84 +51,80 @@ class Gadget(e.Gadget):
self.poller.delete()
self.poller = None
def popup_created(self, popup):
super().popup_created(popup)
box = Box(popup)
popup.part_swallow('main.swallow', box)
def popup_created(self, elm_parent):
# main vertical box
box = Box(elm_parent)
box.show()
# mem
# mem frame
tot = self.format_mb(psutil.virtual_memory().total)
fr = Frame(popup, text='Memory Usage (available {})'.format(tot),
fr = Frame(box, text='Memory Usage (available {})'.format(tot),
size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
box.pack_end(fr)
fr.show()
box2 = Box(popup, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
box2 = Box(fr, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
fr.content = box2
box2.show()
pb1 = Progressbar(popup, text='Total used',
pb1 = Progressbar(box2, text='Total used',
span_size=200, size_hint_align=(1.0, 0.5))
box2.pack_end(pb1)
pb1.show()
pb2 = Progressbar(popup, text='active',
pb2 = Progressbar(box2, text='active',
span_size=200, size_hint_align=(1.0, 0.5))
box2.pack_end(pb2)
pb2.show()
pb3 = Progressbar(popup, text='buffers',
pb3 = Progressbar(box2, text='buffers',
span_size=200, size_hint_align=(1.0, 0.5))
box2.pack_end(pb3)
pb3.show()
pb4 = Progressbar(popup, text='cached',
pb4 = Progressbar(box2, text='cached',
span_size=200, size_hint_align=(1.0, 0.5))
box2.pack_end(pb4)
pb4.show()
# swap
# swap frame
tot = self.format_mb(psutil.swap_memory().total)
fr = Frame(popup, text='Swap Usage (available {})'.format(tot),
fr = Frame(box, text='Swap Usage (available {})'.format(tot),
size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
box.pack_end(fr)
fr.show()
pb5 = Progressbar(popup)
pb5 = Progressbar(fr)
fr.content = pb5
pb5.show()
# force the popup to always recalculate it's size
popup.update_hints = True
# keep widget references in the popup
box.data['usd_pb'] = pb1
box.data['act_pb'] = pb2
box.data['buf_pb'] = pb3
box.data['cac_pb'] = pb4
box.data['swp_pb'] = pb5
# force the poller to update the popup now
popup.data['usd_pb'] = pb1
popup.data['act_pb'] = pb2
popup.data['buf_pb'] = pb3
popup.data['cac_pb'] = pb4
popup.data['swp_pb'] = pb5
self.poller_cb(force=True)
self.popup_update(box)
return box
def poller_cb(self, force=False):
mem = psutil.virtual_memory()
swp = psutil.swap_memory()
def popup_update(self, popup):
self.update_pb(popup.data['usd_pb'], self.mem.used, self.mem.total)
active = self.mem.used - self.mem.buffers - self.mem.cached
self.update_pb(popup.data['act_pb'], active, self.mem.total)
self.update_pb(popup.data['buf_pb'], self.mem.buffers, self.mem.total)
self.update_pb(popup.data['cac_pb'], self.mem.cached, self.mem.total)
self.update_pb(popup.data['swp_pb'], self.swp.used, self.swp.total)
if force or mem.percent != self.mem or swp.percent != self.swp:
for obj in self._instances:
obj.message_send(0, (mem.percent, swp.percent))
def poller_cb(self):
self.mem = psutil.virtual_memory()
self.swp = psutil.swap_memory()
for popup in self._popups:
self.update_pb(popup.data['usd_pb'], mem.used, mem.total)
active = mem.used - mem.buffers - mem.cached
self.update_pb(popup.data['act_pb'], active, mem.total)
self.update_pb(popup.data['buf_pb'], mem.buffers, mem.total)
self.update_pb(popup.data['cac_pb'], mem.cached, mem.total)
self.update_pb(popup.data['swp_pb'], swp.used, swp.total)
for obj in self._instances:
obj.message_send(0, (self.mem.percent, self.swp.percent))
self.mem = mem.percent
self.swp = swp.percent
for popup in self._popups:
self.popup_update(popup)
return ecore.ECORE_CALLBACK_RENEW
@ -135,4 +135,3 @@ class Gadget(e.Gadget):
pb.value = val / total
pb.unit_format = '{0} ({1:.0f} %%)'.format(self.format_mb(val),
val / total * 100)

View File

@ -131,16 +131,4 @@ collections {
#undef LED
}
}
/**
* API [e/gadget/popup] This is the group that will be placed inside popups
*/
group { name: "e/gadgets/mem/popup";
parts {
swallow { "main.swallow";
desc { "default";
}
}
}
}
}

View File

@ -12,31 +12,37 @@ from efl.evas import EXPAND_BOTH, EXPAND_HORIZ, FILL_BOTH
__gadget_name__ = 'Network Speed Monitor'
__gadget_vers__ = '0.1'
__gadget_vers__ = '0.2'
__gadget_auth__ = 'DaveMDS'
__gadget_mail__ = 'dave@gurumeditation.it'
__gadget_desc__ = 'Network speed monitor'
__gadget_vapi__ = 1
__gadget_vapi__ = 2
__gadget_opts__ = { 'popup_on_desktop': False }
# import sys
# def DBG(msg):
# print("NETSPEED: %s" % msg)
# sys.stdout.flush()
# print("NETSPEED: %s" % msg)
# sys.stdout.flush()
class Gadget(e.Gadget):
def __init__(self):
# DBG("init")
super().__init__()
self.poller = None
self.last_in = 0
self.last_out = 0
self.last_time = 0
self.kb_in = 0
self.kb_out = 0
self.in_perc = 0
self.out_perc = 0
def instance_created(self, obj, site):
super().instance_created(obj, site)
# DBG("instance_created (insts: %d popups:%d)" % (len(self._instances), len(self._popups)))
obj.size_hint_aspect = evas.EVAS_ASPECT_CONTROL_BOTH, 16, 16
if self.poller is None:
@ -45,49 +51,52 @@ class Gadget(e.Gadget):
def instance_destroyed(self, obj):
super().instance_destroyed(obj)
# DBG("instance_destroyed (insts: %d popups:%d)" % (len(self._instances), len(self._popups)))
if len(self._instances) < 1 and self.poller is not None:
self.poller.delete()
self.poller = None
def popup_created(self, popup):
super().popup_created(popup)
def popup_created(self, elm_parent):
# DBG("popup_created (insts: %d popups:%d)" % (len(self._instances), len(self._popups)))
box = elm.Box(popup)
popup.part_swallow('main.swallow', box)
box = elm.Box(elm_parent)
box.show()
in_label = elm.Label(popup, size_hint_expand=EXPAND_HORIZ)
in_label = elm.Label(box, size_hint_expand=EXPAND_HORIZ, text="asd")
box.pack_end(in_label)
in_label.show()
out_label = elm.Label(popup, size_hint_expand=EXPAND_HORIZ)
out_label = elm.Label(box, size_hint_expand=EXPAND_HORIZ, text="asd")
box.pack_end(out_label)
out_label.show()
popup.data['in_label'] = in_label
popup.data['out_label'] = out_label
box.data['in_label'] = in_label
box.data['out_label'] = out_label
# tell the popup to always recalculate it's size
popup.update_hints = True
self.popup_update(box)
return box
# do an update now
self.poller_cb()
def popup_destroyed(self, obj):
# DBG("popup_destroyed (insts: %d popups:%d)" % (len(self._instances), len(self._popups)))
def popup_update(self, popup):
popup.data['in_label'].text = 'Recv: %.2f KB/s' % self.kb_in
popup.data['out_label'].text = 'Trans: %.2f KB/s' % self.kb_out
def poller_cb(self):
byte_per_second_in, byte_per_second_out = self.parse_proc()
kb_in = byte_per_second_in / 1000.0
kb_out = byte_per_second_out / 1000.0
self.kb_in = byte_per_second_in / 1000.0
self.kb_out = byte_per_second_out / 1000.0
in_perc = int(kb_in / 1000 * 100) # TODO CONFIGURABLE MAX
out_perc = int(kb_out / 1000 * 100) # TODO CONFIGURABLE MAX
self.in_perc = int(self.kb_in / 1000 * 100) # TODO CONFIGURABLE MAX
self.out_perc = int(self.kb_out / 1000 * 100) # TODO CONFIGURABLE MAX
for obj in self._instances:
obj.message_send(1, (0, in_perc, 0, 0, out_perc, 0))
obj.message_send(1, (0, self.in_perc, 0, 0, self.out_perc, 0))
for popup in self._popups:
popup.data['in_label'].text = 'Recv: %.2f KB/s' % kb_in
popup.data['out_label'].text = 'Trans: %.2f KB/s' % kb_out
self.popup_update(popup)
return ecore.ECORE_CALLBACK_RENEW

View File

@ -16,7 +16,6 @@ images {
image: "over.png" COMP;
image: "rx.png" COMP;
image: "tx.png" COMP;
// TODO gadget icon
}
@ -30,7 +29,7 @@ collections {
desc { "default";
aspect: 1.0 1.0;
aspect_preference: BOTH;
image.normal: "base.png"; // TODO gadget icon
image.normal: "base.png";
}
}
}
@ -123,45 +122,4 @@ collections {
}
}
}
/**
* API [e/gadget/popup] This is the group that will be placed inside popups
*/
group { name: "e/gadgets/netspeed/popup";
parts {
// part { name: "label"; type: TEXTBLOCK;
// description { state: "default" 0.0;
// text {
// text: "";
// font: "sans";
// size: 12;
// text_class: "";
// min: 1 1;
// ellipsis: -1;
// }
// }
// }
// part { name: "out_label"; type: TEXT;
// description { state: "default" 0.0;
// rel1.to_y: "in_label";
// rel1.relative: 0.0 1.0;
// rel2.to_y: "in_label";
// rel2.relative: 1.0 1.0;
// text {
// text: "";
// font: "sans";
// size: 12;
// text_class: "";
// min: 1 1;
// ellipsis: -1;
// }
// }
// }
swallow { "main.swallow";
desc { "default";
}
}
}
}
}