usr bin env python coding utf-8 import pygtk pygtk require import gtk

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
from hosts import *
class NetMap(drawingarea):
def __init__(self):
#gtk.DrawingArea.__init__(self)
drawingarea.__init__(self)
#super(widget, 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")
drawingarea = self.xml.get_widget("drawingarea").__class__
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()
def on_item_scan_activate(self,widget):
SW = ScanWindow()
hosts = Hosts()
print hosts.get_dns_name("10.111.138.201")
class ScanWindow:
def __init__(self):
#Загрузка виджетов из glade
self.gladefile = "data/scan_window.glade"
self.xml = gtk.glade.XML(self.gladefile)
self.scan_window = self.xml.get_widget("scan_window")
self.treeview = self.xml.get_widget("treeview")
self.treestore = gtk.TreeStore(str)
for parent in range(4):
piter = self.treestore.append(None, ['parent %i' % parent])
for child in range(3):
self.treestore.append(piter, ['child %i of parent %i' % (child, parent)])
self.treeview.set_model(self.treestore)
#Загрузка модели колонок
self.service_column = gtk.TreeViewColumn('Service')
self.treeview.append_column(self.service_column)
self.computer_column = gtk.TreeViewColumn('Computer')
self.treeview.append_column(self.computer_column)
self.command_column = gtk.TreeViewColumn('Command for open')
self.treeview.append_column(self.command_column)
#Загрузка свойств модели колонок
self.cell = gtk.CellRendererText()
self.service_column.pack_start(self.cell, True)
self.service_column.add_attribute(self.cell, 'text', 0)
self.computer_column.pack_start(self.cell, True)
self.computer_column.add_attribute(self.cell, 'text', 1)
self.command_column.pack_start(self.cell, True)
self.command_column.add_attribute(self.cell, 'test', 2)
self.treeview.set_search_column(0)
self.service_column.set_sort_column_id(0)
self.treeview.set_reorderable(True)
dic = {"on_scan_window_destroy" : gtk.main_quit}
self.xml.signal_autoconnect(dic)
self.scan_window.show_all()
if __name__ == "__main__":
MW = MainWindow()
gtk.main()