diff options
author | jblum | 2008-11-28 06:51:21 +0000 |
---|---|---|
committer | jblum | 2008-11-28 06:51:21 +0000 |
commit | d01692fa60eb6b08b6b7b5369d2a08cee912395f (patch) | |
tree | baccdedeea2fa35d24ee9f9c3488f2b9caa85de3 /grc/src/gui | |
parent | 277aa8d20c9db1c3de915d284db9e420f3d9f2f6 (diff) | |
download | gnuradio-d01692fa60eb6b08b6b7b5369d2a08cee912395f.tar.gz gnuradio-d01692fa60eb6b08b6b7b5369d2a08cee912395f.tar.bz2 gnuradio-d01692fa60eb6b08b6b7b5369d2a08cee912395f.zip |
new preferences
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10081 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src/gui')
-rw-r--r-- | grc/src/gui/ActionHandler.py | 19 | ||||
-rw-r--r-- | grc/src/gui/Actions.py | 2 | ||||
-rw-r--r-- | grc/src/gui/Bars.py | 3 | ||||
-rw-r--r-- | grc/src/gui/Constants.py | 1 | ||||
-rw-r--r-- | grc/src/gui/Dialogs.py | 21 | ||||
-rw-r--r-- | grc/src/gui/FileDialogs.py | 45 | ||||
-rw-r--r-- | grc/src/gui/MainWindow.py | 20 | ||||
-rw-r--r-- | grc/src/gui/Preferences.py | 142 |
8 files changed, 88 insertions, 165 deletions
diff --git a/grc/src/gui/ActionHandler.py b/grc/src/gui/ActionHandler.py index 85bfcb34e..4c5516311 100644 --- a/grc/src/gui/ActionHandler.py +++ b/grc/src/gui/ActionHandler.py @@ -32,7 +32,7 @@ from .. utils import ParseXML import random from .. platforms.gui.Platform import Platform from MainWindow import MainWindow -from Dialogs import PreferencesDialog, AboutDialog +from Dialogs import AboutDialog from FileDialogs import OpenFlowGraphFileDialog, SaveFlowGraphFileDialog, SaveImageFileDialog gobject.threads_init() @@ -77,13 +77,13 @@ class ActionHandler: """ Handle key presses from the keyboard and translate key combos into actions. This key press handler is called before the gtk accelerators kick in. - This handler ensures that key presses without a mod mask, only pass to the accelerators - if the flow graph is in focus and something is selected. + This handler ensures that key presses without a mod mask, + only pass to the accelerators if the flow graph is in focus. This function also handles keys that accelerators refuse to handle: left/right, and keys that are not registered with an accelerator: +/-. @return false to let the accelerators handle the key action """ - if self.get_focus_flag() and self.get_flow_graph().is_selected(): + if self.get_focus_flag(): try: self.handle_states({ 'Left': Actions.BLOCK_ROTATE_LEFT, @@ -97,9 +97,9 @@ class ActionHandler: 'KP_Subtract': Actions.PORT_CONTROLLER_DEC, }[gtk.gdk.keyval_name(event.keyval)]) return True - #focus + selection: always return false for accelerator to handle + #focus: always return false for accelerator to handle except: return False - #no focus + selection: only allow accelerator to handle when a mod is used + #no focus: only allow accelerator to handle when a mod is used return not event.state def _quit(self, window, event): @@ -141,9 +141,9 @@ class ActionHandler: Actions.APPLICATION_QUIT, Actions.FLOW_GRAPH_NEW, Actions.FLOW_GRAPH_OPEN, Actions.FLOW_GRAPH_SAVE_AS, Actions.FLOW_GRAPH_CLOSE, Actions.ABOUT_WINDOW_DISPLAY, - Actions.PREFS_WINDOW_DISPLAY, Actions.FLOW_GRAPH_SCREEN_CAPTURE, + Actions.FLOW_GRAPH_SCREEN_CAPTURE, ): Actions.get_action_from_name(action).set_sensitive(True) - if not self.init_file_paths and Preferences.restore_files(): + if not self.init_file_paths: self.init_file_paths = Preferences.files_open() if not self.init_file_paths: self.init_file_paths = [''] for file_path in self.init_file_paths: @@ -240,9 +240,6 @@ class ActionHandler: ################################################## # Window stuff ################################################## - elif state == Actions.PREFS_WINDOW_DISPLAY: - PreferencesDialog() - self.get_flow_graph().update() elif state == Actions.ABOUT_WINDOW_DISPLAY: AboutDialog() ################################################## diff --git a/grc/src/gui/Actions.py b/grc/src/gui/Actions.py index 818995a32..16f12dd4c 100644 --- a/grc/src/gui/Actions.py +++ b/grc/src/gui/Actions.py @@ -56,7 +56,6 @@ FLOW_GRAPH_EXEC = 'flow graph exec' FLOW_GRAPH_KILL = 'flow graph kill' FLOW_GRAPH_SCREEN_CAPTURE = 'flow graph screen capture' ABOUT_WINDOW_DISPLAY = 'about window display' -PREFS_WINDOW_DISPLAY = 'prefs window display' ###################################################################################################### # Action Key Map @@ -106,7 +105,6 @@ _actions_list = ( gtk.Action(BLOCK_CUT, 'Cu_t', 'Cut', 'gtk-cut'), gtk.Action(BLOCK_COPY, '_Copy', 'Copy', 'gtk-copy'), gtk.Action(BLOCK_PASTE, '_Paste', 'Paste', 'gtk-paste'), - gtk.Action(PREFS_WINDOW_DISPLAY, '_Preferences', 'Configure Preferences', 'gtk-preferences'), gtk.Action(ABOUT_WINDOW_DISPLAY, '_About', 'About this program', 'gtk-about'), gtk.Action(FLOW_GRAPH_GEN, '_Generate', 'Generate the flow graph', 'gtk-convert'), gtk.Action(FLOW_GRAPH_EXEC, '_Execute', 'Execute the flow graph', 'gtk-execute'), diff --git a/grc/src/gui/Bars.py b/grc/src/gui/Bars.py index 1416d4dd5..c89aea580 100644 --- a/grc/src/gui/Bars.py +++ b/grc/src/gui/Bars.py @@ -86,9 +86,6 @@ MENU_BAR_LIST = ( Actions.FLOW_GRAPH_EXEC, Actions.FLOW_GRAPH_KILL, ]), - (gtk.Action('Options', '_Options', None, None), [ - Actions.PREFS_WINDOW_DISPLAY, - ]), (gtk.Action('Help', '_Help', None, None), [ Actions.ABOUT_WINDOW_DISPLAY, ]), diff --git a/grc/src/gui/Constants.py b/grc/src/gui/Constants.py index ccee7aa60..70e6b6b6e 100644 --- a/grc/src/gui/Constants.py +++ b/grc/src/gui/Constants.py @@ -23,7 +23,6 @@ import os DEFAULT_FILE_PATH = os.getcwd() ##file extensions -FLOW_GRAPH_FILE_EXTENSION = '.grc' IMAGE_FILE_EXTENSION = '.png' ##name for new/unsaved flow graphs diff --git a/grc/src/gui/Dialogs.py b/grc/src/gui/Dialogs.py index 995fe4628..e15f8c574 100644 --- a/grc/src/gui/Dialogs.py +++ b/grc/src/gui/Dialogs.py @@ -41,27 +41,6 @@ class TextDisplay(gtk.TextView): self.set_cursor_visible(False) self.set_wrap_mode(gtk.WRAP_WORD_CHAR) -class PreferencesDialog(gtk.Dialog): - """A dialog box to display the preferences.""" - - def __init__(self): - """PreferencesDialog constructor.""" - gtk.Dialog.__init__(self, buttons=('gtk-close', gtk.RESPONSE_CLOSE)) - self.set_title("Preferences") - self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT) - notebook = gtk.Notebook() - 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) - desc = desc.strip('\n') - if desc: vbox.pack_start(TextDisplay(desc), False, padding=5) - notebook.append_page(vbox, gtk.Label(title)) - self.vbox.pack_start(notebook, True) - self.show_all() - self.run() - self.destroy() - def MessageDialogHelper(type, buttons, title=None, markup=None): """ Create a modal message dialog and run it. diff --git a/grc/src/gui/FileDialogs.py b/grc/src/gui/FileDialogs.py index 2758e909b..78c74c91a 100644 --- a/grc/src/gui/FileDialogs.py +++ b/grc/src/gui/FileDialogs.py @@ -22,8 +22,9 @@ pygtk.require('2.0') import gtk from Dialogs import MessageDialogHelper from Constants import \ - DEFAULT_FILE_PATH, FLOW_GRAPH_FILE_EXTENSION, \ - IMAGE_FILE_EXTENSION, NEW_FLOGRAPH_TITLE + DEFAULT_FILE_PATH, IMAGE_FILE_EXTENSION, \ + NEW_FLOGRAPH_TITLE +import Preferences from os import path OPEN_FLOW_GRAPH = 'open flow graph' @@ -31,20 +32,26 @@ SAVE_FLOW_GRAPH = 'save flow graph' SAVE_IMAGE = 'save image' ##the filter for flow graph files -FLOW_GRAPH_FILE_FILTER = gtk.FileFilter() -FLOW_GRAPH_FILE_FILTER.set_name('GRC Files') -FLOW_GRAPH_FILE_FILTER.add_pattern('*'+FLOW_GRAPH_FILE_EXTENSION) -FLOW_GRAPH_FILE_FILTER.add_pattern('*.xml') #TEMP +def get_flow_graph_files_filter(): + filter = gtk.FileFilter() + filter.set_name('Flow Graph Files') + filter.add_pattern('*'+Preferences.file_extension()) + filter.add_pattern('*.xml') #TEMP + return filter ##the filter for image files -IMAGE_FILE_FILTER = gtk.FileFilter() -IMAGE_FILE_FILTER.set_name('Image Files') -IMAGE_FILE_FILTER.add_pattern('*'+IMAGE_FILE_EXTENSION) +def get_image_files_filter(): + filter = gtk.FileFilter() + filter.set_name('Image Files') + filter.add_pattern('*'+IMAGE_FILE_EXTENSION) + return filter ##the filter for all files -ALL_FILE_FILTER = gtk.FileFilter() -ALL_FILE_FILTER.set_name('All Files') -ALL_FILE_FILTER.add_pattern('*') +def get_all_files_filter(): + filter = gtk.FileFilter() + filter.set_name('All Files') + filter.add_pattern('*') + return filter class FileDialogHelper(gtk.FileChooserDialog): """ @@ -64,7 +71,7 @@ class FileDialogHelper(gtk.FileChooserDialog): gtk.FileChooserDialog.__init__(self, title, None, action, ('gtk-cancel', gtk.RESPONSE_CANCEL, ok_stock, gtk.RESPONSE_OK)) self.set_select_multiple(False) self.set_local_only(True) - self.add_filter(ALL_FILE_FILTER) + self.add_filter(get_all_files_filter()) class FileDialog(FileDialogHelper): """A dialog box to save or open flow graph files. This is a base class, do not use.""" @@ -74,18 +81,18 @@ class FileDialog(FileDialogHelper): FileDialog constructor. @param current_file_path the current directory or path to the open flow graph """ - if not current_file_path: current_file_path = path.join(DEFAULT_FILE_PATH, NEW_FLOGRAPH_TITLE + FLOW_GRAPH_FILE_EXTENSION) + if not current_file_path: current_file_path = path.join(DEFAULT_FILE_PATH, NEW_FLOGRAPH_TITLE + Preferences.file_extension()) if self.type == OPEN_FLOW_GRAPH: FileDialogHelper.__init__(self, gtk.FILE_CHOOSER_ACTION_OPEN, 'Open a Flow Graph from a File...') - self.add_and_set_filter(FLOW_GRAPH_FILE_FILTER) + self.add_and_set_filter(get_flow_graph_files_filter()) self.set_select_multiple(True) 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(FLOW_GRAPH_FILE_FILTER) + self.add_and_set_filter(get_flow_graph_files_filter()) self.set_current_name(path.basename(current_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(IMAGE_FILE_FILTER) + self.add_and_set_filter(get_image_files_filter()) current_file_path = current_file_path + IMAGE_FILE_EXTENSION self.set_current_name(path.basename(current_file_path)) #show the current filename self.set_current_folder(path.dirname(current_file_path)) #current directory @@ -113,8 +120,8 @@ class FileDialog(FileDialogHelper): if self.type in (SAVE_FLOW_GRAPH, SAVE_IMAGE): filename = self.get_filename() for extension, filter in ( - (FLOW_GRAPH_FILE_EXTENSION, FLOW_GRAPH_FILE_FILTER), - (IMAGE_FILE_EXTENSION, IMAGE_FILE_FILTER), + (FLOW_GRAPH_FILE_EXTENSION, get_flow_graph_files_filter()), + (IMAGE_FILE_EXTENSION, get_image_files_filter()), ): #append the missing file extension if the filter matches if filename[len(filename)-len(extension):] != extension \ and filter == self.get_filter(): filename += extension diff --git a/grc/src/gui/MainWindow.py b/grc/src/gui/MainWindow.py index 474da4f33..ffb696a45 100644 --- a/grc/src/gui/MainWindow.py +++ b/grc/src/gui/MainWindow.py @@ -90,7 +90,7 @@ class MainWindow(gtk.Window): self.flow_graph_vpaned.pack2(self.reports_scrolled_window, False) #dont allow resize #load preferences and show the main window Preferences.load(platform) - self.resize(*Preferences.window_size()) + self.resize(*Preferences.main_window_size()) self.flow_graph_vpaned.set_position(Preferences.reports_window_position()) self.hpaned.set_position(Preferences.blocks_window_position()) self.show_all() @@ -190,7 +190,7 @@ class MainWindow(gtk.Window): #save state before closing Preferences.files_open(open_files) Preferences.file_open(open_file) - Preferences.window_size(self.get_size()) + Preferences.main_window_size(self.get_size()) Preferences.reports_window_position(self.flow_graph_vpaned.get_position()) Preferences.blocks_window_position(self.hpaned.get_position()) Preferences.save() @@ -231,16 +231,14 @@ class MainWindow(gtk.Window): Show/hide the reports window. @param title the window title """ - if self.get_page(): - title = ''.join(( - Preferences.window_prefix(), - ' - Editing: ', - (self.get_page().get_file_path() or NEW_FLOGRAPH_TITLE), - (self.get_page().get_saved() and ' ' or '*'), #blank must be non empty - (self.get_page().get_read_only() and ' (read-only)' or ''), - ) + title = ''.join(( + self._platform.get_name(), + ' - Editing: ', + (self.get_page().get_file_path() or NEW_FLOGRAPH_TITLE), + (self.get_page().get_saved() and ' ' or '*'), #blank must be non empty + (self.get_page().get_read_only() and ' (read-only)' or ''), ) - else: title = MAIN_WINDOW_PREFIX + ' - Editor ' + ) gtk.Window.set_title(self, title) #set tab titles for page in self._get_pages(): diff --git a/grc/src/gui/Preferences.py b/grc/src/gui/Preferences.py index d6533586f..1d89920dd 100644 --- a/grc/src/gui/Preferences.py +++ b/grc/src/gui/Preferences.py @@ -17,122 +17,70 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ -from .. platforms.base.Constants import FLOW_GRAPH_DTD -from .. utils import ParseXML -import Messages +import ConfigParser import os -##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() +_platform = None +_config_parser = ConfigParser.ConfigParser() -class _Preferences(object): +def file_extension(): return '.'+_platform.get_key() +def _prefs_file(): return os.path.join(os.path.expanduser('~'), file_extension()) - 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(os.path.expanduser('~'), 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.window_prefix_param = self._prefs_block.get_param('window_prefix') - 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.reports_window_position_param = self._prefs_block.get_param('reports_window_position') - self.blocks_window_position_param = self._prefs_block.get_param('blocks_window_position') - 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') - - 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) - - 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. -''', - [self.snap_to_grid_param, self.grid_size_param, self.show_grid_param], - ), - ( - 'Appearance', - ''' -Show or hide all paramater labels in the signal blocks. -''', - [self.show_params_param], - ), - ( - 'Misc', - ''' -Restore previously opened files on start-up. -''', - [self.restore_files_param], - ), - ] +def load(platform): + global _platform + _platform = platform + #create sections + _config_parser.add_section('main') + _config_parser.add_section('files_open') + try: _config_parser.read(_prefs_file()) + except: pass +def save(): + try: _config_parser.write(open(_prefs_file(), 'w')) + except: pass ########################################################################### # Special methods for specific program functionalities ########################################################################### -def window_prefix(): - return _get_prefs().window_prefix_param.get_value() - -def window_size(size=None): - if size: _get_prefs().window_size_param.set_value(size) +def main_window_size(size=None): + if size is not None: + _config_parser.set('main', 'main_window_width', size[0]) + _config_parser.set('main', 'main_window_height', size[1]) else: - try: return eval(_get_prefs().window_size_param.get_value()) - except: return (-1, -1) - -def restore_files(): - return _get_prefs().restore_files_param.get_value() == 'yes' + try: return ( + _config_parser.getint('main', 'main_window_width'), + _config_parser.getint('main', 'main_window_height'), + ) + except: return (1, 1) def file_open(file=None): - if file is not None: _get_prefs().file_open_param.set_value(file) - else: return _get_prefs().file_open_param.get_value() + if file is not None: _config_parser.set('main', 'file_open', file) + else: + try: return _config_parser.get('main', 'file_open') + except: return '' def files_open(files=None): - 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') + if files is not None: + _config_parser.remove_section('files_open') #clear section + _config_parser.add_section('files_open') + for i, file in enumerate(files): + _config_parser.set('files_open', 'file_open_%d'%i, file) + else: + files = list() + i = 0 + while True: + try: files.append(_config_parser.get('files_open', 'file_open_%d'%i)) + except: return files + i = i + 1 def reports_window_position(pos=None): - if pos is not None: _get_prefs().reports_window_position_param.set_value('%d'%pos) + if pos is not None: _config_parser.set('main', 'reports_window_position', pos) else: - try: return int(_get_prefs().reports_window_position_param.get_value()) or 1 #greater than 0 + try: return _config_parser.getint('main', 'reports_window_position') or 1 #greater than 0 except: return -1 def blocks_window_position(pos=None): - if pos is not None: _get_prefs().blocks_window_position_param.set_value('%d'%pos) + if pos is not None: _config_parser.set('main', 'blocks_window_position', pos) else: - try: return int(_get_prefs().blocks_window_position_param.get_value()) or 1 #greater than 0 + try: return _config_parser.getint('main', 'blocks_window_position') or 1 #greater than 0 except: return -1 - -def get_grid_size(): - return int(_get_prefs().grid_size_param.get_value()) - -def snap_to_grid(): - return _get_prefs().snap_to_grid_param.get_value() == 'on' - -def show_grid(): - return _get_prefs().show_grid_param.get_value() == 'show' - -def show_params(): - return _get_prefs().show_params_param.get_value() == 'show' |