commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 06/10: grc: added save_reports action.


From: git
Subject: [Commit-gnuradio] [gnuradio] 06/10: grc: added save_reports action.
Date: Tue, 26 Aug 2014 19:40:07 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 8aeb5b7e8b52701d1d5c6f40735db469121e6e67
Author: Seth Hitefield <address@hidden>
Date:   Tue Aug 19 15:17:09 2014 -0400

    grc: added save_reports action.
---
 grc/gui/ActionHandler.py | 11 ++++++++---
 grc/gui/Actions.py       |  5 +++++
 grc/gui/Bars.py          |  2 ++
 grc/gui/Constants.py     |  3 ++-
 grc/gui/Dialogs.py       | 13 +++++++++++++
 grc/gui/FileDialogs.py   | 20 +++++++++++++++++---
 6 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 60fa070..c06dc96 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -34,7 +34,7 @@ from MainWindow import MainWindow
 from PropsDialog import PropsDialog
 from ParserErrorsDialog import ParserErrorsDialog
 import Dialogs
-from FileDialogs import OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, 
SaveImageFileDialog
+from FileDialogs import OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, 
SaveReportsFileDialog, SaveImageFileDialog
 
 gobject.threads_init()
 
@@ -117,7 +117,8 @@ class ActionHandler:
                 Actions.FLOW_GRAPH_SCREEN_CAPTURE, Actions.HELP_WINDOW_DISPLAY,
                 Actions.TYPES_WINDOW_DISPLAY, Actions.TOGGLE_BLOCKS_WINDOW,
                 Actions.TOGGLE_REPORTS_WINDOW, 
Actions.TOGGLE_HIDE_DISABLED_BLOCKS,
-                Actions.TOOLS_RUN_FDESIGN, Actions.TOGGLE_SCROLL_LOCK, 
Actions.CLEAR_REPORTS,
+                Actions.TOOLS_RUN_FDESIGN, Actions.TOGGLE_SCROLL_LOCK,
+                Actions.CLEAR_REPORTS, Actions.SAVE_REPORTS,
                 Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, 
Actions.TOGGLE_SNAP_TO_GRID
             ): action.set_sensitive(True)
             if ParseXML.xml_failures:
@@ -385,6 +386,10 @@ class ActionHandler:
             action.save_to_preferences()
         elif action == Actions.CLEAR_REPORTS:
             self.main_window.text_display.clear()
+        elif action == Actions.SAVE_REPORTS:
+            file_path = 
SaveReportsFileDialog(self.get_page().get_file_path()).run()
+            if file_path is not None:
+                self.main_window.text_display.save(file_path)
         elif action == Actions.TOGGLE_HIDE_DISABLED_BLOCKS:
             Actions.NOTHING_SELECT()
         elif action == Actions.TOGGLE_AUTO_HIDE_PORT_LABELS:
@@ -498,7 +503,7 @@ class ActionHandler:
             Messages.send_xml_errors_if_any(ParseXML.xml_failures)
             # Force a redraw of the graph, by getting the current state and 
re-importing it
             self.main_window.update_pages()
-            
+
         elif action == Actions.FIND_BLOCKS:
             self.main_window.btwin.show()
             self.main_window.btwin.search_entry.show()
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index c41798a..35a8023 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -378,6 +378,11 @@ CLEAR_REPORTS = Action(
     tooltip='Clear Reports',
     stock_id=gtk.STOCK_CLEAR,
 )
+SAVE_REPORTS = Action(
+    label='_Save Reports',
+    tooltip='Save Reports',
+    stock_id=gtk.STOCK_SAVE,
+)
 OPEN_HIER = Action(
     label='Open H_ier',
     tooltip='Open the source of the selected hierarchical block',
diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py
index 7433452..7145b56 100644
--- a/grc/gui/Bars.py
+++ b/grc/gui/Bars.py
@@ -55,6 +55,7 @@ TOOLBAR_LIST = (
     Actions.RELOAD_BLOCKS,
     Actions.OPEN_HIER,
     Actions.BUSSIFY_SOURCES,
+    Actions.SAVE_REPORTS,
     Actions.CLEAR_REPORTS,
 )
 
@@ -95,6 +96,7 @@ MENU_BAR_LIST = (
         None,
         Actions.TOGGLE_REPORTS_WINDOW,
         Actions.TOGGLE_SCROLL_LOCK,
+        Actions.SAVE_REPORTS,
         Actions.CLEAR_REPORTS,
         None,
         Actions.TOGGLE_HIDE_DISABLED_BLOCKS,
diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py
index c82449b..8d21ade 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -27,6 +27,7 @@ DEFAULT_FILE_PATH = os.getcwd()
 
 ##file extensions
 IMAGE_FILE_EXTENSION = '.png'
+TEXT_FILE_EXTENSION = '.txt'
 
 ##name for new/unsaved flow graphs
 NEW_FLOGRAPH_TITLE = 'untitled'
@@ -83,4 +84,4 @@ SCROLL_DISTANCE = 15
 LINE_SELECT_SENSITIVITY = 5
 
 # canvas grid size
-CANVAS_GRID_SIZE = 8
\ No newline at end of file
+CANVAS_GRID_SIZE = 8
diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py
index 17562bf..eb0a6c1 100644
--- a/grc/gui/Dialogs.py
+++ b/grc/gui/Dialogs.py
@@ -80,6 +80,12 @@ class TextDisplay(gtk.TextView):
         buffer = self.get_buffer()
         buffer.delete(buffer.get_start_iter(), buffer.get_end_iter())
 
+    def save(self, file_path):
+        report_file = open(file_path, 'w')
+        buffer = self.get_buffer()
+        report_file.write(buffer.get_text(buffer.get_start_iter(), 
buffer.get_end_iter(), True))
+        report_file.close()
+
     # Callback functions to handle the scrolling lock and clear context menus 
options
     # Action functions are set by the ActionHandler's init function
     def clear_cb(self, menu_item, web_view):
@@ -88,6 +94,9 @@ class TextDisplay(gtk.TextView):
     def scroll_back_cb(self, menu_item, web_view):
         Actions.TOGGLE_SCROLL_LOCK()
 
+    def save_cb(self, menu_item, web_view):
+        Actions.SAVE_REPORTS()
+
     def populate_popup(self, view, menu):
         """Create a popup menu for the scroll lock and clear functions"""
         menu.append(gtk.SeparatorMenuItem())
@@ -97,6 +106,10 @@ class TextDisplay(gtk.TextView):
         lock.set_active(self.scroll_lock)
         lock.connect('activate', self.scroll_back_cb, view)
 
+        save = gtk.ImageMenuItem(gtk.STOCK_SAVE)
+        menu.append(save)
+        save.connect('activate', self.save_cb, view)
+
         clear = gtk.ImageMenuItem(gtk.STOCK_CLEAR)
         menu.append(clear)
         clear.connect('activate', self.clear_cb, view)
diff --git a/grc/gui/FileDialogs.py b/grc/gui/FileDialogs.py
index daea7e4..96cbd94 100644
--- a/grc/gui/FileDialogs.py
+++ b/grc/gui/FileDialogs.py
@@ -22,7 +22,7 @@ pygtk.require('2.0')
 import gtk
 from Dialogs import MessageDialogHelper
 from Constants import \
-    DEFAULT_FILE_PATH, IMAGE_FILE_EXTENSION, \
+    DEFAULT_FILE_PATH, IMAGE_FILE_EXTENSION, TEXT_FILE_EXTENSION, \
     NEW_FLOGRAPH_TITLE
 import Preferences
 from os import path
@@ -33,6 +33,7 @@ import Utils
 ##################################################
 OPEN_FLOW_GRAPH = 'open flow graph'
 SAVE_FLOW_GRAPH = 'save flow graph'
+SAVE_REPORTS = 'save reports'
 SAVE_IMAGE = 'save image'
 
 FILE_OVERWRITE_MARKUP_TMPL="""\
@@ -51,6 +52,12 @@ def get_flow_graph_files_filter():
     filter.add_pattern('*'+Preferences.file_extension())
     return filter
 
+def get_text_files_filter():
+    filter = gtk.FileFilter()
+    filter.set_name('Text Files')
+    filter.add_pattern('*'+TEXT_FILE_EXTENSION)
+    return filter
+
 ##the filter for image files
 def get_image_files_filter():
     filter = gtk.FileFilter()
@@ -108,7 +115,12 @@ class FileDialog(FileDialogHelper):
         elif self.type == SAVE_FLOW_GRAPH:
             FileDialogHelper.__init__(self, gtk.FILE_CHOOSER_ACTION_SAVE, 
'Save a Flow Graph to a File...')
             self.add_and_set_filter(get_flow_graph_files_filter())
-            self.set_current_name(path.basename(current_file_path)) #show the 
current filename
+            self.set_current_name(path.basename(current_file_path))
+        elif self.type == SAVE_REPORTS:
+            FileDialogHelper.__init__(self, gtk.FILE_CHOOSER_ACTION_SAVE, 
'Save Reports to a File...')
+            self.add_and_set_filter(get_text_files_filter())
+            file_path = path.splitext(path.basename(current_file_path))[0]
+            self.set_current_name(file_path) #show the current filename
         elif self.type == SAVE_IMAGE:
             FileDialogHelper.__init__(self, gtk.FILE_CHOOSER_ACTION_SAVE, 
'Save a Flow Graph Screen Shot...')
             self.add_and_set_filter(get_image_files_filter())
@@ -140,10 +152,11 @@ class FileDialog(FileDialogHelper):
         #############################################
         # Handle Save Dialogs
         #############################################
-        if self.type in (SAVE_FLOW_GRAPH, SAVE_IMAGE):
+        if self.type in (SAVE_FLOW_GRAPH, SAVE_REPORTS, SAVE_IMAGE):
             filename = self.get_filename()
             extension = {
                 SAVE_FLOW_GRAPH: Preferences.file_extension(),
+                SAVE_REPORTS: TEXT_FILE_EXTENSION,
                 SAVE_IMAGE: IMAGE_FILE_EXTENSION,
             }[self.type]
             #append the missing file extension if the filter matches
@@ -182,4 +195,5 @@ class FileDialog(FileDialogHelper):
 
 class OpenFlowGraphFileDialog(FileDialog): type = OPEN_FLOW_GRAPH
 class SaveFlowGraphFileDialog(FileDialog): type = SAVE_FLOW_GRAPH
+class SaveReportsFileDialog(FileDialog): type = SAVE_REPORTS
 class SaveImageFileDialog(FileDialog): type = SAVE_IMAGE



reply via email to

[Prev in Thread] Current Thread [Next in Thread]