Skip to content

Commit 9316286

Browse files
committed
- version 0.9.2.5
- adding CJK chars support to Groups window - updating docs
1 parent 3aa181c commit 9316286

File tree

4 files changed

+48
-25
lines changed

4 files changed

+48
-25
lines changed

Changelog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
2023-04-05 s-n-g
1+
2023-04-07 s-n-g
22
* version 0.9.2.5
33
* Desktop Notifications will display the image
44
provided by the station (jpg or png).
55
* adding config option "Use station icon"
66
* adding a fourth optional column for pyradio playlists.
77
This column will define a station icon url.
8+
* adding CJK chars support for Group Headers
89
* fixing a potential crash when randomly playing stations.
910
* trying to limit duplicate Desktop Notifications.
1011
* adding a system theme: blue_by_boxer

README.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,14 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
202202
<h2 id="changelog">Changelog <span style="padding-left: 10px;"><sup style="font-size: 50%"><a href="#" title="Go to top of the page">Top</a></sup></span></h2>
203203
<pre style="height: 200px;">
204204

205-
2023-04-05 s-n-g
205+
2023-04-07 s-n-g
206206
* version 0.9.2.5
207207
* Desktop Notifications will display the image
208208
provided by the station (jpg or png).
209209
* adding config option "Use station icon"
210210
* adding a fourth optional column for pyradio playlists.
211211
This column will define a station icon url.
212+
* adding CJK chars support for Group Headers
212213
* fixing a potential crash when randomly playing stations.
213214
* trying to limit duplicate Desktop Notifications.
214215
* adding a system theme: blue_by_boxer

pyradio/cjkwrap.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,40 @@ def cjkslices(text, index):
7474
i = i + 1
7575
return text[:i-1], text[i-1:]
7676

77+
def cjkljust(text, width, char= ' '):
78+
txt_len = cjklen(text)
79+
out = text
80+
if width == txt_len:
81+
return text
82+
elif width > txt_len:
83+
return out + (width - txt_len) * char
84+
elif width < txt_len:
85+
return cjkslices(text, width)[0]
86+
87+
def cjkrjust(text, width, char= ' '):
88+
txt_len = cjklen(text)
89+
out = text
90+
if width == txt_len:
91+
return text
92+
elif width > txt_len:
93+
return (width - txt_len) * char + out
94+
elif width < txt_len:
95+
return cjkslices(text, width)[0]
96+
97+
def cjkcenter(text, width, char= ' '):
98+
txt_len = cjklen(text)
99+
out = text
100+
if width == txt_len:
101+
return text
102+
elif width > txt_len:
103+
pad = int(( width - txt_len ) / 2)
104+
out = pad * char + text + pad * char
105+
while cjklen(out) < width:
106+
out = char + out
107+
return out
108+
elif width < txt_len:
109+
return cjkslices(text, width)[0]
110+
77111

78112
class CJKWrapper(textwrap.TextWrapper):
79113
"""CJK fix for the Greg Ward textwrap lib."""
@@ -161,20 +195,6 @@ def fill(text, width=70, **kwargs):
161195
w = CJKWrapper(width=width, **kwargs)
162196
return w.fill(text)
163197

164-
def cjkcenter(text, width, char= ' '):
165-
txt_len = cjklen(text)
166-
out = text
167-
if width == txt_len:
168-
return text
169-
elif width > txt_len:
170-
pad = int(( width - txt_len ) / 2)
171-
out = pad * char + text + pad * char
172-
while cjklen(out) < width:
173-
out = char + out
174-
return out
175-
elif width < txt_len:
176-
return cjkslices(text, width)[0]
177-
178198
if __name__ == '__main__':
179199
a='这显然不是巧合。美国敌视中国之情绪正在加深、加剧'
180200
print(cjklen(a) * '-')

pyradio/simple_curses_widgets.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# except:
1111
# from cjkwrap import PY3, is_wide, cjklen
1212
# from schedule import PyRadioTime
13-
from .cjkwrap import PY3, is_wide, cjklen
13+
from .cjkwrap import PY3, is_wide, cjklen, cjkljust
1414
from .schedule import PyRadioTime
1515
import locale
1616
locale.setlocale(locale.LC_ALL, '') # set your locale
@@ -1847,7 +1847,7 @@ def _get_window(self):
18471847
self._maxY = Y - 2 * self._outer_margin
18481848

18491849
# logger.error('max = {}'.format(max(len(x) for x in self._items)))
1850-
self._maxX = items_max_X = max(len(x) for x in self._items) + 2
1850+
self._maxX = items_max_X = max(cjklen(x) for x in self._items) + 2
18511851
if self._margin > 0:
18521852
self._maxX = self._maxX + 2 * self._margin
18531853
if self._display_count:
@@ -1917,7 +1917,7 @@ def _calculate_max_height_max_width(self):
19171917
if self._maxX == 0:
19181918
self._maxX = X - 2
19191919
if self._auto_adjust_width:
1920-
self._maxX = len(max(self._items)) + 2 * self._margin
1920+
self._maxX = cjklen(max(self._items)) + 2 * self._margin
19211921
if self._maxX > self._max_width:
19221922
self._maxX = self._max_width
19231923

@@ -2008,7 +2008,7 @@ def _refresh(self):
20082008
# calculate start item
20092009
# TODO: calculate start_pos
20102010

2011-
self._item_max_width = len(max(self._items, key=len))
2011+
self._item_max_width = cjklen(max(self._items, key=cjklen))
20122012
active_item_length = self._maxX - 2 * self._margin - 2
20132013
if self._start_pos < 0:
20142014
self._start_pos = 0
@@ -2052,18 +2052,19 @@ def _format_line(self, i, active_item_length):
20522052
count_len = len(str(len(self._items)))
20532053
# log_it('count_len = {}'.format(count_len))
20542054
disp_item_pref = '{}. '.format(str(item_id+1).rjust(count_len))
2055-
disp_item_suf = self._items[item_id][:active_item_length-len(disp_item_pref)]
2055+
# disp_item_suf = self._items[item_id][:active_item_length-cjklen(disp_item_pref)]
2056+
disp_item_suf = cjkljust(self._items[item_id], self._body_maxX - len(disp_item_pref) - 2 * self._margin)
20562057
disp_item = ' ' * self._margin + disp_item_pref + disp_item_suf + ' ' * self._margin
20572058
else:
20582059
#print('item_id = {}'.format(item_id))
20592060
item = self._items[item_id][:active_item_length]
20602061
if self._align == self.LEFT:
2061-
disp_item = ' ' * self._margin + item.ljust(active_item_length) + ' ' * self._margin
2062+
disp_item = ' ' * self._margin + item.cjkljust(active_item_length) + ' ' * self._margin
20622063
elif self._align == self.RIGHT:
2063-
disp_item = ' ' * self._margin + item.rjust(active_item_length) + ' ' * self._margin
2064+
disp_item = ' ' * self._margin + item.cjkrjust(active_item_length) + ' ' * self._margin
20642065
else:
2065-
disp_item = ' ' * self._margin + item.center(active_item_length) + ' ' * self._margin
2066-
disp_item = disp_item.ljust(self._body_maxX)
2066+
disp_item = ' ' * self._margin + item.cjkcenter(active_item_length) + ' ' * self._margin
2067+
# disp_item = disp_item.ljust(self._body_maxX)
20672068
else:
20682069
# create empty lines
20692070
disp_item = ' ' * self._body_maxX

0 commit comments

Comments
 (0)