Skip to content

Commit

Permalink
Remove automatic gui construction in cli mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rbaltrusch committed Jun 22, 2024
1 parent 59a6d3b commit cacba9e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions bach_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Callable, List, Type

from bach_generator import cli, runner
from bach_generator.gui import app, init
from bach_generator.src import manager, model, music_handler


Expand Down Expand Up @@ -106,7 +105,7 @@ def run_simulation(args):
logging.info("Saved models to file")


def run_gui():
def run_gui(app, init):
"""Runs the graphical interface"""
init.init()
app.data["setup_function"] = setup_simulation
Expand All @@ -121,20 +120,35 @@ def run_gui():


class StreamHandler(logging.StreamHandler):
"""Logging stream handler for gui mode"""

def __init__(self, gui_app):
super().__init__()
self.app = gui_app

def emit(self, record: logging.LogRecord) -> None:
if not app.destroyed:
app.data["message"].set("Status: " + record.getMessage())
if not self.app.destroyed:
self.app.data["message"].set("Status: " + record.getMessage())
super().emit(record)


def main():
"""Main function"""
gui_mode = len(sys.argv) == 1
if gui_mode:
from bach_generator.gui import ( # pylint: disable=import-outside-toplevel
app,
init,
)

logging.basicConfig(
level=logging.INFO, format="%(asctime)s %(message)s", handlers=[StreamHandler()]
level=logging.INFO,
format="%(asctime)s %(message)s",
handlers=[StreamHandler(app if gui_mode else None)],
)
parser = cli.construct_parser()
if len(sys.argv) == 1:
run_gui()
if gui_mode:
run_gui(app, init)
return
args = parser.parse_args()
cli.display_args(args)
Expand Down

0 comments on commit cacba9e

Please sign in to comment.