cli passing

This commit is contained in:
Ian Jauslin 2022-09-23 13:41:26 -04:00
parent 42e9f60c4e
commit 267c5e5c5c

76
src/jam
View File

@ -1,16 +1,67 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys
import os.path,os
import filecheck
## read cli before loading kivy, in case there are errors
# read cli
openfile=""
lattice=""
def read_cli():
global openfile
global lattice
# init flag
flag=""
# loop over arguments
for arg in sys.argv[1:]:
# option flag
if arg[0]=='-':
# loop over options
for c in arg[1:]:
# lattice
if c=='L':
flag="lattice"
else:
# read lattice argument
if flag=="lattice":
if arg!="square":
print("error: unrecognized lattice: '"+arg+"'",file=sys.stderr)
exit(-1)
lattice=arg
# reset flag
flag=""
# no flags
else:
openfile=arg
(ret,message)=filecheck.check_edit(openfile)
if ret<0:
print(message,file=sys.stderr)
exit(-1)
# read cli
read_cli()
## import kivy
# disable kivy argument parser
os.environ["KIVY_NO_ARGS"] = "1"
from kivy.app import App from kivy.app import App
from kivy.uix.widget import Widget from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config from kivy.config import Config
import sys
import os.path
from painter import Painter from painter import Painter
from status_bar import Status_bar from status_bar import Status_bar
from command_prompt import Command_prompt from command_prompt import Command_prompt
import filecheck from lattice import Square_lattice
# App class # App class
class Jam_app(App): class Jam_app(App):
@ -21,6 +72,9 @@ class Jam_app(App):
# the file open for editing # the file open for editing
self.openfile=kwargs.get("openfile","") self.openfile=kwargs.get("openfile","")
# the lattice open for editing
self.lattice=kwargs.get("lattice","")
# readonly mode # readonly mode
self.readonly=False self.readonly=False
@ -37,6 +91,10 @@ class Jam_app(App):
# command prompt # command prompt
self.command_prompt=Command_prompt(self) self.command_prompt=Command_prompt(self)
# load lattice
if self.lattice=="square":
self.painter.lattice=Square_lattice()
layout.add_widget(self.painter) layout.add_widget(self.painter)
layout.add_widget(self.status_bar) layout.add_widget(self.status_bar)
layout.add_widget(self.command_prompt) layout.add_widget(self.command_prompt)
@ -56,16 +114,6 @@ Config.set('input', 'mouse', 'mouse,disable_multitouch')
# do not exit on escape # do not exit on escape
Config.set('kivy', 'exit_on_escape', 0) Config.set('kivy', 'exit_on_escape', 0)
# read cli
openfile=""
if len(sys.argv)==2:
openfile=sys.argv[1]
# check file
(ret,message)=filecheck.check_edit(openfile)
if ret<0:
print(message,file=sys.stderr)
exit(-1)
# run # run
if __name__ == '__main__': if __name__ == '__main__':
Jam_app(openfile=openfile).run() Jam_app(openfile=openfile,lattice=lattice).run()