| 1 | # Copyright (C) 2007 Insecure.Com LLC. |
|---|
| 2 | # |
|---|
| 3 | # Authors: Guilherme Polo <ggpolo@gmail.com> |
|---|
| 4 | # |
|---|
| 5 | # This program is free software; you can redistribute it and/or modify |
|---|
| 6 | # it under the terms of the GNU General Public License as published by |
|---|
| 7 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | # (at your option) any later version. |
|---|
| 9 | # |
|---|
| 10 | # This program is distributed in the hope that it will be useful, |
|---|
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | # GNU General Public License for more details. |
|---|
| 14 | # |
|---|
| 15 | # You should have received a copy of the GNU General Public License |
|---|
| 16 | # along with this program; if not, write to the Free Software |
|---|
| 17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 18 | # USA |
|---|
| 19 | |
|---|
| 20 | import gtk |
|---|
| 21 | import random |
|---|
| 22 | |
|---|
| 23 | from umitCore.I18N import _ |
|---|
| 24 | |
|---|
| 25 | from umitInventory.TLGraph import InteractiveGraph |
|---|
| 26 | from umitInventory.TLConnector import Connector |
|---|
| 27 | from umitInventory.TLBarDisplay import TLSelected |
|---|
| 28 | from umitInventory.TLGraphToolbar import GraphControllerTB |
|---|
| 29 | from umitInventory.TLCategoryFilter import FilterBox |
|---|
| 30 | from umitInventory.DataGrabber import DataGrabber |
|---|
| 31 | |
|---|
| 32 | # sample data for graph |
|---|
| 33 | m = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Out", |
|---|
| 34 | "Nov", "Dec" ] |
|---|
| 35 | |
|---|
| 36 | """ |
|---|
| 37 | ToDO: - Better alignment, and etc, a lot of things =) |
|---|
| 38 | """ |
|---|
| 39 | |
|---|
| 40 | class TLEventsTree(gtk.HBox): |
|---|
| 41 | def __init__(self): |
|---|
| 42 | gtk.HBox.__init__(self) |
|---|
| 43 | |
|---|
| 44 | scrollw = gtk.ScrolledWindow() |
|---|
| 45 | |
|---|
| 46 | self.treestore = gtk.TreeStore(str) |
|---|
| 47 | |
|---|
| 48 | for parent in range(5): |
|---|
| 49 | p = self.treestore.append(None, ['parent %d' % parent]) |
|---|
| 50 | |
|---|
| 51 | for child in range(4): |
|---|
| 52 | self.treestore.append(p, ['child %d of parent %d' % (child, parent)]) |
|---|
| 53 | |
|---|
| 54 | self.treeview = gtk.TreeView(self.treestore) |
|---|
| 55 | self.tcolumn = gtk.TreeViewColumn("Events Listing (%d)" % len(self.treestore)) |
|---|
| 56 | self.treeview.append_column(self.tcolumn) |
|---|
| 57 | |
|---|
| 58 | cell = gtk.CellRendererText() |
|---|
| 59 | self.tcolumn.pack_start(cell, True) |
|---|
| 60 | self.tcolumn.add_attribute(cell, 'text', 0) |
|---|
| 61 | |
|---|
| 62 | scrollw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 63 | scrollw.add_with_viewport(self.treeview) |
|---|
| 64 | scrollw.set_size_request(170, -1) |
|---|
| 65 | |
|---|
| 66 | self.add(scrollw) |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | class TLHolder(gtk.VBox): |
|---|
| 70 | def __init__(self): |
|---|
| 71 | gtk.VBox.__init__(self) |
|---|
| 72 | |
|---|
| 73 | self.connector = Connector() |
|---|
| 74 | |
|---|
| 75 | filter = { } |
|---|
| 76 | filter[0] = (True, _("Changes Sum")) |
|---|
| 77 | max, start, evts = DataGrabber().changes_in_year_by_week(2007) |
|---|
| 78 | |
|---|
| 79 | # graph |
|---|
| 80 | self.graph = InteractiveGraph(evts, start, max, |
|---|
| 81 | y_label=_('Number of events'), |
|---|
| 82 | vdiv_labels=m, filter=filter, |
|---|
| 83 | connector=self.connector) |
|---|
| 84 | self.graph.draw_dashed_vert = True |
|---|
| 85 | # graph toolbar |
|---|
| 86 | self.graphtb = GraphControllerTB(self.graph, self.connector) |
|---|
| 87 | # grap filter |
|---|
| 88 | self.filterbtns = FilterBox(filter=filter, connector=self.connector) |
|---|
| 89 | # categories label |
|---|
| 90 | self.viewing_lbl = gtk.Label(_("Viewing categories")) |
|---|
| 91 | |
|---|
| 92 | self.tlsel = TLSelected(self.connector) |
|---|
| 93 | self.tree = TLEventsTree() |
|---|
| 94 | self.tview = gtk.TextView() |
|---|
| 95 | |
|---|
| 96 | self.__layout() |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | def update_data(self): |
|---|
| 100 | """ |
|---|
| 101 | Update graph data. |
|---|
| 102 | """ |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | def __layout(self): |
|---|
| 106 | """ |
|---|
| 107 | Layout widgets |
|---|
| 108 | """ |
|---|
| 109 | filterbox = gtk.HBox() |
|---|
| 110 | left_vbox = gtk.VBox() |
|---|
| 111 | graph_hbox = gtk.HBox() |
|---|
| 112 | paned = gtk.HPaned() |
|---|
| 113 | swtv = gtk.ScrolledWindow() |
|---|
| 114 | |
|---|
| 115 | # filter |
|---|
| 116 | filterbox.pack_start(self.viewing_lbl, False, False, 0) |
|---|
| 117 | filterbox.pack_start(self.filterbtns, False, False, 0) |
|---|
| 118 | # graph and zoom bar |
|---|
| 119 | graph_hbox.pack_start(self.graph, True, True, 0) |
|---|
| 120 | #graph_hbox.pack_start(self.zoombar, False, False, 0) |
|---|
| 121 | |
|---|
| 122 | tlselbox = gtk.HBox() |
|---|
| 123 | tlselbox.pack_start(self.tlsel, False, False, 0) |
|---|
| 124 | left_vbox.pack_start(tlselbox, False, False, 0) |
|---|
| 125 | left_vbox.pack_start(self.tree, True, True, 0) |
|---|
| 126 | |
|---|
| 127 | swtv.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 128 | swtv.add(self.tview) |
|---|
| 129 | |
|---|
| 130 | paned.add1(left_vbox) |
|---|
| 131 | paned.add2(swtv) |
|---|
| 132 | |
|---|
| 133 | self.pack_start(self.graphtb, False, False, 0) |
|---|
| 134 | self.pack_start(filterbox, False, False, 0) |
|---|
| 135 | self.pack_start(graph_hbox, False, False, 0) |
|---|
| 136 | self.pack_start(paned, True, True, 0) |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | if __name__ == "__main__": |
|---|
| 140 | # sample |
|---|
| 141 | win = gtk.Window() |
|---|
| 142 | win.add(TLHolder()) |
|---|
| 143 | win.show_all() |
|---|
| 144 | win.connect('delete-event', lambda *args:gtk.main_quit()) |
|---|
| 145 | gtk.main() |
|---|
| 146 | |
|---|