Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
wxPython removal (#207)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
galnov committed Jan 23, 2019
1 parent 516547e commit 135f02f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 44 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 9 additions & 25 deletions rl_coach/dashboard_components/experiment_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)

Expand Down
49 changes: 32 additions & 17 deletions rl_coach/dashboard_components/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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 = []
Expand All @@ -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):
Expand All @@ -150,4 +164,5 @@ class FolderType(Enum):

dialog = DialogApp()


doc = curdoc()
3 changes: 3 additions & 0 deletions rl_coach/dashboard_components/signals_file_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 135f02f

Please sign in to comment.