Skip to content

Commit f08406e

Browse files
committed
- Again Remote Control Server: when displaying current playlist stations or playlists list, try to jump to active item
- Working on schedule item again - Started working on active_transparency
1 parent 08a6c57 commit f08406e

File tree

7 files changed

+133
-53
lines changed

7 files changed

+133
-53
lines changed

pyradio/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,6 @@ def __init__(self, user_config_dir=None):
13261326
self.default_encoding = 'utf-8'
13271327
self.connection_timeout = '10'
13281328
self.theme = 'dark'
1329-
self.use_transparency = False
13301329
self.active_transparency = False
13311330
self._distro = 'None'
13321331

pyradio/install.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ def _do_it(self, mode='update'):
13241324
parser.add_argument('-oc', '--open-cache', action='store_true', help=SUPPRESS)
13251325
parser.add_argument('-sc', '--show-cache', action='store_true', help=SUPPRESS)
13261326
parser.add_argument('-cc', '--clear-cache', action='store_true', help=SUPPRESS)
1327-
parser.add_argument('-i', '--isolated', action='store_true', help=SUPPRESS)
1327+
parser.add_argument('-i', '--isolate', action='store_true', help=SUPPRESS)
13281328
if HAS_PIPX:
13291329
parser.add_argument('-gc', '--get-cache', action='store_true',
13301330
help='Download source code, keep it in the cache and exit.')
@@ -1333,7 +1333,10 @@ def _do_it(self, mode='update'):
13331333
parser.add_argument('--python2', action='store_true',
13341334
help='Install using python 2.')
13351335
else:
1336-
parser.add_argument('-i', '--isolated', action='store_true', help=SUPPRESS)
1336+
parser.add_argument('-oc', '--open-cache', action='store_true', help=SUPPRESS)
1337+
parser.add_argument('-sc', '--show-cache', action='store_true', help=SUPPRESS)
1338+
parser.add_argument('-cc', '--clear-cache', action='store_true', help=SUPPRESS)
1339+
parser.add_argument('-i', '--isolate', action='store_true', help=SUPPRESS)
13371340
parser.add_argument('--python2', action='store_true', help=SUPPRESS)
13381341
parser.add_argument('-R', '--uninstall', action='store_true',
13391342
help='Uninstall PyRadio.')

pyradio/radio.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def __init__(self, pyradio_config,
686686
curses.ascii.SO: self._play_next_station,
687687
curses.KEY_NEXT: self._play_next_station,
688688
# ord('d'): self._html_song_title,
689-
# ord('b'): self._show_schedule_player_stop,
689+
ord('b'): self._show_schedule_player_stop,
690690
}
691691

692692
self._remote_control_server = self._remote_control_server_thread = None
@@ -838,6 +838,7 @@ def setup(self, stdscr):
838838
pass
839839

840840
if self._cnf.use_themes:
841+
# TODO: maybe delete this line?
841842
self._theme._transparent = self._cnf.use_transparency
842843
self._theme.config_dir = self._cnf.stations_dir
843844
''' In case we have to download a theme, and it takes too long '''

pyradio/schedule.py

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,43 @@ def format_date_to_iso8851(a_date=None):
2424
cur_month + ' ' + str(a_date.year) + \
2525
a_date.strftime(' %H:%M:%S')
2626

27+
class PyRadioScheduleItemType(object):
28+
29+
TYPE_START_END = 0
30+
TYPE_START = 1
31+
TYPE_END = 2
32+
33+
items = 0, 1, 2
34+
35+
@classmethod
36+
def to_string(cls, a_type):
37+
if a_type == 0:
38+
return 'TYPE_START_END'
39+
elif a_type == 1:
40+
return 'TYPE_START'
41+
elif a_type == 2:
42+
return 'TYPE_END'
43+
else:
44+
return 'UNKNOUN'
45+
46+
47+
class PyRadioScheduleTimeType(object):
48+
49+
TIME_ABSOLUTE = 0
50+
TIME_RELATIVE = 1
51+
52+
items = 0, 1
53+
54+
@classmethod
55+
def to_string(cls, a_type):
56+
if a_type == 0:
57+
return 'TIME_ABSOLUTE'
58+
elif a_type == 1:
59+
return 'TIME_RELATIVE'
60+
else:
61+
return 'UNKNOUN'
62+
63+
2764
class PyRadioScheduleItem(object):
2865
'''
2966
Provide a Schedule Item
@@ -69,9 +106,6 @@ class PyRadioScheduleItem(object):
69106
station name
70107
71108
'''
72-
TYPE_START_END = TIME_ABSOLUTE = 0
73-
TYPE_START = TIME_RELATIVE = 1
74-
TYPE_END = 2
75109

76110
def __init__(self, item=None):
77111
self._item = None
@@ -142,11 +176,7 @@ def type(self):
142176
@type.setter
143177
def type(self, val):
144178
try:
145-
if val in (
146-
self.TYPE_END,
147-
self.TYPE_START,
148-
self.TYPE_START_END
149-
):
179+
if val in (PyRadioScheduleItemType.items):
150180
self._item['type'] = val
151181
return
152182
except:
@@ -178,8 +208,8 @@ def end_type(self, val):
178208
def _check_start_end_type(self, val):
179209
try:
180210
if val in (
181-
self.TIME_ABSOLUTE,
182-
self.TIME_RELATIVE,
211+
PyRadioScheduleTimeType.TIME_ABSOLUTE,
212+
PyRadioScheduleTimeType.TIME_RELATIVE,
183213
):
184214
self._item['start_type'] = val
185215
return True
@@ -193,7 +223,7 @@ def get_active_dates(self):
193223
the (starting date-time, ending date-time)
194224
'''
195225
today = datetime.now().replace(microsecond=0)
196-
if self._item['start_type'] == self.TIME_ABSOLUTE:
226+
if self._item['start_type'] == PyRadioScheduleTimeType.TIME_ABSOLUTE:
197227
start_date = datetime(
198228
year=self._item[ 'start_date' ][0],
199229
month=self._item[ 'start_date' ][1],
@@ -206,7 +236,7 @@ def get_active_dates(self):
206236
self._item['start_duration']
207237
)
208238

209-
if self._item['end_type'] == self.TIME_ABSOLUTE:
239+
if self._item['end_type'] == PyRadioScheduleTimeType.TIME_ABSOLUTE:
210240
end_date = datetime(
211241
self._item['end_date'][0],
212242
self._item['end_date'][1],
@@ -217,7 +247,7 @@ def get_active_dates(self):
217247
seconds=self._item['end_time'][2],
218248
)
219249
else:
220-
if self._item['type'] == self.TYPE_END:
250+
if self._item['type'] == PyRadioScheduleItemType.TYPE_END:
221251
use_date = today
222252
else:
223253
use_date = start_date
@@ -554,7 +584,7 @@ def pyradio_time_diference_in_seconds(cls, s_time, e_time):
554584

555585
print('\n\n============')
556586
an_item = {
557-
'type': 1, # TYPE_START_END, TYPE_START, TYPE_END
587+
'type': PyRadioScheduleItemType.TYPE_START_END,
558588
'start_type': 0, # TIME_ABSOLUTE, TYPE_RELATIVE
559589
'start_date': [2022, 10, 15],
560590
'start_time': [11, 15, 12, 2], # NO_AM_PM_FORMAT, AM_FORMAT, PM_FORMAT
@@ -567,8 +597,13 @@ def pyradio_time_diference_in_seconds(cls, s_time, e_time):
567597
'station': 'mystation'
568598
}
569599

600+
for n,k in an_item.items():
601+
print(n, ":", k)
602+
print('\n\n============')
603+
570604
b = PyRadioScheduleItem(an_item)
571605
x, y = b.get_active_dates()
572606
print('start_date:', str(x))
573607
print(' end_date:', str(y))
574-
print('item =', b.item)
608+
for n,k in b.item.items():
609+
print(n, ":", k)

pyradio/schedule_win.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from .simple_curses_widgets import DisabledWidget, SimpleCursesCheckBox, SimpleCursesPushButton, SimpleCursesTime, SimpleCursesString, SimpleCursesDate
1010
from .cjkwrap import cjklen, cjkslices
11-
from .schedule import PyRadioScheduleItem, PyRadioTime, format_date_to_iso8851
11+
from .schedule import PyRadioScheduleItem, PyRadioScheduleItemType, PyRadioScheduleTimeType, PyRadioTime, format_date_to_iso8851
1212

1313
import locale
1414
locale.setlocale(locale.LC_ALL, '') # set your locale
@@ -288,7 +288,7 @@ def show(self, parent=None):
288288
next_widget_func=self._next_widget,
289289
previous_widget_func=self._previous_widget,
290290
global_functions=self._global_functions,
291-
string=PyRadioTime.pyradio_time_to_string(self._schedule_item.end_time)
291+
string=PyRadioTime.pyradio_time_to_string(self._schedule_item.item['end_time'])
292292
)
293293
)
294294
self._widgets[-1].w_id = 11
@@ -415,7 +415,8 @@ def show(self, parent=None):
415415
self._showed = True
416416

417417
def _dummy_enable(self):
418-
if self._schedule_item.type == 'E':
418+
logger.error('\n\n{}\n\n'.format(self._schedule_item.item))
419+
if self._schedule_item.item['type'] == PyRadioScheduleItemType.TYPE_END:
419420
self._widgets[2].enabled = True
420421
self._widgets[2].checked = False
421422
self._widgets[8].enabled = True

pyradio/server.py

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ class PyRadioServer(object):
312312
var url_to_reload = "";
313313
var last_title = "";
314314
315+
var selection = -1;
316+
315317
function js_refresh_page(){
316318
window.location.href = url_to_reload;
317319
}
@@ -367,6 +369,9 @@ class PyRadioServer(object):
367369
{
368370
js_disable_group_button(true);
369371
}
372+
// if ( ( the_command == '/html/st' ) || ( the_command == '/html/pl' ) || ( ( the_command.startsWith("/html/pl/" ) && ( the_command.length > 9 )) )){
373+
// js_get_selection();
374+
// }
370375
$.get(the_command, function(result){
371376
// console.log(the_command, result, typeof result);
372377
//
@@ -416,30 +421,37 @@ class PyRadioServer(object):
416421
}
417422
// console.log("the_command:", the_command)
418423
if ( ( the_command == '/html/st' ) || ( the_command == '/html/pl' ) || ( ( the_command.startsWith("/html/pl/" ) && ( the_command.length > 9 )) )){
419-
td = document.getElementsByTagName('td');
420-
for(i=0; i<td.length; i++){
421-
try{
422-
var x = td[i].getAttribute('style');
423-
// console.log("x =", x);
424-
if(i>0){
425-
if(x == "color: white;"){
426-
// console.log("found at", i, "id =", td[i].getAttribute('id'));
427-
var this_id = td[i+1].getAttribute('id');
428-
if (i>6){
429-
this_id = "n" + (this_id-2);
430-
}else{
431-
this_id = "myInput";
424+
// console.log("-- selection =", selection);
425+
let the_counter = 0;
426+
//if (selection > 0){
427+
// the_counter = 2 * selection;
428+
// console.log("the_counter =", the_counter);
429+
//}
430+
td = document.getElementsByTagName('td');
431+
for(i=the_counter; i<td.length; i++){
432+
try{
433+
var x = td[i].getAttribute('style');
434+
// console.log("x =", x);
435+
if(i>0){
436+
if(x == "color: white;"){
437+
// console.log("found at", i, "id =", td[i].getAttribute('id'));
438+
var this_id = td[i+1].getAttribute('id');
439+
if (i>6){
440+
this_id = "n" + (this_id-2);
441+
}else{
442+
this_id = "myInput";
443+
}
444+
// console.log("this_id =", this_id);
445+
document.getElementById(this_id).scrollIntoView();
446+
break;
432447
}
433-
// console.log("this_id =", this_id);
434-
document.getElementById(this_id).scrollIntoView();
435-
break;
436448
}
449+
}catch{
450+
// do not care about it!
437451
}
438-
}catch{
439-
// do not care about it!
440452
}
441-
}
442453
}
454+
// console.log("--------");
443455
});
444456
}
445457
@@ -487,6 +499,21 @@ class PyRadioServer(object):
487499
getStopped();
488500
}
489501
502+
function js_get_selection(){
503+
const getSelection = async () => {
504+
const response = await fetch("/html/get_selection");
505+
const data = await response.text();
506+
// console.log("async selection:", data);
507+
if ( data > -1 ){
508+
selection = data;
509+
}else{
510+
selection = -1;
511+
}
512+
}
513+
getSelection();
514+
console.log("==> selection =", selection);
515+
}
516+
490517
function js_disable_group_button(enable){
491518
var element = document.getElementById("group");
492519
element.disabled = enable;
@@ -511,7 +538,7 @@ class PyRadioServer(object):
511538
const response = await fetch("/html/is_logging_titles");
512539
const data = await response.text();
513540
514-
console.log("async:", data);
541+
// console.log("async:", data);
515542
var element = document.getElementById("logging");
516543
if ( data == 0 ){
517544
element.className = "btn btn-warning";
@@ -668,6 +695,8 @@ def start_remote_control_server(
668695
sel = (self.selection, self.playing)
669696
'''
670697
self.sel = sel
698+
''' the item to scroll to when displaying list of stations / playlists '''
699+
self._selected = -1
671700
self.muted = muted
672701
self.lock = lock
673702
try:
@@ -747,6 +776,8 @@ def _handle_client_connection(self, address, request):
747776
self.send_song_title(self.song_title())
748777
elif self._path == '/favicon.ico':
749778
pass
779+
elif self._path == '/get_selection' and self._is_html:
780+
self._send_raw(str(self._selected))
750781
elif self._path == '/is_stopped' and self._is_html:
751782
received = self._commands['/html_is_stopped']()
752783
self._send_raw(received)
@@ -950,10 +981,11 @@ def _handle_client_connection(self, address, request):
950981
has_error = False
951982
if ret == '/stations':
952983
if self._is_html:
984+
self._selected = self.sel()[1]
953985
self._send_raw(
954986
self._format_html_table(
955987
self._list_stations(html=True), 0,
956-
sel=self.sel()[1]
988+
sel=self._selected
957989
)
958990
)
959991
else:
@@ -1121,20 +1153,22 @@ def _handle_client_connection(self, address, request):
11211153
elif ret.startswith('/'):
11221154
if ret == '/stations':
11231155
if self._is_html:
1156+
self._selected = self.sel()[1]
11241157
self._send_raw(
11251158
self._format_html_table(
11261159
self._list_stations(html=True), 0,
1127-
sel=self.sel()[1]
1160+
sel=self._selected
11281161
)
11291162
)
11301163
else:
11311164
self._send_text(self._list_stations())
11321165
elif ret == '/playlists':
11331166
if self._is_html:
1167+
self._selected = self._get_playlist_id(basename(self.playlist_in_editor()[:-4]))
11341168
self._send_raw(
11351169
self._format_html_table(
11361170
self._list_playlists(html=True), 1,
1137-
sel=self._get_playlist_id(basename(self.playlist_in_editor()[:-4]))
1171+
sel=self._selected
11381172
)
11391173
)
11401174
else:
@@ -1486,7 +1520,7 @@ def _format_html_table(
14861520
Parameters
14871521
==========
14881522
in_list list of items
1489-
self selected item
1523+
sel selected item
14901524
index type of output (stations / playlist) and URL formatter
14911525
playlist_index playist index (only valid if index == 2)
14921526
'''

0 commit comments

Comments
 (0)