summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2018-07-14 17:26:32 +0200
committerDave Andreoli <dave@gurumeditation.it>2018-07-14 17:26:32 +0200
commit4a81ad6b471df7d6165f7ab318bcd3589a3a6f82 (patch)
treee95dd79b47ac26ab9442c84303bbabc1b25f9ae8
parent78c6416b09057808cd83d54c3b316c51404bdfd8 (diff)
Update all gadgets to API 2
-rw-r--r--GADGETS/audio/__init__.py98
-rw-r--r--GADGETS/audio/audio.edc35
-rw-r--r--GADGETS/calculator/__init__.py4
-rw-r--r--GADGETS/cpu/__init__.py90
-rw-r--r--GADGETS/cpu/cpu.edc13
-rw-r--r--GADGETS/dropbox/__init__.py42
-rw-r--r--GADGETS/dropbox/dropbox.edc18
-rw-r--r--GADGETS/led_clock/__init__.py9
-rw-r--r--GADGETS/mem/__init__.py91
-rw-r--r--GADGETS/mem/mem.edc12
-rw-r--r--GADGETS/netspeed/__init__.py55
-rw-r--r--GADGETS/netspeed/netspeed.edc44
12 files changed, 208 insertions, 303 deletions
diff --git a/GADGETS/audio/__init__.py b/GADGETS/audio/__init__.py
index 25a873c..a13f73f 100644
--- a/GADGETS/audio/__init__.py
+++ b/GADGETS/audio/__init__.py
@@ -11,20 +11,24 @@ from efl import ecore
11from efl import evas 11from efl import evas
12from efl import edje 12from efl import edje
13from efl.dbus_mainloop import DBusEcoreMainLoop 13from efl.dbus_mainloop import DBusEcoreMainLoop
14from efl.elementary.label import Label 14from efl.evas import EXPAND_HORIZ, FILL_HORIZ
15from efl.elementary.layout import Layout 15from efl import elementary as elm
16from efl.elementary.slider import Slider
17 16
18 17
19__gadget_name__ = 'Audio' 18__gadget_name__ = 'Audio'
20__gadget_vers__ = '0.1' 19__gadget_vers__ = '0.2'
21__gadget_auth__ = 'DaveMDS' 20__gadget_auth__ = 'DaveMDS'
22__gadget_mail__ = 'dave@gurumeditation.it' 21__gadget_mail__ = 'dave@gurumeditation.it'
23__gadget_desc__ = 'The complete audio gadget.' 22__gadget_desc__ = 'The complete audio gadget.'
24__gadget_vapi__ = 1 23__gadget_vapi__ = 2
25__gadget_opts__ = { 'popup_on_desktop': True } 24__gadget_opts__ = { 'popup_on_desktop': True }
26 25
27 26
27# def DBG(msg):
28 # print("AUDIO: %s" % msg)
29 # sys.stdout.flush()
30
31
28_instance = None 32_instance = None
29 33
30 34
@@ -43,6 +47,7 @@ class Gadget(e.Gadget):
43 self.pulse = PulseAudio_Client() 47 self.pulse = PulseAudio_Client()
44 48
45 def instance_created(self, obj, site): 49 def instance_created(self, obj, site):
50 # DBG("INSTANCE CREATED")
46 super().instance_created(obj, site) 51 super().instance_created(obj, site)
47 52
48 obj.signal_callback_add('mouse,down,2', 'over', self.speaker_click_cb) 53 obj.signal_callback_add('mouse,down,2', 'over', self.speaker_click_cb)
@@ -51,6 +56,7 @@ class Gadget(e.Gadget):
51 self.speaker_update(obj) 56 self.speaker_update(obj)
52 57
53 def instance_destroyed(self, obj): 58 def instance_destroyed(self, obj):
59 # DBG("INSTANCE DESTROYED")
54 super().instance_destroyed(obj) 60 super().instance_destroyed(obj)
55 61
56 def speaker_click_cb(self, obj, sig, source): 62 def speaker_click_cb(self, obj, sig, source):
@@ -76,54 +82,55 @@ class Gadget(e.Gadget):
76 return 82 return
77 ch.volume_set(min(max(0, new_vol), 65500)) 83 ch.volume_set(min(max(0, new_vol), 65500))
78 84
79 def popup_created(self, popup): 85 def popup_created(self, elm_parent):
80 super().popup_created(popup) 86 # DBG("POPUP CREATED")
87 main_box = elm.Box(elm_parent)
88 main_box.show()
89
90 players_box = elm.Box(main_box, size_hint_expand=EXPAND_HORIZ,
91 size_hint_fill=FILL_HORIZ)
92 main_box.pack_end(players_box)
93 players_box.show()
94
95 volumes_box = elm.Box(main_box, size_hint_expand=EXPAND_HORIZ,
96 size_hint_fill=FILL_HORIZ)
97 main_box.pack_end(volumes_box)
98 volumes_box.show()
99
100 main_box.data['players_box'] = players_box
101 main_box.data['volumes_box'] = volumes_box
81 102
82 # add all the available players to the popup edje box 103 # add all the available players to the popup edje box
83 for player in self.mpris.players: 104 for player in self.mpris.players:
84 self.popup_player_add(popup, player) 105 self.popup_player_add(main_box, player)
85 106
86 # add all the channel sliders 107 # add all the channel sliders
87 if self.pulse.conn is not None: 108 if self.pulse.conn is not None:
88 for ch in self.pulse.channels: 109 for ch in self.pulse.channels:
89 self.popup_volume_add(popup, ch) 110 self.popup_volume_add(main_box, ch)
90 else: 111 else:
91 lb = Label(popup, text='Cannot connect to PulseAudio') 112 lb = elm.Label(popup, text='Cannot connect to PulseAudio')
113 volumes_box.pack_start(lb)
92 lb.show() 114 lb.show()
93 popup.part_box_append('volumes.box', lb)
94
95 def popup_destroyed(self, popup):
96 super().popup_destroyed(popup)
97 115
98 while True: 116 return main_box
99 # pop an item from the players box
100 obj = popup.part_box_remove_at('players.box', 0)
101 if obj is None: break
102 117
103 # remove the obj from our lists 118 def popup_destroyed(self, popup):
119 # DBG("POPUP DESTROYED")
120 # remove the objects from our lists
121 for obj in popup.data['players_box'].children:
104 for player, objs in self.player_objs.items(): 122 for player, objs in self.player_objs.items():
105 while obj in objs: objs.remove(obj) 123 while obj in objs:
106 124 objs.remove(obj)
107 # delete the player layout 125 for obj in popup.data['volumes_box'].children:
108 obj.delete()
109
110 while True:
111 # pop an item from the players box
112 obj = popup.part_box_remove_at('volumes.box', 0)
113 if obj is None: break
114
115 # remove the obj from our lists
116 for channel, objs in self.channel_objs.items(): 126 for channel, objs in self.channel_objs.items():
117 while obj in objs: objs.remove(obj) 127 while obj in objs:
118 128 objs.remove(obj)
119 # delete the slider
120 obj.delete()
121 129
122 def popup_player_add(self, popup, player): 130 def popup_player_add(self, popup, player):
123 # create the edje obj for this player from 'e/gadgets/audio/player' 131 # create the edje obj for this player from 'e/gadgets/audio/player'
124 o = Layout(popup) 132 o = elm.Layout(popup)
125 e.theme_object_set(o, 'audio', 'player') 133 e.theme_object_set(o, 'audio', 'player')
126 o.size_hint_min = o.edje.size_min
127 134
128 o.signal_callback_add('act,play', '', lambda o,sig,src: player.play()) 135 o.signal_callback_add('act,play', '', lambda o,sig,src: player.play())
129 o.signal_callback_add('act,prev', '', lambda o,sig,src: player.prev()) 136 o.signal_callback_add('act,prev', '', lambda o,sig,src: player.prev())
@@ -134,8 +141,7 @@ class Gadget(e.Gadget):
134 o.show() 141 o.show()
135 142
136 # insert the player in the popup box 143 # insert the player in the popup box
137 popup.part_box_append('players.box', o) 144 popup.data['players_box'].pack_end(o)
138 popup.size_hint_min = popup.size_min
139 145
140 # keep track of this obj in the player_objs dict 146 # keep track of this obj in the player_objs dict
141 if not player in self.player_objs: 147 if not player in self.player_objs:
@@ -158,9 +164,6 @@ class Gadget(e.Gadget):
158 # remove the player from our list 164 # remove the player from our list
159 del self.player_objs[player] 165 del self.player_objs[player]
160 166
161 for popup in self._popups:
162 popup.size_hint_min = popup.size_min
163
164 def player_update(self, obj, player): 167 def player_update(self, obj, player):
165 # player name 168 # player name
166 obj.part_text_set('player_name', player.label or player.name) 169 obj.part_text_set('player_name', player.label or player.name)
@@ -195,8 +198,10 @@ class Gadget(e.Gadget):
195 pass 198 pass
196 199
197 def popup_volume_add(self, popup, channel): 200 def popup_volume_add(self, popup, channel):
198 sl = Slider(popup, text=channel.name, min_max=(0, 65500), 201 sl = elm.Slider(popup, text=channel.name, min_max=(0, 65500),
199 size_hint_align=(evas.EVAS_HINT_FILL, 0.0)) 202 span_size=150,
203 size_hint_expand=EXPAND_HORIZ,
204 size_hint_fill=FILL_HORIZ)
200 sl.value = channel.volume 205 sl.value = channel.volume
201 sl.disabled = True if channel.muted else False 206 sl.disabled = True if channel.muted else False
202 sl.callback_changed_add(self.popup_slider_changed_cb, channel) 207 sl.callback_changed_add(self.popup_slider_changed_cb, channel)
@@ -207,8 +212,7 @@ class Gadget(e.Gadget):
207 sl.show() 212 sl.show()
208 213
209 # insert the slider in the popup box 214 # insert the slider in the popup box
210 popup.part_box_prepend('volumes.box', sl) 215 popup.data['volumes_box'].pack_start(sl)
211 popup.size_hint_min = popup.size_min
212 216
213 # keep track of this obj in the channel_objs dict 217 # keep track of this obj in the channel_objs dict
214 if not channel in self.channel_objs: 218 if not channel in self.channel_objs:
@@ -257,8 +261,6 @@ class Gadget(e.Gadget):
257 del self.channel_objs[channel][:] 261 del self.channel_objs[channel][:]
258 del self.channel_objs[channel] 262 del self.channel_objs[channel]
259 263
260 for popup in self._popups:
261 popup.size_hint_min = popup.size_min
262 264
263class Mpris2_Client(object): 265class Mpris2_Client(object):
264 BASE_PATH = 'org.mpris.MediaPlayer2.' 266 BASE_PATH = 'org.mpris.MediaPlayer2.'
@@ -296,6 +298,7 @@ class Mpris2_Client(object):
296 del player 298 del player
297 break 299 break
298 300
301
299class Mpris2_Player(object): 302class Mpris2_Player(object):
300 MAIN_IFACE = 'org.mpris.MediaPlayer2' 303 MAIN_IFACE = 'org.mpris.MediaPlayer2'
301 PLAYER_IFACE = 'org.mpris.MediaPlayer2.Player' 304 PLAYER_IFACE = 'org.mpris.MediaPlayer2.Player'
@@ -374,6 +377,7 @@ class AudioChannel(object):
374 return '[%s]: "%s" volume: %s' % \ 377 return '[%s]: "%s" volume: %s' % \
375 (self.iface.split('.')[-1], self.name, self.volume[:]) 378 (self.iface.split('.')[-1], self.name, self.volume[:])
376 379
380
377class PulseAudio_Client(object): 381class PulseAudio_Client(object):
378 PULSE_OBJ = '/org/pulseaudio/core1' 382 PULSE_OBJ = '/org/pulseaudio/core1'
379 PULSE_IFACE = 'org.PulseAudio.Core1' 383 PULSE_IFACE = 'org.PulseAudio.Core1'
diff --git a/GADGETS/audio/audio.edc b/GADGETS/audio/audio.edc
index 94e7c8a..5bb9685 100644
--- a/GADGETS/audio/audio.edc
+++ b/GADGETS/audio/audio.edc
@@ -269,41 +269,6 @@ collections {
269 } 269 }
270 } 270 }
271 271
272/**
273 * API [e/gadget/popup] This is the group that will be placed inside popups
274 */
275 group { name: "e/gadgets/audio/popup";
276 min: 310 0;
277 parts {
278 part { name: "players.box";
279 type: BOX;
280 description { state: "default" 0.0;
281 rel2.relative: 1.0 0.0;
282 align: 0.0 0.0;
283 box {
284 layout: "vertical";
285 padding: 0 6;
286 min: 1 1;
287 }
288 }
289 }
290 part { name: "volumes.box";
291 type: BOX;
292 description { state: "default" 0.0;
293 rel1.to: "players.box";
294 rel1.relative: 0.0 1.0;
295 rel1.offset: 0 6;
296 align: 0.0 0.0;
297 box {
298 layout: "vertical";
299 padding: 0 6;
300 min: 1 1;
301 }
302 }
303 }
304 }
305 }
306
307 group { name: "e/gadgets/audio/player"; 272 group { name: "e/gadgets/audio/player";
308 min: 310 100; 273 min: 310 100;
309 styles { 274 styles {
diff --git a/GADGETS/calculator/__init__.py b/GADGETS/calculator/__init__.py
index cc4e99a..375e031 100644
--- a/GADGETS/calculator/__init__.py
+++ b/GADGETS/calculator/__init__.py
@@ -4,11 +4,11 @@ import e
4 4
5 5
6__gadget_name__ = 'Calculator' 6__gadget_name__ = 'Calculator'
7__gadget_vers__ = '0.1' 7__gadget_vers__ = '0.2'
8__gadget_auth__ = 'DaveMDS' 8__gadget_auth__ = 'DaveMDS'
9__gadget_mail__ = 'dave@gurumeditation.it' 9__gadget_mail__ = 'dave@gurumeditation.it'
10__gadget_desc__ = 'A pure edje calculator.' 10__gadget_desc__ = 'A pure edje calculator.'
11__gadget_vapi__ = 1 11__gadget_vapi__ = 2
12 12
13 13
14class Gadget(e.Gadget): 14class Gadget(e.Gadget):
diff --git a/GADGETS/cpu/__init__.py b/GADGETS/cpu/__init__.py
index 7bf9366..da851b4 100644
--- a/GADGETS/cpu/__init__.py
+++ b/GADGETS/cpu/__init__.py
@@ -9,19 +9,23 @@ from efl import ecore
9from efl import evas 9from efl import evas
10from efl import edje 10from efl import edje
11from efl.evas import EXPAND_BOTH, FILL_BOTH 11from efl.evas import EXPAND_BOTH, FILL_BOTH
12from efl.elementary import Box, Label, Entry, Icon, Genlist, GenlistItemClass, \ 12from efl import elementary as elm
13 ELM_OBJECT_SELECT_MODE_NONE, ELM_LIST_COMPRESS
14 13
15 14
16__gadget_name__ = 'CPU Monitor' 15__gadget_name__ = 'CPU Monitor'
17__gadget_vers__ = '0.1' 16__gadget_vers__ = '0.2'
18__gadget_auth__ = 'DaveMDS' 17__gadget_auth__ = 'DaveMDS'
19__gadget_mail__ = 'dave@gurumeditation.it' 18__gadget_mail__ = 'dave@gurumeditation.it'
20__gadget_desc__ = 'Multicore CPU monitor' 19__gadget_desc__ = 'Multicore CPU monitor'
21__gadget_vapi__ = 1 20__gadget_vapi__ = 2
22__gadget_opts__ = { 'popup_on_desktop': False } 21__gadget_opts__ = { 'popup_on_desktop': False }
23 22
24 23
24# def DBG(msg):
25# print("CPU: %s" % msg)
26# sys.stdout.flush()
27
28
25class Gadget(e.Gadget): 29class Gadget(e.Gadget):
26 30
27 def __init__(self): 31 def __init__(self):
@@ -31,7 +35,7 @@ class Gadget(e.Gadget):
31 self.aspect = None 35 self.aspect = None
32 self.main_poller = None 36 self.main_poller = None
33 self.popups_poller = None 37 self.popups_poller = None
34 self.popups_itc = GenlistItemClass(item_style='default', 38 self.popups_itc = elm.GenlistItemClass(item_style='default',
35 text_get_func=self.gl_text_get, 39 text_get_func=self.gl_text_get,
36 content_get_func=self.gl_content_get) 40 content_get_func=self.gl_content_get)
37 41
@@ -73,37 +77,57 @@ class Gadget(e.Gadget):
73 77
74 return ecore.ECORE_CALLBACK_RENEW 78 return ecore.ECORE_CALLBACK_RENEW
75 79
76 def popup_created(self, popup): 80 def popup_created(self, elm_parent):
77 super().popup_created(popup) 81 table = elm.Table(elm_parent)
78 82 table.show()
79 box = Box(popup)
80 popup.part_swallow('main.swallow', box)
81 box.show()
82 83
83 en = Entry(popup, single_line=True, editable=False) 84 en = elm.Entry(table, single_line=True, editable=False)
84 en.text_style_user_push("DEFAULT='font_weight=Bold'") 85 en.text_style_user_push("DEFAULT='font_weight=Bold'")
85 box.pack_end(en) 86 table.pack(en, 0, 0, 1, 1)
86 en.show() 87 en.show()
87 popup.data['head'] = en
88 88
89 li = Genlist(popup, homogeneous=True, mode=ELM_LIST_COMPRESS, 89 li = elm.Genlist(table, homogeneous=True, mode=elm.ELM_LIST_COMPRESS,
90 select_mode=ELM_OBJECT_SELECT_MODE_NONE, 90 select_mode=elm.ELM_OBJECT_SELECT_MODE_NONE,
91 size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) 91 size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
92 box.pack_end(li) 92 table.pack(li, 0, 1, 1, 1)
93 li.show() 93 li.show()
94 popup.data['list'] = li 94
95 rect = evas.Rectangle(table.evas, color=(0,0,0,0),
96 size_hint_min=(300,300))
97 table.pack(rect, 0, 1, 1, 1)
98
99 table.data['head'] = en
100 table.data['list'] = li
95 101
96 self.popups_poller_cb() 102 self.popups_poller_cb()
97 if self.popups_poller is None: 103 if self.popups_poller is None:
98 self.popups_poller = ecore.Poller(16, self.popups_poller_cb) 104 self.popups_poller = ecore.Poller(16, self.popups_poller_cb)
105 self.popup_update(table)
99 106
100 def popup_destroyed(self, popup): 107 return table
101 super().popup_destroyed(popup)
102 108
109 def popup_destroyed(self, popup):
103 if len(self._popups) < 1 and self.popups_poller is not None: 110 if len(self._popups) < 1 and self.popups_poller is not None:
104 self.popups_poller.delete() 111 self.popups_poller.delete()
105 self.popups_poller = None 112 self.popups_poller = None
106 113
114 def popup_update(self, popup):
115 li = popup.data['list']
116
117 # adjust the size (items count) of the genlist
118 items_count = li.items_count()
119 procs_count = len(self.top_procs)
120 if procs_count > items_count:
121 for idx in range(items_count, procs_count):
122 li.item_append(self.popups_itc, idx)
123 elif procs_count < items_count:
124 for idx in range(procs_count, items_count):
125 li.last_item.delete()
126
127 # update visible list items and the header text
128 li.realized_items_update()
129 popup.data['head'].text = '{} Running processes'.format(procs_count)
130
107 def popups_poller_cb(self): 131 def popups_poller_cb(self):
108 # build an orderd list of all running procs (pid, name, cpu_perc, mun_t) 132 # build an orderd list of all running procs (pid, name, cpu_perc, mun_t)
109 if psutil.version_info[0] < 2: 133 if psutil.version_info[0] < 2:
@@ -118,23 +142,9 @@ class Gadget(e.Gadget):
118 for p in psutil.process_iter() ] 142 for p in psutil.process_iter() ]
119 self.top_procs.sort(key=itemgetter(2), reverse=True) 143 self.top_procs.sort(key=itemgetter(2), reverse=True)
120 144
121 # update all the visible genlists 145 # update all the visible popups
122 for popup in self._popups: 146 for popup in self._popups:
123 li = popup.data['list'] 147 self.popup_update(popup)
124
125 # adjust the size (items count) of the genlist
126 items_count = li.items_count()
127 procs_count = len(self.top_procs)
128 if procs_count > items_count:
129 for idx in range(items_count, procs_count):
130 li.item_append(self.popups_itc, idx)
131 elif procs_count < items_count:
132 for idx in range(procs_count, items_count):
133 li.last_item.delete()
134
135 # update visible list items and the header text
136 li.realized_items_update()
137 popup.data['head'].text = '{} Running processes'.format(procs_count)
138 148
139 return ecore.ECORE_CALLBACK_RENEW 149 return ecore.ECORE_CALLBACK_RENEW
140 150
@@ -148,9 +158,9 @@ class Gadget(e.Gadget):
148 def gl_content_get(self, gl, part, idx): 158 def gl_content_get(self, gl, part, idx):
149 pid, name, cpu, num_t = self.top_procs[idx] 159 pid, name, cpu, num_t = self.top_procs[idx]
150 if part == 'elm.swallow.end': 160 if part == 'elm.swallow.end':
151 return Label(gl, text='{0:.1f} %'.format(cpu)) 161 return elm.Label(gl, text='{0:.1f} %'.format(cpu))
152 if part == 'elm.swallow.icon': 162 if part == 'elm.swallow.icon':
153 try: 163 try:
154 return Icon(gl, standard=name) 164 return elm.Icon(gl, standard=name)
155 except RuntimeWarning: # icon not found 165 except RuntimeWarning: # icon not found
156 return None 166 return None
diff --git a/GADGETS/cpu/cpu.edc b/GADGETS/cpu/cpu.edc
index ecc3f0e..56fa77a 100644
--- a/GADGETS/cpu/cpu.edc
+++ b/GADGETS/cpu/cpu.edc
@@ -145,17 +145,4 @@ collections {
145 // } 145 // }
146 } 146 }
147 } 147 }
148
149/**
150 * API [e/gadget/popup] This is the group that will be placed inside popups
151 */
152 group { name: "e/gadgets/cpu/popup";
153 min: 300 300;
154 parts {
155 swallow { "main.swallow";
156 desc { "default";
157 }
158 }
159 }
160 }
161} 148}
diff --git a/GADGETS/dropbox/__init__.py b/GADGETS/dropbox/__init__.py
index c53d308..a87fe29 100644
--- a/GADGETS/dropbox/__init__.py
+++ b/GADGETS/dropbox/__init__.py
@@ -9,23 +9,22 @@ import e
9from efl import ecore 9from efl import ecore
10from efl import evas 10from efl import evas
11from efl import edje 11from efl import edje
12from efl.elementary.label import Label 12from efl import elementary as elm
13from efl.elementary.entry import utf8_to_markup 13from efl.elementary.entry import utf8_to_markup
14from efl.elementary.button import Button
15 14
16 15
17__gadget_name__ = 'Dropbox' 16__gadget_name__ = 'Dropbox'
18__gadget_vers__ = '0.1' 17__gadget_vers__ = '0.2'
19__gadget_auth__ = 'DaveMDS' 18__gadget_auth__ = 'DaveMDS'
20__gadget_mail__ = 'dave@gurumeditation.it' 19__gadget_mail__ = 'dave@gurumeditation.it'
21__gadget_desc__ = 'Dropbox info gadget.' 20__gadget_desc__ = 'Dropbox info gadget.'
22__gadget_vapi__ = 1 21__gadget_vapi__ = 2
23__gadget_opts__ = { 'popup_on_desktop': False } 22__gadget_opts__ = { 'popup_on_desktop': False }
24 23
25 24
26#def DBG(msg): 25# def DBG(msg):
27# print("DB: " + msg) 26# print("DROPBOX: %s" % msg)
28# sys.stdout.flush() 27# sys.stdout.flush()
29 28
30 29
31class Gadget(e.Gadget): 30class Gadget(e.Gadget):
@@ -41,22 +40,24 @@ class Gadget(e.Gadget):
41 def instance_destroyed(self, obj): 40 def instance_destroyed(self, obj):
42 super().instance_destroyed(obj) 41 super().instance_destroyed(obj)
43 42
44 def popup_created(self, popup): 43 def popup_created(self, elm_parent):
45 super().popup_created(popup) 44 box = elm.Box(elm_parent)
45 box.show()
46 46
47 popup.data['lb'] = Label(popup) 47 lb = elm.Label(box)
48 popup.part_box_append('popup.box', popup.data['lb']) 48 box.pack_end(lb)
49 popup.data['lb'].show() 49 lb.show()
50 50
51 popup.data['bt'] = Button(popup) 51 bt = elm.Button(box)
52 popup.data['bt'].callback_clicked_add(self.start_stop_clicked_cb) 52 bt.callback_clicked_add(self.start_stop_clicked_cb)
53 popup.part_box_append('popup.box', popup.data['bt']) 53 box.pack_end(bt)
54 popup.data['bt'].show() 54 bt.show()
55 55
56 self.popup_update(popup) 56 box.data['lb'] = lb
57 box.data['bt'] = bt
57 58
58 def popup_destroyed(self, popup): 59 self.popup_update(box)
59 super().popup_destroyed(popup) 60 return box
60 61
61 def db_status_changed_cb(self): 62 def db_status_changed_cb(self):
62 for icon in self._instances: 63 for icon in self._instances:
@@ -84,9 +85,6 @@ class Gadget(e.Gadget):
84 popup.data['bt'].text = 'Install Dropbox' 85 popup.data['bt'].text = 'Install Dropbox'
85 popup.data['bt'].disabled = True 86 popup.data['bt'].disabled = True
86 87
87 # force the popup to recalculate it's size
88 popup.size_hint_min = popup.size_min
89
90 def start_stop_clicked_cb(self, btn): 88 def start_stop_clicked_cb(self, btn):
91 if self.db.is_running: 89 if self.db.is_running:
92 self.db.stop() 90 self.db.stop()
diff --git a/GADGETS/dropbox/dropbox.edc b/GADGETS/dropbox/dropbox.edc
index b499e19..0781f0e 100644
--- a/GADGETS/dropbox/dropbox.edc
+++ b/GADGETS/dropbox/dropbox.edc
@@ -77,22 +77,4 @@ collections {
77 } 77 }
78 } 78 }
79 } 79 }
80
81/**
82 * API [e/gadget/popup] This is the group that will be placed inside popups
83 */
84 group { name: "e/gadgets/dropbox/popup";
85 // min: 310 0;
86 parts {
87 box { "popup.box";
88 desc { "default";
89 box {
90 layout: "vertical";
91 padding: 0 6;
92 min: 1 1;
93 }
94 }
95 }
96 }
97 }
98} 80}
diff --git a/GADGETS/led_clock/__init__.py b/GADGETS/led_clock/__init__.py
index 2bb4e10..2016f35 100644
--- a/GADGETS/led_clock/__init__.py
+++ b/GADGETS/led_clock/__init__.py
@@ -11,11 +11,16 @@ from efl import edje
11from efl import ecore 11from efl import ecore
12 12
13__gadget_name__ = 'Led Clock' 13__gadget_name__ = 'Led Clock'
14__gadget_vers__ = '0.1' 14__gadget_vers__ = '0.2'
15__gadget_auth__ = 'DaveMDS' 15__gadget_auth__ = 'DaveMDS'
16__gadget_mail__ = 'dave@gurumeditation.it' 16__gadget_mail__ = 'dave@gurumeditation.it'
17__gadget_desc__ = 'The usual led clock.' 17__gadget_desc__ = 'The usual led clock.'
18__gadget_vapi__ = 1 18__gadget_vapi__ = 2
19
20
21# def DBG(msg):
22# print("MEM: %s" % msg)
23# sys.stdout.flush()
19 24
20 25
21COLORS = ('off', 'red', 'green', 'blu') 26COLORS = ('off', 'red', 'green', 'blu')
diff --git a/GADGETS/mem/__init__.py b/GADGETS/mem/__init__.py
index 300e273..c4f0edb 100644
--- a/GADGETS/mem/__init__.py
+++ b/GADGETS/mem/__init__.py
@@ -12,23 +12,27 @@ from efl.elementary import Box, Frame, Progressbar
12 12
13 13
14__gadget_name__ = 'Memory Monitor' 14__gadget_name__ = 'Memory Monitor'
15__gadget_vers__ = '0.1' 15__gadget_vers__ = '0.2'
16__gadget_auth__ = 'DaveMDS' 16__gadget_auth__ = 'DaveMDS'
17__gadget_mail__ = 'dave@gurumeditation.it' 17__gadget_mail__ = 'dave@gurumeditation.it'
18__gadget_desc__ = 'Ram + Swap monitor' 18__gadget_desc__ = 'Ram + Swap monitor'
19__gadget_vapi__ = 1 19__gadget_vapi__ = 2
20__gadget_opts__ = { 'popup_on_desktop': False } 20__gadget_opts__ = { 'popup_on_desktop': False }
21 21
22 22
23# import sys
24# def DBG(msg):
25# print("MEM: %s" % msg)
26# sys.stdout.flush()
27
23 28
24class Gadget(e.Gadget): 29class Gadget(e.Gadget):
25 30
26 def __init__(self): 31 def __init__(self):
27 super().__init__() 32 super().__init__()
28
29 self.poller = None 33 self.poller = None
30 self.mem = 0 34 self.mem = None
31 self.swp = 0 35 self.swp = None
32 36
33 def instance_created(self, obj, site): 37 def instance_created(self, obj, site):
34 super().instance_created(obj, site) 38 super().instance_created(obj, site)
@@ -38,7 +42,7 @@ class Gadget(e.Gadget):
38 int(obj.data_get('aspect_h'))) 42 int(obj.data_get('aspect_h')))
39 43
40 if self.poller is None: 44 if self.poller is None:
41 self.poller = ecore.Poller(8, self.poller_cb, ecore.ECORE_POLLER_CORE) 45 self.poller = ecore.Poller(16, self.poller_cb, ecore.ECORE_POLLER_CORE)
42 46
43 def instance_destroyed(self, obj): 47 def instance_destroyed(self, obj):
44 super().instance_destroyed(obj) 48 super().instance_destroyed(obj)
@@ -47,84 +51,80 @@ class Gadget(e.Gadget):
47 self.poller.delete() 51 self.poller.delete()
48 self.poller = None 52 self.poller = None
49 53
50 def popup_created(self, popup): 54 def popup_created(self, elm_parent):
51 super().popup_created(popup) 55 # main vertical box
52 56 box = Box(elm_parent)
53 box = Box(popup)
54 popup.part_swallow('main.swallow', box)
55 box.show() 57 box.show()
56 58
57 # mem 59 # mem frame
58 tot = self.format_mb(psutil.virtual_memory().total) 60 tot = self.format_mb(psutil.virtual_memory().total)
59 fr = Frame(popup, text='Memory Usage (available {})'.format(tot), 61 fr = Frame(box, text='Memory Usage (available {})'.format(tot),
60 size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) 62 size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
61 box.pack_end(fr) 63 box.pack_end(fr)
62 fr.show() 64 fr.show()
63 65
64 box2 = Box(popup, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) 66 box2 = Box(fr, size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
65 fr.content = box2 67 fr.content = box2
66 box2.show() 68 box2.show()
67 69
68 pb1 = Progressbar(popup, text='Total used', 70 pb1 = Progressbar(box2, text='Total used',
69 span_size=200, size_hint_align=(1.0, 0.5)) 71 span_size=200, size_hint_align=(1.0, 0.5))
70 box2.pack_end(pb1) 72 box2.pack_end(pb1)
71 pb1.show() 73 pb1.show()
72 74
73 pb2 = Progressbar(popup, text='active', 75 pb2 = Progressbar(box2, text='active',
74 span_size=200, size_hint_align=(1.0, 0.5)) 76 span_size=200, size_hint_align=(1.0, 0.5))
75 box2.pack_end(pb2) 77 box2.pack_end(pb2)
76 pb2.show() 78 pb2.show()
77 79
78 pb3 = Progressbar(popup, text='buffers', 80 pb3 = Progressbar(box2, text='buffers',
79 span_size=200, size_hint_align=(1.0, 0.5)) 81 span_size=200, size_hint_align=(1.0, 0.5))
80 box2.pack_end(pb3) 82 box2.pack_end(pb3)
81 pb3.show() 83 pb3.show()
82 84
83 pb4 = Progressbar(popup, text='cached', 85 pb4 = Progressbar(box2, text='cached',
84 span_size=200, size_hint_align=(1.0, 0.5)) 86 span_size=200, size_hint_align=(1.0, 0.5))
85 box2.pack_end(pb4) 87 box2.pack_end(pb4)
86 pb4.show() 88 pb4.show()
87 89
88 # swap 90 # swap frame
89 tot = self.format_mb(psutil.swap_memory().total) 91 tot = self.format_mb(psutil.swap_memory().total)
90 fr = Frame(popup, text='Swap Usage (available {})'.format(tot), 92 fr = Frame(box, text='Swap Usage (available {})'.format(tot),
91 size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH) 93 size_hint_expand=EXPAND_BOTH, size_hint_fill=FILL_BOTH)
92 box.pack_end(fr) 94 box.pack_end(fr)
93 fr.show() 95 fr.show()
94 96
95 pb5 = Progressbar(popup) 97 pb5 = Progressbar(fr)
96 fr.content = pb5 98 fr.content = pb5
97 pb5.show() 99 pb5.show()
98 100
99 # force the popup to always recalculate it's size 101 # keep widget references in the popup
100 popup.update_hints = True 102 box.data['usd_pb'] = pb1
103 box.data['act_pb'] = pb2
104 box.data['buf_pb'] = pb3
105 box.data['cac_pb'] = pb4
106 box.data['swp_pb'] = pb5
101 107
102 # force the poller to update the popup now 108 self.popup_update(box)
103 popup.data['usd_pb'] = pb1 109 return box
104 popup.data['act_pb'] = pb2
105 popup.data['buf_pb'] = pb3
106 popup.data['cac_pb'] = pb4
107 popup.data['swp_pb'] = pb5
108 self.poller_cb(force=True)
109 110
110 def poller_cb(self, force=False): 111 def popup_update(self, popup):
111 mem = psutil.virtual_memory() 112 self.update_pb(popup.data['usd_pb'], self.mem.used, self.mem.total)
112 swp = psutil.swap_memory() 113 active = self.mem.used - self.mem.buffers - self.mem.cached
114 self.update_pb(popup.data['act_pb'], active, self.mem.total)
115 self.update_pb(popup.data['buf_pb'], self.mem.buffers, self.mem.total)
116 self.update_pb(popup.data['cac_pb'], self.mem.cached, self.mem.total)
117 self.update_pb(popup.data['swp_pb'], self.swp.used, self.swp.total)
113 118
114 if force or mem.percent != self.mem or swp.percent != self.swp: 119 def poller_cb(self):
115 for obj in self._instances: 120 self.mem = psutil.virtual_memory()
116 obj.message_send(0, (mem.percent, swp.percent)) 121 self.swp = psutil.swap_memory()
117 122
118 for popup in self._popups: 123 for obj in self._instances:
119 self.update_pb(popup.data['usd_pb'], mem.used, mem.total) 124 obj.message_send(0, (self.mem.percent, self.swp.percent))
120 active = mem.used - mem.buffers - mem.cached
121 self.update_pb(popup.data['act_pb'], active, mem.total)
122 self.update_pb(popup.data['buf_pb'], mem.buffers, mem.total)
123 self.update_pb(popup.data['cac_pb'], mem.cached, mem.total)
124 self.update_pb(popup.data['swp_pb'], swp.used, swp.total)
125 125
126 self.mem = mem.percent 126 for popup in self._popups:
127 self.swp = swp.percent 127 self.popup_update(popup)
128 128
129 return ecore.ECORE_CALLBACK_RENEW 129 return ecore.ECORE_CALLBACK_RENEW
130 130
@@ -135,4 +135,3 @@ class Gadget(e.Gadget):
135 pb.value = val / total 135 pb.value = val / total
136 pb.unit_format = '{0} ({1:.0f} %%)'.format(self.format_mb(val), 136 pb.unit_format = '{0} ({1:.0f} %%)'.format(self.format_mb(val),
137 val / total * 100) 137 val / total * 100)
138
diff --git a/GADGETS/mem/mem.edc b/GADGETS/mem/mem.edc
index 14a2b5c..11a622c 100644
--- a/GADGETS/mem/mem.edc
+++ b/GADGETS/mem/mem.edc
@@ -131,16 +131,4 @@ collections {
131 #undef LED 131 #undef LED
132 } 132 }
133 } 133 }
134
135/**
136 * API [e/gadget/popup] This is the group that will be placed inside popups
137 */
138 group { name: "e/gadgets/mem/popup";
139 parts {
140 swallow { "main.swallow";
141 desc { "default";
142 }
143 }
144 }
145 }
146} 134}
diff --git a/GADGETS/netspeed/__init__.py b/GADGETS/netspeed/__init__.py
index 1f698b6..3b28919 100644
--- a/GADGETS/netspeed/__init__.py
+++ b/GADGETS/netspeed/__init__.py
@@ -12,31 +12,37 @@ from efl.evas import EXPAND_BOTH, EXPAND_HORIZ, FILL_BOTH
12 12
13 13
14__gadget_name__ = 'Network Speed Monitor' 14__gadget_name__ = 'Network Speed Monitor'
15__gadget_vers__ = '0.1' 15__gadget_vers__ = '0.2'
16__gadget_auth__ = 'DaveMDS' 16__gadget_auth__ = 'DaveMDS'
17__gadget_mail__ = 'dave@gurumeditation.it' 17__gadget_mail__ = 'dave@gurumeditation.it'
18__gadget_desc__ = 'Network speed monitor' 18__gadget_desc__ = 'Network speed monitor'
19__gadget_vapi__ = 1 19__gadget_vapi__ = 2
20__gadget_opts__ = { 'popup_on_desktop': False } 20__gadget_opts__ = { 'popup_on_desktop': False }
21 21
22 22
23# import sys 23# import sys
24# def DBG(msg): 24# def DBG(msg):
25 # print("NETSPEED: %s" % msg) 25# print("NETSPEED: %s" % msg)
26 # sys.stdout.flush() 26# sys.stdout.flush()
27 27
28 28
29class Gadget(e.Gadget): 29class Gadget(e.Gadget):
30 30
31 def __init__(self): 31 def __init__(self):
32 # DBG("init")
32 super().__init__() 33 super().__init__()
33 self.poller = None 34 self.poller = None
34 self.last_in = 0 35 self.last_in = 0
35 self.last_out = 0 36 self.last_out = 0
36 self.last_time = 0 37 self.last_time = 0
38 self.kb_in = 0
39 self.kb_out = 0
40 self.in_perc = 0
41 self.out_perc = 0
37 42
38 def instance_created(self, obj, site): 43 def instance_created(self, obj, site):
39 super().instance_created(obj, site) 44 super().instance_created(obj, site)
45 # DBG("instance_created (insts: %d popups:%d)" % (len(self._instances), len(self._popups)))
40 obj.size_hint_aspect = evas.EVAS_ASPECT_CONTROL_BOTH, 16, 16 46 obj.size_hint_aspect = evas.EVAS_ASPECT_CONTROL_BOTH, 16, 16
41 47
42 if self.poller is None: 48 if self.poller is None:
@@ -45,49 +51,52 @@ class Gadget(e.Gadget):
45 51
46 def instance_destroyed(self, obj): 52 def instance_destroyed(self, obj):
47 super().instance_destroyed(obj) 53 super().instance_destroyed(obj)
54 # DBG("instance_destroyed (insts: %d popups:%d)" % (len(self._instances), len(self._popups)))
48 if len(self._instances) < 1 and self.poller is not None: 55 if len(self._instances) < 1 and self.poller is not None:
49 self.poller.delete() 56 self.poller.delete()
50 self.poller = None 57 self.poller = None
51 58
52 def popup_created(self, popup): 59 def popup_created(self, elm_parent):
53 super().popup_created(popup) 60 # DBG("popup_created (insts: %d popups:%d)" % (len(self._instances), len(self._popups)))
54 61
55 box = elm.Box(popup) 62 box = elm.Box(elm_parent)
56 popup.part_swallow('main.swallow', box)
57 box.show() 63 box.show()
58 64
59 in_label = elm.Label(popup, size_hint_expand=EXPAND_HORIZ) 65 in_label = elm.Label(box, size_hint_expand=EXPAND_HORIZ, text="asd")
60 box.pack_end(in_label) 66 box.pack_end(in_label)
61 in_label.show() 67 in_label.show()
62 68
63 out_label = elm.Label(popup, size_hint_expand=EXPAND_HORIZ) 69 out_label = elm.Label(box, size_hint_expand=EXPAND_HORIZ, text="asd")
64 box.pack_end(out_label) 70 box.pack_end(out_label)
65 out_label.show() 71 out_label.show()
66 72
67 popup.data['in_label'] = in_label 73 box.data['in_label'] = in_label
68 popup.data['out_label'] = out_label 74 box.data['out_label'] = out_label
69 75
70 # tell the popup to always recalculate it's size 76 self.popup_update(box)
71 popup.update_hints = True 77 return box
72 78
73 # do an update now 79 def popup_destroyed(self, obj):
74 self.poller_cb() 80 # DBG("popup_destroyed (insts: %d popups:%d)" % (len(self._instances), len(self._popups)))
81
82 def popup_update(self, popup):
83 popup.data['in_label'].text = 'Recv: %.2f KB/s' % self.kb_in
84 popup.data['out_label'].text = 'Trans: %.2f KB/s' % self.kb_out
75 85
76 def poller_cb(self): 86 def poller_cb(self):
77 byte_per_second_in, byte_per_second_out = self.parse_proc() 87 byte_per_second_in, byte_per_second_out = self.parse_proc()
78 88
79 kb_in = byte_per_second_in / 1000.0 89 self.kb_in = byte_per_second_in / 1000.0
80 kb_out = byte_per_second_out / 1000.0 90 self.kb_out = byte_per_second_out / 1000.0
81 91
82 in_perc = int(kb_in / 1000 * 100) # TODO CONFIGURABLE MAX 92 self.in_perc = int(self.kb_in / 1000 * 100) # TODO CONFIGURABLE MAX
83 out_perc = int(kb_out / 1000 * 100) # TODO CONFIGURABLE MAX 93 self.out_perc = int(self.kb_out / 1000 * 100) # TODO CONFIGURABLE MAX
84 94
85 for obj in self._instances: 95 for obj in self._instances:
86 obj.message_send(1, (0, in_perc, 0, 0, out_perc, 0)) 96 obj.message_send(1, (0, self.in_perc, 0, 0, self.out_perc, 0))
87 97
88 for popup in self._popups: 98 for popup in self._popups:
89 popup.data['in_label'].text = 'Recv: %.2f KB/s' % kb_in 99 self.popup_update(popup)
90 popup.data['out_label'].text = 'Trans: %.2f KB/s' % kb_out
91 100
92 return ecore.ECORE_CALLBACK_RENEW 101 return ecore.ECORE_CALLBACK_RENEW
93 102
diff --git a/GADGETS/netspeed/netspeed.edc b/GADGETS/netspeed/netspeed.edc
index c43708c..5053205 100644
--- a/GADGETS/netspeed/netspeed.edc
+++ b/GADGETS/netspeed/netspeed.edc
@@ -16,7 +16,6 @@ images {
16 image: "over.png" COMP; 16 image: "over.png" COMP;
17 image: "rx.png" COMP; 17 image: "rx.png" COMP;
18 image: "tx.png" COMP; 18 image: "tx.png" COMP;
19 // TODO gadget icon
20} 19}
21 20
22 21
@@ -30,7 +29,7 @@ collections {
30 desc { "default"; 29 desc { "default";
31 aspect: 1.0 1.0; 30 aspect: 1.0 1.0;
32 aspect_preference: BOTH; 31 aspect_preference: BOTH;
33 image.normal: "base.png"; // TODO gadget icon 32 image.normal: "base.png";
34 } 33 }
35 } 34 }
36 } 35 }
@@ -123,45 +122,4 @@ collections {
123 } 122 }
124 } 123 }
125 } 124 }
126
127/**
128 * API [e/gadget/popup] This is the group that will be placed inside popups
129 */
130 group { name: "e/gadgets/netspeed/popup";
131 parts {
132 // part { name: "label"; type: TEXTBLOCK;
133 // description { state: "default" 0.0;
134 // text {
135 // text: "";
136 // font: "sans";
137 // size: 12;
138 // text_class: "";
139 // min: 1 1;
140 // ellipsis: -1;
141 // }
142 // }
143 // }
144 // part { name: "out_label"; type: TEXT;
145 // description { state: "default" 0.0;
146 // rel1.to_y: "in_label";
147 // rel1.relative: 0.0 1.0;
148 // rel2.to_y: "in_label";
149 // rel2.relative: 1.0 1.0;
150 // text {
151 // text: "";
152 // font: "sans";
153 // size: 12;
154 // text_class: "";
155 // min: 1 1;
156 // ellipsis: -1;
157 // }
158 // }
159 // }
160
161 swallow { "main.swallow";
162 desc { "default";
163 }
164 }
165 }
166 }
167} 125}