diff --git a/configure.ac b/configure.ac index 73074d43..371fc41d 100644 --- a/configure.ac +++ b/configure.ac @@ -60,19 +60,19 @@ services/presence/Makefile services/nm/Makefile services/clipboard/Makefile services/datastore/Makefile -shell/Makefile -shell/data/Makefile -shell/view/Makefile -shell/view/home/Makefile -shell/view/frame/Makefile -shell/model/Makefile +shell/console/lib/Makefile +shell/console/lib/procmem/Makefile shell/console/Makefile -shell/console/plugins/Makefile -shell/console/plugins/clean_size/Makefile -shell/console/plugins/cpu/Makefile -shell/console/plugins/dirty_size/Makefile -shell/console/plugins/memphis_init/Makefile -shell/console/procmem/Makefile +shell/console/interface/Makefile +shell/console/interface/xo/Makefile +shell/console/interface/memphis/plugins/clean_size/Makefile +shell/console/interface/memphis/plugins/dirty_size/Makefile +shell/console/interface/memphis/plugins/Makefile +shell/console/interface/memphis/plugins/memphis_init/Makefile +shell/console/interface/memphis/plugins/cpu/Makefile +shell/console/interface/memphis/Makefile +shell/console/interface/logviewer/Makefile +shell/console/interface/terminal/Makefile sugar/Makefile sugar/__installed__.py sugar/activity/Makefile diff --git a/shell/console/Makefile.am b/shell/console/Makefile.am index 5b838301..19c9ce91 100644 --- a/shell/console/Makefile.am +++ b/shell/console/Makefile.am @@ -1,10 +1,6 @@ -SUBDIRS = plugins procmem +SUBDIRS = interface lib sugardir = $(pkgdatadir)/shell/console sugar_PYTHON = \ __init__.py \ - console.py \ - memphis.py \ - logviewer.py \ - terminal.py \ - plugin.py + console.py diff --git a/shell/console/console.py b/shell/console/console.py index a95425cb..a8568c1b 100755 --- a/shell/console/console.py +++ b/shell/console/console.py @@ -17,12 +17,17 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +import sys, os import gtk +sys.path.append(os.path.dirname(__file__) + '/lib') +sys.path.append(os.path.dirname(__file__) + '/interface') + # Console interfaces -import memphis -import logviewer -import terminal +from xo import xo +from memphis import memphis +from logviewer import logviewer +from terminal import terminal window = gtk.Window() window.set_title('Developer console') @@ -36,6 +41,10 @@ window.set_default_size(width, height) window.realize() window.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG) +# XO Interface +xo_widget = xo.Interface().widget +xo_widget.show() + # Memphis interface memphis_widget = memphis.Interface().widget memphis_widget.show() @@ -50,6 +59,7 @@ terminal_widget.show() # Notebook notebook = gtk.Notebook() +notebook.append_page(xo_widget, gtk.Label('XO Resources')) notebook.append_page(memphis_widget, gtk.Label('Memphis')) notebook.append_page(logviewer_widget, gtk.Label('Log Viewer')) notebook.append_page(terminal_widget, gtk.Label('Terminal')) diff --git a/shell/console/interface/Makefile.am b/shell/console/interface/Makefile.am new file mode 100644 index 00000000..2654a4b0 --- /dev/null +++ b/shell/console/interface/Makefile.am @@ -0,0 +1,6 @@ +SUBDIRS = memphis logviewer terminal xo + +sugardir = $(pkgdatadir)/shell/console/interface +sugar_PYTHON = \ + __init__.py + diff --git a/shell/console/procmem/__init__.py b/shell/console/interface/__init__.py similarity index 100% rename from shell/console/procmem/__init__.py rename to shell/console/interface/__init__.py diff --git a/shell/console/interface/logviewer/Makefile.am b/shell/console/interface/logviewer/Makefile.am new file mode 100644 index 00000000..e6a69796 --- /dev/null +++ b/shell/console/interface/logviewer/Makefile.am @@ -0,0 +1,4 @@ +sugardir = $(pkgdatadir)/shell/console/interface/logviewer +sugar_PYTHON = \ + __init__.py \ + logviewer.py diff --git a/shell/console/interface/logviewer/__init__.py b/shell/console/interface/logviewer/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shell/console/logviewer.py b/shell/console/interface/logviewer/logviewer.py similarity index 100% rename from shell/console/logviewer.py rename to shell/console/interface/logviewer/logviewer.py diff --git a/shell/console/interface/memphis/Makefile.am b/shell/console/interface/memphis/Makefile.am new file mode 100644 index 00000000..319dad68 --- /dev/null +++ b/shell/console/interface/memphis/Makefile.am @@ -0,0 +1,8 @@ +SUBDIRS = plugins + +sugardir = $(pkgdatadir)/shell/console/interface/memphis +sugar_PYTHON = \ + __init__.py \ + memphis.py \ + plugin.py + diff --git a/shell/console/interface/memphis/__init__.py b/shell/console/interface/memphis/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shell/console/memphis.py b/shell/console/interface/memphis/memphis.py similarity index 100% rename from shell/console/memphis.py rename to shell/console/interface/memphis/memphis.py diff --git a/shell/console/plugin.py b/shell/console/interface/memphis/plugin.py old mode 100755 new mode 100644 similarity index 96% rename from shell/console/plugin.py rename to shell/console/interface/memphis/plugin.py index 62ed947c..5ee8eb7e --- a/shell/console/plugin.py +++ b/shell/console/interface/memphis/plugin.py @@ -2,9 +2,7 @@ # Memphis Plugin Support ############################################### -import sys, os, time -import gtk, gobject - +import sys, os from procmem import proc, proc_smaps, analysis class Plugin: @@ -47,4 +45,4 @@ class Plugin: def proc_analysis(self, pid): return analysis.Analysis(pid) - \ No newline at end of file + diff --git a/shell/console/plugins/Makefile.am b/shell/console/interface/memphis/plugins/Makefile.am similarity index 50% rename from shell/console/plugins/Makefile.am rename to shell/console/interface/memphis/plugins/Makefile.am index 8d71fb86..2c6b1ddf 100644 --- a/shell/console/plugins/Makefile.am +++ b/shell/console/interface/memphis/plugins/Makefile.am @@ -1,4 +1,4 @@ SUBDIRS = clean_size cpu dirty_size memphis_init -sugardir = $(pkgdatadir)/shell/console/plugins +sugardir = $(pkgdatadir)/shell/console/interface/memphis/plugins sugar_PYTHON = diff --git a/shell/console/interface/memphis/plugins/clean_size/Makefile.am b/shell/console/interface/memphis/plugins/clean_size/Makefile.am new file mode 100644 index 00000000..33565f5c --- /dev/null +++ b/shell/console/interface/memphis/plugins/clean_size/Makefile.am @@ -0,0 +1,6 @@ + +sugardir = $(pkgdatadir)/shell/console/interface/memphis/plugins/clean_size +sugar_PYTHON = \ + README \ + __init__.py \ + info.py diff --git a/shell/console/plugins/clean_size/README b/shell/console/interface/memphis/plugins/clean_size/README similarity index 100% rename from shell/console/plugins/clean_size/README rename to shell/console/interface/memphis/plugins/clean_size/README diff --git a/shell/console/plugins/clean_size/__init__.py b/shell/console/interface/memphis/plugins/clean_size/__init__.py similarity index 100% rename from shell/console/plugins/clean_size/__init__.py rename to shell/console/interface/memphis/plugins/clean_size/__init__.py diff --git a/shell/console/plugins/clean_size/info.py b/shell/console/interface/memphis/plugins/clean_size/info.py similarity index 100% rename from shell/console/plugins/clean_size/info.py rename to shell/console/interface/memphis/plugins/clean_size/info.py diff --git a/shell/console/interface/memphis/plugins/cpu/Makefile.am b/shell/console/interface/memphis/plugins/cpu/Makefile.am new file mode 100644 index 00000000..58e9eab5 --- /dev/null +++ b/shell/console/interface/memphis/plugins/cpu/Makefile.am @@ -0,0 +1,6 @@ + +sugardir = $(pkgdatadir)/shell/console/interface/memphis/plugins/cpu +sugar_PYTHON = \ + README \ + __init__.py \ + info.py diff --git a/shell/console/plugins/cpu/README b/shell/console/interface/memphis/plugins/cpu/README similarity index 100% rename from shell/console/plugins/cpu/README rename to shell/console/interface/memphis/plugins/cpu/README diff --git a/shell/console/plugins/cpu/__init__.py b/shell/console/interface/memphis/plugins/cpu/__init__.py similarity index 100% rename from shell/console/plugins/cpu/__init__.py rename to shell/console/interface/memphis/plugins/cpu/__init__.py diff --git a/shell/console/plugins/cpu/info.py b/shell/console/interface/memphis/plugins/cpu/info.py similarity index 100% rename from shell/console/plugins/cpu/info.py rename to shell/console/interface/memphis/plugins/cpu/info.py diff --git a/shell/console/interface/memphis/plugins/dirty_size/Makefile.am b/shell/console/interface/memphis/plugins/dirty_size/Makefile.am new file mode 100644 index 00000000..47c52983 --- /dev/null +++ b/shell/console/interface/memphis/plugins/dirty_size/Makefile.am @@ -0,0 +1,6 @@ + +sugardir = $(pkgdatadir)/shell/console/interface/memphis/plugins/dirty_size +sugar_PYTHON = \ + README \ + __init__.py \ + info.py diff --git a/shell/console/plugins/dirty_size/README b/shell/console/interface/memphis/plugins/dirty_size/README similarity index 100% rename from shell/console/plugins/dirty_size/README rename to shell/console/interface/memphis/plugins/dirty_size/README diff --git a/shell/console/plugins/dirty_size/__init__.py b/shell/console/interface/memphis/plugins/dirty_size/__init__.py similarity index 100% rename from shell/console/plugins/dirty_size/__init__.py rename to shell/console/interface/memphis/plugins/dirty_size/__init__.py diff --git a/shell/console/plugins/dirty_size/info.py b/shell/console/interface/memphis/plugins/dirty_size/info.py similarity index 100% rename from shell/console/plugins/dirty_size/info.py rename to shell/console/interface/memphis/plugins/dirty_size/info.py diff --git a/shell/console/interface/memphis/plugins/memphis_init/Makefile.am b/shell/console/interface/memphis/plugins/memphis_init/Makefile.am new file mode 100644 index 00000000..53b398a5 --- /dev/null +++ b/shell/console/interface/memphis/plugins/memphis_init/Makefile.am @@ -0,0 +1,6 @@ + +sugardir = $(pkgdatadir)/shell/console/interface/memphis/plugins/memphis_init +sugar_PYTHON = \ + README \ + __init__.py \ + info.py diff --git a/shell/console/plugins/memphis_init/README b/shell/console/interface/memphis/plugins/memphis_init/README similarity index 100% rename from shell/console/plugins/memphis_init/README rename to shell/console/interface/memphis/plugins/memphis_init/README diff --git a/shell/console/plugins/memphis_init/__init__.py b/shell/console/interface/memphis/plugins/memphis_init/__init__.py similarity index 100% rename from shell/console/plugins/memphis_init/__init__.py rename to shell/console/interface/memphis/plugins/memphis_init/__init__.py diff --git a/shell/console/plugins/memphis_init/info.py b/shell/console/interface/memphis/plugins/memphis_init/info.py similarity index 100% rename from shell/console/plugins/memphis_init/info.py rename to shell/console/interface/memphis/plugins/memphis_init/info.py diff --git a/shell/console/interface/terminal/Makefile.am b/shell/console/interface/terminal/Makefile.am new file mode 100644 index 00000000..8df46508 --- /dev/null +++ b/shell/console/interface/terminal/Makefile.am @@ -0,0 +1,5 @@ +sugardir = $(pkgdatadir)/shell/console/interface/terminal +sugar_PYTHON = \ + __init__.py \ + terminal.py + diff --git a/shell/console/interface/terminal/__init__.py b/shell/console/interface/terminal/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shell/console/terminal.py b/shell/console/interface/terminal/terminal.py similarity index 100% rename from shell/console/terminal.py rename to shell/console/interface/terminal/terminal.py diff --git a/shell/console/interface/xo/Makefile.am b/shell/console/interface/xo/Makefile.am new file mode 100644 index 00000000..b2035dda --- /dev/null +++ b/shell/console/interface/xo/Makefile.am @@ -0,0 +1,6 @@ +sugardir = $(pkgdatadir)/shell/console/interface/xo +sugar_PYTHON = \ + __init__.py \ + drwarea.py \ + xo.py + diff --git a/shell/console/interface/xo/__init__.py b/shell/console/interface/xo/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shell/console/interface/xo/drwarea.py b/shell/console/interface/xo/drwarea.py new file mode 100644 index 00000000..33976395 --- /dev/null +++ b/shell/console/interface/xo/drwarea.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +# Copyright (C) 2007, Eduardo Silva (edsiper@gmail.com). +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +############################################# +# Drawing area tools +############################################# + +import gtk +import gtk.gdk + +class Drawing_Area_Tools: + + height = 0 + width = 0 + + margin = 5 # Left and bottom margin + + range_x = [] + range_y = [] + + def __init__(self, drwarea): + drwarea_size = drwarea.get_size_request() + + self.width = drwarea_size[0] + self.height = drwarea_size[1] + + # print "width %i" % self.width + # print "height %i" % self.height + + self.range_x = {'from': self.margin+2, 'to': self.width - (self.margin+2)} + self.range_y = {'from': self.margin+2, 'to': self.height - (self.margin+2)} + + def draw_line(self, context, from_x, from_y, to_x, to_y): + context.move_to(from_x, from_y) + context.line_to(to_x, to_y) + + def draw_border_lines(self, context): + context.set_source_rgb(1, 1, 1) + self.draw_line(context, self.margin, self.margin, self.margin, self.height - self.margin) + self.draw_line(context, self.margin, self.height - self.margin - 1, self.width - self.margin, self.height - self.margin - 1) + context.stroke() + + # Draw a grid + def draw_grid(self, context, init_x, init_y, end_x, end_y): + + x_range = (end_x - init_x) + 5 + y_range = (end_y - init_y) + 1 + + current_y = init_y + context.set_line_width(0.3) + + for y in range(y_range): + if (y%20) == 0: + context.move_to(init_x, y) + context.line_to(end_x, y) + + for x in range(x_range): + if (x%20) == 0: + context.move_to(x, init_y) + context.line_to(x, end_y) + + context.stroke() diff --git a/shell/console/interface/xo/xo.py b/shell/console/interface/xo/xo.py new file mode 100644 index 00000000..f2a9cf9c --- /dev/null +++ b/shell/console/interface/xo/xo.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python + +# Copyright (C) 2007, Eduardo Silva (edsiper@gmail.com). +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import os +import gtk, gobject +import gtk.gdk +import cairo +import string +import drwarea + + +class CPU_Usage: + + CPU_HZ = 0 + last_jiffies = 0 + times = 0 + + def __init__(self): + self.CPU_hz = os.sysconf(2) + + def _get_CPU_data(self): + # Uptime info + stat_file = "/proc/stat" + + try: + infile = file(stat_file, "r") + except: + print "Error trying uptime file" + return -1 + + stat_line = infile.readline() + cpu_info = string.split(stat_line, ' ') + infile.close() + + return cpu_info + + def _get_CPU_usage(self): + + cpu_info = self._get_CPU_data() + + used_jiffies = (int(cpu_info[2]) + int(cpu_info[3]) + int(cpu_info[4])) + + if self.times ==0: + self.last_jiffies = used_jiffies + self.times +=1 + return True + + new_ujiffies = (used_jiffies - self.last_jiffies) + new_ajiffies = ((self.frequency/1000) * self.CPU_hz) + + if new_ajiffies <= 0: + pcpu = 0.0 + else: + pcpu = ((new_ujiffies*100)/new_ajiffies) + + if pcpu >100: + pcpu = 100 + + self.times +=1 + self.last_jiffies = used_jiffies + + return pcpu + +class Interface: + + context = None + frequency_timer = 1 + graph_offset = 7 + + def __init__(self): + + self.drw_width = gtk.gdk.screen_width() * 90 / 100 + self.drw_height = gtk.gdk.screen_height() * 20 / 100 + self.y_cpu = self.drw_height - self.graph_offset + self.drw_buffer = [] + + drawingarea = gtk.DrawingArea() + drawingarea.set_size_request(self.drw_width, self.drw_height) + drawingarea.connect("expose-event", self.do_expose) + + self.dat = drwarea.Drawing_Area_Tools(drawingarea) + + fixed = gtk.Fixed(); + fixed.set_border_width(10) + fixed.add(drawingarea) + + self.frame = gtk.Frame('System CPU Usage: 0%') + self.frame.set_border_width(10) + self.frame.add(fixed) + + self.widget = self.hbox = gtk.HBox(False, 3) + self.hbox.pack_start(self.frame, True, True, 0) + self.hbox.show_all() + + DRW_CPU = CPU_Usage() + DRW_CPU.frequency = 1000 # 1 Second + + gobject.timeout_add(DRW_CPU.frequency, self._draw_cpu_usage, DRW_CPU, drawingarea) + + def _draw_cpu_usage(self, DRW_CPU, drwarea): + # End of the graph ? + if ((self.frequency_timer + 1)*self.graph_offset) >= (self.drw_width - self.graph_offset): + self.frequency_timer = 1 + self.drw_buffer = [] + self.do_expose(drwarea, None) + + context = drwarea.window.cairo_create() + + from_x = self.frequency_timer * self.graph_offset + from_y = self.y_cpu + + self.frequency_timer += 1 + + pcpu = DRW_CPU._get_CPU_usage() + + self.drw_buffer.append(pcpu) + + to_x = self.frequency_timer * self.graph_offset + self.y_cpu = to_y = self._get_y_cpu(pcpu) + + # Context properties + context.set_line_width(2) + context.set_source_rgb(0,1,0) + + cpu_label = str(round(pcpu, 4)) + self.frame.set_label('System CPU Usage: ' + cpu_label + ' %') + + self.dat.draw_line(context, from_x, from_y, to_x, to_y) + context.stroke() + + return True + + def _get_y_cpu(self, pcpu): + + height = (self.dat.range_y['to']) - (self.dat.range_y['from']) + + # Get percent of cpu usage + y_value = (height - ((pcpu*height)/100) + 4) + + return int(y_value) + + def do_expose(self, widget, event): + + self.context = widget.window.cairo_create() + self.context.rectangle(0, 0, self.dat.width - 1, self.dat.height - 1) + + self.context.set_source_rgb (0,0,0) + self.context.fill_preserve() + + # Drawing horizontal and vertical border lines + self.dat.draw_border_lines(self.context) + + # Drawing grid + line_margin = self.dat.margin + self.context.set_source_rgb(1, 1, 1) + self.context.set_line_width(1) + self.dat.draw_grid(self.context, line_margin + 1, line_margin + 1, self.dat.width - line_margin - 2, self.dat.height - line_margin - 2) + self.context.stroke() + + self._draw_buffer(widget) + return False + + def _draw_buffer(self, drwarea): + freq = 1 # Frequency timer + last_y = self.drw_height - self.graph_offset + + context = drwarea.window.cairo_create() + for pcpu in self.drw_buffer: + + from_x = freq * self.graph_offset + from_y = last_y + + freq+=1 + + to_x = freq * self.graph_offset + last_y = to_y = self._get_y_cpu(pcpu) + + # Context properties + context.set_line_width(2) + context.set_source_rgb(0,1,0) + + self.dat.draw_line(context, from_x, from_y, to_x, to_y) + context.stroke() + diff --git a/shell/console/lib/Makefile.am b/shell/console/lib/Makefile.am new file mode 100644 index 00000000..16782d7c --- /dev/null +++ b/shell/console/lib/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS = procmem + +sugardir = $(pkgdatadir)/shell/console/lib +sugar_PYTHON = diff --git a/shell/console/procmem/Makefile.am b/shell/console/lib/procmem/Makefile.am similarity index 63% rename from shell/console/procmem/Makefile.am rename to shell/console/lib/procmem/Makefile.am index eface373..257c13fa 100644 --- a/shell/console/procmem/Makefile.am +++ b/shell/console/lib/procmem/Makefile.am @@ -1,5 +1,5 @@ -sugardir = $(pkgdatadir)/shell/console/procmem +sugardir = $(pkgdatadir)/shell/console/lib/procmem sugar_PYTHON = \ __init__.py \ diff --git a/shell/console/lib/procmem/__init__.py b/shell/console/lib/procmem/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/shell/console/procmem/analysis.py b/shell/console/lib/procmem/analysis.py similarity index 100% rename from shell/console/procmem/analysis.py rename to shell/console/lib/procmem/analysis.py diff --git a/shell/console/procmem/proc.py b/shell/console/lib/procmem/proc.py similarity index 100% rename from shell/console/procmem/proc.py rename to shell/console/lib/procmem/proc.py diff --git a/shell/console/procmem/proc_smaps.py b/shell/console/lib/procmem/proc_smaps.py similarity index 100% rename from shell/console/procmem/proc_smaps.py rename to shell/console/lib/procmem/proc_smaps.py diff --git a/shell/console/plugins/clean_size/Makefile.am b/shell/console/plugins/clean_size/Makefile.am deleted file mode 100644 index 9b0a7d0a..00000000 --- a/shell/console/plugins/clean_size/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ - -sugardir = $(pkgdatadir)/shell/console/plugins/clean_size -sugar_PYTHON = \ - README \ - __init__.py \ - info.py diff --git a/shell/console/plugins/cpu/Makefile.am b/shell/console/plugins/cpu/Makefile.am deleted file mode 100644 index e796a97a..00000000 --- a/shell/console/plugins/cpu/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ - -sugardir = $(pkgdatadir)/shell/console/plugins/cpu -sugar_PYTHON = \ - README \ - __init__.py \ - info.py diff --git a/shell/console/plugins/dirty_size/Makefile.am b/shell/console/plugins/dirty_size/Makefile.am deleted file mode 100644 index f97813e8..00000000 --- a/shell/console/plugins/dirty_size/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ - -sugardir = $(pkgdatadir)/shell/console/plugins/dirty_size -sugar_PYTHON = \ - README \ - __init__.py \ - info.py diff --git a/shell/console/plugins/memphis_init/Makefile.am b/shell/console/plugins/memphis_init/Makefile.am deleted file mode 100644 index 3f986185..00000000 --- a/shell/console/plugins/memphis_init/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ - -sugardir = $(pkgdatadir)/shell/console/plugins/memphis_init -sugar_PYTHON = \ - README \ - __init__.py \ - info.py