aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThierry Vignaud <thierry.vignaud@gmail.com>2013-11-20 06:11:05 +0100
committerThierry Vignaud <thierry.vignaud@gmail.com>2013-11-20 06:31:41 +0100
commit6570370e3c4de8ce562aa7754eae6956dd7c414b (patch)
treeeb431e47704f9a895d242da632cda90d57e8fcf0 /src
parente974abc33f45fd4d51865cd4ddb9e23c43db0d44 (diff)
downloadnet_monitor-6570370e3c4de8ce562aa7754eae6956dd7c414b.tar
net_monitor-6570370e3c4de8ce562aa7754eae6956dd7c414b.tar.gz
net_monitor-6570370e3c4de8ce562aa7754eae6956dd7c414b.tar.bz2
net_monitor-6570370e3c4de8ce562aa7754eae6956dd7c414b.tar.xz
net_monitor-6570370e3c4de8ce562aa7754eae6956dd7c414b.zip
convert to gtk3 (using pygi-convert.sh)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/net_monitor146
1 files changed, 73 insertions, 73 deletions
diff --git a/src/net_monitor b/src/net_monitor
index 4caca6b..e01cc86 100755
--- a/src/net_monitor
+++ b/src/net_monitor
@@ -1,8 +1,8 @@
#!/usr/bin/python
-import gobject
-import gtk
-import pango
+from gi.repository import GObject
+from gi.repository import Gtk
+from gi.repository import Pango
import gc
import os
@@ -79,7 +79,7 @@ class LoadGraph:
self.max = max
# size of the GtkDrawingArea
- self.__rect = self.__inner = gtk.gdk.Rectangle()
+ self.__rect = self.__inner = ()
self.maxval = 0 # maximum value in the history
self.__mesh_x = self.__mesh_y = 0 # distance in pixels between items
self.__get_max()
@@ -279,17 +279,17 @@ class MonitorGui:
ICON_CONNECTED="/usr/share/libDrakX/pixmaps/connected.png"
(COLUMN_PROTO, COLUMN_LOC_ADDR, COLUMN_LOC_PORT, COLUMN_REM_ADDR, COLUMN_REM_PORT, COLUMN_STATUS) = range(6)
def __init__(self, default_iface=None):
- self.window = gtk.Window()
+ self.window = Gtk.Window()
self.window.set_title(_("Network monitor"))
self.window.set_default_size(640, 440)
- self.window.connect('delete-event', lambda *w: gtk.main_quit())
+ self.window.connect('delete-event', lambda *w: Gtk.main_quit())
- self.main_vbox = gtk.VBox()
+ self.main_vbox = Gtk.VBox()
self.window.add(self.main_vbox)
# notebook
- self.notebook = gtk.Notebook()
- self.main_vbox.pack_start(self.notebook)
+ self.notebook = Gtk.Notebook()
+ self.main_vbox.pack_start(self.notebook, True, True, 0)
#self.notebook.connect('switch-page', self.show_net_status)
# monitor
@@ -336,7 +336,7 @@ class MonitorGui:
cur_page = self.notebook.append_page(network_stat, network_stat_label)
# global statusbar
- self.statusbar = gtk.Statusbar()
+ self.statusbar = Gtk.Statusbar()
self.context_id = self.statusbar.get_context_id("Statusbar")
self.main_vbox.pack_start(self.statusbar, False, False, padding=1)
@@ -345,7 +345,7 @@ class MonitorGui:
# configure timer
self.signals = Queue.Queue()
- gobject.timeout_add_seconds(1, self.update)
+ GObject.timeout_add_seconds(1, self.update)
self.window.show_all()
@@ -494,49 +494,49 @@ class MonitorGui:
else:
value = "%s (%s)" % (pretty_size, pretty_bytes)
self.ifaces[iface][widget].set_text(str(value))
- gobject.timeout_add_seconds(interval, self.update)
+ GObject.timeout_add_seconds(interval, self.update)
def show_statistics_dialog(self, widget, iface):
"""Shows statistics dialog"""
- dialog = gtk.Dialog(_("Network statistics for %s") % iface,
+ dialog = Gtk.Dialog(_("Network statistics for %s") % iface,
self.window, 0,
- (gtk.STOCK_OK, gtk.RESPONSE_OK)
+ (Gtk.STOCK_OK, Gtk.ResponseType.OK)
)
# statistics vbox
stats_vbox = dialog.vbox
if self.monitor.has_network_accounting(iface):
# graph
- graph_vnstat = gtk.Image()
+ graph_vnstat = Gtk.Image()
pixbuf = self.load_graph_from_vnstat(iface, type="summary")
graph_vnstat.set_from_pixbuf(pixbuf)
- stats_vbox.pack_start(graph_vnstat)
+ stats_vbox.pack_start(graph_vnstat, True, True, 0)
# buttons
- frame = gtk.Frame(_("Network traffic statistics for %s") % iface)
+ frame = Gtk.Frame(_("Network traffic statistics for %s") % iface)
stats_vbox.add(frame)
- vbox = gtk.VBox()
+ vbox = Gtk.VBox()
frame.add(vbox)
# summary
- button = gtk.RadioButton(None, _("Summary"))
+ button = Gtk.RadioButton(None, _("Summary"))
button.connect('toggled', self.update_stat_iface, (iface, graph_vnstat, "summary"))
vbox.pack_start(button, False, False)
# summary
- button = gtk.RadioButton(button, _("Hourly traffic"))
+ button = Gtk.RadioButton(button, _("Hourly traffic"))
button.connect('toggled', self.update_stat_iface, (iface, graph_vnstat, "hourly"))
vbox.pack_start(button, False, False)
# summary
- button = gtk.RadioButton(button, _("Daily traffic"))
+ button = Gtk.RadioButton(button, _("Daily traffic"))
button.connect('toggled', self.update_stat_iface, (iface, graph_vnstat, "daily"))
vbox.pack_start(button, False, False)
# summary
- button = gtk.RadioButton(button, _("Monthly traffic"))
+ button = Gtk.RadioButton(button, _("Monthly traffic"))
button.connect('toggled', self.update_stat_iface, (iface, graph_vnstat, "monthly"))
vbox.pack_start(button, False, False)
# summary
- button = gtk.RadioButton(button, _("Top 10 traffic days"))
+ button = Gtk.RadioButton(button, _("Top 10 traffic days"))
button.connect('toggled', self.update_stat_iface, (iface, graph_vnstat, "top"))
vbox.pack_start(button, False, False)
else:
- label = gtk.Label(_("Network accounting was not enabled on interface %s.\nPlease enable network accounting on the interface in order to view traffic statistics and restart your network connection to start collecting traffic statistics."))
+ label = Gtk.Label(label=_("Network accounting was not enabled on interface %s.\nPlease enable network accounting on the interface in order to view traffic statistics and restart your network connection to start collecting traffic statistics."))
stats_vbox.add(label)
stats_vbox.show_all()
@@ -562,20 +562,20 @@ class MonitorGui:
def build_network_stat(self):
"""Builds graphical view for connections"""
- vbox = gtk.VBox()
- sw = gtk.ScrolledWindow()
- sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
- sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
-
- lstore = gtk.ListStore(
- gobject.TYPE_STRING,
- gobject.TYPE_STRING,
- gobject.TYPE_INT,
- gobject.TYPE_STRING,
- gobject.TYPE_INT,
- gobject.TYPE_STRING
+ vbox = Gtk.VBox()
+ sw = Gtk.ScrolledWindow()
+ sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
+ sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
+
+ lstore = Gtk.ListStore(
+ GObject.TYPE_STRING,
+ GObject.TYPE_STRING,
+ GObject.TYPE_INT,
+ GObject.TYPE_STRING,
+ GObject.TYPE_INT,
+ GObject.TYPE_STRING
)
- treeview = gtk.TreeView(lstore)
+ treeview = Gtk.TreeView(lstore)
treeview.set_rules_hint(True)
treeview.set_search_column(self.COLUMN_LOC_ADDR)
@@ -589,8 +589,8 @@ class MonitorGui:
(self.COLUMN_REM_ADDR, _("Remote address")),
(self.COLUMN_REM_PORT, _("Remote port")),
(self.COLUMN_STATUS, _("Connection status")) ]:
- renderer = gtk.CellRendererText()
- column = gtk.TreeViewColumn(descr, renderer, text=c)
+ renderer = Gtk.CellRendererText()
+ column = Gtk.TreeViewColumn(descr, renderer, text=c)
column.set_sort_column_id(c)
column.set_resizable(True)
column.set_expand(True)
@@ -599,20 +599,20 @@ class MonitorGui:
sw.add(treeview)
# build tab label
- widget = gtk.HBox()
+ widget = Gtk.HBox()
try:
- icon = gtk.Image()
- pixbuf = gtk.gdk.pixbuf_new_from_file(self.ICON_CONNECTED)
+ icon = Gtk.Image()
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.ICON_CONNECTED)
icon.set_from_pixbuf(pixbuf)
- widget.pack_start(icon)
+ widget.pack_start(icon, True, True, 0)
except:
traceback.print_exc()
- widget.pack_start(gtk.Label(_("connections")))
+ widget.pack_start(Gtk.Label(_("connections", True, True, 0)))
widget.show_all()
- vbox.pack_start(sw)
+ vbox.pack_start(sw, True, True, 0)
- button = gtk.Button(_("Refresh"))
+ button = Gtk.Button(_("Refresh"))
button.connect('clicked', self.refresh_connections)
vbox.pack_start(button, False, False)
@@ -620,10 +620,10 @@ class MonitorGui:
def build_iface_stat(self, iface):
"""Builds graphical view for interface"""
- traf_vbox = gtk.VBox(spacing=5)
+ traf_vbox = Gtk.VBox(spacing=5)
# graph
- draw = gtk.DrawingArea()
- traf_vbox.pack_start(draw)
+ draw = Gtk.DrawingArea()
+ traf_vbox.pack_start(draw, True, True, 0)
histogram = {"in": [], "out": []}
graph = LoadGraph(draw, histogram, HISTOGRAM_SIZE)
draw.connect('expose_event', graph.on_expose)
@@ -631,16 +631,16 @@ class MonitorGui:
self.ifaces[iface]['histogram'] = histogram
# configuring callbacks
- sizegroup1 = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
- sizegroup2 = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
- sizegroup3 = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
- sizegroup4 = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
+ sizegroup1 = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
+ sizegroup2 = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
+ sizegroup3 = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
+ sizegroup4 = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
# traffic
- frame = gtk.Frame(_("Traffic statistics"))
+ frame = Gtk.Frame(_("Traffic statistics"))
traf_vbox.pack_start(frame, False, False)
- table = gtk.Table(2, 2, False)
+ table = Gtk.Table(2, 2, False)
frame.add(table)
cur_row = 0
@@ -663,10 +663,10 @@ class MonitorGui:
self.__add_row(table, cur_row, items)
cur_row += 1
- frame_global = gtk.Frame(_("Interface settings"))
+ frame_global = Gtk.Frame(_("Interface settings"))
traf_vbox.pack_start(frame_global, False, False)
- table = gtk.Table(2, 2, False)
+ table = Gtk.Table(2, 2, False)
frame_global.add(table)
cur_row = 0
@@ -711,7 +711,7 @@ class MonitorGui:
self.ifaces[iface]["quality"] = quality
# link quality graph
- draw = gtk.DrawingArea()
+ draw = Gtk.DrawingArea()
histogram = {"in": [], "out": []}
graph = LoadGraph(draw, histogram, HISTOGRAM_SIZE, min_height=40, axes_text="%", draw_both=False, max=100, draw_legend=False)
draw.connect('expose_event', graph.on_expose)
@@ -728,23 +728,23 @@ class MonitorGui:
cur_row += 1
# statistics button
- frame_accounting = gtk.Frame(_("Traffic accounting"))
- vbox = gtk.VBox()
+ frame_accounting = Gtk.Frame(_("Traffic accounting"))
+ vbox = Gtk.VBox()
frame_accounting.add(vbox)
if self.monitor.has_network_accounting(iface):
iface_u, iface_uptime = self.build_value_pair(sizegroup1, _("Connection time:"))
self.ifaces[iface]["widget_uptime"] = iface_uptime
vbox.pack_start(iface_u, False, False)
- button = gtk.Button(_("Show detailed network statistics"))
+ button = Gtk.Button(_("Show detailed network statistics"))
button.connect('clicked', self.show_statistics_dialog, iface)
vbox.pack_start(button, False, False)
else:
- label = gtk.Label("\n".join(textwrap.wrap(_("Network accounting is not enabled for this interface. Please enable it in Network center (press Configure button next to the interface item, then check \"Enable traffic accounting\" item) in order to view detailed traffic statistics"))))
+ label = Gtk.Label("\n".join(textwrap.wrap(_("Network accounting is not enabled for this interface. Please enable it in Network center (press Configure button next to the interface item, then check \"Enable traffic accounting\" item) in order to view detailed traffic statistics"))))
vbox.pack_start(label, False, False)
traf_vbox.pack_start(frame_accounting, False, False)
# building notebook label icons
- traf_label = gtk.HBox(False, 2)
+ traf_label = Gtk.HBox(False, 2)
if iface in self.wireless_ifaces:
# wifi
self.__load_interface_icon(traf_label, 'wireless')
@@ -758,7 +758,7 @@ class MonitorGui:
# ethernet
self.__load_interface_icon(traf_label, 'bluetooth')
- traf_label.pack_start(gtk.Label(iface))
+ traf_label.pack_start(Gtk.Label(iface, True, True, 0))
traf_label.show_all()
return traf_vbox, traf_label
@@ -766,17 +766,17 @@ class MonitorGui:
def __load_interface_icon(self, widget, icon_title):
"""Loads interface icon"""
try:
- icon = gtk.Image()
- pixbuf = gtk.gdk.pixbuf_new_from_file(self.ICON_PATTERN % icon_title)
+ icon = Gtk.Image()
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.ICON_PATTERN % icon_title)
icon.set_from_pixbuf(pixbuf)
- widget.pack_start(icon)
+ widget.pack_start(icon, True, True, 0)
except:
traceback.print_exc()
def __add_row(self, table, row, items, markup=False, wrap=False):
cur_pos = 1
for item in items:
- table.attach(item, cur_pos - 1, cur_pos, row, row + 1, gtk.EXPAND | gtk.FILL, 0, 0, 0)
+ table.attach(item, cur_pos - 1, cur_pos, row, row + 1, Gtk.AttachOptions.EXPAND | Gtk.AttachOptions.FILL, 0, 0, 0)
cur_pos += 1
def build_widget_pair(self, container, w1, w2):
@@ -788,11 +788,11 @@ class MonitorGui:
def build_value_pair(self, sizegroup, text, value_text=None, value_sizegroup=None):
"""Builds a value pair"""
- hbox = gtk.HBox(spacing=10)
- name = gtk.Label(text)
+ hbox = Gtk.HBox(spacing=10)
+ name = Gtk.Label(label=text)
name.set_property("xalign", 0.0)
hbox.pack_start(name, False, False)
- value = gtk.Label(value_text)
+ value = Gtk.Label(label=value_text)
value.set_property("xalign", 0.0)
hbox.pack_start(value, False, False)
if sizegroup:
@@ -825,7 +825,7 @@ class MonitorGui:
print "Unknown parameter %s, showing summary.." % type
param="-s"
data = os.popen("vnstati %s -o - -i %s" % (param, iface)).read()
- loader = gtk.gdk.PixbufLoader()
+ loader = GdkPixbuf.PixbufLoader()
loader.write(data)
loader.close()
pixbuf = loader.get_pixbuf()
@@ -871,4 +871,4 @@ if __name__ == "__main__":
iface = o[1]
monitor = MonitorGui(default_iface=iface)
signal.signal(signal.SIGHUP, lambda s, f: monitor.queue_update(s))
- gtk.main()
+ Gtk.main()