summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Hitefield <sdhitefield@gmail.com>2016-08-09 18:48:31 -0400
committerSeth Hitefield <sdhitefield@gmail.com>2016-09-22 12:05:42 -0400
commit8b2f679202c95896647231820eb07f42a2bc204b (patch)
treed00cda213070b9c4566207edc9fa91caaccde7e0
parent577cd09c42a02c7824bbd6f6c3a76c53dc114658 (diff)
grc: gtk3: Converted to Gtk.Application (ActionHandler) and Gtk.ApplicationWindow (MainWindow)
-rw-r--r--grc/gui/ActionHandler.py24
-rw-r--r--grc/gui/MainWindow.py7
-rwxr-xr-xgrc/main.py10
-rwxr-xr-xgrc/scripts/gnuradio-companion2
4 files changed, 27 insertions, 16 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index b10737d4db..ad4dc35073 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -23,7 +23,7 @@ from __future__ import absolute_import, print_function
import os
import subprocess
-from gi.repository import Gtk
+from gi.repository import Gtk, GObject
from . import Dialogs, Preferences, Actions, Executor, FileDialogs, Utils
from .MainWindow import MainWindow
@@ -33,13 +33,14 @@ from .PropsDialog import PropsDialog
from ..core import ParseXML, Messages
-class ActionHandler:
+class ActionHandler(Gtk.Application):
"""
The action handler will setup all the major window components,
and handle button presses and flow graph operations from the GUI.
"""
def __init__(self, file_paths, platform):
+ Gtk.Application.__init__(self)
"""
ActionHandler constructor.
Create the main window, setup the message handler, import the preferences,
@@ -54,16 +55,25 @@ class ActionHandler:
for action in Actions.get_all_actions(): action.connect('activate', self._handle_action)
#setup the main window
self.platform = platform
- self.main_window = MainWindow(platform, self._handle_action)
+
+ #initialize
+ self.init_file_paths = [os.path.abspath(file_path) for file_path in file_paths]
+ self.init = False
+
+ def do_startup(self):
+ Gtk.Application.do_startup(self)
+
+ def do_activate(self):
+ Gtk.Application.do_activate(self)
+
+ self.main_window = MainWindow(self, self.platform, self._handle_action)
self.main_window.connect('delete-event', self._quit)
self.main_window.connect('key-press-event', self._handle_key_press)
self.get_focus_flag = self.main_window.get_focus_flag
#setup the messages
Messages.register_messenger(self.main_window.add_console_line)
- Messages.send_init(platform)
- #initialize
- self.init_file_paths = [os.path.abspath(file_path) for file_path in file_paths]
- self.init = False
+ Messages.send_init(self.platform)
+
Actions.APPLICATION_INITIALIZE()
def _handle_key_press(self, widget, event):
diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index 3d4bf10308..e86273e288 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -41,7 +41,7 @@ from ..core import Messages
############################################################
# Main window
############################################################
-class MainWindow(Gtk.Window):
+class MainWindow(Gtk.ApplicationWindow):
"""The topmost window with menus, the tool bar, and other major windows."""
# Constants the action handler can use to indicate which panel visibility to change.
@@ -49,16 +49,17 @@ class MainWindow(Gtk.Window):
CONSOLE = 1
VARIABLES = 2
- def __init__(self, platform, action_handler_callback):
+ def __init__(self, app, platform, action_handler_callback):
"""
MainWindow constructor
Setup the menu, toolbar, flow graph editor notebook, block selection window...
"""
+ Gtk.ApplicationWindow.__init__(self, title="GNU Radio Companion", application=app)
+
self._platform = platform
Preferences.load(platform)
# Setup window
- GObject.GObject.__init__(self)
vbox = Gtk.VBox()
self.add(vbox)
diff --git a/grc/main.py b/grc/main.py
index 40a61a299f..e4d2cef234 100755
--- a/grc/main.py
+++ b/grc/main.py
@@ -15,16 +15,14 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-import argparse
+import argparse, sys
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('PangoCairo', '1.0')
-
from gi.repository import Gtk
from gnuradio import gr
-
from .gui.Platform import Platform
from .gui.ActionHandler import ActionHandler
@@ -55,6 +53,6 @@ def main():
prefs=gr.prefs(),
install_prefix=gr.prefix()
)
- ActionHandler(args.flow_graphs, platform)
- Gtk.main()
-
+
+ app = ActionHandler(args.flow_graphs, platform)
+ sys.exit(app.run())
diff --git a/grc/scripts/gnuradio-companion b/grc/scripts/gnuradio-companion
index 8f267c8198..21d989164f 100755
--- a/grc/scripts/gnuradio-companion
+++ b/grc/scripts/gnuradio-companion
@@ -39,6 +39,8 @@ Is the library path environment variable set correctly?
def die(error, message):
msg = "{0}\n\n({1})".format(message, error)
try:
+ import gi
+ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
d = Gtk.MessageDialog(
message_type=Gtk.MessageType.ERROR,