| 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 | from DataGrabber import DataGrabber |
|---|
| 23 | from TLGraph import InteractiveGraph |
|---|
| 24 | from TLBarDisplay import TLSelected |
|---|
| 25 | from GraphToolbar import GraphControllerTB |
|---|
| 26 | |
|---|
| 27 | # sample data for graph |
|---|
| 28 | m = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Out", |
|---|
| 29 | "Nov", "Dec" ] |
|---|
| 30 | |
|---|
| 31 | """ |
|---|
| 32 | ToDO: Too much to write before take a nap. |
|---|
| 33 | """ |
|---|
| 34 | |
|---|
| 35 | class TLEventsTree(gtk.HBox): |
|---|
| 36 | def __init__(self): |
|---|
| 37 | gtk.HBox.__init__(self) |
|---|
| 38 | |
|---|
| 39 | scrollw = gtk.ScrolledWindow() |
|---|
| 40 | |
|---|
| 41 | self.treestore = gtk.TreeStore(str) |
|---|
| 42 | |
|---|
| 43 | for parent in range(5): |
|---|
| 44 | p = self.treestore.append(None, ['parent %d' % parent]) |
|---|
| 45 | |
|---|
| 46 | for child in range(4): |
|---|
| 47 | self.treestore.append(p, ['child %d of parent %d' % (child, parent)]) |
|---|
| 48 | |
|---|
| 49 | self.treeview = gtk.TreeView(self.treestore) |
|---|
| 50 | self.tcolumn = gtk.TreeViewColumn("Events Listing (%d)" % len(self.treestore)) |
|---|
| 51 | self.treeview.append_column(self.tcolumn) |
|---|
| 52 | |
|---|
| 53 | cell = gtk.CellRendererText() |
|---|
| 54 | self.tcolumn.pack_start(cell, True) |
|---|
| 55 | self.tcolumn.add_attribute(cell, 'text', 0) |
|---|
| 56 | |
|---|
| 57 | scrollw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 58 | scrollw.add_with_viewport(self.treeview) |
|---|
| 59 | scrollw.set_size_request(170, -1) |
|---|
| 60 | |
|---|
| 61 | self.add(scrollw) |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | class win(gtk.Window): |
|---|
| 65 | def __init__(self): |
|---|
| 66 | gtk.Window.__init__(self) |
|---|
| 67 | |
|---|
| 68 | dg = DataGrabber() |
|---|
| 69 | max, start, evts = dg.changes_in_year_by_week(2007) |
|---|
| 70 | |
|---|
| 71 | self.graph = InteractiveGraph(evts, start, max, 'Number of events', |
|---|
| 72 | vdiv_labels=m) |
|---|
| 73 | self.graphtb = GraphControllerTB(self.graph) |
|---|
| 74 | |
|---|
| 75 | self.graph.draw_dashed_vert = True |
|---|
| 76 | self.tlsel = TLSelected() |
|---|
| 77 | self.tree = TLEventsTree() |
|---|
| 78 | self.tview = gtk.TextView() |
|---|
| 79 | |
|---|
| 80 | self.__layout() |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | def __layout(self): |
|---|
| 84 | """ |
|---|
| 85 | Layout widgets |
|---|
| 86 | """ |
|---|
| 87 | main_vbox = gtk.VBox() |
|---|
| 88 | left_vbox = gtk.VBox() |
|---|
| 89 | paned = gtk.HPaned() |
|---|
| 90 | swtv = gtk.ScrolledWindow() |
|---|
| 91 | |
|---|
| 92 | tlselbox = gtk.HBox() |
|---|
| 93 | tlselbox.pack_start(self.tlsel, False, False, 0) |
|---|
| 94 | left_vbox.pack_start(tlselbox, False, False, 0) |
|---|
| 95 | left_vbox.pack_start(self.tree, True, True, 0) |
|---|
| 96 | |
|---|
| 97 | swtv.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 98 | swtv.add(self.tview) |
|---|
| 99 | |
|---|
| 100 | paned.add1(left_vbox) |
|---|
| 101 | paned.add2(swtv) |
|---|
| 102 | |
|---|
| 103 | main_vbox.pack_start(self.graphtb, False, False, 0) |
|---|
| 104 | main_vbox.pack_start(self.graph, False, False, 0) |
|---|
| 105 | main_vbox.pack_start(paned, True, True, 0) |
|---|
| 106 | |
|---|
| 107 | self.add(main_vbox) |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | if __name__ == "__main__": |
|---|
| 111 | w = win() |
|---|
| 112 | w.show_all() |
|---|
| 113 | w.connect('delete-event', lambda *args:gtk.main_quit()) |
|---|
| 114 | gtk.main() |
|---|
| 115 | |
|---|