@@ -107,18 +107,18 @@ class SettingsDataBase(object):
107107 used to refer to parent form(pref.PreferencesView)
108108 disp_strings(list):
109109 list of formatted strings which will be used to display settings in the window
110- when_changed(dict):
111- dict of str:function; str is a setting; function to be executed when corresponding
112- setting is changed
113110 """
114111 def __init__ (self ):
115112 self .parent = None # set by parent; see docstring
116- self .settings = dict () # also set by parent
113+ self .settings = None # also set by parent
117114 self .disp_strings = []
118- self .when_changed = {
119- 'music_dir' : self .music_dir ,
120- 'preview_format' : self .preview_format
121- }
115+ self .when_changed = None
116+
117+ def set_attrs (self , parent , settings , when_changed ):
118+ """Set attributes that can only be set after a particular external operation"""
119+ self .parent = parent
120+ self .settings = settings
121+ self .when_changed = when_changed
122122
123123 def make_strings (self ):
124124 """Make a list of strings which will be used to display the settings
@@ -141,7 +141,7 @@ def change_setting(self, key, new):
141141 validators .VALIDATORS [key ](new )
142142 self .settings [key ] = new
143143 self .settings .write ()
144- self .when_changed [key ]()
144+ self .when_changed . when_changed [key ]()
145145 except validators .ValidationError as error :
146146 # self.parent.wCommand.print_message(str(error), 'WARNING')
147147 npyscreen .notify_confirm (message = str (error ), title = 'Error' , editw = 1 )
@@ -151,15 +151,38 @@ def change_setting(self, key, new):
151151 title = 'Error' , editw = 1
152152 )
153153
154+
155+ class WhenChanged (object ):
156+ """Class with functions to be executed when an option is changed.
157+ This is class is used by SettingsDataBase
158+
159+ Attributes:
160+ settings(configobj.ConfigObj):
161+ For accessing settings
162+ main_form(npy.FormMuttActiveTraditionl):
163+ Actually the main form with the files view
164+ when_changed(dict):
165+ dict of str:function; str is a setting; function to be executed when corresponding
166+ setting is changed
167+ """
168+ def __init__ (self , main_form , settings ):
169+ self .settings = settings
170+ self .main_form = main_form
171+ self .when_changed = {
172+ 'music_dir' : self .music_dir ,
173+ 'smooth_scroll' : self .smooth_scroll ,
174+ 'preview_format' : self .preview_format
175+ }
176+
154177 def music_dir (self ):
155- """To be executed when `music_dir` option is changed"""
156- main_form = self .parent .parentApp .getForm ("MAIN" )
157- main_form .value .load_files_and_set_values ()
158- main_form .load_files ()
178+ self .main_form .value .load_files_and_set_values ()
179+ self .main_form .load_files ()
159180
160181 def preview_format (self ):
161- """To be executed when `preview_format` option is changed"""
162- main_form = self .parent .parentApp .getForm ("MAIN" )
163- main_form .value .meta_cache = dict ()
164- main_form .value .load_preview_format ()
165- main_form .wMain .set_status (main_form .wMain .get_selected ()) # change current file's preview into new format
182+ self .main_form .value .meta_cache = dict ()
183+ self .main_form .value .load_preview_format ()
184+ self .main_form .wMain .set_status (self .main_form .wMain .get_selected ()) # change current file's preview into new format
185+
186+ def smooth_scroll (self ):
187+ smooth = self .settings ['smooth_scroll' ]
188+ self .main_form .wMain .slow_scroll = True if smooth == 'true' else False
0 commit comments