Skip to content

Commit

Permalink
- version 0.9.2.5
Browse files Browse the repository at this point in the history
- adding CJK chars support to Groups window
- updating docs
  • Loading branch information
s-n-g committed Apr 7, 2023
1 parent 3aa181c commit 9316286
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Changelog
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
2023-04-05 s-n-g
2023-04-07 s-n-g
* version 0.9.2.5
* Desktop Notifications will display the image
provided by the station (jpg or png).
* adding config option "Use station icon"
* adding a fourth optional column for pyradio playlists.
This column will define a station icon url.
* adding CJK chars support for Group Headers
* fixing a potential crash when randomly playing stations.
* trying to limit duplicate Desktop Notifications.
* adding a system theme: blue_by_boxer
Expand Down
3 changes: 2 additions & 1 deletion README.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@ <h2 id="requirements">Requirements <span style="padding-left: 10px;"><sup style=
<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>
<pre style="height: 200px;">

2023-04-05 s-n-g
2023-04-07 s-n-g
* version 0.9.2.5
* Desktop Notifications will display the image
provided by the station (jpg or png).
* adding config option "Use station icon"
* adding a fourth optional column for pyradio playlists.
This column will define a station icon url.
* adding CJK chars support for Group Headers
* fixing a potential crash when randomly playing stations.
* trying to limit duplicate Desktop Notifications.
* adding a system theme: blue_by_boxer
Expand Down
48 changes: 34 additions & 14 deletions pyradio/cjkwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,40 @@ def cjkslices(text, index):
i = i + 1
return text[:i-1], text[i-1:]

def cjkljust(text, width, char= ' '):
txt_len = cjklen(text)
out = text
if width == txt_len:
return text
elif width > txt_len:
return out + (width - txt_len) * char
elif width < txt_len:
return cjkslices(text, width)[0]

def cjkrjust(text, width, char= ' '):
txt_len = cjklen(text)
out = text
if width == txt_len:
return text
elif width > txt_len:
return (width - txt_len) * char + out
elif width < txt_len:
return cjkslices(text, width)[0]

def cjkcenter(text, width, char= ' '):
txt_len = cjklen(text)
out = text
if width == txt_len:
return text
elif width > txt_len:
pad = int(( width - txt_len ) / 2)
out = pad * char + text + pad * char
while cjklen(out) < width:
out = char + out
return out
elif width < txt_len:
return cjkslices(text, width)[0]


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

def cjkcenter(text, width, char= ' '):
txt_len = cjklen(text)
out = text
if width == txt_len:
return text
elif width > txt_len:
pad = int(( width - txt_len ) / 2)
out = pad * char + text + pad * char
while cjklen(out) < width:
out = char + out
return out
elif width < txt_len:
return cjkslices(text, width)[0]

if __name__ == '__main__':
a='这显然不是巧合。美国敌视中国之情绪正在加深、加剧'
print(cjklen(a) * '-')
Expand Down
19 changes: 10 additions & 9 deletions pyradio/simple_curses_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# except:
# from cjkwrap import PY3, is_wide, cjklen
# from schedule import PyRadioTime
from .cjkwrap import PY3, is_wide, cjklen
from .cjkwrap import PY3, is_wide, cjklen, cjkljust
from .schedule import PyRadioTime
import locale
locale.setlocale(locale.LC_ALL, '') # set your locale
Expand Down Expand Up @@ -1847,7 +1847,7 @@ def _get_window(self):
self._maxY = Y - 2 * self._outer_margin

# logger.error('max = {}'.format(max(len(x) for x in self._items)))
self._maxX = items_max_X = max(len(x) for x in self._items) + 2
self._maxX = items_max_X = max(cjklen(x) for x in self._items) + 2
if self._margin > 0:
self._maxX = self._maxX + 2 * self._margin
if self._display_count:
Expand Down Expand Up @@ -1917,7 +1917,7 @@ def _calculate_max_height_max_width(self):
if self._maxX == 0:
self._maxX = X - 2
if self._auto_adjust_width:
self._maxX = len(max(self._items)) + 2 * self._margin
self._maxX = cjklen(max(self._items)) + 2 * self._margin
if self._maxX > self._max_width:
self._maxX = self._max_width

Expand Down Expand Up @@ -2008,7 +2008,7 @@ def _refresh(self):
# calculate start item
# TODO: calculate start_pos

self._item_max_width = len(max(self._items, key=len))
self._item_max_width = cjklen(max(self._items, key=cjklen))
active_item_length = self._maxX - 2 * self._margin - 2
if self._start_pos < 0:
self._start_pos = 0
Expand Down Expand Up @@ -2052,18 +2052,19 @@ def _format_line(self, i, active_item_length):
count_len = len(str(len(self._items)))
# log_it('count_len = {}'.format(count_len))
disp_item_pref = '{}. '.format(str(item_id+1).rjust(count_len))
disp_item_suf = self._items[item_id][:active_item_length-len(disp_item_pref)]
# disp_item_suf = self._items[item_id][:active_item_length-cjklen(disp_item_pref)]
disp_item_suf = cjkljust(self._items[item_id], self._body_maxX - len(disp_item_pref) - 2 * self._margin)
disp_item = ' ' * self._margin + disp_item_pref + disp_item_suf + ' ' * self._margin
else:
#print('item_id = {}'.format(item_id))
item = self._items[item_id][:active_item_length]
if self._align == self.LEFT:
disp_item = ' ' * self._margin + item.ljust(active_item_length) + ' ' * self._margin
disp_item = ' ' * self._margin + item.cjkljust(active_item_length) + ' ' * self._margin
elif self._align == self.RIGHT:
disp_item = ' ' * self._margin + item.rjust(active_item_length) + ' ' * self._margin
disp_item = ' ' * self._margin + item.cjkrjust(active_item_length) + ' ' * self._margin
else:
disp_item = ' ' * self._margin + item.center(active_item_length) + ' ' * self._margin
disp_item = disp_item.ljust(self._body_maxX)
disp_item = ' ' * self._margin + item.cjkcenter(active_item_length) + ' ' * self._margin
# disp_item = disp_item.ljust(self._body_maxX)
else:
# create empty lines
disp_item = ' ' * self._body_maxX
Expand Down

0 comments on commit 9316286

Please sign in to comment.