Skip to content

Commit

Permalink
Applying hallo_doei's GUI fixes (RLBot#133)
Browse files Browse the repository at this point in the history
* Applying hallo_doei's GUI fixes.

* Including dependency on PyQt5.

* Making good use of pathlib.
  • Loading branch information
tarehart committed Jun 10, 2018
1 parent fb3a15d commit cc505a7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
11 changes: 9 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
psutil
inputs
# This installs the rlbot package in 'editable' mode
# - Your changes to python files will still be reflected, even though pip is involved.
# - This will automatically install any runtime dependencies indicated in src/main/python/setup.py (see install_requires)
# If you add a runtime dependency you should be adding it there, not here!
# See https://stackoverflow.com/a/49684835 for more details.
-e ./src/main/python


# If there are any dependencies needed for development only, e.g. lint tools, unit testing, etc, add them below.
14 changes: 10 additions & 4 deletions src/main/python/rlbot/gui/preset_editors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from PyQt5 import QtWidgets, QtCore
import configparser
import pathlib

from rlbot.gui.design.car_customisation import Ui_LoadoutPresetCustomiser
from rlbot.gui.design.agent_customisation import Ui_AgentPresetCustomiser
Expand Down Expand Up @@ -94,11 +95,11 @@ def load_preset_cfg(self):
file_path = QtWidgets.QFileDialog.getOpenFileName(self, 'Load Config', '', 'Config Files (*.cfg)')[0]
if not os.path.isfile(file_path):
return
if os.path.splitext(file_path)[1] != "cfg":
if pathlib.Path(file_path).suffix != '.cfg':
self.popup_message("This file is not a config file!", "Invalid File Extension", QtWidgets.QMessageBox.Warning)
return
try:
preset = self.preset_class(self.validate_name(os.path.basename(file_path).replace(".cfg", ""), None), file_path)
preset = self.preset_class(self.validate_name(pathlib.Path(file_path).stem, None), file_path)
except configparser.NoSectionError:
self.popup_message("This file does not have the right sections!", "Invalid Config File", QtWidgets.QMessageBox.Warning)
return
Expand All @@ -115,7 +116,7 @@ def save_preset_cfg(self):
preset.config_path = file_path
del self.presets[preset.get_name()]
old_name = preset.name
new_name = self.validate_name(os.path.basename(preset.config_path).replace(".cfg", ""), preset)
new_name = self.validate_name(pathlib.Path(preset.config_path).stem, preset)
preset.name = new_name
self.presets[preset.get_name()] = preset
preset.save_config(time_out=0)
Expand Down Expand Up @@ -433,7 +434,12 @@ def load_python_file(self):
start = get_python_root()
else:
start = os.path.dirname(preset.config_path)
rel_path = os.path.relpath(file_path, start)

try:
rel_path = os.path.relpath(file_path, start)
except ValueError:
rel_path = file_path

preset.config.set_value("Locations", "python_file", rel_path)
self.preset_python_file_lineedit.setText(rel_path)

Expand Down
5 changes: 4 additions & 1 deletion src/main/python/rlbot/gui/presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def __init__(self, name, file_path=None):
basic_config.parse_file(file_path)
else:
base_agent_path = os.path.join(get_python_root(), "rlbot", "agents", "base_agent.py")
rel_path = os.path.relpath(base_agent_path, get_python_root())
try:
rel_path = os.path.relpath(base_agent_path, get_python_root())
except ValueError:
rel_path = base_agent_path
basic_config.set_value(BOT_CONFIG_MODULE_HEADER, PYTHON_FILE_KEY, rel_path)

python_file_path = os.path.realpath(os.path.join(os.path.dirname(
Expand Down
12 changes: 7 additions & 5 deletions src/main/python/rlbot/gui/qt_root.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
import sys
from PyQt5.QtCore import QTimer
from PyQt5 import QtCore
Expand Down Expand Up @@ -201,10 +202,12 @@ def bot_config_edit_event(self, value=None):
listwidget = self.orange_listwidget
name = self.validate_name(value, agent)
old_name = self.validate_name(agent.ingame_name, agent)
listwidget.findItems(old_name, QtCore.Qt.MatchExactly)[0].setText(name)
row = listwidget.currentRow()
del self.bot_names_to_agent_dict[old_name]
agent.set_name(value)
self.bot_names_to_agent_dict[name] = agent
self.update_teams_listwidgets()
listwidget.setCurrentRow(row)
elif sender is self.loadout_preset_combobox:
if value and self.bot_config_groupbox.isEnabled() and self.current_bot is not None:
self.current_bot.set_loadout_preset(self.loadout_presets[value])
Expand Down Expand Up @@ -281,8 +284,7 @@ def load_overall_config(self, config_path=None):
return
if config_path is None or not os.path.isfile(config_path):
return
paths = os.path.splitext(config_path)
if paths[-1] != ".cfg":
if pathlib.Path(config_path).suffix != '.cfg':
self.popup_message("This file is not a config file!", "Invalid File Extension", QMessageBox.Warning)
return
raw_parser = configparser.RawConfigParser()
Expand Down Expand Up @@ -543,7 +545,7 @@ def add_loadout_preset(self, file_path: str):
:return preset: the loadout preset created
"""
if file_path is not None and os.path.isfile(file_path):
name = os.path.basename(file_path).replace(".cfg", "")
name = pathlib.Path(file_path).stem
else:
name = "new preset"
if name in self.loadout_presets:
Expand All @@ -559,7 +561,7 @@ def add_agent_preset(self, file_path):
:return preset: the agent preset created
"""
if os.path.isfile(file_path):
name = os.path.basename(file_path).replace(".cfg", "")
name = pathlib.Path(file_path).stem
else:
name = "new preset"
if name in self.agent_presets:
Expand Down
4 changes: 2 additions & 2 deletions src/main/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
setuptools.setup(
name='rlbot',
packages=setuptools.find_packages(),
install_requires=['psutil', 'inputs'],
version='0.0.9',
install_requires=['psutil', 'inputs', 'PyQt5'],
version='0.0.10',
description='A framework for writing custom Rocket League bots that run offline.',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit cc505a7

Please sign in to comment.