Skip to content

Commit

Permalink
Use TOML format for launch config
Browse files Browse the repository at this point in the history
  • Loading branch information
blueaxis committed Apr 15, 2022
1 parent 570edfc commit abab9f9
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 159 deletions.
26 changes: 11 additions & 15 deletions code/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,29 +190,25 @@ def toggle_mouse_mode(self):
self.canvas.toggleZoomPanMode()

def toggle_stylesheet(self):
config = "./utils/config.py"
config = "./utils/config.toml"
light_mode = "./assets/styles.qss"
dark_mode = "./assets/styles-dark.qss"
light_text = f"stylesheet_path = '{light_mode}'\n"
dark_text = f"stylesheet_path = '{dark_mode}'\n"
with open(config, 'r') as fh:
lines = fh.readlines()
mode_text = ""
if lines[18] == light_text:
mode_text = dark_text
mode_ = dark_mode
elif lines[18] == dark_text:
mode_text = light_text
mode_ = light_mode
lines[18] = mode_text

import toml
data = toml.load(config)
if data["STYLES_DEFAULT"] == light_mode:
data["STYLES_DEFAULT"] = dark_mode
elif data["STYLES_DEFAULT"] == dark_mode:
data["STYLES_DEFAULT"] = light_mode
with open(config, 'w') as fh:
fh.writelines(lines)
toml.dump(data, fh)

app = QApplication.instance()
if app is None:
raise RuntimeError("No Qt Application found.")

styles = mode_
styles = data["STYLES_DEFAULT"]
cfg["STYLES_DEFAULT"] = data["STYLES_DEFAULT"]
with open(styles, 'r') as fh:
app.setStyleSheet(fh.read())

Expand Down
146 changes: 2 additions & 144 deletions code/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,147 +16,5 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

stylesheet_path = './assets/styles.qss'
cfg = {
"IMAGE_EXTENSIONS": ["*.bmp", "*.gif", "*.jpg", "*.jpeg", "*.png",
"*.pbm", "*.pgm", "*.ppm", "*.webp", "*.xbm", "*.xpm"],

"LANGUAGE": [" Japanese", " Korean", " Chinese SIM", " Chinese TRA ", " English"],
"ORIENTATION": [" Vertical", " Horizontal"],
"LANG_PATH": "./assets/languages/",

"STYLES_PATH": "./assets/",
"STYLES_DEFAULT": stylesheet_path,

"NAV_VIEW_RATIO": [3,11],
"NAV_ROOT": "./assets/images/",

"NAV_FUNCS": {
"path_changed": "view_image_from_fdialog",
"nav_clicked": "view_image_from_explorer"
},

"LOGO": "./assets/images/icons/logo.ico",
"HOME_IMAGE": "./assets/images/home.png",

"RBN_HEIGHT": 2.4,

"TBAR_ISIZE_REL": 0.1,
"TBAR_ISIZE_MARGIN": 1.3,

"TBAR_ICONS": "./assets/images/icons/",
"TBAR_ICONS_LIGHT": "./assets/images/icons/",
"TBAR_ICON_DEFAULT": "./assets/images/icons/default_icon.png",

"TBAR_FUNCS": {
"FILE": {
"open_dir": {
"help_title": "Open manga directory",
"help_msg": "Open a directory containing images.",
"path": "open_dir.png",
"toggle": False,
"align": "AlignLeft",
"icon_h": 1.0,
"icon_w": 1.0
},
"open_manga": {
"help_title": "Open manga file",
"help_msg": "Supports the following formats: cbr, cbz, pdf.",
"path": "open_manga.png",
"toggle": False,
"align": "AlignLeft",
"icon_h": 1.0,
"icon_w": 1.0
}
},
"SETTINGS": {
"load_model": {
"help_title": "Switch detection model",
"help_msg": "Switch between MangaOCR and Tesseract models.",
"path": "load_model.png",
"toggle": True,
"align": "AlignLeft",
"icon_h": 1.0,
"icon_w": 1.0
},
"toggle_logging": {
"help_title": "Enable text logging",
"help_msg": "Save detected text to a text file located in the \
current project directory.",
"path": "toggle_logging.png",
"toggle": True,
"align": "AlignLeft",
"icon_h": 1.0,
"icon_w": 1.0
},
"toggle_mouse_mode": {
"help_title": "Change mouse behavior",
"help_msg": "This will disable text detection. Turn this on \
only if do not want to hold CTRL key to zoom and pan \
on an image.",
"path": "toggle_mouse_mode.png",
"toggle": True,
"align": "AlignLeft",
"icon_h": 1.0,
"icon_w": 1.0
},
"toggle_stylesheet": {
"help_title": "Change theme",
"help_msg": "Switch between light and dark mode.",
"path": "toggle_stylesheet.png",
"toggle": False,
"align": "AlignLeft",
"icon_h": 1.0,
"icon_w": 1.0
}
}
},

"MODE_FUNCS": {
"zoom_in": {
"help_title": "Zoom in",
"help_msg": "Hint: Double click the image to reset zoom.",
"path": "zoom_in.png",
"toggle": False,
"align": "AlignRight",
"icon_h": 0.45,
"icon_w": 0.45
},
"zoom_out": {
"help_title": "Zoom out",
"help_msg": "Hint: Double click the image to reset zoom.",
"path": "zoom_out.png",
"toggle": False,
"align": "AlignRight",
"icon_h": 0.45,
"icon_w": 0.45
},
"load_image_at_idx": {
"help_title": "",
"help_msg": "Jump to page",
"path": "load_image_at_idx.png",
"toggle": False,
"align": "AlignRight",
"icon_h": 0.45,
"icon_w": 1.3
},
"load_prev_image": {
"help_title": "",
"help_msg": "Show previous image",
"path": "load_prev_image.png",
"toggle": False,
"align": "AlignRight",
"icon_h": 0.45,
"icon_w": 0.6
},
"load_next_image": {
"help_title": "",
"help_msg": "Show next image",
"path": "load_next_image.png",
"toggle": False,
"align": "AlignRight",
"icon_h": 0.45,
"icon_w": 0.6
}
}
}
import toml
cfg = toml.load("./utils/config.toml")
119 changes: 119 additions & 0 deletions code/utils/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
IMAGE_EXTENSIONS = [ "*.bmp", "*.gif", "*.jpg", "*.jpeg", "*.png", "*.pbm", "*.pgm", "*.ppm", "*.webp", "*.xbm", "*.xpm",]
LANGUAGE = [ " Japanese", " Korean", " Chinese SIM", " Chinese TRA ", " English",]
ORIENTATION = [ " Vertical", " Horizontal",]
LANG_PATH = "./assets/languages/"
STYLES_PATH = "./assets/"
STYLES_DEFAULT = "./assets/styles.qss"
NAV_VIEW_RATIO = [ 3, 11,]
NAV_ROOT = "./assets/images/"
LOGO = "./assets/images/icons/logo.ico"
HOME_IMAGE = "./assets/images/home.png"
RBN_HEIGHT = 2.4
TBAR_ISIZE_REL = 0.1
TBAR_ISIZE_MARGIN = 1.3
TBAR_ICONS = "./assets/images/icons/"
TBAR_ICONS_LIGHT = "./assets/images/icons/"
TBAR_ICON_DEFAULT = "./assets/images/icons/default_icon.png"

[NAV_FUNCS]
path_changed = "view_image_from_fdialog"
nav_clicked = "view_image_from_explorer"

[MODE_FUNCS.zoom_in]
help_title = "Zoom in"
help_msg = "Hint: Double click the image to reset zoom."
path = "zoom_in.png"
toggle = false
align = "AlignRight"
icon_h = 0.45
icon_w = 0.45

[MODE_FUNCS.zoom_out]
help_title = "Zoom out"
help_msg = "Hint: Double click the image to reset zoom."
path = "zoom_out.png"
toggle = false
align = "AlignRight"
icon_h = 0.45
icon_w = 0.45

[MODE_FUNCS.load_image_at_idx]
help_title = ""
help_msg = "Jump to page"
path = "load_image_at_idx.png"
toggle = false
align = "AlignRight"
icon_h = 0.45
icon_w = 1.3

[MODE_FUNCS.load_prev_image]
help_title = ""
help_msg = "Show previous image"
path = "load_prev_image.png"
toggle = false
align = "AlignRight"
icon_h = 0.45
icon_w = 0.6

[MODE_FUNCS.load_next_image]
help_title = ""
help_msg = "Show next image"
path = "load_next_image.png"
toggle = false
align = "AlignRight"
icon_h = 0.45
icon_w = 0.6

[TBAR_FUNCS.FILE.open_dir]
help_title = "Open manga directory"
help_msg = "Open a directory containing images."
path = "open_dir.png"
toggle = false
align = "AlignLeft"
icon_h = 1.0
icon_w = 1.0

[TBAR_FUNCS.FILE.open_manga]
help_title = "Open manga file"
help_msg = "Supports the following formats: cbr, cbz, pdf."
path = "open_manga.png"
toggle = false
align = "AlignLeft"
icon_h = 1.0
icon_w = 1.0

[TBAR_FUNCS.SETTINGS.load_model]
help_title = "Switch detection model"
help_msg = "Switch between MangaOCR and Tesseract models."
path = "load_model.png"
toggle = true
align = "AlignLeft"
icon_h = 1.0
icon_w = 1.0

[TBAR_FUNCS.SETTINGS.toggle_logging]
help_title = "Enable text logging"
help_msg = "Save detected text to a text file located in the current project directory."
path = "toggle_logging.png"
toggle = true
align = "AlignLeft"
icon_h = 1.0
icon_w = 1.0

[TBAR_FUNCS.SETTINGS.toggle_mouse_mode]
help_title = "Change mouse behavior"
help_msg = "This will disable text detection. Turn this on only if do not want to hold CTRL key to zoom and pan on an image."
path = "toggle_mouse_mode.png"
toggle = true
align = "AlignLeft"
icon_h = 1.0
icon_w = 1.0

[TBAR_FUNCS.SETTINGS.toggle_stylesheet]
help_title = "Change theme"
help_msg = "Switch between light and dark mode."
path = "toggle_stylesheet.png"
toggle = false
align = "AlignLeft"
icon_h = 1.0
icon_w = 1.0

0 comments on commit abab9f9

Please sign in to comment.