@@ -35,7 +35,8 @@ class PyRadioStationsBrowser(object):
35
35
# This property value is half the difference (normally 2 / 2 = 1)
36
36
# Used to chgat the columns' separators in internal body
37
37
# Check if the cursor is divided as required and adjust
38
- _outer_internal_body_diff = 1
38
+ _outer_internal_body_diff = 2
39
+ _outer_internal_body_half_diff = 1
39
40
40
41
def __init__ (self , search = None ):
41
42
"""Initialize the station's browser.
@@ -53,11 +54,11 @@ def __init__(self, search=None):
53
54
pass
54
55
55
56
@property
56
- def outer_internal_body_diff (self ):
57
- return self ._outer_internal_body_diff
57
+ def outer_internal_body_half_diff (self ):
58
+ return self ._outer_internal_body_half_diff
58
59
59
- @outer_internal_body_diff .setter
60
- def outer_internal_body_diff (self , value ):
60
+ @outer_internal_body_half_diff .setter
61
+ def outer_internal_body_half_diff (self , value ):
61
62
raise ValueError ('property is read only' )
62
63
63
64
@property
@@ -158,6 +159,14 @@ class PyRadioBrowserInfoBrowser(PyRadioStationsBrowser):
158
159
_have_to_retrieve_url = True
159
160
_internal_header_height = 1
160
161
162
+ _columns_width = {
163
+ 'votes' : 7 ,
164
+ 'clickcount' : 7 ,
165
+ 'bitrate' : 7 ,
166
+ 'country' : 14 ,
167
+ 'language' : 15
168
+ }
169
+
161
170
def __init__ (self , search = None ):
162
171
if search :
163
172
self .search (search )
@@ -495,40 +504,88 @@ def _get_output_format(self, width):
495
504
else :
496
505
self ._output_format = 5
497
506
498
- def get_columns_separators (self , width , use_old_output_format = False , adjust = 0 ):
499
- actual_width = width - 2
500
- actual_width = width
507
+ def _populate_columns_separators (self , a_tuple , width ):
508
+ ret = []
509
+ for i , n in enumerate (a_tuple ):
510
+ if i == 0 :
511
+ ret .append (width - self ._columns_width [n ])
512
+ else :
513
+ ret .append (ret [- 1 ] - 1 - self ._columns_width [n ])
514
+ ret .reverse ()
515
+ return ret
516
+
517
+ def get_columns_separators (self ,
518
+ width ,
519
+ use_old_output_format = False ,
520
+ adjust = 0 ,
521
+ adjust_for_body = False ,
522
+ adjust_for_header = False ,
523
+ ):
524
+ """Calculates columns separators for a given width
525
+ based on self._output_format.
526
+
527
+ Parameters
528
+ ----------
529
+ width
530
+ Window width to use for the calculation.
531
+ use_old_output_format
532
+ If True, do not calculate self._output_format
533
+ (use what's already calculated).
534
+ adjust
535
+ Delete adjust from the output
536
+ Example:
537
+ if the output was [55, 67]
538
+ and adjust was 2
539
+ the output would become [53, 65]
540
+ adjust_for_header
541
+ Delete self._outer_internal_body_diff from output
542
+ This is to be used for displaying the internal header
543
+ adjust_for_body
544
+ Delete self._outer_internal_body_half_diff from output
545
+ This is to be used for changing columns' separators
546
+ color, when displaying body lines (stations' lines).
547
+
548
+ IMPORTANT
549
+ ---------
550
+ The adjust* parameters are mutually exclusive, which means
551
+ that ONLY ONE of them can be used at any given call to the
552
+ function. If you fail to comply, the result will be wrong.
553
+
554
+ Returns
555
+ -------
556
+ A list containing columns_separotors (e.g. [55, 65]).
557
+ """
558
+
559
+ columns_separotors = []
501
560
if not use_old_output_format :
502
- self ._get_output_format (actual_width )
561
+ self ._get_output_format (width )
503
562
if self ._output_format == 0 :
504
563
columns_separotors = []
505
564
elif self ._output_format == 1 :
506
- columns_separotors = [ actual_width - 7 ]
565
+ columns_separotors = [width - col_width [ 'bitrate' ] ]
507
566
elif self ._output_format == 2 :
508
- columns_separotors = [actual_width - 15 ,
509
- actual_width - 7
510
- ]
567
+ columns_separotors = self ._populate_columns_separators (('bitrate' , 'votes' ), width )
568
+
511
569
elif self ._output_format == 3 :
512
- columns_separotors = [actual_width - 23 ,
513
- actual_width - 15 ,
514
- actual_width - 7
515
- ]
570
+ columns_separotors = self ._populate_columns_separators (('bitrate' , 'clickcount' , 'votes' ), width )
571
+
516
572
elif self ._output_format == 4 :
517
- columns_separotors = [actual_width - 38 ,
518
- actual_width - 30 ,
519
- actual_width - 22 ,
520
- actual_width - 14
521
- ]
573
+ columns_separotors = self ._populate_columns_separators (('country' , 'bitrate' , 'clickcount' , 'votes' ), width )
574
+
522
575
elif self ._output_format == 5 :
523
- columns_separotors = [actual_width - 54 ,
524
- actual_width - 46 ,
525
- actual_width - 38 ,
526
- actual_width - 30 ,
527
- actual_width - 15
528
- ]
576
+ columns_separotors = self ._populate_columns_separators (('language' , 'country' , 'bitrate' , 'clickcount' , 'votes' ), width )
577
+
578
+ if adjust_for_header :
579
+ for n in range (0 , len (columns_separotors )):
580
+ columns_separotors [n ] -= self ._outer_internal_body_diff
581
+
582
+ if adjust_for_body :
583
+ for n in range (0 , len (columns_separotors )):
584
+ columns_separotors [n ] -= self ._outer_internal_body_half_diff
585
+
529
586
if adjust > 0 :
530
587
for n in range (0 , len (columns_separotors )):
531
- columns_separotors [n ] -= 2
588
+ columns_separotors [n ] -= adjust
532
589
return columns_separotors
533
590
534
591
def get_internal_header (self , pad , width ):
@@ -539,7 +596,9 @@ def get_internal_header(self, pad, width):
539
596
(' Votes' , ' Clicks' , 'Bitrate' , 'Country' ),
540
597
(' Votes' , ' Clicks' , 'Bitrate' , 'Country' , 'Language' )
541
598
)
542
- columns_separotors = self .get_columns_separators (width , use_old_output_format = True , adjust = 2 )
599
+ columns_separotors = self .get_columns_separators (width , use_old_output_format = True )
600
+ for i in range (0 , len (columns_separotors )):
601
+ columns_separotors [i ] -= 2
543
602
title = '#' .rjust (pad ) + ' Name'
544
603
return ((title , columns_separotors , columns [self ._output_format ]), )
545
604
0 commit comments