-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogsim.py
executable file
·106 lines (90 loc) · 3.08 KB
/
logsim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
"""Parse command line options and arguments for the Logic Simulator.
This script parses options and arguments specified on the command line, and
runs either the command line user interface or the graphical user interface.
Usage
-----
Show help: logsim.py -h
Command line user interface: logsim.py -c <file path>
Graphical user interface: logsim.py <file path>
"""
import getopt
import sys
import wx
from names import Names
from devices import Devices
from network import Network
from monitors import Monitors
from scanner import Scanner
from parse import Parser
from userint import UserInterface
from gui import Gui
import builtins
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.
"""
app = wx.App()
# Internationalisation
builtins._ = wx.GetTranslation
locale = wx.Locale()
locale.Init(wx.LANGUAGE_DEFAULT)
locale.AddCatalogLookupPathPrefix("./locale")
locale.AddCatalog("logsim_fr.mo")
usage_message = _(
"\nUsage:\n"
"Show help: logsim.py -h\n"
"Command line user interface: logsim.py -c <file path>\n"
"Graphical user interface: logsim.py\n"
"This will bring up a file dialog where you can choose the "
"file you wish to run."
)
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)
# 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 = wx.App()
# # Internationalisation
# builtins._ = wx.GetTranslation
# locale = wx.Locale()
# locale.Init(wx.LANGUAGE_DEFAULT)
# locale.AddCatalogLookupPathPrefix('./locale')
# locale.AddCatalog('logsim_fr.mo')
gui = Gui(
_(
"\uB17C\uB9AC \uD68C\uB85C \uBAA8\uC758 \uC2E4\uD5D8 "
"Logic Simulator"
),
names,
devices,
network,
monitors,
)
gui.Show(True)
app.MainLoop()
if __name__ == "__main__":
main(sys.argv[1:])