Moving to PEP-8
This commit is contained in:
parent
3dd0def247
commit
15f586e61a
@ -60,6 +60,12 @@ services/presence/Makefile
|
|||||||
services/nm/Makefile
|
services/nm/Makefile
|
||||||
services/clipboard/Makefile
|
services/clipboard/Makefile
|
||||||
services/datastore/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/Makefile
|
||||||
shell/console/lib/procmem/Makefile
|
shell/console/lib/procmem/Makefile
|
||||||
shell/console/Makefile
|
shell/console/Makefile
|
||||||
|
@ -25,75 +25,75 @@ sys.path.append(os.path.dirname(__file__) + '/interface')
|
|||||||
|
|
||||||
class Console:
|
class Console:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
# Main Window
|
# Main Window
|
||||||
self.window = gtk.Window()
|
self.window = gtk.Window()
|
||||||
self.window.set_title('Developer console')
|
self.window.set_title('Developer console')
|
||||||
self.window.connect("delete-event", self._minimize_main_window)
|
self.window.connect("delete-event", self._minimize_main_window)
|
||||||
|
|
||||||
self.default_width = gtk.gdk.screen_width() * 95 / 100
|
self.default_width = gtk.gdk.screen_width() * 95 / 100
|
||||||
self.default_height = gtk.gdk.screen_height() * 95 / 100
|
self.default_height = gtk.gdk.screen_height() * 95 / 100
|
||||||
self.default_mini_width = 150
|
self.default_mini_width = 150
|
||||||
self.default_mini_height = 30
|
self.default_mini_height = 30
|
||||||
|
|
||||||
self.window.set_default_size(self.default_width, self.default_height)
|
self.window.set_default_size(self.default_width, self.default_height)
|
||||||
|
|
||||||
self.window.realize()
|
self.window.realize()
|
||||||
self.window.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
self.window.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
|
||||||
|
|
||||||
# Minimize Window
|
# Minimize Window
|
||||||
self.mini_fixed = gtk.Fixed()
|
self.mini_fixed = gtk.Fixed()
|
||||||
|
|
||||||
# Minimize buttons
|
# Minimize buttons
|
||||||
button_restore = gtk.Button('Restore')
|
button_restore = gtk.Button('Restore')
|
||||||
button_restore.connect("clicked", self._restore_window)
|
button_restore.connect("clicked", self._restore_window)
|
||||||
|
|
||||||
button_quit = gtk.Button('Quit')
|
button_quit = gtk.Button('Quit')
|
||||||
button_quit.connect("clicked", gtk.main_quit)
|
button_quit.connect("clicked", gtk.main_quit)
|
||||||
|
|
||||||
mini_hbox = gtk.HBox()
|
mini_hbox = gtk.HBox()
|
||||||
mini_hbox.pack_start(button_restore, True, True, 0)
|
mini_hbox.pack_start(button_restore, True, True, 0)
|
||||||
mini_hbox.pack_start(button_quit, True, True, 0)
|
mini_hbox.pack_start(button_quit, True, True, 0)
|
||||||
self.mini_fixed.add(mini_hbox)
|
self.mini_fixed.add(mini_hbox)
|
||||||
|
|
||||||
# Notebook
|
# Notebook
|
||||||
self.notebook = gtk.Notebook()
|
self.notebook = gtk.Notebook()
|
||||||
|
|
||||||
self._load_interface('xo', 'XO Resources')
|
self._load_interface('xo', 'XO Resources')
|
||||||
self._load_interface('memphis', 'Memphis')
|
self._load_interface('memphis', 'Memphis')
|
||||||
self._load_interface('logviewer', 'Log Viewer')
|
self._load_interface('logviewer', 'Log Viewer')
|
||||||
self._load_interface('terminal', 'Terminal')
|
self._load_interface('terminal', 'Terminal')
|
||||||
|
|
||||||
main_hbox = gtk.HBox()
|
main_hbox = gtk.HBox()
|
||||||
main_hbox.pack_start(self.notebook, True, True, 0)
|
main_hbox.pack_start(self.notebook, True, True, 0)
|
||||||
main_hbox.pack_start(self.mini_fixed, True, True, 0)
|
main_hbox.pack_start(self.mini_fixed, True, True, 0)
|
||||||
main_hbox.show()
|
main_hbox.show()
|
||||||
|
|
||||||
self.notebook.show()
|
self.notebook.show()
|
||||||
self.window.add(main_hbox)
|
self.window.add(main_hbox)
|
||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
self.mini_fixed.hide()
|
self.mini_fixed.hide()
|
||||||
|
|
||||||
def _load_interface(self, interface, label):
|
def _load_interface(self, interface, label):
|
||||||
mod = __import__(interface)
|
mod = __import__(interface)
|
||||||
widget = mod.Interface().widget
|
widget = mod.Interface().widget
|
||||||
widget.show()
|
widget.show()
|
||||||
|
|
||||||
self.notebook.append_page(widget, gtk.Label(label))
|
self.notebook.append_page(widget, gtk.Label(label))
|
||||||
|
|
||||||
|
|
||||||
def _restore_window(self, button):
|
def _restore_window(self, button):
|
||||||
self.mini_fixed.hide_all()
|
self.mini_fixed.hide_all()
|
||||||
self.window.resize(self.default_mini_width, self.default_mini_height)
|
self.window.resize(self.default_mini_width, self.default_mini_height)
|
||||||
self.notebook.show_all()
|
self.notebook.show_all()
|
||||||
|
|
||||||
def _minimize_main_window(self, window, gdkevent):
|
def _minimize_main_window(self, window, gdkevent):
|
||||||
self.notebook.hide_all()
|
self.notebook.hide_all()
|
||||||
window.resize(self.default_mini_width, self.default_mini_height)
|
window.resize(self.default_mini_width, self.default_mini_height)
|
||||||
self.mini_fixed.show_all()
|
self.mini_fixed.show_all()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
CS = Console()
|
CS = Console()
|
||||||
|
@ -29,101 +29,100 @@ import gobject
|
|||||||
from sugar import env
|
from sugar import env
|
||||||
|
|
||||||
class MultiLogView(gtk.VBox):
|
class MultiLogView(gtk.VBox):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
|
self._active_log = None
|
||||||
|
self._iters = []
|
||||||
|
|
||||||
self._active_log = None
|
# Creating Main treeview with Actitivities list
|
||||||
self._iters = []
|
tv_menu = gtk.TreeView()
|
||||||
|
tv_menu.connect('cursor-changed', self._load_log)
|
||||||
|
tv_menu.set_rules_hint(True)
|
||||||
|
|
||||||
# Creating Main treeview with Actitivities list
|
# Set width
|
||||||
tv_menu = gtk.TreeView()
|
box_width = gtk.gdk.screen_width() * 80 / 100
|
||||||
tv_menu.connect('cursor-changed', self._load_log)
|
tv_menu.set_size_request(box_width*25/100, 0)
|
||||||
tv_menu.set_rules_hint(True)
|
|
||||||
|
|
||||||
# Set width
|
self.store_menu = gtk.TreeStore(str)
|
||||||
box_width = gtk.gdk.screen_width() * 80 / 100
|
tv_menu.set_model(self.store_menu)
|
||||||
tv_menu.set_size_request(box_width*25/100, 0)
|
|
||||||
|
|
||||||
self.store_menu = gtk.TreeStore(str)
|
self._add_column(tv_menu, 'Sugar logs', 0)
|
||||||
tv_menu.set_model(self.store_menu)
|
self._logs_path = os.path.join(env.get_profile_path(), 'logs')
|
||||||
|
self._activity = {}
|
||||||
|
|
||||||
self._add_column(tv_menu, 'Sugar logs', 0)
|
# Activities menu
|
||||||
self._logs_path = os.path.join(env.get_profile_path(), 'logs')
|
self.hbox = gtk.HBox(False, 3)
|
||||||
self._activity = {}
|
self.hbox.pack_start(tv_menu, True, True, 0)
|
||||||
|
|
||||||
# Activities menu
|
# Activity log, set width
|
||||||
self.hbox = gtk.HBox(False, 3)
|
self._view = LogView()
|
||||||
self.hbox.pack_start(tv_menu, True, True, 0)
|
self._view.set_size_request(box_width*75/100, 0)
|
||||||
|
|
||||||
# Activity log, set width
|
self.hbox.pack_start(self._view, True, True, 0)
|
||||||
self._view = LogView()
|
self.hbox.show_all()
|
||||||
self._view.set_size_request(box_width*75/100, 0)
|
|
||||||
|
|
||||||
self.hbox.pack_start(self._view, True, True, 0)
|
gobject.timeout_add(1000, self._update, tv_menu)
|
||||||
self.hbox.show_all()
|
|
||||||
|
|
||||||
gobject.timeout_add(1000, self._update, tv_menu)
|
# Load the log information in View (textview)
|
||||||
|
def _load_log(self, treeview):
|
||||||
|
treeselection = treeview.get_selection()
|
||||||
|
|
||||||
# Load the log information in View (textview)
|
treestore, iter = treeselection.get_selected()
|
||||||
def _load_log(self, treeview):
|
|
||||||
treeselection = treeview.get_selection()
|
|
||||||
|
|
||||||
treestore, iter = treeselection.get_selected()
|
# Get current selection
|
||||||
|
act_log = self.store_menu.get_value(iter, 0)
|
||||||
|
|
||||||
# Get current selection
|
# Set buffer and scroll down
|
||||||
act_log = self.store_menu.get_value(iter, 0)
|
self._view.textview.set_buffer(self._activity[act_log])
|
||||||
|
self._view.textview.scroll_to_mark(self._activity[act_log].get_insert(), 0);
|
||||||
|
self._active_log = act_log
|
||||||
|
|
||||||
# Set buffer and scroll down
|
def _update(self, tv_menu):
|
||||||
self._view.textview.set_buffer(self._activity[act_log])
|
# Searching log files
|
||||||
self._view.textview.scroll_to_mark(self._activity[act_log].get_insert(), 0);
|
for logfile in os.listdir(self._logs_path):
|
||||||
self._active_log = act_log
|
|
||||||
|
|
||||||
def _update(self, tv_menu):
|
if not self._activity.has_key(logfile):
|
||||||
# Searching log files
|
self._add_activity(logfile)
|
||||||
for logfile in os.listdir(self._logs_path):
|
full_log_path = os.path.join(self._logs_path, logfile)
|
||||||
|
model = LogBuffer(full_log_path)
|
||||||
|
self._activity[logfile] = model
|
||||||
|
|
||||||
if not self._activity.has_key(logfile):
|
self._activity[logfile].update()
|
||||||
self._add_activity(logfile)
|
written = self._activity[logfile]._written
|
||||||
full_log_path = os.path.join(self._logs_path, logfile)
|
|
||||||
model = LogBuffer(full_log_path)
|
|
||||||
self._activity[logfile] = model
|
|
||||||
|
|
||||||
self._activity[logfile].update()
|
# Load the first iter
|
||||||
written = self._activity[logfile]._written
|
if self._active_log == None:
|
||||||
|
self._active_log = logfile
|
||||||
|
iter = tv_menu.get_model().get_iter_root()
|
||||||
|
tv_menu.get_selection().select_iter(iter)
|
||||||
|
self._load_log(tv_menu)
|
||||||
|
|
||||||
# Load the first iter
|
if written > 0 and self._active_log == logfile:
|
||||||
if self._active_log == None:
|
self._view.textview.scroll_to_mark(self._activity[logfile].get_insert(), 0);
|
||||||
self._active_log = logfile
|
|
||||||
iter = tv_menu.get_model().get_iter_root()
|
|
||||||
tv_menu.get_selection().select_iter(iter)
|
|
||||||
self._load_log(tv_menu)
|
|
||||||
|
|
||||||
if written > 0 and self._active_log == logfile:
|
return True
|
||||||
self._view.textview.scroll_to_mark(self._activity[logfile].get_insert(), 0);
|
|
||||||
|
|
||||||
return True
|
def _add_activity(self, name):
|
||||||
|
self._insert_row(self.store_menu, None, name)
|
||||||
|
|
||||||
def _add_activity(self, name):
|
# Add a new column to the main treeview, (code from Memphis)
|
||||||
self._insert_row(self.store_menu, None, name)
|
def _add_column(self, treeview, column_name, index):
|
||||||
|
cell = gtk.CellRendererText()
|
||||||
|
col_tv = gtk.TreeViewColumn(column_name, cell, text=index)
|
||||||
|
col_tv.set_resizable(True)
|
||||||
|
col_tv.set_property('clickable', True)
|
||||||
|
|
||||||
# Add a new column to the main treeview, (code from Memphis)
|
treeview.append_column(col_tv)
|
||||||
def _add_column(self, treeview, column_name, index):
|
|
||||||
cell = gtk.CellRendererText()
|
|
||||||
col_tv = gtk.TreeViewColumn(column_name, cell, text=index)
|
|
||||||
col_tv.set_resizable(True)
|
|
||||||
col_tv.set_property('clickable', True)
|
|
||||||
|
|
||||||
treeview.append_column(col_tv)
|
# Set the last column index added
|
||||||
|
self.last_col_index = index
|
||||||
|
|
||||||
# Set the last column index added
|
# Insert a Row in our TreeView
|
||||||
self.last_col_index = index
|
def _insert_row(self, store, parent, name):
|
||||||
|
iter = store.insert_before(parent, None)
|
||||||
|
index = 0
|
||||||
|
store.set_value(iter, index , name)
|
||||||
|
|
||||||
# Insert a Row in our TreeView
|
return iter
|
||||||
def _insert_row(self, store, parent, name):
|
|
||||||
iter = store.insert_before(parent, None)
|
|
||||||
index = 0
|
|
||||||
store.set_value(iter, index , name)
|
|
||||||
|
|
||||||
return iter
|
|
||||||
|
|
||||||
class LogBuffer(gtk.TextBuffer):
|
class LogBuffer(gtk.TextBuffer):
|
||||||
def __init__(self, logfile):
|
def __init__(self, logfile):
|
||||||
@ -138,14 +137,14 @@ class LogBuffer(gtk.TextBuffer):
|
|||||||
|
|
||||||
init_pos = self._pos
|
init_pos = self._pos
|
||||||
|
|
||||||
f.seek(self._pos)
|
f.seek(self._pos)
|
||||||
self.insert(self.get_end_iter(), f.read())
|
self.insert(self.get_end_iter(), f.read())
|
||||||
self._pos = f.tell()
|
self._pos = f.tell()
|
||||||
|
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
self._written = (self._pos - init_pos)
|
self._written = (self._pos - init_pos)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class LogView(gtk.ScrolledWindow):
|
class LogView(gtk.ScrolledWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -155,6 +154,11 @@ class LogView(gtk.ScrolledWindow):
|
|||||||
|
|
||||||
self.textview = gtk.TextView()
|
self.textview = gtk.TextView()
|
||||||
self.textview.set_wrap_mode(gtk.WRAP_WORD)
|
self.textview.set_wrap_mode(gtk.WRAP_WORD)
|
||||||
|
|
||||||
|
# Set background color
|
||||||
|
bgcolor = gtk.gdk.color_parse("#FFFFFF")
|
||||||
|
self.textview.modify_base(gtk.STATE_NORMAL, bgcolor)
|
||||||
|
|
||||||
self.textview.set_editable(False)
|
self.textview.set_editable(False)
|
||||||
|
|
||||||
self.add(self.textview)
|
self.add(self.textview)
|
||||||
@ -163,7 +167,7 @@ class LogView(gtk.ScrolledWindow):
|
|||||||
class Interface:
|
class Interface:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
path = None
|
path = None
|
||||||
viewer = MultiLogView(path)
|
viewer = MultiLogView(path)
|
||||||
self.widget = viewer.hbox
|
self.widget = viewer.hbox
|
||||||
|
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
import sys, os
|
import sys
|
||||||
|
import os
|
||||||
import string
|
import string
|
||||||
import wnck
|
import wnck
|
||||||
import plugin
|
import plugin
|
||||||
@ -37,30 +38,30 @@ class Interface:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
# Our GtkTree (Treeview)
|
# Our GtkTree (Treeview)
|
||||||
self.treeview = gtk.TreeView()
|
self.treeview = gtk.TreeView()
|
||||||
self.treeview.show()
|
self.treeview.show()
|
||||||
|
|
||||||
self.button_start = gtk.Button('Start Memphis')
|
self.button_start = gtk.Button('Start Memphis')
|
||||||
self.button_stop = gtk.Button('Stop Memphis')
|
self.button_stop = gtk.Button('Stop Memphis')
|
||||||
|
|
||||||
fixed = gtk.Fixed()
|
fixed = gtk.Fixed()
|
||||||
fixed.add(self.button_start)
|
fixed.add(self.button_start)
|
||||||
fixed.add(self.button_stop)
|
fixed.add(self.button_stop)
|
||||||
|
|
||||||
vbox = gtk.VBox(False)
|
vbox = gtk.VBox(False)
|
||||||
vbox.set_border_width(5)
|
vbox.set_border_width(5)
|
||||||
vbox.pack_start(fixed, True, True, 0)
|
vbox.pack_start(fixed, True, True, 0)
|
||||||
|
|
||||||
# Our GtkTree (Treeview)
|
# Our GtkTree (Treeview)
|
||||||
self.treeview = gtk.TreeView()
|
self.treeview = gtk.TreeView()
|
||||||
t_width = gtk.gdk.screen_width()
|
t_width = gtk.gdk.screen_width()
|
||||||
t_height = gtk.gdk.screen_height() * 83 / 100
|
t_height = gtk.gdk.screen_height() * 83 / 100
|
||||||
|
|
||||||
self.treeview.set_size_request(t_width, t_height)
|
self.treeview.set_size_request(t_width, t_height)
|
||||||
vbox.pack_start(self.treeview, True, True, 0)
|
vbox.pack_start(self.treeview, True, True, 0)
|
||||||
vbox.show_all()
|
vbox.show_all()
|
||||||
self.widget = vbox
|
self.widget = vbox
|
||||||
|
|
||||||
# Loading plugins
|
# Loading plugins
|
||||||
self.plg = plugin.Plugin()
|
self.plg = plugin.Plugin()
|
||||||
@ -79,9 +80,9 @@ class Interface:
|
|||||||
#self.store = gtk.TreeStore(*self.store_data_types)
|
#self.store = gtk.TreeStore(*self.store_data_types)
|
||||||
self.data = Data(self, self.treeview, self.plg.list)
|
self.data = Data(self, self.treeview, self.plg.list)
|
||||||
|
|
||||||
self.button_stop.hide()
|
self.button_stop.hide()
|
||||||
self.button_start.connect('clicked', self.data._start_memphis)
|
self.button_start.connect('clicked', self.data._start_memphis)
|
||||||
self.button_stop.connect('clicked', self.data._stop_memphis)
|
self.button_stop.connect('clicked', self.data._stop_memphis)
|
||||||
|
|
||||||
class Data:
|
class Data:
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ class Data:
|
|||||||
|
|
||||||
def __init__(self, interface, treeview, plg_list):
|
def __init__(self, interface, treeview, plg_list):
|
||||||
|
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
|
|
||||||
# Top data types
|
# Top data types
|
||||||
self.plg_list = plg_list
|
self.plg_list = plg_list
|
||||||
@ -132,17 +133,17 @@ class Data:
|
|||||||
|
|
||||||
def _start_memphis(self, button):
|
def _start_memphis(self, button):
|
||||||
|
|
||||||
# Update information every 1.5 second
|
# Update information every 1.5 second
|
||||||
button.hide()
|
button.hide()
|
||||||
self.interface.button_stop.show()
|
self.interface.button_stop.show()
|
||||||
self._running_status = True
|
self._running_status = True
|
||||||
gobject.timeout_add(1500, self.load_data, self.treeview)
|
gobject.timeout_add(1500, self.load_data, self.treeview)
|
||||||
|
|
||||||
def _stop_memphis(self, button):
|
def _stop_memphis(self, button):
|
||||||
|
|
||||||
self._running_status = False
|
self._running_status = False
|
||||||
button.hide()
|
button.hide()
|
||||||
self.interface.button_start.show()
|
self.interface.button_start.show()
|
||||||
|
|
||||||
# Add a new column to the main treeview
|
# Add a new column to the main treeview
|
||||||
def add_column(self, column_name, index):
|
def add_column(self, column_name, index):
|
||||||
|
@ -84,6 +84,7 @@ class Terminal(gtk.HBox):
|
|||||||
else:
|
else:
|
||||||
blink = False
|
blink = False
|
||||||
conf.set('terminal', 'cursor_blink', blink)
|
conf.set('terminal', 'cursor_blink', blink)
|
||||||
|
|
||||||
self._vte.set_cursor_blinks(blink)
|
self._vte.set_cursor_blinks(blink)
|
||||||
|
|
||||||
if conf.has_option('terminal', 'bell'):
|
if conf.has_option('terminal', 'bell'):
|
||||||
@ -149,11 +150,11 @@ class Multiple:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.notebook = gtk.Notebook()
|
self.notebook = gtk.Notebook()
|
||||||
t_width = gtk.gdk.screen_width()
|
t_width = gtk.gdk.screen_width()
|
||||||
t_height = gtk.gdk.screen_height() * 83 / 100
|
t_height = gtk.gdk.screen_height() * 83 / 100
|
||||||
self.notebook.set_size_request(t_width, t_height)
|
self.notebook.set_size_request(t_width, t_height)
|
||||||
|
|
||||||
self.add_new_terminal()
|
self.add_new_terminal()
|
||||||
|
|
||||||
open_terminal = gtk.Button('Open a new terminal')
|
open_terminal = gtk.Button('Open a new terminal')
|
||||||
open_terminal.connect("clicked", self.add_new_terminal)
|
open_terminal.connect("clicked", self.add_new_terminal)
|
||||||
|
@ -25,53 +25,53 @@ import gtk.gdk
|
|||||||
|
|
||||||
class Drawing_Area_Tools:
|
class Drawing_Area_Tools:
|
||||||
|
|
||||||
height = 0
|
height = 0
|
||||||
width = 0
|
width = 0
|
||||||
|
|
||||||
margin = 5 # Left and bottom margin
|
margin = 5 # Left and bottom margin
|
||||||
|
|
||||||
range_x = []
|
range_x = []
|
||||||
range_y = []
|
range_y = []
|
||||||
|
|
||||||
def __init__(self, drwarea):
|
def __init__(self, drwarea):
|
||||||
drwarea_size = drwarea.get_size_request()
|
drwarea_size = drwarea.get_size_request()
|
||||||
|
|
||||||
self.width = drwarea_size[0]
|
self.width = drwarea_size[0]
|
||||||
self.height = drwarea_size[1]
|
self.height = drwarea_size[1]
|
||||||
|
|
||||||
# print "width %i" % self.width
|
# print "width %i" % self.width
|
||||||
# print "height %i" % self.height
|
# print "height %i" % self.height
|
||||||
|
|
||||||
self.range_x = {'from': self.margin+2, 'to': self.width - (self.margin+2)}
|
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)}
|
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):
|
def draw_line(self, context, from_x, from_y, to_x, to_y):
|
||||||
context.move_to(from_x, from_y)
|
context.move_to(from_x, from_y)
|
||||||
context.line_to(to_x, to_y)
|
context.line_to(to_x, to_y)
|
||||||
|
|
||||||
def draw_border_lines(self, context):
|
def draw_border_lines(self, context):
|
||||||
context.set_source_rgb(1, 1, 1)
|
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.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)
|
self.draw_line(context, self.margin, self.height - self.margin - 1, self.width - self.margin, self.height - self.margin - 1)
|
||||||
context.stroke()
|
context.stroke()
|
||||||
|
|
||||||
# Draw a grid
|
# Draw a grid
|
||||||
def draw_grid(self, context, init_x, init_y, end_x, end_y):
|
def draw_grid(self, context, init_x, init_y, end_x, end_y):
|
||||||
|
|
||||||
x_range = (end_x - init_x) + 5
|
x_range = (end_x - init_x) + 5
|
||||||
y_range = (end_y - init_y) + 1
|
y_range = (end_y - init_y) + 1
|
||||||
|
|
||||||
current_y = init_y
|
current_y = init_y
|
||||||
context.set_line_width(0.3)
|
context.set_line_width(0.3)
|
||||||
|
|
||||||
for y in range(y_range):
|
for y in range(y_range):
|
||||||
if (y%20) == 0:
|
if (y%20) == 0:
|
||||||
context.move_to(init_x, y)
|
context.move_to(init_x, y)
|
||||||
context.line_to(end_x, y)
|
context.line_to(end_x, y)
|
||||||
|
|
||||||
for x in range(x_range):
|
for x in range(x_range):
|
||||||
if (x%20) == 0:
|
if (x%20) == 0:
|
||||||
context.move_to(x, init_y)
|
context.move_to(x, init_y)
|
||||||
context.line_to(x, end_y)
|
context.line_to(x, end_y)
|
||||||
|
|
||||||
context.stroke()
|
context.stroke()
|
||||||
|
@ -26,174 +26,174 @@ import drwarea
|
|||||||
|
|
||||||
class CPU_Usage:
|
class CPU_Usage:
|
||||||
|
|
||||||
CPU_HZ = 0
|
CPU_HZ = 0
|
||||||
last_jiffies = 0
|
last_jiffies = 0
|
||||||
times = 0
|
times = 0
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.CPU_hz = os.sysconf(2)
|
self.CPU_hz = os.sysconf(2)
|
||||||
|
|
||||||
def _get_CPU_data(self):
|
def _get_CPU_data(self):
|
||||||
# Uptime info
|
# Uptime info
|
||||||
stat_file = "/proc/stat"
|
stat_file = "/proc/stat"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
infile = file(stat_file, "r")
|
infile = file(stat_file, "r")
|
||||||
except:
|
except:
|
||||||
print "Error trying uptime file"
|
print "Error trying uptime file"
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
stat_line = infile.readline()
|
stat_line = infile.readline()
|
||||||
cpu_info = string.split(stat_line, ' ')
|
cpu_info = string.split(stat_line, ' ')
|
||||||
infile.close()
|
infile.close()
|
||||||
|
|
||||||
return cpu_info
|
return cpu_info
|
||||||
|
|
||||||
def _get_CPU_usage(self):
|
def _get_CPU_usage(self):
|
||||||
|
|
||||||
cpu_info = self._get_CPU_data()
|
cpu_info = self._get_CPU_data()
|
||||||
|
|
||||||
used_jiffies = (int(cpu_info[2]) + int(cpu_info[3]) + int(cpu_info[4]))
|
used_jiffies = (int(cpu_info[2]) + int(cpu_info[3]) + int(cpu_info[4]))
|
||||||
|
|
||||||
if self.times ==0:
|
if self.times ==0:
|
||||||
self.last_jiffies = used_jiffies
|
self.last_jiffies = used_jiffies
|
||||||
self.times +=1
|
self.times +=1
|
||||||
return True
|
return True
|
||||||
|
|
||||||
new_ujiffies = (used_jiffies - self.last_jiffies)
|
new_ujiffies = (used_jiffies - self.last_jiffies)
|
||||||
new_ajiffies = ((self.frequency/1000) * self.CPU_hz)
|
new_ajiffies = ((self.frequency/1000) * self.CPU_hz)
|
||||||
|
|
||||||
if new_ajiffies <= 0:
|
if new_ajiffies <= 0:
|
||||||
pcpu = 0.0
|
pcpu = 0.0
|
||||||
else:
|
else:
|
||||||
pcpu = ((new_ujiffies*100)/new_ajiffies)
|
pcpu = ((new_ujiffies*100)/new_ajiffies)
|
||||||
|
|
||||||
if pcpu >100:
|
if pcpu >100:
|
||||||
pcpu = 100
|
pcpu = 100
|
||||||
|
|
||||||
self.times +=1
|
self.times +=1
|
||||||
self.last_jiffies = used_jiffies
|
self.last_jiffies = used_jiffies
|
||||||
|
|
||||||
return pcpu
|
return pcpu
|
||||||
|
|
||||||
class Interface:
|
class Interface:
|
||||||
|
|
||||||
context = None
|
context = None
|
||||||
frequency_timer = 1
|
frequency_timer = 1
|
||||||
graph_offset = 7
|
graph_offset = 7
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.drw_width = gtk.gdk.screen_width() * 90 / 100
|
self.drw_width = gtk.gdk.screen_width() * 90 / 100
|
||||||
self.drw_height = gtk.gdk.screen_height() * 20 / 100
|
self.drw_height = gtk.gdk.screen_height() * 20 / 100
|
||||||
self.y_cpu = self.drw_height - self.graph_offset
|
self.y_cpu = self.drw_height - self.graph_offset
|
||||||
self.drw_buffer = []
|
self.drw_buffer = []
|
||||||
|
|
||||||
drawingarea = gtk.DrawingArea()
|
drawingarea = gtk.DrawingArea()
|
||||||
drawingarea.set_size_request(self.drw_width, self.drw_height)
|
drawingarea.set_size_request(self.drw_width, self.drw_height)
|
||||||
drawingarea.connect("expose-event", self.do_expose)
|
drawingarea.connect("expose-event", self.do_expose)
|
||||||
|
|
||||||
self.dat = drwarea.Drawing_Area_Tools(drawingarea)
|
self.dat = drwarea.Drawing_Area_Tools(drawingarea)
|
||||||
|
|
||||||
fixed = gtk.Fixed();
|
fixed = gtk.Fixed();
|
||||||
fixed.set_border_width(10)
|
fixed.set_border_width(10)
|
||||||
fixed.add(drawingarea)
|
fixed.add(drawingarea)
|
||||||
|
|
||||||
self.frame = gtk.Frame('System CPU Usage: 0%')
|
self.frame = gtk.Frame('System CPU Usage: 0%')
|
||||||
self.frame.set_border_width(10)
|
self.frame.set_border_width(10)
|
||||||
self.frame.add(fixed)
|
self.frame.add(fixed)
|
||||||
|
|
||||||
self.widget = self.hbox = gtk.HBox(False, 3)
|
self.widget = self.hbox = gtk.HBox(False, 3)
|
||||||
self.hbox.pack_start(self.frame, True, True, 0)
|
self.hbox.pack_start(self.frame, True, True, 0)
|
||||||
self.hbox.show_all()
|
self.hbox.show_all()
|
||||||
|
|
||||||
DRW_CPU = CPU_Usage()
|
DRW_CPU = CPU_Usage()
|
||||||
DRW_CPU.frequency = 1000 # 1 Second
|
DRW_CPU.frequency = 1000 # 1 Second
|
||||||
|
|
||||||
gobject.timeout_add(DRW_CPU.frequency, self._draw_cpu_usage, DRW_CPU, drawingarea)
|
gobject.timeout_add(DRW_CPU.frequency, self._draw_cpu_usage, DRW_CPU, drawingarea)
|
||||||
|
|
||||||
def _draw_cpu_usage(self, DRW_CPU, drwarea):
|
def _draw_cpu_usage(self, DRW_CPU, drwarea):
|
||||||
# End of the graph ?
|
# End of the graph ?
|
||||||
if ((self.frequency_timer + 1)*self.graph_offset) >= (self.drw_width - self.graph_offset):
|
if ((self.frequency_timer + 1)*self.graph_offset) >= (self.drw_width - self.graph_offset):
|
||||||
self.frequency_timer = 1
|
self.frequency_timer = 1
|
||||||
self.drw_buffer = []
|
self.drw_buffer = []
|
||||||
self.do_expose(drwarea, None)
|
self.do_expose(drwarea, None)
|
||||||
|
|
||||||
context = drwarea.window.cairo_create()
|
context = drwarea.window.cairo_create()
|
||||||
|
|
||||||
from_x = self.frequency_timer * self.graph_offset
|
from_x = self.frequency_timer * self.graph_offset
|
||||||
from_y = self.y_cpu
|
from_y = self.y_cpu
|
||||||
|
|
||||||
self.frequency_timer += 1
|
self.frequency_timer += 1
|
||||||
|
|
||||||
pcpu = DRW_CPU._get_CPU_usage()
|
pcpu = DRW_CPU._get_CPU_usage()
|
||||||
|
|
||||||
self.drw_buffer.append(pcpu)
|
self.drw_buffer.append(pcpu)
|
||||||
|
|
||||||
to_x = self.frequency_timer * self.graph_offset
|
to_x = self.frequency_timer * self.graph_offset
|
||||||
self.y_cpu = to_y = self._get_y_cpu(pcpu)
|
self.y_cpu = to_y = self._get_y_cpu(pcpu)
|
||||||
|
|
||||||
# Context properties
|
# Context properties
|
||||||
context.set_line_width(2)
|
context.set_line_width(2)
|
||||||
context.set_source_rgb(0,1,0)
|
context.set_source_rgb(0,1,0)
|
||||||
|
|
||||||
cpu_label = str(round(pcpu, 4))
|
cpu_label = str(round(pcpu, 4))
|
||||||
self.frame.set_label('System CPU Usage: ' + cpu_label + ' %')
|
self.frame.set_label('System CPU Usage: ' + cpu_label + ' %')
|
||||||
|
|
||||||
self.dat.draw_line(context, from_x, from_y, to_x, to_y)
|
self.dat.draw_line(context, from_x, from_y, to_x, to_y)
|
||||||
context.stroke()
|
context.stroke()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _get_y_cpu(self, pcpu):
|
def _get_y_cpu(self, pcpu):
|
||||||
|
|
||||||
height = (self.dat.range_y['to']) - (self.dat.range_y['from'])
|
height = (self.dat.range_y['to']) - (self.dat.range_y['from'])
|
||||||
|
|
||||||
# Get percent of cpu usage
|
# Get percent of cpu usage
|
||||||
y_value = (height - ((pcpu*height)/100) + 4)
|
y_value = (height - ((pcpu*height)/100) + 4)
|
||||||
|
|
||||||
return int(y_value)
|
return int(y_value)
|
||||||
|
|
||||||
def do_expose(self, widget, event):
|
def do_expose(self, widget, event):
|
||||||
|
|
||||||
self.context = widget.window.cairo_create()
|
self.context = widget.window.cairo_create()
|
||||||
self.context.rectangle(0, 0, self.dat.width - 1, self.dat.height - 1)
|
self.context.rectangle(0, 0, self.dat.width - 1, self.dat.height - 1)
|
||||||
|
|
||||||
self.context.set_source_rgb (0,0,0)
|
self.context.set_source_rgb (0,0,0)
|
||||||
self.context.fill_preserve()
|
self.context.fill_preserve()
|
||||||
|
|
||||||
# Drawing horizontal and vertical border lines
|
# Drawing horizontal and vertical border lines
|
||||||
self.dat.draw_border_lines(self.context)
|
self.dat.draw_border_lines(self.context)
|
||||||
|
|
||||||
# Drawing grid
|
# Drawing grid
|
||||||
line_margin = self.dat.margin
|
line_margin = self.dat.margin
|
||||||
self.context.set_source_rgb(1, 1, 1)
|
self.context.set_source_rgb(1, 1, 1)
|
||||||
self.context.set_line_width(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.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.context.stroke()
|
||||||
|
|
||||||
self._draw_buffer(widget)
|
self._draw_buffer(widget)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _draw_buffer(self, drwarea):
|
def _draw_buffer(self, drwarea):
|
||||||
freq = 1 # Frequency timer
|
freq = 1 # Frequency timer
|
||||||
last_y = self.drw_height - self.graph_offset
|
last_y = self.drw_height - self.graph_offset
|
||||||
|
|
||||||
context = drwarea.window.cairo_create()
|
context = drwarea.window.cairo_create()
|
||||||
for pcpu in self.drw_buffer:
|
for pcpu in self.drw_buffer:
|
||||||
|
|
||||||
from_x = freq * self.graph_offset
|
from_x = freq * self.graph_offset
|
||||||
from_y = last_y
|
from_y = last_y
|
||||||
|
|
||||||
freq+=1
|
freq+=1
|
||||||
|
|
||||||
to_x = freq * self.graph_offset
|
to_x = freq * self.graph_offset
|
||||||
last_y = to_y = self._get_y_cpu(pcpu)
|
last_y = to_y = self._get_y_cpu(pcpu)
|
||||||
|
|
||||||
# Context properties
|
# Context properties
|
||||||
context.set_line_width(2)
|
context.set_line_width(2)
|
||||||
context.set_source_rgb(0,1,0)
|
context.set_source_rgb(0,1,0)
|
||||||
|
|
||||||
self.dat.draw_line(context, from_x, from_y, to_x, to_y)
|
self.dat.draw_line(context, from_x, from_y, to_x, to_y)
|
||||||
context.stroke()
|
context.stroke()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user