Skip to content

Commit 3d68a89

Browse files
committed
added smooth_scroll
1 parent 468907c commit 3d68a89

File tree

7 files changed

+84
-26
lines changed

7 files changed

+84
-26
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
CHANGELOG
22
=========
33

4+
v0.7.0
5+
------
6+
7+
- [ ] Vi keybindings
8+
- [x] Added option for smooth scroll
9+
- [ ] Batch tag files(more than one file at a time)
10+
- [ ] Preferences are now saved when updating the app
11+
- [x] Validators for smooth_scroll and preview_format
12+
413
v0.6.2
514
------
615

clid.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.1
22
Name: clid
3-
Version: 0.6.3
3+
Version: 0.6.2
44
Summary: Command line app based on ncurses to edit ID3 tags of mp3 files
55
Home-page: https://github.com/GokulSoumya/clid
66
Author: Gokul

clid/config.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
music_dir = ~/Music
2+
smooth_scroll = true
23
preview_format = %a - %l - %n. %t

clid/database.py

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

clid/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ class ClidMultiline(npy.MultiLine):
6060
self.parent.value refers to database.Mp3DataBase -> class
6161
"""
6262

63+
def __init__(self, *args, **kwargs):
64+
super().__init__(*args, **kwargs)
65+
smooth = self.parent.parentApp.settings['smooth_scroll'] # is smooth scroll enabled ?
66+
self.slow_scroll = True if smooth == 'true' else False
67+
6368
def set_status(self, filename):
6469
"""Set the the value of self.parent.wStatus2 with metadata of file under cursor."""
6570
self.parent.wStatus2.value = self.parent.value.parse_meta_for_status(filename=filename)
@@ -94,7 +99,7 @@ def h_revert_escape(self, char):
9499
def h_switch_to_settings(self, char):
95100
self.parent.parentApp.switchForm("SETTINGS")
96101

97-
102+
98103
# NOTE: The if blocks with self.cursor_line is mainly to prevent the app from
99104
# crashing Eg: when there is nothing to display(empty folder)
100105

clid/pref.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ class PreferencesView(npy.FormMuttActiveTraditional):
4040
def __init__(self, *args, **kwargs):
4141
super().__init__(*args, **kwargs)
4242
self.set_value(database.SettingsDataBase())
43-
self.value.parent = self
44-
self.value.settings = self.parentApp.settings
43+
settings = self.parentApp.settings
44+
when_changed = database.WhenChanged(main_form=self.parentApp.getForm("MAIN"),
45+
settings=settings)
46+
self.value.set_attrs(parent=self, settings=settings, when_changed=when_changed)
4547
self.value.make_strings()
4648
self.load_pref()
4749

clid/validators.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ class ValidationError(Exception):
1515

1616
def music_dir(test):
1717
"""Checks whether `test` exists and is a directory.
18-
1918
Args:
2019
test(str): path to be tested.
21-
2220
Raises:
2321
ValidationError: if `test` doesn't exist or is not directory
2422
"""
@@ -29,9 +27,29 @@ def music_dir(test):
2927

3028

3129
def preview_format(test):
32-
pass
30+
"""Checks whether is a valid which can be used as a preview format
31+
Args:
32+
test(str): str to be tested
33+
Raises:
34+
ValidationError
35+
"""
36+
valid_specs_list = _const.FORMAT.keys()
37+
specs_list = _const.FORMAT_PAT.findall(test)
38+
39+
for spec in specs_list:
40+
if spec not in valid_specs_list:
41+
raise ValidationError('"' + spec + '"' + ' is not a valid format specifier')
42+
43+
44+
def smooth_scroll(test):
45+
"""Checks whether test is either 'true' or 'false'"""
46+
if not(test == 'true' or test == 'false'):
47+
raise ValidationError('Sorry, but I can\'t make sense of ' + '"' + test + '"' + '; \
48+
acceptable values for smooth_scroll are "true" or "false"')
49+
3350

3451
VALIDATORS = {
3552
'music_dir': music_dir,
36-
'preview_format': preview_format
53+
'preview_format': preview_format,
54+
'smooth_scroll': smooth_scroll
3755
}

0 commit comments

Comments
 (0)