Skip to content

Commit

Permalink
Last changes/bugs before new release
Browse files Browse the repository at this point in the history
  • Loading branch information
greenwyrt committed Aug 14, 2023
1 parent 7cbb5f5 commit 115968b
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 61 deletions.
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CHANGES

Unreleased (ver 2.2.0):
# Ver 2.2.0 (2023-08-13)

- Change: Style submenu added, now style change shortcuts are visible to user (`Ctrl + {0-9}`) for first ten styles.

Expand All @@ -12,7 +12,11 @@ Unreleased (ver 2.2.0):

- Bug: Multiple empty line strings were not generating the paragraphs needed, ie `\n\n`

- Change: text elements and stroke elements now have `__add__`, other classes raise errors. This is used to collapse like-class elements for steno wrapping.
- Change: text elements and stroke elements now have `__add__` and `__radd__`, other classes raise errors. This is used to collapse like-class elements for steno wrapping.

- Change: Window titlebar now updates with transcript name when transcript is opened.

- Bug: removed thread deletion from `export_*` as before, a second export would crash.

## Ver 2.1.1 (2023-08-06)

Expand Down
2 changes: 2 additions & 0 deletions docs/howto/captions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Plover2CAT can display input text in a separate window as captions.

![Gif showing captioning.](images/caption_example.gif)

## Caption set up

Click `Audiovisual > Captioning` to activate the captioning settings dialog, use or set the settings below, and then click `OK`.
Expand Down
Binary file added docs/howto/images/caption_example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 12 additions & 5 deletions docs/reference/elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ It has the methods:
- `__getitem__`: returns new instance after deepcopy
- `__repr__`: representation as `dict`
- `__add__`: adds together text, and updates time from other
- `__radd__`: returns `NotImplemented`
- `length`: returns length of string, here as placeholder in order to keep consistency with other subclassed elements, the functional length
- `split`: splits text string on whitespace (re from textwrapper), returns list of elements containing each text piece separately, but same otherwise as original
- `from_dict`: can populate class using a dict
Expand All @@ -50,7 +51,8 @@ It has the additional attributes:

Overriding methods:

- `__add__`: will only combine elements but not across word boundaries (spaces)
- `__add__`: will only combine elements but not across word boundaries (spaces), can accept `stroke_text` and `text_element`
- `__radd__`: works with `text_element` addition properly, `NotImplemented` otherwise
- `to_rtf`
- `to_display`

Expand All @@ -67,7 +69,7 @@ It has the additional attributes:

Overriding methods:

- `__add__`: throws error
- `__add__`: `NotImplemented`
- `length`: 1
- `to_display`
- `to_odt`
Expand All @@ -85,7 +87,7 @@ It has the additional elements:

Overriding methods:

- `__add__`: throws error
- `__add__`: `NotImplemented`
- `length`: 1
- `to_json`: do not output `user_field_dict`, no need for a copy of all fields with each element
- `to_display`:
Expand All @@ -111,7 +113,8 @@ It has the additional attributes:

It has the methods:

- `__add__`: throws error
- `__add__`: `NotImplemented`
- `__radd__`: `NotImplemented`, overrides `__radd__` from `stroke_text`
- *`length`*: the length of the text only, the element's "functional" length
- `__len__`: returns length of prefix + text + suffix
- `to_text`: string of prefix + text + suffix
Expand All @@ -137,12 +140,16 @@ It has the additional attributes:

Overriding methods:

- `__add__`: throws error
- `__add__`: `NotImplemented`

The actual "number" for the exhibit is stored in the `text` attribute.

Has non-breaking space in `to_text` so that "prefix" and "number" are always together even for text formats.

## Combining elements

Only strictly text and stroke elements can be combined through `__add__` and `__radd__`, ie while `automatic_text` subclasses `stroke_text`, the two should not be combined. This is primarily for the use of collapsing elements into word chunks, as `pre` and `pare ` may be two stroke elements, but should be treated as one for wrapping, otherwise, steno wrapping may wrap in unwanted places.

## element_collection

This is the container holding a list of elements. It subclasses `UserList` and overrides some methods. Despite being an `UserList` list, the methods mean it behaves like a `string` in many ways.
Expand Down
2 changes: 1 addition & 1 deletion plover_cat/captionWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def make_caps(self):
else:
self.cap_line += self.next_word
def send_cap(self):
print(f"queue size {self.cap_queue.qsize()}.")
# print(f"queue size {self.cap_queue.qsize()}.")
try:
cap, time = self.cap_queue.get_nowait()
self.capSend.emit(cap)
Expand Down
3 changes: 3 additions & 0 deletions plover_cat/caption_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<property name="toolTip">
<string>Optional, only display this number of lines in caption window</string>
</property>
<property name="value">
<number>2</number>
</property>
</widget>
</item>
<item row="5" column="0">
Expand Down
1 change: 0 additions & 1 deletion plover_cat/documentWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,5 +529,4 @@ def save_srt(self):
with open(file_path, "w", encoding="utf-8") as f:
for line in doc_lines:
f.write(f"{line}\n")
# self.statusBar.showMessage("Exported in srt format")
self.finished.emit()
85 changes: 52 additions & 33 deletions plover_cat/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def __init__(self, engine):
self.actionShowVideo.triggered.connect(lambda: self.show_hide_video())
self.actionCaptioning.triggered.connect(self.setup_captions)
self.actionFlushCaption.triggered.connect(self.flush_caption)
self.actionAddChangeAudioTimestamps.triggered.connect(self.modify_audiotime)
## editor related connections
self.actionClearParagraph.triggered.connect(lambda: self.reset_paragraph())
self.textEdit.complete.connect(self.insert_autocomplete)
Expand Down Expand Up @@ -648,7 +649,6 @@ def autosave_setup(self, checked):
# open/close/save
def create_new(self):
self.mainTabs.setCurrentIndex(1)
## make new dir, sets gui input
project_dir = QFileDialog.getExistingDirectory(self, "Select Directory", plover.oslayer.config.CONFIG_DIR)
if not project_dir:
log.debug("No directory selected, not creating transcript folder.")
Expand Down Expand Up @@ -708,7 +708,8 @@ def create_new(self):
self.textEdit.setCurrentCharFormat(self.txt_formats[self.style_selector.currentText()])
self.textEdit.setTextCursor(document_cursor)
self.textEdit.document().setDefaultFont(self.txt_formats[self.style_selector.currentText()].font())
self.undo_stack.clear()
self.undo_stack.clear()
self.parent().setWindowTitle(f"Plover2CAT - {str(self.file_name.stem)}")

def open_file(self, file_path = ""):
self.mainTabs.setCurrentIndex(1)
Expand Down Expand Up @@ -797,7 +798,8 @@ def open_file(self, file_path = ""):
document_cursor.setBlockFormat(self.par_formats[self.style_selector.currentText()])
document_cursor.setCharFormat(self.txt_formats[self.style_selector.currentText()])
self.textEdit.document().setDefaultFont(self.txt_formats[self.style_selector.currentText()].font())
self.undo_stack.clear()
self.undo_stack.clear()
self.parent().setWindowTitle(f"Plover2CAT - {str(self.file_name.stem)}")

def save_file(self):
if not self.file_name:
Expand Down Expand Up @@ -828,7 +830,7 @@ def save_transcript(self, path):
if block.userData():
block_dict = deepcopy(block.userData().return_all())
else:
return
return False
block_num = block.blockNumber()
# print(f"Paragraph {block_num} changed.")
block_dict["strokes"] = block_dict["strokes"].to_json()
Expand All @@ -844,6 +846,7 @@ def save_transcript(self, path):
json_document.pop(str(num), None)
save_json(json_document, path)
QApplication.restoreOverrideCursor()
return True

def dulwich_save(self, message = "autosave"):
self.statusBar.showMessage("Saving versioned copy.")
Expand Down Expand Up @@ -1015,11 +1018,11 @@ def autosave(self):
transcript = pathlib.Path(transcript)
if transcript.exists():
transcript.unlink()
self.save_transcript(transcript)
if os.name == "nt":
save_res = self.save_transcript(transcript)
if save_res and os.name == "nt":
# hide file on windows systems
hide_file(str(transcript))
self.statusBar.showMessage("Autosave complete.")
self.statusBar.showMessage("Autosave complete.")

def close_file(self):
if not self.undo_stack.isClean():
Expand Down Expand Up @@ -1057,6 +1060,7 @@ def close_file(self):
self.parSteno.clear()
self.autosave_time.stop()
self.statusBar.showMessage("Project closed")
self.parent()._update_title()
return True

def action_close(self):
Expand Down Expand Up @@ -2506,19 +2510,21 @@ def extract_indexes(self):
if len(self.textEdit.toPlainText()) == 0:
return
while True:
block_strokes = block.userData()["strokes"]
for ind, el in enumerate(block_strokes.data):
# print(ind)
if el.element == "index":
if el.indexname not in index_dict:
index_dict[el.indexname] = {}
if "prefix" not in index_dict[el.indexname]:
index_dict[el.indexname]["prefix"] = el.prefix
if "hidden" not in index_dict[el.indexname]:
index_dict[el.indexname]["hidden"] = el.hidden
if "entries" not in index_dict[el.indexname]:
index_dict[el.indexname]["entries"] = {}
index_dict[el.indexname]["entries"][el.data] = el.description
# print(block.blockNumber())
if block.userData():
block_strokes = block.userData()["strokes"]
for ind, el in enumerate(block_strokes.data):
# print(ind)
if el.element == "index":
if el.indexname not in index_dict:
index_dict[el.indexname] = {}
if "prefix" not in index_dict[el.indexname]:
index_dict[el.indexname]["prefix"] = el.prefix
if "hidden" not in index_dict[el.indexname]:
index_dict[el.indexname]["hidden"] = el.hidden
if "entries" not in index_dict[el.indexname]:
index_dict[el.indexname]["entries"] = {}
index_dict[el.indexname]["entries"][el.data] = el.description
if block == self.textEdit.document().lastBlock():
break
block = block.next()
Expand Down Expand Up @@ -3042,7 +3048,7 @@ def setup_captions(self, checked):
self.thread.started.connect(self.cap_worker.make_caps)
self.cap_worker.finished.connect(self.thread.quit)
self.cap_worker.finished.connect(self.cap_worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
# self.thread.finished.connect(self.thread.deleteLater)
self.cap_worker.capSend.connect(self.add_cap)
self.cap_worker.postMessage.connect(self.statusBar.showMessage)
self.thread.start()
Expand Down Expand Up @@ -3079,6 +3085,19 @@ def flush_caption(self):
self.cap_worker.intake(new_text + "\u2029")
self.caption_cursor_pos = max(current_cursor.position(), current_cursor.anchor())

def modify_audiotime(self):
block = self.textEdit.document().begin()
times = []
for i in range(self.textEdit.document().blockCount()):
if block.userData():
times.append(block.userData["creationtime"])
block_time = block.userData()["strokes"].collection_time()
times.append(block_time)
if block == self.textEdit.document().lastBlock():
break
block = block.next()
earliest = min([t for t in times if t])
print(earliest)
# export functions
def export_text(self):
selected_folder = pathlib.Path(self.file_name) / "export"
Expand Down Expand Up @@ -3127,8 +3146,8 @@ def export_ascii(self):
self.worker.progress.connect(self.progressBar.setValue)
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.thread.finished.connect(lambda: self.statusBar.showMessage("Exported in ASCII format."))
self.worker.finished.connect(lambda: self.statusBar.showMessage("Exported in ASCII format."))
# self.thread.finished.connect(self.thread.deleteLater)
self.thread.start()

def export_html(self):
Expand Down Expand Up @@ -3159,8 +3178,8 @@ def export_html(self):
self.worker.progress.connect(self.progressBar.setValue)
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.thread.finished.connect(lambda: self.statusBar.showMessage("Exported in HTML format."))
self.worker.finished.connect(lambda: self.statusBar.showMessage("Exported in HTML format."))
# self.thread.finished.connect(self.thread.deleteLater)
self.thread.start()

def export_plain_ascii(self):
Expand Down Expand Up @@ -3190,8 +3209,8 @@ def export_plain_ascii(self):
self.worker.progress.connect(self.progressBar.setValue)
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.thread.finished.connect(lambda: self.statusBar.showMessage("Exported in plain ASCII format."))
self.worker.finished.connect(lambda: self.statusBar.showMessage("Exported in plain ASCII format."))
# self.thread.finished.connect(self.thread.deleteLater)
self.thread.start()

def export_srt(self):
Expand Down Expand Up @@ -3227,8 +3246,8 @@ def export_srt(self):
self.worker.progress.connect(self.progressBar.setValue)
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.thread.finished.connect(lambda: self.statusBar.showMessage("Exported in srt format."))
self.worker.finished.connect(lambda: self.statusBar.showMessage("Exported in srt format."))
# self.thread.finished.connect(self.thread.deleteLater)
self.thread.start()

def export_odt(self):
Expand Down Expand Up @@ -3259,8 +3278,8 @@ def export_odt(self):
self.worker.progress.connect(self.progressBar.setValue)
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.thread.finished.connect(lambda: self.statusBar.showMessage("Exported in Open Document Format."))
self.worker.finished.connect(lambda: self.statusBar.showMessage("Exported in Open Document Format."))
# self.thread.finished.connect(self.thread.deleteLater)
self.thread.start()
# import rtf
def import_rtf(self):
Expand Down Expand Up @@ -3353,7 +3372,7 @@ def export_rtf(self):
self.worker.progress.connect(self.progressBar.setValue)
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.thread.finished.connect(lambda: self.statusBar.showMessage("Exported in RTF/CRE format."))
self.worker.finished.connect(lambda: self.statusBar.showMessage("Exported in RTF/CRE format."))
# self.thread.finished.connect(self.thread.deleteLater)
self.thread.start()

Loading

0 comments on commit 115968b

Please sign in to comment.