Skip to content

Commit 4f87509

Browse files
committed
- displaying update notification for v 0.8 (fake)
- updating purple theme
1 parent d120654 commit 4f87509

File tree

3 files changed

+80
-4
lines changed

3 files changed

+80
-4
lines changed

pyradio/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
FOREIGN_PLAYLIST_COPY_ERROR_MODE = 302
4444
CONFIG_SAVE_ERROR_MODE = 303
4545
THEME_MODE = 400
46-
NOT_IMPLEMENTED_YET_MODE = 1000
46+
UPDATE_NOTIFICATION_MODE = 1000
47+
NOT_IMPLEMENTED_YET_MODE = 1001
4748

4849
""" Theming constants """
4950
def FOREGROUND(): return 0

pyradio/radio.py

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
from . import player
2929
import logging
3030

31+
CAN_CHECK_FOR_UPDATES = True
32+
try:
33+
from urllib.request import urlopen
34+
except ImportError:
35+
try:
36+
from urllib2 import urlopen
37+
except ImportError:
38+
CAN_CHECK_FOR_UPDATES = False
39+
3140
logger = logging.getLogger(__name__)
3241

3342
import locale
@@ -89,7 +98,10 @@ class PyRadio(object):
8998

9099
_old_config_encoding = ''
91100

92-
#_recovery_lock = threading.Lock()
101+
102+
_update_version = '0.8'
103+
_update_notify_lock = threading.Lock()
104+
_update_version_do_display = ''
93105

94106
def __init__(self, pyradio_config, play=False, req_player='', theme=''):
95107
self._cnf = pyradio_config
@@ -399,6 +411,10 @@ def run(self):
399411
except KeyboardInterrupt:
400412
pass
401413
else:
414+
# start update thread
415+
if CAN_CHECK_FOR_UPDATES:
416+
pass
417+
402418
#signal.signal(signal.SIGINT, self.ctrl_c_handler)
403419
self.log.write('Selected player: {}'.format(self._format_player_string()), help_msg=True)
404420
#self.log.write_right('Press ? for help')
@@ -1191,6 +1207,23 @@ def _print_config_save_error(self):
11911207
prompt = ' Press any key to exit ',
11921208
is_message=True)
11931209

1210+
def _print_update_notification(self):
1211+
txt = '''A new |PyRadio| release (|{0}|) is available!
1212+
1213+
You are strongly encouraged to update now, so that
1214+
you enjoy new features and bug fixes.
1215+
1216+
You can get more info at:
1217+
|https://github.com/coderholic/pyradio#installation|
1218+
'''
1219+
self._show_help(txt.format(self._update_version_do_display),
1220+
mode_to_set = UPDATE_NOTIFICATION_MODE,
1221+
caption = ' New Release Available ',
1222+
prompt = ' Press any key to hide ',
1223+
is_message=True)
1224+
self._update_version = ''
1225+
1226+
11941227
def _align_stations_and_refresh(self, cur_mode):
11951228
need_to_scan_playlist = False
11961229
""" refresh reference """
@@ -1380,6 +1413,8 @@ def _redisplay_transient_window(self):
13801413
self.operation_mode == SELECT_PLAYLIST_HELP_MODE or \
13811414
self.operation_mode == SELECT_STATION_HELP_MODE:
13821415
self._print_help()
1416+
elif self.operation_mode == UPDATE_NOTIFICATION_MODE:
1417+
self._print_update_notification()
13831418
elif self.operation_mode == SELECT_ENCODING_HELP_MODE:
13841419
if self.window_mode == NORMAL_MODE:
13851420
self._encoding_select_win.refresh_and_resize(self.bodyMaxY, self.bodyMaxX)
@@ -1827,6 +1862,18 @@ def keypress(self, char):
18271862
self.refreshBody()
18281863
return
18291864

1865+
elif self.operation_mode == UPDATE_NOTIFICATION_MODE:
1866+
self.helpWinContainer = None
1867+
self.helpWin = None
1868+
self.operation_mode = NORMAL_MODE
1869+
self._update_notify_lock.acquire()
1870+
self._update_version = ''
1871+
self._update_notify_lock.release()
1872+
if logger.isEnabledFor(logging.DEBUG):
1873+
logger.debug('MODE: UPDATE_NOTIFICATION_MODE => NORMAL_MODE')
1874+
self.refreshBody()
1875+
return
1876+
18301877
elif self.operation_mode == NO_PLAYER_ERROR_MODE:
18311878
""" if no player, don't serve keyboard """
18321879
return
@@ -1973,6 +2020,16 @@ def keypress(self, char):
19732020
self.stopPlayer()
19742021
return -1
19752022

2023+
elif self.operation_mode == UPDATE_NOTIFICATION_MODE:
2024+
self.helpWinContainer = None
2025+
self.helpWin = None
2026+
self.operation_mode = self.window_mode = NORMAL_MODE
2027+
#self.setupAndDrawScreen()
2028+
self.refreshBody()
2029+
if logger.isEnabledFor(logging.DEBUG):
2030+
logger.debug('MODE: UPDATE_NOTIFICATION_MODE -> NORMAL_MODE')
2031+
return
2032+
19762033
elif self.operation_mode == PLAYLIST_RECOVERY_ERROR_MODE:
19772034
self._cnf.playlist_recovery_result = 0
19782035
self.operation_mode = PLAYLIST_MODE
@@ -2420,7 +2477,11 @@ def keypress(self, char):
24202477
if self.number_of_items > 0:
24212478
self.playSelection()
24222479
self.refreshBody()
2423-
#self.setupAndDrawScreen()
2480+
self._update_notify_lock.acquire()
2481+
if self._update_version:
2482+
self._update_version_do_display = self._update_version
2483+
self._print_update_notification()
2484+
self._update_notify_lock.release()
24242485
return
24252486

24262487
elif char in (ord(' '), curses.KEY_LEFT, ord('h')):
@@ -2432,6 +2493,11 @@ def keypress(self, char):
24322493
else:
24332494
self.playSelection()
24342495
self.refreshBody()
2496+
self._update_notify_lock.acquire()
2497+
if self._update_version:
2498+
self._update_version_do_display = self._update_version
2499+
self._print_update_notification()
2500+
self._update_notify_lock.release()
24352501
return
24362502

24372503
elif char in(ord('x'), curses.KEY_DC):
@@ -2529,4 +2595,13 @@ def keypress(self, char):
25292595
self.selections[self.operation_mode] = (self.selection, self.startPos, self.playing, self._cnf.playlists)
25302596
self.refreshBody()
25312597

2598+
def detectUpdateThread(self, *args):
2599+
""" a thread to check if an update is available
2600+
2601+
arg[0]: config dir
2602+
arg[1]: lock
2603+
"""
2604+
while True:
2605+
2606+
pass
25322607
# pymode:lint_ignore=W901

pyradio/themes/purple_by_sng.pyradio-theme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ PyRadio URL = 57,134
22
Messages Border = 129,134
33
Status Bar = 226,129
44
Stations = 195,134
5-
Active Station = 91,134
5+
Active Station = 56,134
66
Active Cursor = 226,129
77
Normal Cursor = 123,171

0 commit comments

Comments
 (0)