Skip to content

Commit

Permalink
Merge pull request #1061 from benoit-pierre/fix_machine_type_i18n_sup…
Browse files Browse the repository at this point in the history
…port

Fix machine type i18n support
  • Loading branch information
TheaMorin authored Apr 23, 2019
2 parents cecdb42 + c25ef78 commit 450704b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
17 changes: 6 additions & 11 deletions plover/gui_qt/config_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,16 @@ class ChoiceOption(QComboBox):

def __init__(self, choices=None):
super().__init__()
self._choices = {} if choices is None else choices
self._reversed_choices = {
translation: choice
for choice, translation in choices.items()
}
self.addItems(sorted(choices.values()))
choices = {} if choices is None else choices
for value, label in sorted(choices.items()):
self.addItem(label, value)
self.activated.connect(self.on_activated)

def setValue(self, value):
translation = self._choices[value]
self.setCurrentText(translation)
self.setCurrentIndex(self.findData(value))

def on_activated(self):
choice = self._reversed_choices[self.currentText()]
self.valueChanged.emit(choice)
def on_activated(self, index):
self.valueChanged.emit(self.itemData(index))


class FileOption(QWidget, Ui_FileWidget):
Expand Down
17 changes: 9 additions & 8 deletions plover/gui_qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ def __init__(self, engine, use_qt_notifications):
self._dialog_class[tool_plugin.name] = tool
engine.signal_connect('output_changed', self.on_output_changed)
# Machine.
self.machine_type.addItems(
_(plugin.name)
for plugin in registry.list_plugins('machine')
)
for plugin in registry.list_plugins('machine'):
self.machine_type.addItem(_(plugin.name), plugin.name)
engine.signal_connect('config_changed', self.on_config_changed)
engine.signal_connect('machine_state_changed',
lambda machine, state:
Expand All @@ -147,7 +145,7 @@ def __init__(self, engine, use_qt_notifications):
self.on_configure()
# Apply configuration settings.
config = self._engine.config
self.machine_type.setCurrentText(config['machine_type'])
self._update_machine(config['machine_type'])
self._configured = False
self.dictionaries.on_config_changed(config)
self.set_visible(not config['start_minimized'])
Expand Down Expand Up @@ -212,18 +210,21 @@ def _save_state(self, settings):
hidden_toolbar_tools.add(action.objectName())
settings.setValue('hidden_toolbar_tools', json.dumps(list(sorted(hidden_toolbar_tools))))

def _update_machine(self, machine_type):
self.machine_type.setCurrentIndex(self.machine_type.findData(machine_type))

def on_config_changed(self, config_update):
if 'machine_type' in config_update:
self.machine_type.setCurrentText(config_update['machine_type'])
self._update_machine(config_update['machine_type'])
if not self._configured:
self._configured = True
if config_update.get('show_suggestions_display', False):
self._activate_dialog('suggestions')
if config_update.get('show_stroke_display', False):
self._activate_dialog('paper_tape')

def on_machine_changed(self, machine_type):
self._engine.config = { 'machine_type': machine_type }
def on_machine_changed(self, machine_index):
self._engine.config = { 'machine_type': self.machine_type.itemData(machine_index) }

def on_output_changed(self, enabled):
self._trayicon.update_output(enabled)
Expand Down
6 changes: 3 additions & 3 deletions plover/gui_qt/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@
</connection>
<connection>
<sender>machine_type</sender>
<signal>activated(QString)</signal>
<signal>activated(int)</signal>
<receiver>MainWindow</receiver>
<slot>on_machine_changed(QString)</slot>
<slot>on_machine_changed(int)</slot>
<hints>
<hint type="sourcelabel">
<x>86</x>
Expand Down Expand Up @@ -484,7 +484,7 @@
<slot>on_toggle_output(bool)</slot>
<slot>on_about()</slot>
<slot>on_show_hide()</slot>
<slot>on_machine_changed(QString)</slot>
<slot>on_machine_changed(int)</slot>
<slot>on_enable_output()</slot>
<slot>on_disable_output()</slot>
</slots>
Expand Down

0 comments on commit 450704b

Please sign in to comment.