davemds pushed a commit to branch master. http://git.enlightenment.org/enlightenment/modules/edgar.git/commit/?id=e396e51f337d2ecfe12c359a983a398c229419b3
commit e396e51f337d2ecfe12c359a983a398c229419b3 Author: Dave Andreoli <[email protected]> Date: Wed Sep 9 21:42:51 2015 +0200 Add a multicore CPU monitor gadget. As always this prove the coolness of edgar :) the whole gadget are just 69 lines of python code (plus 150 of the edc) A bit more of info at: https://phab.enlightenment.org/w/emodules/edgar/ --- GADGETS/cpu/Makefile | 36 +++++++++ GADGETS/cpu/__init__.py | 68 ++++++++++++++++ GADGETS/cpu/cpu.edc | 168 +++++++++++++++++++++++++++++++++++++++ GADGETS/cpu/images/bar_bg.png | Bin 0 -> 664 bytes GADGETS/cpu/images/cpu.png | Bin 0 -> 2137 bytes GADGETS/cpu/images/green_on.png | Bin 0 -> 284 bytes GADGETS/cpu/images/mockup.xcf | Bin 0 -> 67599 bytes GADGETS/cpu/images/red_on.png | Bin 0 -> 276 bytes GADGETS/cpu/images/yellow_on.png | Bin 0 -> 284 bytes 9 files changed, 272 insertions(+) diff --git a/GADGETS/cpu/Makefile b/GADGETS/cpu/Makefile new file mode 100644 index 0000000..26d1f77 --- /dev/null +++ b/GADGETS/cpu/Makefile @@ -0,0 +1,36 @@ +# Simple Makefile for Enlightenment (edgar) gadgets + +# gadget specific config +GADGET_NAME = cpu +EXTRA_FILES = + + +# nothing should be changed below this point +GADGET_FILES = __init__.pyc $(GADGET_NAME).edj +prefix = $(shell pkg-config --variable=libdir enlightenment) +gadget_folder = ${prefix}/enlightenment/gadgets/$(GADGET_NAME) + +.PHONY: all install clean + +all: $(GADGET_FILES) $(EXTRA_FILES) + +install: all + @mkdir -p -v ${gadget_folder} + @cp --preserve=mode -v $(GADGET_FILES) $(EXTRA_FILES) $(gadget_folder) + +uninstall: all + @rm -rfv ${gadget_folder} + +clean: + @rm -fv *.edj *.pyc + + +EDJE_CC = edje_cc +EDJE_FLAGS = -v -id images/ -fd fonts/ + +%.edj: %.edc images/* + $(EDJE_CC) $(EDJE_FLAGS) $< + @chmod -v og+r $@ + +%.pyc: %.py + python3 -c "from py_compile import compile; compile('$<', '$@')" diff --git a/GADGETS/cpu/__init__.py b/GADGETS/cpu/__init__.py new file mode 100644 index 0000000..5fc5aa7 --- /dev/null +++ b/GADGETS/cpu/__init__.py @@ -0,0 +1,68 @@ +# This python file use the following encoding: utf-8 + +import psutil + +import e + +from efl import ecore +from efl import evas +from efl import edje +from efl.evas import EXPAND_BOTH, FILL_BOTH + + +__gadget_name__ = 'CPU Monitor' +__gadget_vers__ = '0.1' +__gadget_auth__ = 'DaveMDS' +__gadget_mail__ = '[email protected]' +__gadget_desc__ = 'Multicore CPU monitor' +__gadget_vapi__ = 1 +__gadget_opts__ = { 'popup_on_desktop': False } + + + +class Gadget(e.Gadget): + + def __init__(self): + super().__init__() + + self.num_cores = psutil.cpu_count() + self.aspect = None + self.poller = None + + def instance_created(self, obj, site): + super().instance_created(obj, site) + + if self.aspect is None: + w, h = obj.data_get('aspect_w'), obj.data_get('aspect_h') + self.aspect = int(w), int(h) + + obj.data['bars'] = list() + for i in range(self.num_cores): + bar = edje.Edje(obj.evas, size_hint_expand=EXPAND_BOTH, + size_hint_fill=FILL_BOTH) + e.theme_object_set(bar, 'cpu', 'bar') + obj.part_box_append('main.box', bar) + bar.show() + obj.data['bars'].append(bar) + + obj.size_hint_aspect = (evas.EVAS_ASPECT_CONTROL_BOTH, + self.aspect[0] * self.num_cores, self.aspect[1]) + + if self.poller is None: + self.poller = ecore.Poller(8, self.poller_cb, ecore.ECORE_POLLER_CORE) + + def instance_destroyed(self, obj): + super().instance_destroyed(obj) + + if len(self._instances) < 1 and self.poller is not None: + self.poller.delete() + self.poller = None + + def poller_cb(self): + percents = psutil.cpu_percent(percpu=True) + + for obj in self._instances: + for i, bar in enumerate(obj.data['bars']): + bar.message_send(0, percents[i]) + + return ecore.ECORE_CALLBACK_RENEW diff --git a/GADGETS/cpu/cpu.edc b/GADGETS/cpu/cpu.edc new file mode 100644 index 0000000..6686263 --- /dev/null +++ b/GADGETS/cpu/cpu.edc @@ -0,0 +1,168 @@ +/** + * EDGAR Dropbox Gadget + */ + +#define DBG_SHOW(_PART, _R, _G, _B) \ + part { name: "dbg_show"_PART; \ + type: RECT; mouse_events: 0; \ + description { state: "default" 0.0; \ + rel1.to: _PART; rel2.to: _PART; \ + color: _R _G _B 50; } } + +#define SHOW(_PART) DBG_SHOW(_PART, 50, 0, 0) + +images { + image: "cpu.png" COMP; + image: "bar_bg.png" COMP; + image: "green_on.png" COMP; + image: "yellow_on.png" COMP; + image: "red_on.png" COMP; +} + + +collections { +/** + * API [e/gadget/icon] The group used for the icon of the gadget + */ + group { name: "e/gadgets/cpu/icon"; + parts { + image { "icon"; + desc { "default"; + aspect: 1.0 1.0; + aspect_preference: BOTH; + image.normal: "cpu.png"; + } + } + } + } + +/** + * API [e/gadget/main] The main group of the gadget + */ + group { name: "e/gadgets/cpu/main"; + data { + item: "aspect_w" "10"; + item: "aspect_h" "54"; + } + parts { + box { "main.box"; + desc { "default"; + box.layout: "horizontal"; + box.min: 1 1; + } + } + } + } + + group { name: "e/gadgets/cpu/bar"; + script { + public message(Msg_Type:type, id, ...) { + if ((type == MSG_FLOAT) && (id == 0)) { + new Float:val = getfarg(2); + + if (val > (100 / 7 * 1)) set_state(PART:"led1", "on", 0.0); + else set_state(PART:"led1", "default", 0.0); + if (val > (100 / 7 * 2)) set_state(PART:"led2", "on", 0.0); + else set_state(PART:"led2", "default", 0.0); + if (val > (100 / 7 * 3)) set_state(PART:"led3", "on", 0.0); + else set_state(PART:"led3", "default", 0.0); + if (val > (100 / 7 * 4)) set_state(PART:"led4", "on", 0.0); + else set_state(PART:"led4", "default", 0.0); + if (val > (100 / 7 * 5)) set_state(PART:"led5", "on", 0.0); + else set_state(PART:"led5", "default", 0.0); + if (val > (100 / 7 * 6)) set_state(PART:"led6", "on", 0.0); + else set_state(PART:"led6", "default", 0.0); + + // custom_state(PART:"test_bar", "default", 0.0); + // set_state_val(PART:"test_bar", STATE_REL1, 0.0, 1.0 - val / 100); + // set_state(PART:"test_bar", "custom", 0.0); + } + } + } + parts { + part { name: "bg"; + desc { "default"; + color: 255 255 255 200; + aspect: (10 / 54) (10 / 54); aspect_preference: BOTH; + image.normal: "bar_bg.png"; + } + part { name: "led1"; + desc { "default"; hid; + rel1.relative: 0.0 (1.0 / 6 * 5); + rel2.relative: 1.0 (1.0 / 6 * 6); + image.normal: "green_on.png"; + } + desc { "on"; inherit: "default"; vis; } + } + part { name: "led2"; + desc { "default"; hid; + rel1.relative: 0.0 (1.0 / 6 * 4); + rel2.relative: 1.0 (1.0 / 6 * 5); + image.normal: "green_on.png"; + } + desc { "on"; inherit: "default"; vis; } + } + part { name: "led3"; + desc { "default"; hid; + rel1.relative: 0.0 (1.0 / 6 * 3); + rel2.relative: 1.0 (1.0 / 6 * 4); + image.normal: "green_on.png"; + } + desc { "on"; inherit: "default"; vis; } + } + part { name: "led4"; + desc { "default"; hid; + rel1.relative: 0.0 (1.0 / 6 * 2); + rel2.relative: 1.0 (1.0 / 6 * 3); + image.normal: "yellow_on.png"; + } + desc { "on"; inherit: "default"; vis; } + } + part { name: "led5"; + desc { "default"; hid; + rel1.relative: 0.0 (1.0 / 6 * 1); + rel2.relative: 1.0 (1.0 / 6 * 2); + image.normal: "yellow_on.png"; + } + desc { "on"; inherit: "default"; vis; } + } + part { name: "led6"; + desc { "default"; hid; + rel1.relative: 0.0 (1.0 / 6 * 0); + rel2.relative: 1.0 (1.0 / 6 * 1); + image.normal: "red_on.png"; + } + desc { "on"; inherit: "default"; vis; } + } + } + // rect { "test_bar"; + // desc { "default"; + // color: 255 255 255 50; + // rel1.relative: 0.0 1.0; + // rel1.to: "bg"; + // rel2.to: "bg"; + // } + // } + } + } + +/** + * API [e/gadget/popup] This is the group that will be placed inside popups + */ +/* + group { name: "e/gadgets/cpu/popup"; + min: 310 0; + parts { + box { "popup.box"; + desc { "default"; + box { + layout: "vertical"; + padding: 0 6; + min: 1 1; + } + } + } + } + } +*/ +} diff --git a/GADGETS/cpu/images/bar_bg.png b/GADGETS/cpu/images/bar_bg.png new file mode 100644 index 0000000..ca9a29a Binary files /dev/null and b/GADGETS/cpu/images/bar_bg.png differ diff --git a/GADGETS/cpu/images/cpu.png b/GADGETS/cpu/images/cpu.png new file mode 100644 index 0000000..5c58cfe Binary files /dev/null and b/GADGETS/cpu/images/cpu.png differ diff --git a/GADGETS/cpu/images/green_on.png b/GADGETS/cpu/images/green_on.png new file mode 100644 index 0000000..10a57bd Binary files /dev/null and b/GADGETS/cpu/images/green_on.png differ diff --git a/GADGETS/cpu/images/mockup.xcf b/GADGETS/cpu/images/mockup.xcf new file mode 100644 index 0000000..ec00d27 Binary files /dev/null and b/GADGETS/cpu/images/mockup.xcf differ diff --git a/GADGETS/cpu/images/red_on.png b/GADGETS/cpu/images/red_on.png new file mode 100644 index 0000000..aaba514 Binary files /dev/null and b/GADGETS/cpu/images/red_on.png differ diff --git a/GADGETS/cpu/images/yellow_on.png b/GADGETS/cpu/images/yellow_on.png new file mode 100644 index 0000000..8a6e9e9 Binary files /dev/null and b/GADGETS/cpu/images/yellow_on.png differ --
