Skip to content

Commit

Permalink
Fix #91: add a checkbox to disable auto-send-paste
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-lg committed Nov 12, 2017
1 parent 4994e1b commit 4518593
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/config.py
Expand Up @@ -144,13 +144,15 @@ def load_config_file(self, filename, spec, root_dir=None):

# Create the ConfigObj
try:
config = ConfigObj(fullpath + ".conf", encoding="utf-8",
config = ConfigObj(fullpath + ".conf", encoding="UTF8",
configspec=spec.split("\n"))
config.backup_encoding = "utf-8"
except (ParseError, UnicodeError):
logger.warning("Unable to parse {}, try in latin-1 encoding".format(
repr(fullpath)))
config = ConfigObj(fullpath + ".conf", configspec=spec.split("\n"), encoding="latin-1")
config.encoding = "utf-8"
config.encoding = "UTF8"
config.backup_encoding = "utf-8"
config.write()

# Validates the configuration
Expand Down Expand Up @@ -243,14 +245,15 @@ def load(self):
def load_options(self):
"""Load the file containing the options."""
lang = locale.getdefaultlocale()[0].split("_")[0]
spec = dedent("""
spec = dedent(u"""
[general]
language = option('en', 'fr', default='{lang}')
encoding = string(default="iso8859_15")
screenreader = boolean(default=True)
[input]
command_stacking = string(default=";")
auto_send_paste = boolean(default=True)
[output]
richtext = boolean(default=True)
Expand Down Expand Up @@ -285,7 +288,7 @@ def load(self):
def load_options(self):
"""Load the file containing the options."""
world = self.world
spec = dedent("""
spec = dedent(u"""
[connection]
name = string
hostname = string
Expand Down
1 change: 1 addition & 0 deletions src/translations/en/ui/dialog/preferences.yml
Expand Up @@ -3,6 +3,7 @@ display: Display
encodings: Encodings
input: Input
command_stacking: Command stacking
auto_send_paste: Send the text to the server when pasting from the clipboard
accessibility: Accessibility
screenreader: Enable screen reader support
TTS:
Expand Down
1 change: 1 addition & 0 deletions src/translations/fr/ui/dialog/preferences.yml
Expand Up @@ -3,6 +3,7 @@ display: Affichage
encodings: Encodages
input: Commandes
command_stacking: Multiple commandes
auto_send_paste: Envoyer le texte au serveur quand on colle depuis le presse-papier
accessibility: Accessibilité
screenreader: Activer le support pour lecteur d'écran
TTS:
Expand Down
10 changes: 10 additions & 0 deletions src/ui/dialogs/preferences.py
Expand Up @@ -250,10 +250,16 @@ def InitUI(self):
h_stacking = wx.Button(self,
label=t("ui.button.what.command_stacking"))

# Auto-send
self.auto_send_paste = wx.CheckBox(self,
label=t("ui.dialog.preferences.auto_send_paste"))
self.auto_send_paste.SetValue(settings["options.input.auto_send_paste"])

# Append to the sizer
sizer.Add(l_stacking, pos=(0, 0))
sizer.Add(t_stacking, pos=(1, 0))
sizer.Add(h_stacking, pos=(0, 1))
sizer.Add(self.auto_send_paste, pos=(2, 0))

# Event binding
h_stacking.Bind(wx.EVT_BUTTON, self.OnHelpStacking)
Expand Down Expand Up @@ -379,16 +385,20 @@ def OnOK(self, e):
old_language = settings.get_language()
interrupt = accessibility.TTS_interrupt.GetValue()
old_richtext = settings["options.output.richtext"]
auto_send_paste = input.auto_send_paste.GetValue()
richtext = accessibility.richtext.GetValue()
srs = accessibility.srs_on.GetValue()
settings["options.general.language"] = new_language
settings["options.general.encoding"] = encoding
settings["options.general.screenreader"] = srs
settings["options.input.command_stacking"] = command_stacking
settings["options.input.auto_send_paste"] = auto_send_paste
settings["options.TTS.on"] = accessibility.TTS_on.GetValue()
settings["options.TTS.outside"] = accessibility.TTS_outside.GetValue()
settings["options.TTS.interrupt"] = interrupt
settings["options.output.richtext"] = richtext
print repr(settings["options.input.command_stacking"])
import pdb; pdb.set_trace()
settings["options"].write()
self.engine.TTS_on = accessibility.TTS_on.GetValue()
self.engine.TTS_outside = accessibility.TTS_outside.GetValue()
Expand Down
3 changes: 2 additions & 1 deletion src/ui/window.py
Expand Up @@ -668,7 +668,8 @@ def OnPaste(self, e):
self.output.SetInsertionPoint(self.output.GetLastPosition())

input = self.input + clipboard
if input.endswith("\n"):
if input.endswith("\n") and self.engine.settings[
"options.input.auto_send_paste"]:
lines = input.splitlines()
for line in lines:
self.OnInput(line)
Expand Down
8 changes: 4 additions & 4 deletions src/world.py
Expand Up @@ -163,12 +163,12 @@ def save(self):

if self.settings is None:
try:
self.settings = ConfigObj(spec.split("\n"), encoding="latin-1")
except ParseError:
self.settings = ConfigObj(spec.split("\n"), encoding="utf-8")
except (ParseError, UnicodeError):
logger.warning("Error while parsing the config file, " \
"trying without encoding")
self.settings = ConfigObj(spec.split("\n"))
self.settings.encoding = "latin-1"
self.settings.encoding = "utf-8"
self.settings.write()

connection = self.settings["connection"]
Expand Down Expand Up @@ -347,7 +347,7 @@ def open_notepad(self):
@classmethod
def get_infos(cls, configuration):
"""Get the information in the configuration and return a dict."""
config = ConfigObj(StringIO(configuration), encoding="latin-1")
config = ConfigObj(StringIO(configuration), encoding="utf-8")
data = {}

for key, value in config.items():
Expand Down

0 comments on commit 4518593

Please sign in to comment.