From 89335e70a94e302c4a2cc520509bd8ddc65c9206 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Thu, 21 Jan 2016 13:45:45 -0500 Subject: [PATCH] Add a bunch of usability stuff, including GUI support in Windows. --- requirements.txt | 1 + update_inara.py | 13 +++++++++++-- utils.py | 32 +++++++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8f33f7d --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +easygui diff --git a/update_inara.py b/update_inara.py index ff672df..63ed32f 100755 --- a/update_inara.py +++ b/update_inara.py @@ -11,11 +11,20 @@ inara_session = InaraSession(settings.get('inara', 'username'), settings.get('in try: companion_session.login(settings.get('ed_companion', 'username'), settings.get('ed_companion', 'password')) except companion.VerificationRequired: - code = raw_input("Input Verification Code: ") + if utils.windows_detected(): + code = easygui.enterbox("Input Verification Code (check your email)", + "Verification Required") + else: + code = raw_input("Input Verification Code (check your email): ") companion_session.verify(code) data = companion_session.query() +companion_session.close() + inara_session.update_credits(data['commander']['credits']) inara_session.update_location(data['lastSystem']['name']) -companion_session.close() +if utils.windows_detected(): + easygui.msgbox("Inara updated!") +else: + print("Inara updated!") diff --git a/utils.py b/utils.py index d254de4..cfc26d9 100644 --- a/utils.py +++ b/utils.py @@ -1,5 +1,7 @@ from ConfigParser import ConfigParser import os +import easygui +import platform def get_config_dir(): return os.path.join(os.path.expanduser('~'), '.ed_tools/') @@ -19,15 +21,39 @@ def get_settings(): return settings +def windows_detected(): + return platform.system() == 'Windows' def _init_settings(settings, filename): settings.add_section('ed_companion') settings.add_section('inara') + if windows_detected(): + _settings_prompt_gui(settings) + else: + _settings_prompt_cli(settings) + + with open(filename, 'wb') as f: + settings.write(f) + +def _settings_prompt_gui(settings): + data = [] + easygui.multenterbox( + "Enter your E:D and Inara credentials. You only need to do this once.", + "Authentication Data", + ["Elite Username (email address)", "Elite Password", + "Inara Username", "Inara Password"], + data + ) + settings.set('ed_companion', 'username', data[0]) + settings.set('ed_companion', 'password', data[1]) + settings.set('inara', 'username', data[2]) + settings.set('inara', 'password', data[3]) + easygui.msgbox("To change your settings later, edit " + filename) + + +def _settings_prompt_cli(settings): settings.set('ed_companion', 'username', raw_input("Elite Username (email address): ")) settings.set('ed_companion', 'password', raw_input("Elite Password: ")) settings.set('inara', 'username', raw_input("Inara Username: ")) settings.set('inara', 'password', raw_input("Inara Password: ")) print "To change these settings later, edit " + filename - - with open(filename, 'wb') as f: - settings.write(f)