Skip to content

Commit

Permalink
Add "Save as..." feature for dictionary conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
user202729 committed Oct 16, 2020
1 parent 9f1bdde commit c098a8a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
12 changes: 12 additions & 0 deletions plover/gui_qt/dictionaries_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from PyQt5.QtWidgets import QWidget, QMenu, QAction, QTableWidget

class DictionariesTable(QTableWidget):
def contextMenuEvent(self, event: "QContextMenuEvent"):
menu = QMenu(self)
saveAsAction = QAction("Save as...", self)
row = self.rowAt(event.y())
assert row >= 0
saveAsAction.triggered.connect(lambda: self.parent().on_save_as(row))
menu.addAction(saveAsAction)
menu.popup(event.globalPos())

16 changes: 16 additions & 0 deletions plover/gui_qt/dictionaries_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,22 @@ def _create_new_dictionary(self):
self._update_dictionaries(dictionaries, keep_selection=False,
loaded_dictionaries=self._loaded_dictionaries)

def on_save_as(self, row: int) -> None:
new_filename = QFileDialog.getSaveFileName(
self, _('Save dictionary as'), None,
_dictionary_filters(include_readonly=False),
)[0]
if not new_filename:
return
new_filename = normalize_path(new_filename)
try:
d = create_dictionary(new_filename, threaded_save=False)
d.update(self._loaded_dictionaries[self._config_dictionaries[row].path])
d.save()
except:
log.error('creating dictionary %s failed', new_filename, exc_info=True)
return

def on_add_translation(self):
selection = self._get_selection()
if selection:
Expand Down
9 changes: 8 additions & 1 deletion plover/gui_qt/dictionaries_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<number>0</number>
</property>
<item>
<widget class="QTableWidget" name="table">
<widget class="DictionariesTable" name="table">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
Expand Down Expand Up @@ -173,6 +173,13 @@
</action>
</widget>
<layoutdefault spacing="5" margin="8"/>
<customwidgets>
<customwidget>
<class>DictionariesTable</class>
<extends>QTableWidget</extends>
<header>plover.gui_qt.dictionaries_table</header>
</customwidget>
</customwidgets>
<resources>
<include location="resources/resources.qrc"/>
</resources>
Expand Down

0 comments on commit c098a8a

Please sign in to comment.