cli passing
This commit is contained in:
parent
42e9f60c4e
commit
267c5e5c5c
76
src/jam
76
src/jam
@ -1,16 +1,67 @@
|
||||
#!/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.uix.widget import Widget
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.config import Config
|
||||
import sys
|
||||
import os.path
|
||||
|
||||
from painter import Painter
|
||||
from status_bar import Status_bar
|
||||
from command_prompt import Command_prompt
|
||||
import filecheck
|
||||
from lattice import Square_lattice
|
||||
|
||||
# App class
|
||||
class Jam_app(App):
|
||||
@ -21,6 +72,9 @@ class Jam_app(App):
|
||||
# the file open for editing
|
||||
self.openfile=kwargs.get("openfile","")
|
||||
|
||||
# the lattice open for editing
|
||||
self.lattice=kwargs.get("lattice","")
|
||||
|
||||
# readonly mode
|
||||
self.readonly=False
|
||||
|
||||
@ -37,6 +91,10 @@ class Jam_app(App):
|
||||
# command prompt
|
||||
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.status_bar)
|
||||
layout.add_widget(self.command_prompt)
|
||||
@ -56,16 +114,6 @@ Config.set('input', 'mouse', 'mouse,disable_multitouch')
|
||||
# do not exit on escape
|
||||
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
|
||||
if __name__ == '__main__':
|
||||
Jam_app(openfile=openfile).run()
|
||||
Jam_app(openfile=openfile,lattice=lattice).run()
|
||||
|
Loading…
Reference in New Issue
Block a user