Skip to content

Commit

Permalink
use dict to translate cfg to settings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
uyitroa committed Jun 30, 2020
1 parent f51881a commit de333ed
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 44 deletions.
36 changes: 20 additions & 16 deletions Parents.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from PyQt5.QtWidgets import QGraphicsBlurEffect, QPushButton, QFileDialog, QLabel, QToolTip
from pathlib import Path

from autologging import traced, logged

from abspath import abspath, configpath
from config_data import current_config, current_settings
from helper import getsize, changesize
from username_parser import get_configInfo
from username_parser import get_configInfo, settings_translator
import logging


Expand Down Expand Up @@ -195,41 +197,43 @@ def changesize(self):
self.text.setGeometry(x, y, self.width() * 0.95, self.height() * 0.5)


@logged(logging.getLogger(__name__))
@traced
class PopupButton(ButtonBrowse):
def afteropenfile(self, filename):
if filename == "": # if user cancel select
return
logging.info("after open file popupbutton")
logging.info(filename)
if current_config["Output path"] != "" and current_config["osu! path"] != "":
logging.info("entering output")
self.main_window.delete_popup()
self.main_window.popup_bool = False

logging.info("searching for replay")

self.main_window.check_replay_map()
self.main_window.resizeEvent(True)

logging.info("get cfg info skin")
self.main_window.skin_dropdown.get_configInfo(current_config["osu! path"])
with open(configpath, 'w+') as f:
json.dump(current_config, f, indent=4)
f.close()
logging.info(configpath)
logging.info("loading settings page")

self.main_window.settingspage.load_settings()

settings = get_configInfo(current_config["osu! path"])
counter = 0
osusettings = get_configInfo(current_config["osu! path"])

logging.info(current_settings)
logging.info(settings)
for x in current_settings:
current_settings[x] = float(settings[counter])
if counter >= 10:
break
counter += 1
self.set_settings(osusettings)

self.main_window.osrbutton.browsepath = os.path.join(current_config["osu! path"], "Replays/")
self.main_window.mapsetbutton.browsepath = os.path.join(current_config["osu! path"], "Songs/")

def set_settings(self, osusettings):
logging.info(current_settings)
logging.info(osusettings)
for osukey in osusettings:
mykey = settings_translator[osukey]
try:
setting = float(osusettings[osukey])
except ValueError:
setting = osusettings[osukey]

current_settings[mykey] = setting
48 changes: 20 additions & 28 deletions username_parser.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import glob
import io
import os, json
import configparser
import logging


settings = {
"CursorSize": "",
"ShowInterface": "",
"ScoreboardVisible": "",
"DimLevel": "",
"KeyOverlay": "",
"AutomaticCursorSizing": "",
"ScoreMeterScale": "",
"VolumeMusic": "",
"VolumeEffect": "",
"IgnoreBeatmapSamples": "",
"SkinSamples": ""
settings_translator = {
"CursorSize": "Cursor Size",
"ShowInterface": "In-game interface",
"ScoreboardVisible": "Show scoreboard",
"DimLevel": "Background dim",
"KeyOverlay": "Always show key overlay",
"AutomaticCursorSizing": "Automatic cursor size",
"ScoreMeterScale": "Score meter size",
"VolumeMusic": "Song volume",
"VolumeEffect": "Effect volume",
"IgnoreBeatmapSamples": "Ignore beatmap hitsounds",
"SkinSamples": "Use skin's sound samples"
}


def read_properties_file(file_path):
with open(file_path, encoding="utf-8") as f:

config = "[dummy_section]\n#" + f.read().replace('%', '%%')
cp = configparser.SafeConfigParser()
cp.read_string(config)
Expand All @@ -32,20 +28,20 @@ def read_properties_file(file_path):

def get_configInfo(path):
try:
settings_result = []
settings_result = {}
if path != "":
c = glob.glob(path + "/*.cfg")
logging.info(c)
if not c:
return
cfg = [ x for x in c if "osu!.cfg" not in x ]
logging.info(cfg)
raise Exception
cfg = [x for x in c if "osu!.cfg" not in x]
logging.info(f"cfg {cfg}")
props = read_properties_file(cfg[0])
for x in settings:
settings_result.append(props[x.lower()])
for x in settings_translator:
settings_result[x] = props[x.lower()]
return settings_result
except Exception as e:
print(e)
logging.error(repr(e))
return {
"CursorSize": 1,
"ShowInterface": 1,
Expand All @@ -57,9 +53,5 @@ def get_configInfo(path):
"VolumeMusic": 100,
"VolumeEffect": 100,
"IgnoreBeatmapSamples": 0,
"SkinSamples": 1,
"Global leaderboard": 0,
"Mods leaderboard": "*",
"api key": "",
"Rotate sliderball": 0
"SkinSamples": 1
}

0 comments on commit de333ed

Please sign in to comment.