21
21
22
22
logger = logging .getLogger (__name__ )
23
23
24
+ def set_global_functions (global_functions ):
25
+ ret = {}
26
+ if global_functions is not None :
27
+ ret = dict (global_functions )
28
+ if 't' in ret .keys ():
29
+ del ret ['t' ]
30
+ del ret ['T' ]
31
+ return ret
24
32
25
33
class PyRadioConfigWindow (object ):
26
34
n_u = Window_Stack_Constants
@@ -85,13 +93,14 @@ def __init__(self, parent, config,
85
93
toggle_transparency_function ,
86
94
show_theme_selector_function ,
87
95
save_parameters_function ,
88
- reset_parameters_function
89
- ):
96
+ reset_parameters_function ,
97
+ global_functions = None ):
90
98
self .parent = parent
91
99
self ._cnf = config
92
100
self ._toggle_transparency_function = toggle_transparency_function
93
101
self ._show_theme_selector_function = show_theme_selector_function
94
102
self ._save_parameters_function = save_parameters_function
103
+ self ._global_functions = set_global_functions (global_functions )
95
104
self ._reset_parameters_function = reset_parameters_function
96
105
self ._saved_config_options = deepcopy (config .opts )
97
106
self ._config_options = deepcopy (config .opts )
@@ -354,7 +363,9 @@ def keypress(self, char):
354
363
if self .too_small :
355
364
return 1 , []
356
365
val = list (self ._config_options .items ())[self .selection ]
357
- if val [0 ] == 'radiobrowser' :
366
+ if chr (char ) in self ._global_functions .keys ():
367
+ self ._global_functions [chr (char )]()
368
+ elif val [0 ] == 'radiobrowser' :
358
369
if char in (curses .KEY_RIGHT , ord ('l' ),
359
370
ord (' ' ), curses .KEY_ENTER , ord ('\n ' )):
360
371
return 2 , []
@@ -518,7 +529,8 @@ class PyRadioExtraParams(object):
518
529
519
530
def __init__ (self ,
520
531
config ,
521
- parent ):
532
+ parent ,
533
+ global_functions = None ):
522
534
''' setting editing to 0 so that help functions work '''
523
535
self .editing = 0
524
536
self ._max_lines = 16
@@ -532,6 +544,7 @@ def __init__(self,
532
544
self ._title = ' Player Extra Parameters '
533
545
self ._too_small_str = 'Window too small'
534
546
self ._cnf .get_player_params_from_backup (param_type = 1 )
547
+ self ._global_functions = global_functions
535
548
self ._redisplay ()
536
549
537
550
@property
@@ -547,7 +560,9 @@ def set_parrent(self, window):
547
560
self ._redisplay ()
548
561
549
562
def _redisplay (self ):
563
+ logger .error ('_redisplay()' )
550
564
pY , pX = self ._parent .getmaxyx ()
565
+ logger .error ('pY = {0}, pX = {1}' .format (pY , pX ))
551
566
if pY < self ._max_lines + 2 or pX < 30 :
552
567
self ._too_small = True
553
568
self ._win = curses .newwin (
@@ -559,6 +574,8 @@ def _redisplay(self):
559
574
else :
560
575
self ._too_small = False
561
576
self .maxX = pX - 2 if pX < 40 else 40
577
+ logger .error ('maxX = {}' .format (self .maxX ))
578
+ logger .error ('max_lines = {}' .format (self ._max_lines ))
562
579
self ._win = curses .newwin (
563
580
self ._max_lines , self .maxX ,
564
581
int ((pY - self ._max_lines ) / 2 ) + 2 ,
@@ -573,10 +590,12 @@ def _redisplay(self):
573
590
self ._cnf .PLAYER_NAME ,
574
591
self ._win ,
575
592
lambda : True ,
576
- from_config = False
593
+ from_config = False ,
594
+ global_functions = self ._global_functions
577
595
)
578
596
579
597
def show (self ):
598
+ logger .error ('show()' )
580
599
self ._win .bkgdset (' ' , curses .color_pair (3 ))
581
600
self ._win .erase ()
582
601
self ._win .box ()
@@ -612,13 +631,15 @@ class ExtraParametersEditor(object):
612
631
def __init__ (self ,
613
632
parent ,
614
633
config ,
615
- string = '' ):
634
+ string = '' ,
635
+ global_functions = None ):
616
636
self ._parent = parent
617
637
self ._cnf = config
618
638
self .edit_string = string
619
639
self ._caption = ' Parameter value '
620
640
self ._string = self ._orig_string = string
621
641
642
+ self ._global_functions = set_global_functions (global_functions )
622
643
self .Y , self .X = self ._parent .getbegyx ()
623
644
self .Y += 1
624
645
self .X += 1
@@ -771,7 +792,10 @@ def keypress(self, char):
771
792
2: Display line editor help
772
793
'''
773
794
ret = 1
774
- if char == ord ('?' ) and self ._focus > 0 :
795
+ if chr (char ) in self ._global_functions .keys ():
796
+ self ._global_functions [chr (char )]()
797
+ return 1
798
+ elif char == ord ('?' ) and self ._focus > 0 :
775
799
return 2
776
800
elif char in (curses .KEY_EXIT , 27 , ord ('q' )) and \
777
801
self ._focus > 0 :
@@ -864,9 +888,11 @@ def __init__(self,
864
888
startY = 1 ,
865
889
startX = 1 ,
866
890
max_lines = 11 ,
867
- from_config = True ):
891
+ from_config = True ,
892
+ global_functions = None ):
868
893
self ._cnf = config
869
894
self ._orig_params = deepcopy (self ._cnf .saved_params )
895
+ self ._global_functions = set_global_functions (global_functions )
870
896
if logger .isEnabledFor (logging .DEBUG ):
871
897
logger .debug ('original parameters = {}' .format (self ._orig_params ))
872
898
self ._orig_player = player
@@ -1138,7 +1164,10 @@ def keypress(self, char):
1138
1164
5 - add parameter
1139
1165
6 - line editor help
1140
1166
'''
1141
- if char in (
1167
+ if chr (char ) in self ._global_functions .keys ():
1168
+ self ._global_functions [chr (char )]()
1169
+ return - 1
1170
+ elif char in (
1142
1171
curses .KEY_ENTER , ord ('\n ' ),
1143
1172
ord ('\r ' ), ord (' ' ), ord ('l' ),
1144
1173
curses .KEY_RIGHT , ord ('s' )):
@@ -1253,14 +1282,16 @@ class PyRadioSelectPlayer(object):
1253
1282
'''
1254
1283
mlength = 13
1255
1284
1256
- def __init__ (self , config , parent , player ):
1285
+ def __init__ (self , config , parent , player ,
1286
+ global_functions = None ):
1257
1287
if logger .isEnabledFor (logging .DEBUG ):
1258
1288
logger .debug ('current players = {}' .format (player ))
1259
1289
self ._cnf = config
1260
1290
self ._parent = parent
1261
1291
self ._parent_maxY , self ._parent_maxX = parent .getmaxyx ()
1262
1292
self .player = player
1263
1293
self ._orig_player = player
1294
+ self ._global_functions = set_global_functions (global_functions )
1264
1295
self .focus = True
1265
1296
1266
1297
''' Is editor active?
@@ -1432,7 +1463,9 @@ def keypress(self, char):
1432
1463
3 - Editor is visible
1433
1464
4 - Editor exited
1434
1465
'''
1435
- if self .editing == 0 :
1466
+ if chr (char ) in self ._global_functions .keys ():
1467
+ self ._global_functions [chr (char )]()
1468
+ elif self .editing == 0 :
1436
1469
''' focus on players '''
1437
1470
if char in (9 , ):
1438
1471
if self ._players [self .selection ][1 ]:
@@ -1598,7 +1631,8 @@ class PyRadioSelectEncodings(object):
1598
1631
1599
1632
_invalid = []
1600
1633
1601
- def __init__ (self , maxY , maxX , encoding , config_encoding ):
1634
+ def __init__ (self , maxY , maxX , encoding , config_encoding ,
1635
+ global_functions = None ):
1602
1636
self ._parent_maxY = maxY
1603
1637
self ._parent_maxX = maxX
1604
1638
self .encoding = encoding
@@ -1609,6 +1643,12 @@ def __init__(self, maxY, maxX, encoding, config_encoding):
1609
1643
self ._num_of_rows = int (len (self ._encodings ) / self ._num_of_columns )
1610
1644
self .init_window ()
1611
1645
1646
+ def set_global_functions (self , global_functions ):
1647
+ self ._global_functions = global_functions
1648
+
1649
+ def set_reduced_global_functions (self , global_functions ):
1650
+ self ._global_functions = set_global_functions (global_functions )
1651
+
1612
1652
def init_window (self , set_encoding = True ):
1613
1653
self ._win = None
1614
1654
self ._win = curses .newwin (
@@ -1827,7 +1867,10 @@ def _col_row_to_selection(self, a_column, a_row):
1827
1867
def keypress (self , char ):
1828
1868
''' Encoding key press
1829
1869
'''
1830
- if char in (ord ('c' ), ):
1870
+ if chr (char ) in self ._global_functions .keys ():
1871
+ self ._global_functions [chr (char )]()
1872
+
1873
+ elif char in (ord ('c' ), ):
1831
1874
self .encoding = self ._config_encoding
1832
1875
self .setEncoding (self .encoding , init = True )
1833
1876
@@ -1951,7 +1994,8 @@ def __init__(self,
1951
1994
parent ,
1952
1995
config_path ,
1953
1996
default_playlist ,
1954
- include_registers = False ):
1997
+ include_registers = False ,
1998
+ global_functions = None ):
1955
1999
''' Select a playlist from a list
1956
2000
1957
2001
include_registers changes its behavior
@@ -1980,6 +2024,7 @@ def __init__(self,
1980
2024
if self ._include_registers :
1981
2025
self ._title = ' Paste: Select target '
1982
2026
self ._playlist_in_editor = self ._selected_playlist
2027
+ self ._global_functions = set_global_functions (global_functions )
1983
2028
self .init_window ()
1984
2029
1985
2030
def __del__ (self ):
@@ -2221,7 +2266,10 @@ def keypress(self, char):
2221
2266
0, station path - selected station path (for paste window)
2222
2267
1, '' - Cancel
2223
2268
'''
2224
- if self ._select_playlist_error == - 1 or \
2269
+ if chr (char ) in self ._global_functions .keys ():
2270
+ self ._global_functions [chr (char )]()
2271
+
2272
+ elif self ._select_playlist_error == - 1 or \
2225
2273
self ._select_playlist_error == 0 :
2226
2274
self ._error_win = None
2227
2275
self ._select_playlist_error = - 2
@@ -2350,12 +2398,14 @@ class PyRadioSelectStation(PyRadioSelectPlaylist):
2350
2398
2351
2399
_default_playlist = ''
2352
2400
2353
- def __init__ (self , parent , config_path , default_playlist , default_station ):
2401
+ def __init__ (self , parent , config_path , default_playlist , default_station ,
2402
+ global_functions = None ):
2354
2403
self ._default_playlist = default_playlist
2355
2404
self ._orig_default_playlist = default_playlist
2356
2405
if logger .isEnabledFor (logging .INFO ):
2357
2406
logger .info ('displaying stations from: "{}"' .format (default_playlist ))
2358
2407
PyRadioSelectPlaylist .__init__ (self , parent , config_path , default_station )
2408
+ self ._global_functions = set_global_functions (global_functions )
2359
2409
self ._title = ' Station Selection '
2360
2410
''' adding 2 to padding calculation
2361
2411
(i.e. no selection and random selection
@@ -2456,6 +2506,10 @@ def keypress(self, char):
2456
2506
self .setStation (self ._orig_playlist )
2457
2507
return - 1 , ''
2458
2508
2509
+ elif chr (char ) in self ._global_functions .keys ():
2510
+ self ._global_functions [chr (char )]()
2511
+ return - 1 , ''
2512
+
2459
2513
return PyRadioSelectPlaylist .keypress (self , char )
2460
2514
2461
2515
# pymode:lint_ignore=W901
0 commit comments