commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 85/101: grc: refactor: Moved the notebook a


From: git
Subject: [Commit-gnuradio] [gnuradio] 85/101: grc: refactor: Moved the notebook and console into separate classes.
Date: Thu, 16 Mar 2017 14:58:12 +0000 (UTC)

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

jcorgan pushed a commit to branch python3
in repository gnuradio.

commit 03af90b98904b636b6fca75c3a4837391e3c03e2
Author: Seth Hitefield <address@hidden>
Date:   Thu Aug 11 14:24:00 2016 -0400

    grc: refactor: Moved the notebook and console into separate classes.
---
 grc/gui/ActionHandler.py                 |  8 ++--
 grc/gui/Console.py                       | 51 +++++++++++++++++++++++++
 grc/gui/MainWindow.py                    | 64 ++++++++++++++------------------
 grc/gui/{NotebookPage.py => Notebook.py} | 27 +++++++++++++-
 4 files changed, 108 insertions(+), 42 deletions(-)

diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 0d7a900..7898146 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -398,16 +398,16 @@ class ActionHandler(Gtk.Application):
             action.save_to_preferences()
         elif action == Actions.TOGGLE_SCROLL_LOCK:
             active = action.get_active()
-            main.text_display.scroll_lock = active
+            main.console.text_display.scroll_lock = active
             if active:
-                main.text_display.scroll_to_end()
+                main.console.text_display.scroll_to_end()
             action.save_to_preferences()
         elif action == Actions.CLEAR_CONSOLE:
-            main.text_display.clear()
+            main.console.text_display.clear()
         elif action == Actions.SAVE_CONSOLE:
             file_path = FileDialogs.SaveConsole(main, page.file_path).run()
             if file_path is not None:
-                main.text_display.save(file_path)
+                main.console.text_display.save(file_path)
         elif action == Actions.TOGGLE_HIDE_DISABLED_BLOCKS:
             Actions.NOTHING_SELECT()
         elif action == Actions.TOGGLE_AUTO_HIDE_PORT_LABELS:
diff --git a/grc/gui/Console.py b/grc/gui/Console.py
new file mode 100644
index 0000000..d40f300
--- /dev/null
+++ b/grc/gui/Console.py
@@ -0,0 +1,51 @@
+"""
+Copyright 2008, 2009, 2011 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+"""
+
+from __future__ import absolute_import
+
+import os
+
+import gi
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk, Gdk, GObject
+
+from .Constants import DEFAULT_CONSOLE_WINDOW_WIDTH
+from .Dialogs import TextDisplay, MessageDialogWrapper
+
+from ..core import Messages
+
+
+class Console(Gtk.ScrolledWindow):
+    def __init__(self):
+        Gtk.ScrolledWindow.__init__(self)
+
+        self.text_display = TextDisplay()
+
+        self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
+        self.add(self.text_display)
+        self.set_size_request(-1, DEFAULT_CONSOLE_WINDOW_WIDTH)
+
+    def add_line(self, line):
+        """
+        Place line at the end of the text buffer, then scroll its window all 
the way down.
+
+        Args:
+            line: the new text
+        """
+        self.text_display.insert(line)
diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index 1caec28..c371601 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -25,11 +25,12 @@ from gi.repository import Gtk, Gdk, GObject
 
 from . import Bars, Actions, Utils
 from .BlockTreeWindow import BlockTreeWindow
+from .Console import Console
 from .VariableEditor import VariableEditor
 from .Constants import \
     NEW_FLOGRAPH_TITLE, DEFAULT_CONSOLE_WINDOW_WIDTH
 from .Dialogs import TextDisplay, MessageDialogWrapper
-from .NotebookPage import NotebookPage
+from .Notebook import Notebook, Page
 
 from ..core import Messages
 
@@ -71,19 +72,13 @@ class MainWindow(Gtk.ApplicationWindow):
         vbox.pack_start(self.main, True, True, 0)
 
         # Create the notebook
-        self.notebook = Gtk.Notebook()
+        self.notebook = Notebook()
         self.page_to_be_closed = None
-        self.current_page = None  # type: NotebookPage
-        self.notebook.set_show_border(False)
-        self.notebook.set_scrollable(True)  # scroll arrows for page tabs
-        self.notebook.connect('switch-page', self._handle_page_change)
+
+        self.current_page = None  # type: Page
 
         # Create the console window
-        self.text_display = TextDisplay()
-        self.console_window = Gtk.ScrolledWindow()
-        self.console_window.set_policy(Gtk.PolicyType.AUTOMATIC, 
Gtk.PolicyType.AUTOMATIC)
-        self.console_window.add(self.text_display)
-        self.console_window.set_size_request(-1, DEFAULT_CONSOLE_WINDOW_WIDTH)
+        self.console = Console()
 
         # Create the block tree and variable panels
         self.btwin = BlockTreeWindow(platform)
@@ -100,13 +95,13 @@ class MainWindow(Gtk.ApplicationWindow):
         self.variable_panel_sidebar = self.config.variable_editor_sidebar()
         if self.variable_panel_sidebar:
             self.left.pack1(self.notebook)
-            self.left.pack2(self.console_window, False)
+            self.left.pack2(self.console, False)
             self.right.pack1(self.btwin)
             self.right.pack2(self.vars, False)
         else:
             # Put the variable editor in a panel with the console
             self.left.pack1(self.notebook)
-            self.left_subpanel.pack1(self.console_window, shrink=False)
+            self.left_subpanel.pack1(self.console, shrink=False)
             self.left_subpanel.pack2(self.vars, resize=False, shrink=True)
             self.left.pack2(self.left_subpanel, False)
 
@@ -126,7 +121,7 @@ class MainWindow(Gtk.ApplicationWindow):
             
self.left_subpanel.set_position(self.config.variable_editor_position())
 
         self.show_all()
-        self.console_window.hide()
+        self.console.hide()
         self.vars.hide()
         self.btwin.hide()
 
@@ -153,20 +148,6 @@ class MainWindow(Gtk.ApplicationWindow):
         Actions.APPLICATION_QUIT()
         return True
 
-    def _handle_page_change(self, notebook, page, page_num):
-        """
-        Handle a page change. When the user clicks on a new tab,
-        reload the flow graph to update the vars window and
-        call handle states (select nothing) to update the buttons.
-
-        Args:
-            notebook: the notebook
-            page: new page
-            page_num: new page number
-        """
-        self.current_page = self.notebook.get_nth_page(page_num)
-        Actions.PAGE_CHANGE()
-
     def update_panel_visibility(self, panel, visibility=True):
         """
         Handles changing visibility of panels.
@@ -176,19 +157,19 @@ class MainWindow(Gtk.ApplicationWindow):
 
         if panel == self.BLOCKS:
             if visibility:
-               self.btwin.show()
+                self.btwin.show()
             else:
-               self.btwin.hide()
+                self.btwin.hide()
         elif panel == self.CONSOLE:
             if visibility:
-               self.console_window.show()
+                self.console.show()
             else:
-               self.console_window.hide()
+                self.console.hide()
         elif panel == self.VARIABLES:
             if visibility:
-               self.vars.show()
+                self.vars.show()
             else:
-               self.vars.hide()
+                self.vars.hide()
         else:
             return
 
@@ -203,7 +184,7 @@ class MainWindow(Gtk.ApplicationWindow):
                 self.right.hide()
             else:
                 self.right.show()
-            if not (self.vars.get_property('visible')) and not 
(self.console_window.get_property('visible')):
+            if not (self.vars.get_property('visible')) and not 
(self.console.get_property('visible')):
                 self.left_subpanel.hide()
             else:
                 self.left_subpanel.show()
@@ -212,6 +193,15 @@ class MainWindow(Gtk.ApplicationWindow):
     # Console Window
     ############################################################
 
+    @property
+    def current_page(self):
+        return self.notebook.current_page
+
+    @current_page.setter
+    def current_page(self, page):
+        self.notebook.current_page = page
+
+
     def add_console_line(self, line):
         """
         Place line at the end of the text buffer, then scroll its window all 
the way down.
@@ -219,7 +209,7 @@ class MainWindow(Gtk.ApplicationWindow):
         Args:
             line: the new text
         """
-        self.text_display.insert(line)
+        self.console.add_line(line)
 
     ############################################################
     # Pages: create and close
@@ -244,7 +234,7 @@ class MainWindow(Gtk.ApplicationWindow):
             flow_graph = self._platform.get_new_flow_graph()
             flow_graph.grc_file_path = file_path
             #print flow_graph
-            page = NotebookPage(
+            page = Page(
                 self,
                 flow_graph=flow_graph,
                 file_path=file_path,
diff --git a/grc/gui/NotebookPage.py b/grc/gui/Notebook.py
similarity index 85%
rename from grc/gui/NotebookPage.py
rename to grc/gui/Notebook.py
index 347be8e..080505a 100644
--- a/grc/gui/NotebookPage.py
+++ b/grc/gui/Notebook.py
@@ -28,7 +28,32 @@ from .Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT
 from .DrawingArea import DrawingArea
 
 
-class NotebookPage(Gtk.HBox):
+class Notebook(Gtk.Notebook):
+    def __init__(self):
+        Gtk.Notebook.__init__(self)
+
+        self.current_page = None
+        self.set_show_border(False)
+        self.set_scrollable(True)
+        self.connect('switch-page', self._handle_page_change)
+
+
+    def _handle_page_change(self, notebook, page, page_num):
+        """
+        Handle a page change. When the user clicks on a new tab,
+        reload the flow graph to update the vars window and
+        call handle states (select nothing) to update the buttons.
+
+        Args:
+            notebook: the notebook
+            page: new page
+            page_num: new page number
+        """
+        self.current_page = self.get_nth_page(page_num)
+        Actions.PAGE_CHANGE()
+
+
+class Page(Gtk.HBox):
     """A page in the notebook."""
 
     def __init__(self, main_window, flow_graph, file_path=''):



reply via email to

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