Skip to content

Commit

Permalink
Merge pull request #150 from GliderGeek/149-wx-gui
Browse files Browse the repository at this point in the history
use wx instead of tkinter for gui
  • Loading branch information
GliderGeek authored May 31, 2019
2 parents 411bc36 + 4203499 commit e93d73e
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 260 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ hidden
PySoar/standalone/*.zip
PySoar/standalone/windows
PySoar-manual.dvi
PySoar/*.pyc

*.pyc
PySoar/bin
env
venv
.idea
*.DS_Store
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Master

[unreleased]
- use wxpython instead of tkinter for GUI

v0.57.2
- try, except around performance creation
- bump opensoar to v0.1.3
Expand Down
19 changes: 9 additions & 10 deletions PySoar/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from opensoar.competition.strepla import StreplaDaily
from opensoar.competition.soaringspot import SoaringSpotDaily
from PySoar.exportClass import ExcelExport
from PySoar.performanceClass import Performance
from PySoar.settingsClass import Settings

from exportClass import ExcelExport
from performanceClass import Performance
from settingsClass import Settings

settings = Settings()

Expand Down Expand Up @@ -37,7 +38,7 @@ def download_progress(downloads, total_number_of_flights):
return download_progress


def run(url, source, url_status=None, download_progress_label=None, analysis_progress_label=None):
def run(url, source, url_status=None, download_progress=None, analysis_progress=None):
target_directory = os.path.join(settings.current_dir, 'bin')
if source == 'cuc':
daily_result_page = SoaringSpotDaily(url)
Expand All @@ -46,15 +47,11 @@ def run(url, source, url_status=None, download_progress_label=None, analysis_pro
else:
raise ValueError('This source is not supported: %s' % source)

analysis_progress = get_analysis_progress_function(analysis_progress_label)
download_progress = get_download_progress_function(download_progress_label)

competition_day = daily_result_page.generate_competition_day(target_directory, download_progress)

if url_status is not None and competition_day.task.multistart:
url_status.configure(text="Multiple starting points not implemented!", foreground='red')
url_status.update()
return
url_status(False, "Multiple starting points not implemented!")
return False

classification_method = 'pysoar'
failed_comp_ids = competition_day.analyse_flights(classification_method, analysis_progress,
Expand Down Expand Up @@ -84,3 +81,5 @@ def run(url, source, url_status=None, download_progress_label=None, analysis_pro

excel_sheet = ExcelExport(settings, competition_day.task.no_legs)
excel_sheet.write_file(competition_day, settings, daily_result_page.igc_directory)

return True
252 changes: 155 additions & 97 deletions PySoar/main_pysoar.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
from tkinter import Label, Tk, Button, Entry, W, E

import subprocess

import os

from PySoar.analysis import run
from functools import partial
from PySoar.settingsClass import Settings
import sys

import wx

from analysis import run
from settingsClass import Settings

settings = Settings()


def url_format_correct(url_string):
def url_format_correct(url_string, status_handle):

if 'soaringspot.com' in url_string:
daily_results = _is_daily_soaringspot_url(url_string)
elif 'strepla.de' in url_string:
daily_results = _is_daily_strepla_url(url_string)
else:
return 'Use SoaringSpot or Strepla URL'
status_handle('Wrong URL: Use SoaringSpot or Strepla URL')
return False

if not daily_results:
return 'URL does not give daily results'
status_handle('Wrong URL: no daily results')
return False
else:
return 'URL correct'
status_handle('URL correct')
return True


def _is_daily_strepla_url(strepla_url):
Expand All @@ -39,108 +40,165 @@ def _is_daily_soaringspot_url(soaringspot_url):
return results == 'daily'


def go_bugform(url_entry, event):
import webbrowser
def get_url_source(url):
if 'soaringspot.com' in url:
return 'cuc'
elif 'strepla.de' in url:
return 'scs'
else:
raise ValueError('Unknown source')

form_url = settings.debug_form_url
versionID = settings.pysoar_version_formID
urlID = settings.competition_url_formID
pysoar_version = settings.version

comp_url = url_entry.get()
class MyFrame(wx.Frame):
def __init__(self):
super().__init__(parent=None, title='PySoar (%s)' % settings.version)
panel = wx.Panel(self)

complete_url = '%s?entry.%s=%s&entry.%s=%s' % (form_url, versionID, pysoar_version, urlID, comp_url)
webbrowser.open(complete_url)
complete_sizer = wx.BoxSizer(wx.VERTICAL)

my_sizer = wx.BoxSizer(wx.VERTICAL)

def open_analysis_file():
text = wx.StaticText(panel, label="Fill in URL:")
my_sizer.Add(text, 0, wx.ALL | wx.CENTER, 5)
self.url_input = wx.TextCtrl(panel)
my_sizer.Add(self.url_input, 0, wx.ALL | wx.EXPAND, 5)

if sys.platform.startswith("darwin"):
subprocess.call(["open", settings.file_name])
elif sys.platform.startswith('linux'):
subprocess.call(["xdg-open", settings.file_name])
elif sys.platform.startswith('win32'):
os.startfile(settings.file_name)
self.status = wx.StaticText(panel, label="")
my_sizer.Add(self.status)

self.download_status = wx.StaticText(panel, label="")
my_sizer.Add(self.download_status)

def get_url_source(url):
if 'soaringspot.com' in url:
return 'cuc'
elif 'strepla.de' in url:
return 'scs'
else:
raise ValueError('Unknown source')
self.analyse_status = wx.StaticText(panel, label="")
my_sizer.Add(self.analyse_status)

buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)

my_btn = wx.Button(panel, label='Start analysis')
my_btn.Bind(wx.EVT_BUTTON, self.on_press)
buttons_sizer.Add(my_btn, 0, wx.EXPAND)

self.open_spreadsheet = wx.Button(panel, label="Open")
self.open_spreadsheet.Disable()
self.open_spreadsheet.Bind(wx.EVT_BUTTON, self.open_analysis_file)
buttons_sizer.Add(self.open_spreadsheet)

bug_report = wx.Button(panel, label='Report problem')
bug_report.Bind(wx.EVT_BUTTON, self.go_bugform)
buttons_sizer.Add(bug_report)

complete_sizer.Add(my_sizer, 0, wx.ALL | wx.EXPAND, 5)
complete_sizer.Add(buttons_sizer, 0, wx.ALL | wx.CENTER, 5)

panel.SetSizer(complete_sizer)
self.Show()

def go_bugform(self, event):
import webbrowser

form_url = settings.debug_form_url
versionID = settings.pysoar_version_formID
urlID = settings.competition_url_formID
pysoar_version = settings.version

comp_url = self.url_input.GetValue()

complete_url = '%s?entry.%s=%s&entry.%s=%s' % (form_url, versionID, pysoar_version, urlID, comp_url)
webbrowser.open(complete_url)

def open_analysis_file(self, event):
if sys.platform.startswith("darwin"):
subprocess.call(["open", settings.file_name])
elif sys.platform.startswith('linux'):
subprocess.call(["xdg-open", settings.file_name])
elif sys.platform.startswith('win32'):
os.startfile(settings.file_name)

def set_download_status(self, new, total=None):
if total is not None:
download_str = 'Downloaded: %s/%s' % (new, total)
else:
download_str = 'Downloaded: %s' % new

self.download_status.SetLabel(download_str)
wx.Yield()

def set_analyse_status(self, new, total=None):
if total is not None:
analysis_str = 'Analyzed: %s/%s' % (new, total)
else:
analysis_str = 'Analyzed: %s' % new

self.analyse_status.SetLabel(analysis_str)
wx.Yield()

def update_status(self, message):
self.status.SetLabel(message)
wx.Yield()

def on_press(self, event):
self.open_spreadsheet.Disable()
self.download_status.SetLabel('')
self.analyse_status.SetLabel('')

url = self.url_input.GetValue()
success = url_format_correct(url, self.update_status)

if success:
success = run(url, get_url_source(url), self.update_status, self.set_download_status, self.set_analyse_status)
if success:
self.update_status("Analysis is complete.")
self.open_spreadsheet.Enable()


def start_gui():
app = wx.App()
frame = MyFrame()
app.MainLoop()


def run_commandline_program(sys_argv):

def print_help():
print('There are two options for running PySoar from the commandline:\n'
'1. `python main_python` for GUI\n'
'2. `python main_pysoar [url]` - where [url] is the daily competition url')

def status_handle(message):
print(message)

root = Tk()
root.resizable(0, 0)
def download_handle(new, total=None):
if total is not None:
analysis_str = 'Downloaded: %s/%s' % (new, total)
else:
analysis_str = 'Downloaded: %s' % new
print(analysis_str)

def analysis_handle(new, total=None):
if total is not None:
analysis_str = 'Analyzed: %s/%s' % (new, total)
else:
analysis_str = 'Analyzed: %s' % new
print(analysis_str)

def url_check(event):
checked_url = url_format_correct(url_entry.get())
if checked_url == 'URL correct':
url_status.configure(text=checked_url, foreground='green')
url_status.update()
start_analysis()
if len(sys.argv) == 2:
if sys.argv[1] == '--help':
print_help()
else:
url_status.configure(text=checked_url, foreground='red')
url_status.update()

def start_analysis():

url = url_entry.get()
source = get_url_source(url)
run(url, source, url_status, download_progress_label, analysis_progress_label)

analysis_done = Button(root, text='Excel produced', command=open_analysis_file)
analysis_done.grid(row=6, column=0, pady=5)
print("Analysis complete, excel produced")

title = Label(root, text=' PySoar', font=("Helvetica", 30))
url_accompanying_text = Label(root, text='Give Soaringspot/scoringStrepla URL:')
url_entry = Entry(root, width=60)
url_confirmation = Button(root, text='ok')
url_confirmation.bind('<Button-1>', url_check)
url_status = Label(root, text='', foreground='red')
download_progress_label = Label(root, text='Downloaded: ')
analysis_progress_label = Label(root, text='Analyzed: ')
report_problem = Button(root, text='Report problem')
report_problem.bind('<Button-1>', partial(go_bugform, url_entry))
root.bind('<Return>', url_check)
version = Label(root, text='v %s' % settings.version)

title.grid(row=0, column=0)
url_accompanying_text.grid(row=1, column=0, sticky=W)
url_entry.grid(row=2, column=0)
url_confirmation.grid(row=2, column=1)
url_status.grid(row=3, column=0)
download_progress_label.grid(row=4, column=0, pady=5)
analysis_progress_label.grid(row=5, column=0, pady=5)
report_problem.grid(row=7, column=0, sticky=W)
version.grid(row=7, column=1, sticky=E)

root.mainloop()


def print_help():
print('There are two options for running PySoar from the commandline:\n'
'1. `python main_python` for GUI\n'
'2. `python main_pysoar [url]` - where [url] is the daily competition url')


if len(sys.argv) == 1:
start_gui()
elif len(sys.argv) == 2:
if sys.argv[1] == '--help':
url = sys.argv[1]
correct = url_format_correct(url, status_handle)
if correct:
source = get_url_source(url)
run(url, source, status_handle, download_handle, analysis_handle)
else:
print_help()


if __name__ == '__main__':
if len(sys.argv) == 1:
start_gui()
else:
url = sys.argv[1]
if url_format_correct(url) == 'URL correct':
source = get_url_source(url)
run(url, source)
else:
print_help()
run_commandline_program(sys.argv)

############################# LICENSE #####################################

Expand Down
Loading

0 comments on commit e93d73e

Please sign in to comment.