13
13
from . import player
14
14
15
15
import locale
16
- locale .setlocale (locale .LC_ALL ,"" )
16
+ locale .setlocale (locale .LC_ALL , "" )
17
17
18
18
19
19
logger = logging .getLogger (__name__ )
@@ -82,7 +82,7 @@ def setupAndDrawScreen(self):
82
82
def initHead (self ):
83
83
from pyradio import version
84
84
85
- info = " PyRadio %s " % version
85
+ info = " PyRadio {0} " . format ( version )
86
86
self .headWin .addstr (0 , 0 , info , curses .color_pair (4 ))
87
87
rightStr = "www.coderholic.com/pyradio"
88
88
self .headWin .addstr (0 , self .maxX - len (rightStr ) - 1 , rightStr ,
@@ -106,35 +106,30 @@ def initFooter(self):
106
106
def refreshBody (self ):
107
107
self .bodyWin .erase ()
108
108
self .bodyWin .box ()
109
-
110
109
self .bodyWin .move (1 , 1 )
111
110
maxDisplay = self .bodyMaxY - 1
112
- for idx in range (maxDisplay - 1 ):
113
- if (idx > maxDisplay ):
114
- break
115
- try :
116
- station = self .stations [idx + self .startPos ]
117
- col = curses .color_pair (5 )
118
-
119
- if idx + self .startPos == self .selection and \
120
- self .selection == self .playing :
121
- col = curses .color_pair (9 )
122
- self .bodyWin .hline (idx + 1 , 1 , ' ' , self .bodyMaxX - 2 , col )
123
- elif idx + self .startPos == self .selection :
124
- col = curses .color_pair (6 )
125
- self .bodyWin .hline (idx + 1 , 1 , ' ' , self .bodyMaxX - 2 , col )
126
- elif idx + self .startPos == self .playing :
127
- col = curses .color_pair (4 )
128
- self .bodyWin .hline (idx + 1 , 1 , ' ' , self .bodyMaxX - 2 , col )
129
- self .bodyWin .addstr (idx + 1 , 1 ,
130
- "%2.d. %s" % (idx + self .startPos + 1 ,
131
- station [0 ]), col )
132
-
133
- except IndexError :
134
- break
135
-
111
+ for lineNum in range (maxDisplay - 1 ):
112
+ i = lineNum + self .startPos
113
+ if i < len (self .stations ):
114
+ self .__displayBodyLine (lineNum , self .stations [i ])
136
115
self .bodyWin .refresh ()
137
116
117
+ def __displayBodyLine (self , lineNum , station ):
118
+ col = curses .color_pair (5 )
119
+
120
+ if lineNum + self .startPos == self .selection and \
121
+ self .selection == self .playing :
122
+ col = curses .color_pair (9 )
123
+ self .bodyWin .hline (lineNum + 1 , 1 , ' ' , self .bodyMaxX - 2 , col )
124
+ elif lineNum + self .startPos == self .selection :
125
+ col = curses .color_pair (6 )
126
+ self .bodyWin .hline (lineNum + 1 , 1 , ' ' , self .bodyMaxX - 2 , col )
127
+ elif lineNum + self .startPos == self .playing :
128
+ col = curses .color_pair (4 )
129
+ self .bodyWin .hline (lineNum + 1 , 1 , ' ' , self .bodyMaxX - 2 , col )
130
+ line = "{0}. {1}" .format (lineNum + self .startPos + 1 , station [0 ])
131
+ self .bodyWin .addstr (lineNum + 1 , 1 , line , col )
132
+
138
133
def run (self ):
139
134
140
135
if not self .play is False :
@@ -155,8 +150,12 @@ def run(self):
155
150
156
151
def setStation (self , number ):
157
152
""" Select the given station number """
158
- number = max (0 , number )
159
- number = min (number , len (self .stations ) - 1 )
153
+ # If we press up at the first station, we go to the last one
154
+ # and if we press down on the last one we go back to the first one.
155
+ if number < 0 :
156
+ number = len (self .stations ) - 1
157
+ elif number >= len (self .stations ):
158
+ number = 0
160
159
161
160
self .selection = number
162
161
0 commit comments