| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # Copyright (C) 2008 Adriano Monteiro Marques |
|---|
| 4 | # |
|---|
| 5 | # Author: Francesco Piccinno <stack.box@gmail.com> |
|---|
| 6 | # |
|---|
| 7 | # This program is free software; you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program; if not, write to the Free Software |
|---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | import gtk |
|---|
| 22 | import sys |
|---|
| 23 | |
|---|
| 24 | from umitPlugin.Core import Core |
|---|
| 25 | from umitPlugin.Engine import Plugin |
|---|
| 26 | from higwidgets.higanimates import HIGAnimatedBar |
|---|
| 27 | from umitGUI.ScanNotebook import ScanNotebookPage |
|---|
| 28 | |
|---|
| 29 | class FlowContainer(gtk.VBox): |
|---|
| 30 | def __init__(self): |
|---|
| 31 | gtk.VBox.__init__(self) |
|---|
| 32 | |
|---|
| 33 | paned = gtk.VPaned() |
|---|
| 34 | |
|---|
| 35 | self.text1 = gtk.TextView() |
|---|
| 36 | self.text2 = gtk.TextView() |
|---|
| 37 | |
|---|
| 38 | def scroll(widget): |
|---|
| 39 | sw = gtk.ScrolledWindow() |
|---|
| 40 | sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 41 | sw.set_shadow_type(gtk.SHADOW_ETCHED_IN) |
|---|
| 42 | sw.add(widget) |
|---|
| 43 | return sw |
|---|
| 44 | |
|---|
| 45 | paned.pack1(scroll(self.text1)) |
|---|
| 46 | paned.pack2(scroll(self.text2)) |
|---|
| 47 | |
|---|
| 48 | message = "Not yet avaiable. Try to start a scan!" |
|---|
| 49 | |
|---|
| 50 | self.text1.get_buffer().set_text(message) |
|---|
| 51 | self.text2.get_buffer().set_text(message) |
|---|
| 52 | |
|---|
| 53 | self.pack_start(paned) |
|---|
| 54 | self.show_all() |
|---|
| 55 | |
|---|
| 56 | def update(self, page): |
|---|
| 57 | # Simple set the xml and normal output to textviews |
|---|
| 58 | |
|---|
| 59 | if hasattr(page, 'command_execution') and page.command_execution: |
|---|
| 60 | f = open(page.command_execution.get_xml_output_file(), "r") |
|---|
| 61 | txt = "".join(f.readlines()) |
|---|
| 62 | |
|---|
| 63 | self.text1.get_buffer().set_text(txt) |
|---|
| 64 | |
|---|
| 65 | f = open(page.command_execution.get_output_file(), "r") |
|---|
| 66 | txt = "".join(f.readlines()) |
|---|
| 67 | |
|---|
| 68 | self.text2.get_buffer().set_text(txt) |
|---|
| 69 | |
|---|
| 70 | class FlowPlugin(Plugin): |
|---|
| 71 | def start(self, reader): |
|---|
| 72 | self.id = Core().connect('ScanNotebookPage-created', self.__on_created) |
|---|
| 73 | |
|---|
| 74 | for page in Core().get_main_scan_notebook(): |
|---|
| 75 | if isinstance(page, ScanNotebookPage): |
|---|
| 76 | self.__on_created(Core(), page) |
|---|
| 77 | page.emit('scan-finished') |
|---|
| 78 | |
|---|
| 79 | def stop(self): |
|---|
| 80 | Core().disconnect(self.id) |
|---|
| 81 | |
|---|
| 82 | for page in Core().get_main_scan_notebook(): |
|---|
| 83 | if not isinstance(page, ScanNotebookPage): |
|---|
| 84 | continue |
|---|
| 85 | |
|---|
| 86 | for child in page.scan_result.scan_result_notebook: |
|---|
| 87 | if not isinstance(child, FlowContainer): |
|---|
| 88 | continue |
|---|
| 89 | |
|---|
| 90 | idx = page.scan_result.scan_result_notebook.page_num(child) |
|---|
| 91 | page.scan_result.scan_result_notebook.remove_page(idx) |
|---|
| 92 | |
|---|
| 93 | child.hide() |
|---|
| 94 | child.destroy() |
|---|
| 95 | |
|---|
| 96 | def __on_created(self, core, page): |
|---|
| 97 | container = FlowContainer() |
|---|
| 98 | |
|---|
| 99 | page.connect('scan-finished', container.update) |
|---|
| 100 | page.scan_result.scan_result_notebook.append_page(container, gtk.Label("Flow Analyzer")) |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | __plugins__ = [FlowPlugin] |
|---|