import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
from hosts import *
class NetMap(gtk.DrawingArea):
def __init__(self,drawingarea):
#gtk.DrawingArea.__init__(self)
#drawingarea.__init__(self)
super(drawingarea, self).__init__()
self.connect("expose_event", self.expose)
def expose(self, widget, event):
self.context = widget.window.cairo_create()
# set a clip region for the expose event
self.context.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
self.context.clip()
self.draw(self.context)
return False
def draw(self, context):
rect = self.get_allocation()
x = rect.x + rect.width / 2
y = rect.y + rect.height / 2
radius = min(rect.width / 2, rect.height / 2) - 5
# clock back
context.arc(x, y, radius, 0, 2 * math.pi)
context.set_source_rgb(1, 1, 1)
context.fill_preserve()
context.set_source_rgb(0, 0, 0)
context.stroke()
for i in xrange(12):
inset = 0.1 * radius
context.move_to(x + (radius - inset) * math.cos(i * math.pi / 6),
y + (radius - inset) * math.sin(i * math.pi / 6))
context.line_to(x + radius * math.cos(i * math.pi / 6),
y + radius * math.sin(i * math.pi / 6))
context.stroke()
class MainWindow:
def __init__(self):
#Загрузка виджетов из glade
self.gladefile = "data/main_window.glade"
self.xml = gtk.glade.XML(self.gladefile)
self.main_window = self.xml.get_widget("main_window")
self.drawingarea = self.xml.get_widget("drawingarea")
net_map = NetMap(self.drawingarea)
dic = {"on_main_window_destroy" : gtk.main_quit,
"on_item_scan_activate" : self.on_item_scan_activate}
self.xml.signal_autoconnect(dic)
self.main_window.show_all()