Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Save as..." feature for dictionary conversion #1149

Closed
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plover/gui_qt/dictionaries_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from PyQt5.QtWidgets import QTableWidget

class DictionariesTable(QTableWidget):
def contextMenuEvent(self, event):
row = self.rowAt(event.y())
self.parent().on_table_context_menu(row, event.globalPos())
33 changes: 33 additions & 0 deletions plover/gui_qt/dictionaries_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
QMenu,
QTableWidgetItem,
QWidget,
QAction,
)

from plover.config import DictionaryConfig
Expand Down Expand Up @@ -377,6 +378,38 @@ def _create_new_dictionary(self):
self._update_dictionaries(dictionaries, keep_selection=False,
loaded_dictionaries=self._loaded_dictionaries)

def on_table_context_menu(self, row, global_pos):
if row == -1:
# when the user right-clicks in the empty area of the table
return

menu = QMenu(self)
saveAsAction = QAction("Save a Copy As...", self)
user202729 marked this conversation as resolved.
Show resolved Hide resolved
saveAsAction.triggered.connect(lambda: self.on_save_as(row))

selected_rows = self._get_selection()
assert row in selected_rows
saveAsAction.setDisabled(len(selected_rows) != 1)
menu.addAction(saveAsAction)
menu.popup(global_pos)

def on_save_as(self, row):
dictionary_path = self._config_dictionaries[row].path
new_filename = QFileDialog.getSaveFileName(
self, _('Save a Copy As...'), dictionary_path,
_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[dictionary_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