[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9025 - in grc/trunk: notes src/grc src/grc/elements s
From: |
jblum |
Subject: |
[Commit-gnuradio] r9025 - in grc/trunk: notes src/grc src/grc/elements src/grc/gui src/grc/gui/elements src/grc_gnuradio/blocks |
Date: |
Sat, 26 Jul 2008 13:45:52 -0600 (MDT) |
Author: jblum
Date: 2008-07-26 13:45:51 -0600 (Sat, 26 Jul 2008)
New Revision: 9025
Modified:
grc/trunk/notes/todo.txt
grc/trunk/src/grc/ActionHandler.py
grc/trunk/src/grc/Constants.py
grc/trunk/src/grc/Messages.py
grc/trunk/src/grc/Preferences.py
grc/trunk/src/grc/elements/Param.py
grc/trunk/src/grc/elements/Platform.py
grc/trunk/src/grc/gui/Dialogs.py
grc/trunk/src/grc/gui/MainWindow.py
grc/trunk/src/grc/gui/elements/FlowGraph.py
grc/trunk/src/grc_gnuradio/blocks/options.xml
grc/trunk/src/grc_gnuradio/blocks/preferences.xml
Log:
modular preferences
Modified: grc/trunk/notes/todo.txt
===================================================================
--- grc/trunk/notes/todo.txt 2008-07-26 00:44:08 UTC (rev 9024)
+++ grc/trunk/notes/todo.txt 2008-07-26 19:45:51 UTC (rev 9025)
@@ -1,13 +1,12 @@
-############ Blocks to Add: ####################
+############ Blocks: ####################
-optparse block
-ofdm wrappers
-controlled step block
-throttle with sink only (source is nulled)
-############ Features to Add: ####################
+############ Features: ####################
-param editor, expand entry boxes in focus
-change param dialog to panel within main window
--default platform for preferences block
-command line option for additional block wrappers
-hotkeys in action descriptions
-log slider gui control
@@ -22,6 +21,7 @@
-auto generate hier library
-auto clean hier library
-add hier blocks to tree without restart?
+-block looses highlight on nports grow
############ Suggestions: ####################
-simple usrp
Modified: grc/trunk/src/grc/ActionHandler.py
===================================================================
--- grc/trunk/src/grc/ActionHandler.py 2008-07-26 00:44:08 UTC (rev 9024)
+++ grc/trunk/src/grc/ActionHandler.py 2008-07-26 19:45:51 UTC (rev 9025)
@@ -20,7 +20,8 @@
#ActionHandler builds the interface and handles most of the user inputs.
address@hidden Josh Blum
-import os, sys, signal
+import os
+import signal
from Constants import *
from Actions import *
import pygtk
@@ -61,7 +62,6 @@
self.get_focus_flag =
self.main_window.drawing_area.get_focus_flag
#setup the messages
Messages.register_messenger(self.main_window.add_report_line)
- Messages.register_messenger(sys.stdout.write)
Messages.send_init()
#initialize
self.init_file_paths = file_paths
Modified: grc/trunk/src/grc/Constants.py
===================================================================
--- grc/trunk/src/grc/Constants.py 2008-07-26 00:44:08 UTC (rev 9024)
+++ grc/trunk/src/grc/Constants.py 2008-07-26 19:45:51 UTC (rev 9025)
@@ -152,6 +152,6 @@
##The default icon for the gtk windows.
PY_GTK_ICON = os.path.join(DATA_DIR, 'grc-icon-256.png')
-##The default user preferences file path.
-PREFERENCES_FILE_PATH = os.path.join(os.path.expanduser('~'),
FLOW_GRAPH_FILE_EXTENSION)
+##The users home directory.
+HOME_DIR = os.path.expanduser('~')
Modified: grc/trunk/src/grc/Messages.py
===================================================================
--- grc/trunk/src/grc/Messages.py 2008-07-26 00:44:08 UTC (rev 9024)
+++ grc/trunk/src/grc/Messages.py 2008-07-26 19:45:51 UTC (rev 9025)
@@ -20,8 +20,9 @@
#Handle all of the system messages and error reports.
address@hidden Josh Blum
-from Constants import VERSION,PREFERENCES_FILE_PATH
+from Constants import VERSION
import traceback
+import sys
## A list of functions that can receive a message.
MESSENGERS_LIST = list()
@@ -40,6 +41,9 @@
"""
for messenger in MESSENGERS_LIST: messenger(message)
+#register stdout by default
+register_messenger(sys.stdout.write)
+
###########################################################################
# Special functions for specific program functionalities
###########################################################################
@@ -93,9 +97,9 @@
send('>>> Warning: A connection can only be created between a source
and an unconnected sink.\n')
################# functions for preferences
########################################
-def send_fail_load_preferences():
- send('>>> Error: Cannot load preferences file:
"%s"\n'%PREFERENCES_FILE_PATH)
+def send_fail_load_preferences(prefs_file_path):
+ send('>>> Error: Cannot load preferences file: "%s"\n'%prefs_file_path)
-def send_fail_save_preferences():
- send('>>> Error: Cannot save preferences file:
"%s"\n'%PREFERENCES_FILE_PATH)
+def send_fail_save_preferences(prefs_file_path):
+ send('>>> Error: Cannot save preferences file: "%s"\n'%prefs_file_path)
Modified: grc/trunk/src/grc/Preferences.py
===================================================================
--- grc/trunk/src/grc/Preferences.py 2008-07-26 00:44:08 UTC (rev 9024)
+++ grc/trunk/src/grc/Preferences.py 2008-07-26 19:45:51 UTC (rev 9025)
@@ -20,112 +20,115 @@
#Holds global paramerences
address@hidden Josh Blum
-from Constants import PREFERENCES_FILE_PATH, FLOW_GRAPH_DTD
+from Constants import HOME_DIR, FLOW_GRAPH_DTD
import ParseXML
import Messages
import os
-from grc_gnuradio.Platform import Platform
-platform = Platform(block_paths_internal_only=['preferences.xml'])
+##Access the loaded preferences in this module
+_prefs = list()
+def _set_prefs(prefs): _prefs.append(prefs)
+def _get_prefs(): return _prefs[0]
+def load(platform): _Preferences(platform)
+def save(): _get_prefs().save()
+def get_preferences(): return _get_prefs().get_preferences()
-from grc.gui.elements.Platform import Platform
-platform = Platform(platform)
+class _Preferences(object):
-flow_graph = platform.get_new_flow_graph()
-block = flow_graph.get_new_block('preferences')
+ def __init__(self, platform):
+ #make self available to module
+ _set_prefs(self)
+ #get prefs block
+ self._prefs_block = platform.get_prefs_block()
+ #prefs file path
+ self._prefs_file_path = os.path.join(HOME_DIR,
self._prefs_block.get_param('prefs_file').get_value())
+ #load
+ try:
+ ParseXML.validate_dtd(self._prefs_file_path,
FLOW_GRAPH_DTD)
+ n = ParseXML.from_file(self._prefs_file_path)
+ self._prefs_block.import_data(n['block'])
+ except:
Messages.send_fail_load_preferences(self._prefs_file_path)
+ ##all params
+ self.snap_to_grid_param =
self._prefs_block.get_param('snap_to_grid')
+ self.grid_size_param = self._prefs_block.get_param('grid_size')
+ self.show_grid_param = self._prefs_block.get_param('show_grid')
+ self.show_reports_param =
self._prefs_block.get_param('show_reports')
+ self.restore_files_param =
self._prefs_block.get_param('restore_files')
+ self.window_size_param =
self._prefs_block.get_param('window_size')
+ self.file_open_param = self._prefs_block.get_param('file_open')
+ self.files_open_param =
self._prefs_block.get_param('files_open')
+ self.show_params_param =
self._prefs_block.get_param('show_params')
+ self.show_id_param = self._prefs_block.get_param('show_id')
-##all params
-snap_to_grid_param = block.get_param('snap_to_grid')
-grid_size_param = block.get_param('grid_size')
-show_grid_param = block.get_param('show_grid')
+ def save(self):
+ try: ParseXML.to_file({'block':
self._prefs_block.export_data()}, self._prefs_file_path)
+ except IOError:
Messages.send_fail_save_preferences(self._prefs_file_path)
-show_reports_param = block.get_param('show_reports')
-restore_files_param = block.get_param('restore_files')
-
-window_size_param = block.get_param('window_size')
-file_open_param = block.get_param('file_open')
-files_open_param = block.get_param('files_open')
-show_params_param = block.get_param('show_params')
-show_id_param = block.get_param('show_id')
-
-##Preferences: title, notes, params
-PREFERENCES = [
- (
- 'Grid',
- '''
+ def get_preferences(self):
+ ##Preferences: title, notes, params
+ return [
+ (
+ 'Grid',
+ '''
Show grid will draw a square grid onto the flow graph with grid points
separated by grid size pixels. \
Snap to Grid forces the upper right corner of the signal block to align with a
grid point.
''',
- [snap_to_grid_param, grid_size_param, show_grid_param],
- ),
- (
- 'Appearance',
- '''
+ [self.snap_to_grid_param, self.grid_size_param,
self.show_grid_param],
+ ),
+ (
+ 'Appearance',
+ '''
Show or hide the reports window at the bottom of the main window.
Show or hide all paramater labels in the signal blocks.
Show or hide the ID label in the signal blocks.
''',
- [show_reports_param, show_params_param, show_id_param],
- ),
- (
- 'Misc',
- '''
+ [self.show_reports_param,
self.show_params_param, self.show_id_param],
+ ),
+ (
+ 'Misc',
+ '''
Restore previously opened files on start-up.
''',
- [restore_files_param],
- ),
-]
+ [self.restore_files_param],
+ ),
+ ]
-def load():
- """!
- Load the preferences from the preferences file.
- """
- try:
- ParseXML.validate_dtd(PREFERENCES_FILE_PATH, FLOW_GRAPH_DTD)
- n = ParseXML.from_file(PREFERENCES_FILE_PATH)
- block.import_data(n['block'])
- except: Messages.send_fail_load_preferences()
-
-def save():
- try: ParseXML.to_file({'block': block.export_data()},
PREFERENCES_FILE_PATH)
- except IOError: Messages.send_fail_save_preferences()
-
###########################################################################
# Special methods for specific program functionalities
###########################################################################
def window_size(size=None):
- if size: window_size_param.set_value(size)
+ if size: _get_prefs().window_size_param.set_value(size)
else:
- try: return window_size_param.evaluate()
+ try: return eval(_get_prefs().window_size_param.get_value())
except: return (-1, -1)
def restore_files():
- return restore_files_param.get_value() == 'yes'
+ return _get_prefs().restore_files_param.get_value() == 'yes'
def file_open(file=None):
- if file is not None: file_open_param.set_value(file)
- else: return file_open_param.get_value()
+ if file is not None: _get_prefs().file_open_param.set_value(file)
+ else: return _get_prefs().file_open_param.get_value()
def files_open(files=None):
- if files is not None: files_open_param.set_value('\n'.join(files))
- else: return files_open_param.get_value().split('\n')
+ if files is not None:
_get_prefs().files_open_param.set_value('\n'.join(files))
+ else: return _get_prefs().files_open_param.get_value().split('\n')
def show_reports_window():
- return show_reports_param.get_value() == 'show'
+ return _get_prefs().show_reports_param.get_value() == 'show'
def get_grid_size():
- return int(grid_size_param.get_value())
+ return int(_get_prefs().grid_size_param.get_value())
def snap_to_grid():
- return snap_to_grid_param.get_value() == 'on'
+ return _get_prefs().snap_to_grid_param.get_value() == 'on'
def show_grid():
- return show_grid_param.get_value() == 'show'
+ return _get_prefs().show_grid_param.get_value() == 'show'
def show_params():
- return show_params_param.get_value() == 'show'
+ return _get_prefs().show_params_param.get_value() == 'show'
def show_id():
- return show_id_param.get_value() == 'show'
+ return _get_prefs().show_id_param.get_value() == 'show'
Modified: grc/trunk/src/grc/elements/Param.py
===================================================================
--- grc/trunk/src/grc/elements/Param.py 2008-07-26 00:44:08 UTC (rev 9024)
+++ grc/trunk/src/grc/elements/Param.py 2008-07-26 19:45:51 UTC (rev 9025)
@@ -90,7 +90,6 @@
@param n the nested odict
@return a new param
"""
- self._cached_params = list()
#grab the data
name = n['name']
key = n['key']
Modified: grc/trunk/src/grc/elements/Platform.py
===================================================================
--- grc/trunk/src/grc/elements/Platform.py 2008-07-26 00:44:08 UTC (rev
9024)
+++ grc/trunk/src/grc/elements/Platform.py 2008-07-26 19:45:51 UTC (rev
9025)
@@ -65,6 +65,8 @@
for filename in filter(lambda f:
f.endswith('.xml'), filenames):
self._load_block(os.path.join(dirpath, filename))
+ def get_prefs_block(self): return
self.get_new_flow_graph().get_new_block('preferences')
+
def _load_block(self, f):
"""!
Load the block wrapper from the file path.
Modified: grc/trunk/src/grc/gui/Dialogs.py
===================================================================
--- grc/trunk/src/grc/gui/Dialogs.py 2008-07-26 00:44:08 UTC (rev 9024)
+++ grc/trunk/src/grc/gui/Dialogs.py 2008-07-26 19:45:51 UTC (rev 9025)
@@ -53,7 +53,7 @@
self.set_title("Preferences")
self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
notebook = gtk.Notebook()
- for title,desc,params in Preferences.PREFERENCES:
+ for title,desc,params in Preferences.get_preferences():
vbox = gtk.VBox()
vbox.pack_start(gtk.Label(''), False) #blank label for
spacing
for param in params:
vbox.pack_start(param.get_input_object(), False)
Modified: grc/trunk/src/grc/gui/MainWindow.py
===================================================================
--- grc/trunk/src/grc/gui/MainWindow.py 2008-07-26 00:44:08 UTC (rev 9024)
+++ grc/trunk/src/grc/gui/MainWindow.py 2008-07-26 19:45:51 UTC (rev 9025)
@@ -91,7 +91,7 @@
self.notebook.hide()
self._show_reports_window(False)
# load preferences and show the main window
- Preferences.load()
+ Preferences.load(platform)
self.resize(*Preferences.window_size())
self.show()#show after resize in preferences
Modified: grc/trunk/src/grc/gui/elements/FlowGraph.py
===================================================================
--- grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-26 00:44:08 UTC (rev
9024)
+++ grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-26 19:45:51 UTC (rev
9025)
@@ -142,8 +142,7 @@
@return true for success
"""
if self.get_selected_block():
- for get_ports_attr in ('get_sources', 'get_sinks'):
- ports = getattr(self.get_selected_element(),
get_ports_attr)()
+ for ports in (self.get_selected_block().get_sources(),
self.get_selected_block().get_sinks()):
if ports and hasattr(ports[0], 'get_nports')
and ports[0].get_nports():
#find the param that controls port0
for param in
self.get_selected_block().get_params():
Modified: grc/trunk/src/grc_gnuradio/blocks/options.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/options.xml 2008-07-26 00:44:08 UTC
(rev 9024)
+++ grc/trunk/src/grc_gnuradio/blocks/options.xml 2008-07-26 19:45:51 UTC
(rev 9025)
@@ -83,6 +83,7 @@
For example, an id of my_block will generate the file my_block.py and class
my_block(gr....
The category parameter determines the placement of the block in the block
selection window. \
-The category only applies when creating hier blocks.
+The category only applies when creating hier blocks. \
+To put hier blocks into the root category, enter / for the category.
</doc>
</block>
Modified: grc/trunk/src/grc_gnuradio/blocks/preferences.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/preferences.xml 2008-07-26 00:44:08 UTC
(rev 9024)
+++ grc/trunk/src/grc_gnuradio/blocks/preferences.xml 2008-07-26 19:45:51 UTC
(rev 9025)
@@ -11,6 +11,12 @@
<make></make>
<!-- Hidden Prefs -->
<param>
+ <name>Prefs File</name>
+ <key>prefs_file</key>
+ <value>.grc</value>
+ <type>string</type>
+ </param>
+ <param>
<name>File Open</name>
<key>file_open</key>
<value></value>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9025 - in grc/trunk: notes src/grc src/grc/elements src/grc/gui src/grc/gui/elements src/grc_gnuradio/blocks,
jblum <=