Change update_inara to use a Tkinter-based GUI by default.
This commit is contained in:
parent
ae9a1ed77c
commit
5b959aa87f
|
@ -10,7 +10,7 @@ flag_parser = argparse.ArgumentParser(description="Report information about your
|
||||||
flag_parser.add_argument('--dump', action='store_true', help="Dump raw data.")
|
flag_parser.add_argument('--dump', action='store_true', help="Dump raw data.")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
settings = utils.get_settings()
|
settings = utils.get_settings(use_gui=False)
|
||||||
flags = flag_parser.parse_args()
|
flags = flag_parser.parse_args()
|
||||||
|
|
||||||
companion.login(settings.get('ed_companion', 'username'), settings.get('ed_companion', 'password'))
|
companion.login(settings.get('ed_companion', 'username'), settings.get('ed_companion', 'password'))
|
||||||
|
|
|
@ -1,22 +1,76 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from datetime import datetime
|
||||||
from elite_api import companion
|
from elite_api import companion
|
||||||
from elite_api.inara import InaraSession
|
from elite_api.inara import InaraSession
|
||||||
|
import Tkinter as tk
|
||||||
import utils
|
import utils
|
||||||
|
import easygui
|
||||||
|
|
||||||
if utils.windows_detected():
|
arg_parser = argparse.ArgumentParser()
|
||||||
import easygui
|
arg_parser.add_argument("--no-gui",
|
||||||
|
help="Just update and report to the command line.",
|
||||||
|
action="store_false", dest="gui")
|
||||||
|
|
||||||
settings = utils.get_settings()
|
|
||||||
inara_session = InaraSession(settings.get('inara', 'username'), settings.get('inara', 'password'))
|
|
||||||
|
|
||||||
companion.login(settings.get('ed_companion', 'username'), settings.get('ed_companion', 'password'))
|
def do_logins(settings):
|
||||||
data = companion.get_data()
|
inara_session = InaraSession(settings.get('inara', 'username'), settings.get('inara', 'password'))
|
||||||
|
companion.login(settings.get('ed_companion', 'username'), settings.get('ed_companion', 'password'))
|
||||||
|
return inara_session
|
||||||
|
|
||||||
inara_session.update_credits(data['commander']['credits'])
|
|
||||||
inara_session.update_location(data['lastSystem']['name'])
|
|
||||||
|
|
||||||
if utils.windows_detected():
|
def update_inara(inara_session):
|
||||||
easygui.msgbox("Inara updated!")
|
data = companion.get_data()
|
||||||
else:
|
inara_session.update_credits(data['commander']['credits'])
|
||||||
print("Inara updated!")
|
inara_session.update_location(data['lastSystem']['name'])
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateWindow:
|
||||||
|
def __init__(self, parent, settings):
|
||||||
|
frame = tk.Frame(parent)
|
||||||
|
frame.pack(expand=True, fill=tk.BOTH)
|
||||||
|
|
||||||
|
self.message = tk.StringVar()
|
||||||
|
self.message.set("Click Update to update!")
|
||||||
|
message_label = tk.Label(frame, textvariable=self.message)
|
||||||
|
message_label.grid(columnspan=3, padx=20, pady=20)
|
||||||
|
|
||||||
|
self.update_button = tk.Button(frame, text="Update", height=2, width=4,
|
||||||
|
command=self._update_inara)
|
||||||
|
self.update_button.grid(row=1, column=0, columnspan=2, pady=10)
|
||||||
|
|
||||||
|
config_button = tk.Button(frame, text="Config", height=1, width=2,
|
||||||
|
command=utils.init_settings)
|
||||||
|
config_button.grid(row=1, column=2)
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.session = do_logins(settings)
|
||||||
|
except:
|
||||||
|
self.update_button['state'] = tk.DISABLED
|
||||||
|
self.message.set("Error logging in. Double-check your config,\nthen restart the program.")
|
||||||
|
|
||||||
|
def _update_inara(self):
|
||||||
|
self.message.set("Updating, please wait...")
|
||||||
|
update_inara(self.session)
|
||||||
|
self.message.set("Update successful! (Last update: %s)" %
|
||||||
|
datetime.now().isoformat(' ')[:16])
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
|
settings = utils.get_settings(args.gui)
|
||||||
|
|
||||||
|
if args.gui:
|
||||||
|
root = tk.Tk()
|
||||||
|
root.wm_title("Inara Updater")
|
||||||
|
app = UpdateWindow(root, settings)
|
||||||
|
root.mainloop()
|
||||||
|
else:
|
||||||
|
inara_session = do_logins(settings)
|
||||||
|
update_inara(inara_session)
|
||||||
|
print("Inara updated!")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
20
utils.py
20
utils.py
|
@ -4,14 +4,14 @@ import easygui
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
def get_config_dir(make=False):
|
def get_config_dir(make=False):
|
||||||
if windows_detected():
|
if platform.system() == 'Windows':
|
||||||
config_suffix = os.path.join('AppData', 'Local', 'ed_tools')
|
config_suffix = os.path.join('AppData', 'Local', 'ed_tools')
|
||||||
else:
|
else:
|
||||||
config_suffix = '.ed_tools'
|
config_suffix = '.ed_tools'
|
||||||
|
|
||||||
return os.path.join(os.path.expanduser('~'), config_suffix)
|
return os.path.join(os.path.expanduser('~'), config_suffix)
|
||||||
|
|
||||||
def get_settings():
|
def get_settings(use_gui=True):
|
||||||
"""
|
"""
|
||||||
Try to read the settings from file into ConfigParser object.
|
Try to read the settings from file into ConfigParser object.
|
||||||
If the config file isn't found, initialize it.
|
If the config file isn't found, initialize it.
|
||||||
|
@ -26,26 +26,26 @@ def get_settings():
|
||||||
os.makedirs(get_config_dir())
|
os.makedirs(get_config_dir())
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
_init_settings(settings, filename)
|
|
||||||
|
settings = init_settings(use_gui)
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
def windows_detected():
|
def init_settings(gui=True):
|
||||||
return platform.system() == 'Windows'
|
settings = ConfigParser()
|
||||||
|
|
||||||
def _init_settings(settings, filename):
|
|
||||||
settings.add_section('ed_companion')
|
settings.add_section('ed_companion')
|
||||||
settings.add_section('inara')
|
settings.add_section('inara')
|
||||||
if windows_detected():
|
if gui:
|
||||||
_settings_prompt_gui(settings)
|
_settings_prompt_gui(settings)
|
||||||
easygui.msgbox("To change your settings later, edit " + filename)
|
|
||||||
else:
|
else:
|
||||||
_settings_prompt_cli(settings)
|
_settings_prompt_cli(settings)
|
||||||
print "To change these settings later, edit " + filename
|
print "To change these settings later, edit " + filename
|
||||||
|
|
||||||
with open(filename, 'wb') as f:
|
with open(os.path.join(get_config_dir(), 'settings.conf'), 'wb') as f:
|
||||||
settings.write(f)
|
settings.write(f)
|
||||||
|
|
||||||
|
return settings
|
||||||
|
|
||||||
def _settings_prompt_gui(settings):
|
def _settings_prompt_gui(settings):
|
||||||
data = []
|
data = []
|
||||||
data = easygui.multenterbox(
|
data = easygui.multenterbox(
|
||||||
|
|
Reference in New Issue
Block a user