summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
Diffstat (limited to 'grc')
-rwxr-xr-xgrc/checks.py80
-rw-r--r--grc/core/Config.py13
-rw-r--r--grc/core/Constants.py1
-rw-r--r--grc/core/Platform.py9
-rw-r--r--grc/grc.conf.in1
-rwxr-xr-xgrc/scripts/gnuradio-companion91
6 files changed, 93 insertions, 102 deletions
diff --git a/grc/checks.py b/grc/checks.py
deleted file mode 100755
index fd0e5de06a..0000000000
--- a/grc/checks.py
+++ /dev/null
@@ -1,80 +0,0 @@
-# Copyright 2009-2016 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
-
-import os
-import warnings
-
-
-GR_IMPORT_ERROR_MESSAGE = """\
-Cannot import gnuradio.
-
-Is the model path environment variable set correctly?
- All OS: PYTHONPATH
-
-Is the library path environment variable set correctly?
- Linux: LD_LIBRARY_PATH
- Windows: PATH
- MacOSX: DYLD_LIBRARY_PATH
-"""
-
-
-def die(error, message):
- msg = "{0}\n\n({1})".format(message, error)
- try:
- import gtk
- d = gtk.MessageDialog(
- type=gtk.MESSAGE_ERROR,
- buttons=gtk.BUTTONS_CLOSE,
- message_format=msg,
- )
- d.set_title(type(error).__name__)
- d.run()
- exit(1)
- except ImportError:
- exit(type(error).__name__ + '\n\n' + msg)
-
-
-def check_gtk():
- try:
- warnings.filterwarnings("error")
- import pygtk
- pygtk.require('2.0')
- import gtk
- gtk.init_check()
- warnings.filterwarnings("always")
- except Exception as err:
- die(err, "Failed to initialize GTK. If you are running over ssh, "
- "did you enable X forwarding and start ssh with -X?")
-
-
-def check_gnuradio_import():
- try:
- from gnuradio import gr
- except ImportError as err:
- die(err, GR_IMPORT_ERROR_MESSAGE)
-
-
-def check_blocks_path():
- if 'GR_DONT_LOAD_PREFS' in os.environ and not os.environ.get('GRC_BLOCKS_PATH', ''):
- die(EnvironmentError("No block definitions available"),
- "Can't find block definitions. Use config.conf or GRC_BLOCKS_PATH.")
-
-
-def do_all():
- check_gnuradio_import()
- check_gtk()
- check_blocks_path()
diff --git a/grc/core/Config.py b/grc/core/Config.py
index ac38d9978c..78ff344998 100644
--- a/grc/core/Config.py
+++ b/grc/core/Config.py
@@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import os
from os.path import expanduser, normpath, expandvars, exists
+from . import Constants
+
class Config(object):
@@ -28,7 +30,7 @@ class Config(object):
license = __doc__.strip()
website = 'http://gnuradio.org'
- hier_block_lib_dir = os.environ.get('GRC_HIER_PATH', expanduser('~/.grc_gnuradio'))
+ hier_block_lib_dir = os.environ.get('GRC_HIER_PATH', Constants.DEFAULT_HIER_BLOCK_LIB_DIR)
def __init__(self, prefs_file, version, version_parts=None):
self.prefs = prefs_file
@@ -53,3 +55,12 @@ class Config(object):
for path in collected_paths if exists(path)]
return valid_paths
+
+ @property
+ def default_flow_graph(self):
+ user_default = (
+ os.environ.get('GRC_DEFAULT_FLOW_GRAPH') or
+ self.prefs.get_string('grc', 'default_flow_graph', '') or
+ os.path.join(self.hier_block_lib_dir, 'default_flow_graph.grc')
+ )
+ return user_default if exists(user_default) else Constants.DEFAULT_FLOW_GRAPH
diff --git a/grc/core/Constants.py b/grc/core/Constants.py
index eeb1d7f848..61a44d0c78 100644
--- a/grc/core/Constants.py
+++ b/grc/core/Constants.py
@@ -27,6 +27,7 @@ FLOW_GRAPH_DTD = os.path.join(DATA_DIR, 'flow_graph.dtd')
BLOCK_TREE_DTD = os.path.join(DATA_DIR, 'block_tree.dtd')
BLOCK_DTD = os.path.join(DATA_DIR, 'block.dtd')
DEFAULT_FLOW_GRAPH = os.path.join(DATA_DIR, 'default_flow_graph.grc')
+DEFAULT_HIER_BLOCK_LIB_DIR = os.path.expanduser('~/.grc_gnuradio')
DOMAIN_DTD = os.path.join(DATA_DIR, 'domain.dtd')
# File format versions:
diff --git a/grc/core/Platform.py b/grc/core/Platform.py
index 9b25e67d65..0dc6eb055a 100644
--- a/grc/core/Platform.py
+++ b/grc/core/Platform.py
@@ -60,9 +60,6 @@ class Platform(Element):
callback_finished=lambda: self.block_docstrings_loaded_callback()
)
- self._block_dtd = Constants.BLOCK_DTD
- self._default_flow_graph = Constants.DEFAULT_FLOW_GRAPH
-
# Create a dummy flow graph for the blocks
self._flow_graph = Element(self)
self._flow_graph.connections = []
@@ -188,7 +185,7 @@ class Platform(Element):
def load_block_xml(self, xml_file):
"""Load block description from xml file"""
# Validate and import
- ParseXML.validate_dtd(xml_file, self._block_dtd)
+ ParseXML.validate_dtd(xml_file, Constants.BLOCK_DTD)
n = ParseXML.from_file(xml_file).find('block')
n['block_wrapper_path'] = xml_file # inject block wrapper path
# Get block instance and add it to the list of blocks
@@ -291,8 +288,8 @@ class Platform(Element):
nested data
@throws exception if the validation fails
"""
- flow_graph_file = flow_graph_file or self._default_flow_graph
- open(flow_graph_file, 'r') # Test open
+ flow_graph_file = flow_graph_file or self.config.default_flow_graph
+ open(flow_graph_file, 'r').close() # Test open
ParseXML.validate_dtd(flow_graph_file, Constants.FLOW_GRAPH_DTD)
return ParseXML.from_file(flow_graph_file)
diff --git a/grc/grc.conf.in b/grc/grc.conf.in
index 71c4f63bca..1dbb13bfaa 100644
--- a/grc/grc.conf.in
+++ b/grc/grc.conf.in
@@ -5,6 +5,7 @@
[grc]
global_blocks_path = @blocksdir@
local_blocks_path =
+default_flow_graph =
xterm_executable = @GRC_XTERM_EXE@
canvas_font_size = 8
canvas_default_size = 1280, 1024
diff --git a/grc/scripts/gnuradio-companion b/grc/scripts/gnuradio-companion
index 04a1cb44e7..34bb0bf110 100755
--- a/grc/scripts/gnuradio-companion
+++ b/grc/scripts/gnuradio-companion
@@ -20,19 +20,80 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import os
import sys
+import warnings
-script_path = os.path.dirname(os.path.abspath(__file__))
-source_tree_subpath = "/grc/scripts"
-
-if not script_path.endswith(source_tree_subpath):
- # run the installed version
- from gnuradio.grc.main import main
- from gnuradio.grc import checks
-else:
- print("Running from source tree")
- sys.path.insert(1, script_path[:-len(source_tree_subpath)])
- from grc.main import main
- from grc import checks
-
-checks.do_all()
-exit(main())
+
+GR_IMPORT_ERROR_MESSAGE = """\
+Cannot import gnuradio.
+
+Is the model path environment variable set correctly?
+ All OS: PYTHONPATH
+
+Is the library path environment variable set correctly?
+ Linux: LD_LIBRARY_PATH
+ Windows: PATH
+ MacOSX: DYLD_LIBRARY_PATH
+"""
+
+
+def die(error, message):
+ msg = "{0}\n\n({1})".format(message, error)
+ try:
+ import gtk
+ d = gtk.MessageDialog(
+ type=gtk.MESSAGE_ERROR,
+ buttons=gtk.BUTTONS_CLOSE,
+ message_format=msg,
+ )
+ d.set_title(type(error).__name__)
+ d.run()
+ exit(1)
+ except ImportError:
+ exit(type(error).__name__ + '\n\n' + msg)
+
+
+def check_gtk():
+ try:
+ warnings.filterwarnings("error")
+ import pygtk
+ pygtk.require('2.0')
+ import gtk
+ gtk.init_check()
+ warnings.filterwarnings("always")
+ except Exception as err:
+ die(err, "Failed to initialize GTK. If you are running over ssh, "
+ "did you enable X forwarding and start ssh with -X?")
+
+
+def check_gnuradio_import():
+ try:
+ from gnuradio import gr
+ except ImportError as err:
+ die(err, GR_IMPORT_ERROR_MESSAGE)
+
+
+def check_blocks_path():
+ if 'GR_DONT_LOAD_PREFS' in os.environ and not os.environ.get('GRC_BLOCKS_PATH', ''):
+ die(EnvironmentError("No block definitions available"),
+ "Can't find block definitions. Use config.conf or GRC_BLOCKS_PATH.")
+
+
+def run_main():
+ script_path = os.path.dirname(os.path.abspath(__file__))
+ source_tree_subpath = "/grc/scripts"
+
+ if not script_path.endswith(source_tree_subpath):
+ # run the installed version
+ from gnuradio.grc.main import main
+ else:
+ print("Running from source tree")
+ sys.path.insert(1, script_path[:-len(source_tree_subpath)])
+ from grc.main import main
+ exit(main())
+
+
+if __name__ == '__main__':
+ check_gnuradio_import()
+ check_gtk()
+ check_blocks_path()
+ run_main()