118 lines
3.6 KiB
Python
Executable File
118 lines
3.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import os
|
|
import logging
|
|
|
|
# Configuração de logging para toda a aplicação - APENAS ARQUIVO, SEM TERMINAL
|
|
log_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'mosaicode.log')
|
|
|
|
# Configurar logging para arquivo apenas, sem stdout/stderr
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s %(levelname)s: %(message)s',
|
|
filename=log_path,
|
|
filemode='w', # sobrescreve a cada execução
|
|
force=True # força a configuração mesmo se já configurado
|
|
)
|
|
|
|
# Desabilitar completamente logs no terminal
|
|
root_logger = logging.getLogger()
|
|
root_logger.handlers = [] # Remove todos os handlers existentes
|
|
|
|
# Adicionar apenas handler de arquivo
|
|
file_handler = logging.FileHandler(log_path, mode='w')
|
|
file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s'))
|
|
root_logger.addHandler(file_handler)
|
|
root_logger.setLevel(logging.INFO)
|
|
|
|
# Desabilitar propagação para evitar logs duplicados
|
|
root_logger.propagate = False
|
|
|
|
import gi
|
|
gi.require_version('Gtk', '3.0')
|
|
from gi.repository import Gtk
|
|
import sys
|
|
import signal
|
|
import argparse
|
|
from mosaicode.control.blockcontrol import BlockControl
|
|
from mosaicode.control.codetemplatecontrol import CodeTemplateControl
|
|
from mosaicode.control.maincontrol import MainControl
|
|
from mosaicode.control.portcontrol import PortControl
|
|
from mosaicode.GUI.mainwindow import MainWindow
|
|
from mosaicode.system import System
|
|
from mosaicode.utils.FileUtils import *
|
|
|
|
|
|
# Libraries
|
|
|
|
# ---------------------------------------------------
|
|
# --------MOSAICODE FRONTEND MAIN FUNCTION--------------
|
|
# ---------------------------------------------------
|
|
|
|
|
|
def main(argv):
|
|
"""
|
|
The Mosaicode-Frontend class is where the main function starts the system.
|
|
It initializes the interface.
|
|
"""
|
|
|
|
# reload(sys)
|
|
# sys.setdefaultencoding('utf8')
|
|
|
|
# Parameter passing
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('file', type=str, nargs='*',
|
|
help="List of files to open")
|
|
parser.add_argument(
|
|
"--print-ports", action="store_true", help="Print ports")
|
|
parser.add_argument("--print-blockmodels",
|
|
action="store_true", help="Print blockmodels")
|
|
parser.add_argument("--print-templates",
|
|
action="store_true", help="Print code templates")
|
|
args = parser.parse_args()
|
|
|
|
System()
|
|
if args.print_ports:
|
|
# This method is used by the launcher class
|
|
ports = System.get_ports()
|
|
for port in ports:
|
|
logging.info("--------------------- ")
|
|
PortControl.print_port(ports[port])
|
|
return
|
|
|
|
if args.print_blockmodels:
|
|
blocks = System.get_blocks()
|
|
for block in blocks:
|
|
logging.info("--------------------- ")
|
|
BlockControl.print_block(blocks[block])
|
|
return
|
|
|
|
if args.print_templates:
|
|
code_templates = System.get_code_templates()
|
|
for template in code_templates:
|
|
logging.info("--------------------- ")
|
|
CodeTemplateControl.print_template(code_templates[template])
|
|
return
|
|
|
|
# Initialize the Frontend
|
|
win = MainWindow()
|
|
win.show_all()
|
|
|
|
if args.file:
|
|
for arg in args.file:
|
|
win.main_control.open(get_absolute_path_from_file(arg))
|
|
else:
|
|
win.main_control.new()
|
|
|
|
# to kill with Terminal Ctrl+C
|
|
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
Gtk.main()
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv)
|
|
|
|
# ----------------------------------------------------------------------
|