def main(): # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) [s1, s2] = devices.names.lookup(["S1", "S2"]) devices.make_switch(s1, 0) devices.make_switch(s2, 0) devices.make_gate(1, devices.names.query("NAND"), 2) devices.make_gate(2, devices.names.query("NAND"), 2) network.make_connection(s1, None, 1, devices.names.query("I1")) network.make_connection(s2, None, 2, devices.names.query("I2")) network.make_connection(1, None, 2, devices.names.query("I1")) network.make_connection(2, None, 1, devices.names.query("I2")) print(network.check_network()) print(monitors.make_monitor(1, None)) monitors.display_signals() userint = UserInterface(names, devices, network, monitors) userint.command_interface()
def main(arg_list): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ usage_message = ("Usage:\n" "Show help: logsim.py -h\n" "Command line user interface: logsim.py -c <file path>\n" "Graphical user interface: logsim.py <file path>") try: options, arguments = getopt.getopt(arg_list, "hc:") except getopt.GetoptError: print("Error: invalid command line arguments\n") print(usage_message) sys.exit() # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) for option, path in options: if option == "-h": # print the usage message print(usage_message) sys.exit() elif option == "-c": # use the command line user interface scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() if not options: # no option given, use the graphical user interface if len(arguments) != 1: # wrong number of arguments print("Error: one file path required\n") print(usage_message) sys.exit() [path] = arguments scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the gui.Gui() class app = wx.App() builtins._ = wx.GetTranslation locale = wx.Locale() locale.Init(wx.LANGUAGE_DEFAULT) locale.AddCatalogLookupPathPrefix('./locale') locale.AddCatalog('zh_CN') gui = Gui("Logic Simulator", path, names, devices, network, monitors) gui.Show(True) app.MainLoop()
def main(arg_list): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ usage_message = ("Usage:\n" "Show help: logsim.py -h\n" "Command line user interface: logsim.py -c <file path>\n" "Graphical user interface: logsim.py <file path>") try: options, arguments = getopt.getopt(arg_list, "hc:") except getopt.GetoptError: print("Error: invalid command line arguments\n") print(usage_message) sys.exit() # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) for option, path in options: if option == "-h": # print the usage message print(usage_message) sys.exit() elif option == "-c": # use the command line user interface scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() if not options: # no option given, use the graphical user interface # Initialise an instance of the gui.Gui() class app = wx.App() gui = Gui("Logic Simulator") # gui = Gui("Logic Simulator", None, names, devices, network, monitors) gui.Show(True) app.MainLoop()
def main(arg_parser): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ # Add check to see if path leads to a .txt file if arg_parser.path is not None: if arg_parser.path[-3:] != "txt": raise TypeError("***ERROR: Please load in a .txt file") # Check if user tries to input translation into command line # interface if arg_parser.c and arg_parser.r: print("Cannot launch command line mode with translator") sys.exit() # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) scanner = Scanner(arg_parser.path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): if arg_parser.c: # Initialise instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() else: if arg_parser.r: lang = u"el" else: lang = u"en" # Initialise an instance of the gui.Gui() class file_name = get_file_name(arg_parser.path) title = "Logic Simulator - " + file_name app = wx.App() gui = Gui(title, arg_parser.path, names, devices, network, monitors, lang) gui.Show(True) app.MainLoop()
def main(arg_list): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ usage_message = ("Usage:\n" "Show help: logsim.py -h\n" "Command line user interface: logsim.py -c <file path>\n" "Graphical user interface: logsim.py <file path>") try: options, arguments = getopt.getopt(arg_list, "hc:") except getopt.GetoptError: print("Error: invalid command line arguments\n") print(usage_message) sys.exit() for option, path in options: if option == "-h": # print the usage message print(usage_message) sys.exit() elif option == "-c": # use the command line user interface names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): error_list = scanner.error_list for error in error_list: print(error) # Initialise an instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() else: error_list = scanner.error_list for error in error_list: print(error) if not options: # no option given, use the graphical user interface path = None names = None devices = None network = None monitors = None filename = None app = wx.App() # Internationalisation builtins._ = wx.GetTranslation locale = wx.Locale() locale.Init(wx.LANGUAGE_DEFAULT) locale.AddCatalogLookupPathPrefix('./locale') locale.AddCatalog('messages') gui = Gui(_("பனி Logic Simulator"), path, names, devices, network, monitors, filename, True) gui.Show(True) gui.startup_load() app.MainLoop() while gui.load_new is True: path = gui.current_pathname filename = gui.current_filename names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the gui.Gui() class gui = Gui( _("பனி Logic Simulator - {}").format(filename), path, names, devices, network, monitors, filename) gui.Show(True) app.MainLoop()
def main(arg_list): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ usage_message = ("Usage:\n" "Show help: logsim.py -h\n" "Command line user interface: logsim.py -c <file path>\n" "Graphical user interface: logsim.py <file path>") try: options, arguments = getopt.getopt(arg_list, "hc:") except getopt.GetoptError: print("Error: invalid command line arguments\n") print(usage_message) sys.exit() # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) for option, path in options: if option == "-h": # print the usage message print(usage_message) sys.exit() elif option == "-c": # use the command line user interface scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() if not options: # no option given, use the graphical user interface if len(arguments) != 1: # wrong number of arguments print("Error: one file path required\n") print(usage_message) sys.exit() [path] = arguments scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the gui.Gui() class app = wx.App() gui = Gui("Logic Simulator", path, names, devices, network, monitors) gui.Show(True) app.MainLoop() while hasattr(gui, 'edit_restart'): # GUI terminated and set the edit_restart flag. # We open the file in an editor to allow the user # to change the file, then restart the GUI. del app run_editor(path) # Re-initialise everything names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): app = wx.App() gui = Gui("Logic Simulator", path, names, devices, network, monitors) gui.Show(True) app.MainLoop() else: # Parser error messages would be enough, no need to # re-inform users of parser failure. break
def main(arg_list): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ usage_message = ( "Usage:\n" "Show help: logsim.py -h\n" "Command line user interface: logsim.py -c <file path>\n" "Graphical user interface: logsim.py <file path> or logsim.py") try: options, arguments = getopt.getopt(arg_list, "hc:") except getopt.GetoptError: print("Error: invalid command line arguments\n") print(usage_message) sys.exit() # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) #device = Device(self.names.lookup([names])) #names = None #devices = None #network = None #monitors = None for option, path in options: if option == "-h": # print the usage message print(usage_message) sys.exit() elif option == "-c": # use the command line user interface scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() if not options: # no option given, use the graphical user interface app = ab.BaseApp(redirect=False) error = ErrorFrame() if len(arguments) == 0: # wrong number of arguments # Initialise an instance of the gui.Gui() class path = None #print('len(arguments) = 0 if statement is accessed') scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) gui = Gui("LogicSim", path, names, devices, network, monitors) gui.Show(True) elif len(arguments) != 0 and len(arguments) != 1: print("Error: one or no file path required\n") print(usage_message) sys.exit() else: [path] = arguments scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the gui.Gui() class #import app_base as ab #app = ab.BaseApp(redirect=False) #app = wx.App() gui = Gui("LogicSim", path, names, devices, network, monitors) gui.Show(True) error.ShowModal() app.MainLoop()
def main(arg_list): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ usage_message = ( "Usage:\n" "Show help: logsim.py -h\n" "Command line user interface: logsim.py -c <file path>\n" "Graphical user interface with a blank circuit: logsim.py\n" "Graphical user interface with a predefined test circuit: logsim.py -t <circuit_number>\n" "Graphical user interface with loading a file: logsim.py <file path>") try: options, arguments = getopt.getopt(arg_list, "hct:") except getopt.GetoptError: print("Error: invalid command line arguments\n") print(usage_message) sys.exit() # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) import app_base as ab for option, path in options: if option == "-h": # print the usage message print(usage_message) sys.exit() elif option == "-c": # use the command line user interface scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() elif option == "-t": # manually create the devices, network, and monitors for testing if path == "1": names, devices, network, monitors = test_1() elif path == "2": names, devices, network, monitors = test_2() elif path == "3": names, devices, network, monitors = test_3() elif path == "4": names, devices, network, monitors = test_4() else: print("Error: invalid test number.\n") sys.exit() # Initialise an instance of the gui.Gui() class app = wx.App() gui = Gui("Logic Simulator", path, names, devices, network, monitors, "en", 0) gui.Show(True) app.MainLoop() if not options: # no option given, use the graphical user interface if len(arguments) == 0: # Open the blank gui # Initialise an instance of the gui.Gui() class app = wx.App() gui = Gui("Logic Simulator", None, names, devices, network, monitors, "en", 0) gui.Show(True) app.MainLoop() elif len(arguments) == 1: [path] = arguments scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the gui.Gui() class app = wx.App() gui = Gui("Logic Simulator", path, names, devices, network, monitors, "en", 0) gui.Show(True) app.MainLoop() else: # wrong number of arguments print("Error: Too many arguments given\n") print(usage_message) sys.exit()
def main(arg_list): """Parse the command line options and arguments specified in arg_list. Run either the command line user interface, the graphical user interface, or display the usage message. """ print('arg_list', arg_list) usage_message = ("Usage:\n" "Show help: logsim.py -h\n" "Command line user interface: logsim.py -c <file path>\n" "Graphical user interface: logsim.py <file path>") try: options, arguments = getopt.getopt(arg_list, "hc:") except getopt.GetoptError: print(_(u"Error: invalid command line arguments\n")) print(usage_message) sys.exit() # Initialise instances of the four inner simulator classes names = Names() devices = Devices(names) network = Network(names, devices) monitors = Monitors(names, devices, network) for option, path in options: if option == "-h": # print the usage message print(usage_message) sys.exit() elif option == "-c": # use the command line user interface scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the userint.UserInterface() class userint = UserInterface(names, devices, network, monitors) userint.command_interface() if not options: # no option given, use the graphical user interface if len(arguments) != 1: if len(arguments) == 2: # wrong number of arguments [path] = [arguments[0]] else: print(_(u"Error: one file path required\./logsim.yn")) print(usage_message) sys.exit() else: [path] = arguments scanner = Scanner(path, names) parser = Parser(names, devices, network, monitors, scanner) if parser.parse_network(): # Initialise an instance of the gui.Gui() class app = ab.BaseApp(redirect=False) language = LanguageGui() language.Show(True) app.MainLoop() from gui_3D import lang app = ab.BaseApp(redirect=False) if lang == "Chinese": app.updateLanguage(u"zh_CN") gui = Gui(_(u"Logic Simulator"), path, names, devices, network, monitors, app) gui.Show(True) gui.load_file() app.MainLoop()