davemds pushed a commit to branch master.

http://git.enlightenment.org/enlightenment/modules/edgar.git/commit/?id=b803a06a31ba287184739cf187abb1d0702c97b3

commit b803a06a31ba287184739cf187abb1d0702c97b3
Author: Dave Andreoli <d...@gurumeditation.it>
Date:   Sat Sep 12 16:26:50 2015 +0200

    Mem gadget: add a popup with exensive info
---
 GADGETS/mem/__init__.py | 96 ++++++++++++++++++++++++++++++++++++++++++++-----
 GADGETS/mem/mem.edc     | 10 +-----
 2 files changed, 89 insertions(+), 17 deletions(-)

diff --git a/GADGETS/mem/__init__.py b/GADGETS/mem/__init__.py
index 4dce6c6..300e273 100644
--- a/GADGETS/mem/__init__.py
+++ b/GADGETS/mem/__init__.py
@@ -7,6 +7,8 @@ import e
 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, Frame, Progressbar
 
 
 __gadget_name__ = 'Memory Monitor'
@@ -45,14 +47,92 @@ class Gadget(e.Gadget):
             self.poller.delete()
             self.poller = None
 
-    def poller_cb(self):
-        mem = psutil.virtual_memory().percent
-        swp = psutil.swap_memory().percent
-
-        if mem != self.mem or swp != self.swp:
+    def popup_created(self, popup):
+        super().popup_created(popup)
+
+        box = Box(popup)
+        popup.part_swallow('main.swallow', box)
+        box.show()
+
+        # mem
+        tot = self.format_mb(psutil.virtual_memory().total)
+        fr = Frame(popup, 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)
+        fr.content = box2
+        box2.show()
+
+        pb1 = Progressbar(popup, text='Total used',
+                          span_size=200, size_hint_align=(1.0, 0.5))
+        box2.pack_end(pb1)
+        pb1.show()
+
+        pb2 = Progressbar(popup, text='active',
+                          span_size=200, size_hint_align=(1.0, 0.5))
+        box2.pack_end(pb2)
+        pb2.show()
+
+        pb3 = Progressbar(popup, text='buffers',
+                          span_size=200, size_hint_align=(1.0, 0.5))
+        box2.pack_end(pb3)
+        pb3.show()
+
+        pb4 = Progressbar(popup, text='cached',
+                          span_size=200, size_hint_align=(1.0, 0.5))
+        box2.pack_end(pb4)
+        pb4.show()
+
+        # swap
+        tot = self.format_mb(psutil.swap_memory().total)
+        fr = Frame(popup, 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)
+        fr.content = pb5
+        pb5.show()
+
+        # force the popup to always recalculate it's size
+        popup.update_hints = True
+
+        # 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)
+
+    def poller_cb(self, force=False):
+        mem = psutil.virtual_memory()
+        swp = psutil.swap_memory()
+
+        if force or mem.percent != self.mem or swp.percent != self.swp:
             for obj in self._instances:
-                obj.message_send(0, (mem, swp))
-            self.mem = mem
-            self.swp = swp
+                obj.message_send(0, (mem.percent, swp.percent))
+
+            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)
+
+            self.mem = mem.percent
+            self.swp = swp.percent
 
         return ecore.ECORE_CALLBACK_RENEW
+
+    def format_mb(self, val):
+        return '{0:.0f} MB'.format(val / 1048576)
+
+    def update_pb(self, pb, val, total):
+        pb.value = val / total
+        pb.unit_format = '{0} ({1:.0f} %%)'.format(self.format_mb(val),
+                                                   val / total * 100)
+        
diff --git a/GADGETS/mem/mem.edc b/GADGETS/mem/mem.edc
index 055b2df..14a2b5c 100644
--- a/GADGETS/mem/mem.edc
+++ b/GADGETS/mem/mem.edc
@@ -135,20 +135,12 @@ collections {
 /**
  *  API [e/gadget/popup] This is the group that will be placed inside popups
  */
-/*
    group { name: "e/gadgets/mem/popup";
-      min: 310 0;
       parts {
-         box { "popup.box";
+         swallow { "main.swallow";
             desc { "default";
-               box {
-                  layout: "vertical";
-                  padding: 0 6;
-                  min: 1 1;
-               }
             }
          }
       }
    }
-*/
 }

-- 


Reply via email to