| 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 | |
|---|
| 22 | from umitCore.I18N import _ |
|---|
| 23 | |
|---|
| 24 | from GraphPreferences import GraphPreferences |
|---|
| 25 | |
|---|
| 26 | """ |
|---|
| 27 | ToDO: Add support for time range change, show current visualization date. |
|---|
| 28 | Add support for change graph kind. |
|---|
| 29 | Add support for filtering graph lines. |
|---|
| 30 | """ |
|---|
| 31 | |
|---|
| 32 | class GraphControllerTB(gtk.Toolbar): |
|---|
| 33 | """ |
|---|
| 34 | Builds a Toolbar for controlling Interactive Timeline Graph. |
|---|
| 35 | """ |
|---|
| 36 | |
|---|
| 37 | def __init__(self, daddy): |
|---|
| 38 | gtk.Toolbar.__init__(self) |
|---|
| 39 | |
|---|
| 40 | self.daddy = daddy |
|---|
| 41 | |
|---|
| 42 | index = (i for i in xrange(5)) |
|---|
| 43 | self.tooltips = gtk.Tooltips() |
|---|
| 44 | |
|---|
| 45 | self.insert(self.zoom_control(), index.next()) |
|---|
| 46 | self.insert(self.graph_pref(), index.next()) |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | def zoom_control(self): |
|---|
| 50 | """ |
|---|
| 51 | Setup buttons for managing graph zoom level. |
|---|
| 52 | """ |
|---|
| 53 | self.btn_zoomin = gtk.Button(stock=gtk.STOCK_ZOOM_IN) |
|---|
| 54 | self.btn_zoomout = gtk.Button(stock=gtk.STOCK_ZOOM_OUT) |
|---|
| 55 | |
|---|
| 56 | #btn_zoomin.connect('clicked', self.perform_search, cbentry.child) |
|---|
| 57 | #btn_zoomout.connect('clicked', self.perform_search, cbentry.child) |
|---|
| 58 | |
|---|
| 59 | self.btn_zoomin.show() |
|---|
| 60 | self.btn_zoomout.show() |
|---|
| 61 | self.tooltips.set_tip(self.btn_zoomin, _("Zoom In")) |
|---|
| 62 | self.tooltips.set_tip(self.btn_zoomout, _("Zoom Out")) |
|---|
| 63 | |
|---|
| 64 | tbox = gtk.HBox() |
|---|
| 65 | tbox.pack_start(self.btn_zoomin, False, False, 0) |
|---|
| 66 | tbox.pack_start(self.btn_zoomout, False, False, 0) |
|---|
| 67 | |
|---|
| 68 | titem = gtk.ToolItem() |
|---|
| 69 | titem.add(tbox) |
|---|
| 70 | |
|---|
| 71 | return titem |
|---|
| 72 | |
|---|
| 73 | def graph_pref(self): |
|---|
| 74 | """ |
|---|
| 75 | Button for opening Graph Preferences window. |
|---|
| 76 | """ |
|---|
| 77 | self.btn_gpref = gtk.Button(stock=gtk.STOCK_EDIT) |
|---|
| 78 | self.sched_name_edit = gtk.Button(stock=gtk.STOCK_EDIT) |
|---|
| 79 | blbl = self.btn_gpref.get_children()[0].get_children()[0].get_children()[1] |
|---|
| 80 | blbl.set_text(_("Graph Preferences")) |
|---|
| 81 | |
|---|
| 82 | self.btn_gpref.connect('clicked', self._open_graph_pref) |
|---|
| 83 | self.btn_gpref.show() |
|---|
| 84 | |
|---|
| 85 | self.tooltips.set_tip(self.btn_gpref, _("Edit Graph Preferences")) |
|---|
| 86 | |
|---|
| 87 | tbox = gtk.HBox() |
|---|
| 88 | tbox.pack_start(self.btn_gpref, False, False, 0) |
|---|
| 89 | |
|---|
| 90 | titem = gtk.ToolItem() |
|---|
| 91 | titem.add(tbox) |
|---|
| 92 | |
|---|
| 93 | return titem |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | def update_graph(self): |
|---|
| 97 | """ |
|---|
| 98 | Active options set. |
|---|
| 99 | """ |
|---|
| 100 | self.daddy.setup_new_graph() |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | def _open_graph_pref(self, event): |
|---|
| 104 | """ |
|---|
| 105 | Open Graph Preferences window. |
|---|
| 106 | """ |
|---|
| 107 | w = GraphPreferences(self) |
|---|
| 108 | w.show_all() |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | def __set_graph_mode(self, mode): |
|---|
| 112 | """ |
|---|
| 113 | Change graph mode. |
|---|
| 114 | """ |
|---|
| 115 | getattr(self.daddy, mode)() |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | def __set_graph_attr(self, (attr, value)): |
|---|
| 119 | """ |
|---|
| 120 | Change some graph attribute. |
|---|
| 121 | """ |
|---|
| 122 | setattr(self.daddy, attr, value) |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | # Properties |
|---|
| 126 | change_graph_mode = property(fset=__set_graph_mode) |
|---|
| 127 | change_graph_attr = property(fset=__set_graph_attr) |
|---|
| 128 | |
|---|
| 129 | |
|---|