From 135f02fb461bd31bcb3d2d32e5f7d72fe6417478 Mon Sep 17 00:00:00 2001 From: Gal Novik Date: Wed, 23 Jan 2019 20:49:37 +0200 Subject: [PATCH] wxPython removal (#207) Replacing wxPython with Python's Tkinter. Also removing the option to choose multiple files as it is unused and causes errors, and fixing the load file/directory spinner. --- requirements.txt | 1 - .../dashboard_components/experiment_board.py | 34 ++++--------- rl_coach/dashboard_components/globals.py | 49 ++++++++++++------- .../dashboard_components/signals_file_base.py | 3 ++ setup.py | 2 +- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/requirements.txt b/requirements.txt index 898283c59..f64ffe210 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,6 @@ scikit-image>=0.13.0 gym>=0.10.5 bokeh>=0.13.0 futures>=3.1.1 -wxPython>=4.0.1 kubernetes>=8.0.0b1 redis>=2.10.6 minio>=4.0.5 diff --git a/rl_coach/dashboard_components/experiment_board.py b/rl_coach/dashboard_components/experiment_board.py index b1d82855a..e77ffb7bb 100644 --- a/rl_coach/dashboard_components/experiment_board.py +++ b/rl_coach/dashboard_components/experiment_board.py @@ -156,20 +156,17 @@ def create_files_group_signal(files): # load files from disk as a group -def load_files_group(): - show_spinner("Loading files group...") - files = open_file_dialog() - # no files selected - if not files or not files[0]: +def load_file(): + file = open_file_dialog() + show_spinner("Loading file...") + # no file selected + if not file: hide_spinner() return display_boards() - if len(files) == 1: - create_files_signal(files) - else: - create_files_group_signal(files) + create_files_signal([file]) change_selected_signals_in_data_selector([""]) hide_spinner() @@ -230,8 +227,8 @@ def handle_dir(dir_path, run_type): # load directory from disk as a group def load_directory_group(): - show_spinner("Loading directories group...") directory = open_directory_dialog() + show_spinner("Loading directories group...") # no files selected if not directory: hide_spinner() @@ -277,19 +274,6 @@ def create_files_signal(files, use_dir_name=False): selected_file = new_signal_files[0] -# load files from disk -def load_files(): - show_spinner("Loading files...") - files = open_file_dialog() - - # no files selected - if not files or not files[0]: - hide_spinner() - return - - display_files(files) - - def display_files(files): pause_auto_update() @@ -497,8 +481,8 @@ def toggle_auto_update(new): plot.extra_y_ranges['secondary'] = Range1d(0, 100) # select file -file_selection_button = Button(label="Select Files", button_type="success", width=120) -file_selection_button.on_click(load_files_group) +file_selection_button = Button(label="Select File", button_type="success", width=120) +file_selection_button.on_click(load_file) files_selector_spacer = Spacer(width=10) diff --git a/rl_coach/dashboard_components/globals.py b/rl_coach/dashboard_components/globals.py index cde05a65a..397b18226 100644 --- a/rl_coach/dashboard_components/globals.py +++ b/rl_coach/dashboard_components/globals.py @@ -22,7 +22,8 @@ from enum import Enum from bokeh.models import Div from bokeh.plotting import curdoc -import wx +import tkinter as tk +from tkinter import filedialog import colorsys patches = {} @@ -96,7 +97,7 @@ def hide_spinner(): spinner.text = "" -# takes path to dir and recursively adds all it's files to paths +# takes path to dir and recursively adds all its files to paths def add_directory_csv_files(dir_path, paths=None): if not paths: paths = [] @@ -113,24 +114,37 @@ def add_directory_csv_files(dir_path, paths=None): return paths -class DialogApp(wx.App): + + +class DialogApp(): + def getFileDialog(self): - with wx.FileDialog(None, "Open CSV file", wildcard="CSV files (*.csv)|*.csv", - style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_CHANGE_DIR | wx.FD_MULTIPLE) as fileDialog: - if fileDialog.ShowModal() == wx.ID_CANCEL: - return None # the user changed their mind - else: - # Proceed loading the file chosen by the user - return fileDialog.GetPaths() + application_window = tk.Tk() + + # Build a list of tuples for each file type the file dialog should display + my_filetypes = [('csv files', '.csv')] + + # Ask the user to select a one or more file names. + answer = filedialog.askopenfilename(parent=application_window, + initialdir=os.getcwd(), + title="Please select a file", + filetypes=my_filetypes) + application_window.destroy() + return answer + def getDirDialog(self): - with wx.DirDialog(None, "Choose input directory", "", - style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.FD_CHANGE_DIR) as dirDialog: - if dirDialog.ShowModal() == wx.ID_CANCEL: - return None # the user changed their mind - else: - # Proceed loading the dir chosen by the user - return dirDialog.GetPath() + application_window = tk.Tk() + + # Ask the user to select a folder. + answer = filedialog.askdirectory(parent=application_window, + initialdir=os.getcwd(), + title="Please select a folder") + application_window.destroy() + return answer + + + class RunType(Enum): @@ -150,4 +164,5 @@ class FolderType(Enum): dialog = DialogApp() + doc = curdoc() diff --git a/rl_coach/dashboard_components/signals_file_base.py b/rl_coach/dashboard_components/signals_file_base.py index 29ce4dcee..d853db6b5 100644 --- a/rl_coach/dashboard_components/signals_file_base.py +++ b/rl_coach/dashboard_components/signals_file_base.py @@ -55,6 +55,9 @@ def toggle_y_axis(self, signal_name=None): signal.toggle_axis() def update_source_and_signals(self): + # Remove old index + self.csv = self.csv.reset_index(drop=True) + # create bokeh data sources self.bokeh_source_orig = ColumnDataSource(self.csv) diff --git a/setup.py b/setup.py index ae29d1869..f047dde1a 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ install_requires = list() extras = dict() -excluded_packages = ['wxPython', 'kubernetes', 'tensorflow'] if slim_package else [] +excluded_packages = ['kubernetes', 'tensorflow'] if slim_package else [] with open(path.join(here, 'requirements.txt'), 'r') as f: for line in f: