Skip to content

Commit 075192e

Browse files
authored
Merge pull request #392 from MorseKOB/es-wip
Telegram: Add option to do form advance on key open or not.
2 parents 892cf70 + f4989b1 commit 075192e

File tree

6 files changed

+61
-22
lines changed

6 files changed

+61
-22
lines changed

Documentation/Telegram/User-Manual-Telegram.adoc

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ There are four keyboard commands:
100100
3. ((ESC - Toggle the key open/closed state))
101101
4. ((F8 - Toggle the wire connection (connect/disconnect)))
102102
5. ((F11 - Clear the form without showing a new Masthead))
103-
6. ((Ctrl-X - Clear the form (instantly show a new form)))
104-
7. ((Ctrl-Q - Quit/Exit))
105-
8. ((Ctrl-C - Quit/Exit))
103+
6. ((Ctrl-A - Advance in a new form (scroll current form up)))
104+
7. ((Ctrl-X - Clear the form (instantly show a new form)))
105+
8. ((Ctrl-Q - Quit/Exit))
106+
9. ((Ctrl-C - Quit/Exit))
106107

107108
If the key is open (either physically or by using '~'), other text typed will be sounded, displayed, and encoded and sent to the wire if connected.
108109

@@ -232,6 +233,7 @@ The Telegram Configuration controls:
232233
* Masthead text color
233234
* Welcome message (shown on completely new form)
234235
* Display sender office/station ID (true/false)
236+
* Page (form) advance on key opened
235237
* Page (form) clear idle time
236238
* Page (form) page scroll speed
237239

@@ -275,6 +277,7 @@ that you use the file provided as a starting point, as it is used for testing.
275277
"list_sender":false,
276278
"page_clear_idle_time":15.5,
277279
"page_advance_seconds":2.2,
280+
"page_new_on_key_open":false,
278281
"wrap_columns":8
279282
}
280283
```
@@ -416,7 +419,7 @@ wire or entered on the local key or keyboard.
416419
Default: 18.0
417420

418421
[%nonfacing]
419-
==== ((page_clear_speed))
422+
==== ((page_advance_seconds))
420423
Specifies the amount of time, in seconds, for complete page (form) to be scrolled off
421424
and a new page to be displayed. A fractional value is allowed. A value of 0 will instantly replace the
422425
current page with a fresh one (full form without scrolling). The special value of -1 indicates that
@@ -425,6 +428,14 @@ cleared using the ((F11)) key, or cleared and a masthead displayed using the ((C
425428

426429
Default: 2.8
427430

431+
[%nonfacing]
432+
==== ((page_new_on_key_open))
433+
If true, a new form is scrolled in when the key is opened (from being closed). If false, opening
434+
the key will keep the current form and start displaying the locally keyed code. In this mode
435+
a new form can be scrolled in using the ((Ctrl-A)) key if desired.
436+
437+
Default: false
438+
428439
[%nonfacing]
429440
==== ((list_sender))
430441
Specifies that the current sender's office/station ID be displayed when Telegram is started or the
@@ -439,8 +450,8 @@ endif::[]
439450

440451
[colophon]
441452
= Colophon
442-
This document reflects the features of ((Telegram)) ((Version 1.1.0))
443-
Edit date: 12-20-2024
453+
This document reflects the features of ((Telegram)) ((Version 1.2.0))
454+
Edit date: 12-22-2024
444455

445456
MIT License
446457

5.58 KB
Binary file not shown.

Documentation/Telegram/tg_config.tgc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"list_sender":false,
1919
"page_clear_idle_time":15.5,
2020
"page_advance_seconds":2.2,
21+
"page_new_on_key_open":false,
2122
"wrap_columns":8
2223
}

msuiteversion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.5.0
1+
4.6.0

src.py/Telegram.py

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
from pykob.morse import Reader, Sender
7272

7373
COMPILE_INFO = globals().get("__compiled__")
74-
__version__ = '1.1.0'
74+
__version__ = '1.2.0'
7575
VERSION = __version__ if COMPILE_INFO is None else __version__ + 'c'
7676
TELEGRAM_VERSION_TEXT = "Telegram " + VERSION
7777

@@ -402,7 +402,7 @@ def print(self, text, bold=False, italic=False, update=True, spacing=0.0): # ty
402402
pygame.display.flip()
403403
return
404404

405-
def show_closer_state(self, open): # type: (bool) -> None
405+
def show_closer_state(self, open, update=False): # type: (bool,bool) -> None
406406
"""
407407
Render a '~' or '+' in the bottom left corner of the screen
408408
based on the open/closed state. Erase what might have been
@@ -414,9 +414,11 @@ def show_closer_state(self, open): # type: (bool) -> None
414414
self._screen.blit(self._KC_open_sprite, self._KC_state_pt)
415415
else:
416416
self._screen.blit(self._KC_closed_sprite, self._KC_state_pt)
417+
if update:
418+
pygame.display.flip()
417419
return
418420

419-
def show_wire_state(self, connected): # type: (bool) -> None
421+
def show_wire_state(self, connected, update=False): # type: (bool,bool) -> None
420422
"""
421423
Render a closed or open circle for connected or disconnected
422424
in the bottom right corner of the screen based on the connected
@@ -428,6 +430,8 @@ def show_wire_state(self, connected): # type: (bool) -> None
428430
self._screen.blit(self._WC_sprite, self._W_state_pt)
429431
else:
430432
self._screen.blit(self._WD_sprite, self._W_state_pt)
433+
if update:
434+
pygame.display.flip()
431435
return
432436

433437
def shutdown(self): # type: () -> None
@@ -535,6 +539,7 @@ class TelegramConfig:
535539
FONT_SIZE_KEY = "font_size"
536540
PAGE_CLEAR_IDLE_TIME_KEY = "page_clear_idle_time"
537541
PAGE_ADVANCE_SECONDS_KEY = "page_advance_seconds"
542+
PAGE_NEW_ON_KEY_OPEN_KEY = "page_new_on_key_open"
538543
PAGE_COLOR_KEY = "page_color"
539544
PAGE_WIDTH_KEY = "page_width"
540545
TEXT_COLOR_KEY = "text_color"
@@ -562,6 +567,7 @@ def __init__(self, tgcfg_file_path): # type: (str|None) -> None
562567
self._text_color = "black" # type: str|tuple[int,int,int]
563568
self._page_clear_idle_time = 18.0 # type: float # Seconds of idle before clear
564569
self._page_advance_seconds = 2.8 # type: float # Time to take to scroll the page (-1 means no 'new page')
570+
self._page_new_on_key_open = False # type: bool # Scroll in a new form when the key is opened
565571
self._page_color = (198,189,150) # type: str|tuple[int,int,int] # Tan
566572
self._page_width = 980 # type: int # The page color portion width. 980 is reasonable.
567573
self._masthead_filep = None # type: str|None
@@ -701,6 +707,14 @@ def page_color(self, color): # type: (str|tuple[int,int,int]) -> None
701707
self._page_color = color
702708
return
703709

710+
@property
711+
def page_new_on_key_open(self): # type: () -> bool
712+
return self._page_new_on_key_open
713+
@page_new_on_key_open.setter
714+
def page_new_on_key_open(self, b): # type: (bool) -> None
715+
self._page_new_on_key_open = b
716+
return
717+
704718
@property
705719
def page_width(self): # type: () -> int
706720
return self._page_width
@@ -798,6 +812,8 @@ def load(self, filep=None): # type: (str|None) -> None
798812
self._page_advance_seconds = value
799813
case self.PAGE_COLOR_KEY:
800814
self._page_color = literal_eval(value) if value and value[0] == '(' else value
815+
case self.PAGE_NEW_ON_KEY_OPEN_KEY:
816+
self._page_new_on_key_open = value
801817
case self.PAGE_WIDTH_KEY:
802818
self._page_width = value
803819
case self.TEXT_COLOR_KEY:
@@ -990,7 +1006,7 @@ def _from_internet(self, code):
9901006
if code == STARTMSG:
9911007
self._form.new_form()
9921008
self._form.show_closer_state(self._kob.virtual_closer_is_open)
993-
self._form.show_wire_state(self._connected)
1009+
self._form.show_wire_state(self._connected, update=True)
9941010
elif code == ENDMSG:
9951011
# Don't do anything at end. Timeout or new message (STARTMSG)
9961012
# will display a new form.
@@ -1124,15 +1140,16 @@ def _set_virtual_closer_closed(self, close):
11241140
Handle change of Circuit Closer state.
11251141
11261142
A state of:
1127-
True: 'latch'
1128-
False: 'unlatch'
1143+
close=True: 'latch'
1144+
close=False: 'unlatch'
11291145
"""
11301146
was_closed = not self._kob.virtual_closer_is_open
1147+
log.debug("Telegram._set_virtual_closer_closed: {}:{}".format(was_closed, close), 2, dt="")
11311148
if close and was_closed:
11321149
return
11331150
open = not close
11341151
self._kob.virtual_closer_is_open = open
1135-
self._form.show_closer_state(open)
1152+
self._form.show_closer_state(open, update=True)
11361153
code = LATCH_CODE if close else UNLATCH_CODE
11371154
# if not self._internet_station_active:
11381155
if True: # Allow breaking in to an active wire message
@@ -1154,17 +1171,18 @@ def _set_virtual_closer_closed(self, close):
11541171
self._set_local_loop_active(True)
11551172
if was_closed:
11561173
# The closer was closed and now it's open
1157-
# Flush the reader and display a new form
1174+
# Flush the reader
1175+
ignoring_inet = self._ignore_internet.is_set()
11581176
self._ignore_internet.set()
11591177
rdr = self._reader
11601178
if rdr is not None:
11611179
rdr.setCallback(None) # Don't have it call back
1180+
if self._tgcfg.page_new_on_key_open:
11621181
self._form.new_form()
1163-
self._form.show_closer_state(self._kob.virtual_closer_is_open)
1164-
self._form.show_wire_state(self._connected)
1182+
if rdr is not None:
11651183
self._new_Reader()
1166-
else:
1167-
self._ignore_internet.clear()
1184+
if not ignoring_inet:
1185+
self._ignore_internet.clear()
11681186
return
11691187

11701188

@@ -1231,13 +1249,21 @@ def main_loop(self):
12311249
self._shutdown.set()
12321250
self._control_c_pressed.set()
12331251
break
1252+
elif c == '\x01': # advance the form on ^A
1253+
ignoring_inet = self._ignore_internet.is_set()
1254+
self._ignore_internet.set()
1255+
self._form.new_form()
1256+
self._last_display_t = sys.float_info.max
1257+
if not ignoring_inet:
1258+
self._ignore_internet.clear()
12341259
elif c == '\x18': # display a new form on ^X
12351260
ignoring_inet = self._ignore_internet.is_set()
12361261
self._ignore_internet.set()
12371262
self._form.new_form(fresh=True)
12381263
if self._tgcfg.welcome_msg is not None:
12391264
self._form.print(self._tgcfg.welcome_msg)
12401265
self._form.new_line(2)
1266+
self._last_display_t = sys.float_info.max
12411267
if not ignoring_inet:
12421268
self._ignore_internet.clear()
12431269
else:
@@ -1257,6 +1283,7 @@ def main_loop(self):
12571283
self._ignore_internet.set()
12581284
self._form.new_form(fresh=True, disp_masthead=False)
12591285
self._form.new_line(1)
1286+
self._last_display_t = sys.float_info.max
12601287
if not ignoring_inet:
12611288
self._ignore_internet.clear()
12621289
continue
@@ -1276,7 +1303,7 @@ def main_loop(self):
12761303
self._form.print(self._tgcfg.welcome_msg)
12771304
self._form.new_line(2)
12781305
self._form.show_closer_state(self._kob.virtual_closer_is_open)
1279-
self._form.show_wire_state(self._connected)
1306+
self._form.show_wire_state(self._connected, update=True)
12801307
if not ignoring_inet:
12811308
self._ignore_internet.clear()
12821309
self._last_display_t = sys.float_info.max
@@ -1366,7 +1393,7 @@ def start(self):
13661393
self._clock = pygame.time.Clock()
13671394
self._form.new_form(fresh=True)
13681395
self._form.show_closer_state(self._kob.virtual_closer_is_open)
1369-
self._form.show_wire_state(self._connected)
1396+
self._form.show_wire_state(self._connected, update=True)
13701397
self._running = True
13711398
self._dt = 0
13721399
return

telegramversion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0
1+
1.2.0

0 commit comments

Comments
 (0)