THEMES = ['tablet_modern', 'tablet_modern', 'auto'] LOCAL_ROOT_PATH = os.path.abspath(os.path.join(_lp, "..")) ROOT_PATH = _rp URL_ROOT_PREFIX = "" if not LOCAL_ROOT_PATH in sys.path: sys.path.append(LOCAL_ROOT_PATH) if PRODUCTION_VERSION and platform_name()!='Android' and not 'main.py' in sys.argv[0] \ and not 'pytigon' in sys.argv[0] and not 'pytigon_task.py' in sys.argv[0] and not MAIN_PRJ: URL_ROOT_FOLDER = 'schsetup' URL_ROOT_PREFIX = URL_ROOT_FOLDER + "/" STATIC_URL = '/' + URL_ROOT_FOLDER + '/static/' MEDIA_URL = '/' + URL_ROOT_FOLDER + '/site_media/' from pytigon_lib.schtools.install_init import init init(PRJ_NAME, ROOT_PATH, DATA_PATH, PRJ_PATH, STATIC_APP_ROOT, [MEDIA_ROOT, UPLOAD_PATH]) START_PAGE = 'None' SHOW_LOGIN_WIN = True PACKS = [] for app in APPS: if '.' in app: pack = app.split('.')[0] if not pack in PACKS: PACKS.append(pack) p1 = os.path.join(LOCAL_ROOT_PATH, pack) if not p1 in sys.path: sys.path.append(p1) if not app in [x if type(x) == str else x.label for x in INSTALLED_APPS]: INSTALLED_APPS.append(get_app_config(app))
PATHS = get_main_paths(os.environ["PRJ_NAME"]) else: PRJ_NAME = None PATHS = get_main_paths() sys.path.append(PATHS["PRJ_PATH"]) from pytigon_lib.schtools.install_init import init DATA_PATH = PATHS["DATA_PATH"] PYTIGON_PATH = PATHS["PYTIGON_PATH"] init( "_schall", PATHS["ROOT_PATH"], PATHS["DATA_PATH"], PATHS["PRJ_PATH"], PATHS["STATIC_PATH"], [PATHS["MEDIA_PATH"], PATHS["UPLOAD_PATH"]] if PRJ_NAME else None, ) import wx _ = wx.GetTranslation def process_adv_argv(): global _PARAM if not ("args" in _PARAM and len(_PARAM["args"]) > 0): _app = wx.App() choices = [
def run(param=None): if param: argv = param else: argv = sys.argv base_path = os.path.dirname(os.path.abspath(__file__)) os.chdir(base_path) ext_lib_path = os.path.join(base_path, "ext_lib") if not ext_lib_path in sys.path: sys.path.append(ext_lib_path) os.environ['PYTIGON_ROOT_PATH'] = base_path if len(argv) > 1 and argv[1].startswith('manage'): if '_' in argv[1]: from pytigon.schserw.settings import ROOT_PATH, DATA_PATH, PRJ_PATH, \ STATIC_APP_ROOT, MEDIA_ROOT, UPLOAD_PATH x = argv[1].split('_', 1) app = x[1] if not os.path.exists(PRJ_PATH) or not os.path.exists(DATA_PATH): from pytigon_lib.schtools.install_init import init init(app, ROOT_PATH, DATA_PATH, PRJ_PATH, STATIC_APP_ROOT, [MEDIA_ROOT, UPLOAD_PATH]) path3 = os.path.join(PRJ_PATH, app) os.chdir(path3) subprocess.run([get_executable(), "manage.py"] + argv[2:]) os.chdir(base_path) else: subprocess.run([get_executable(), "manage.py"] + argv[2:]) elif len(argv) > 1 and argv[1].startswith('run_'): from pytigon.schserw.settings import ROOT_PATH, DATA_PATH, PRJ_PATH, \ STATIC_APP_ROOT, MEDIA_ROOT, UPLOAD_PATH x = argv[1].split('_', 1) if '/' in x[1]: x2 = x[1].split('/', 1) app = x2[0] script = x2[1] else: app = x[1] script = "run.py" path3 = os.path.join(PRJ_PATH, app) subprocess.run([ get_executable(), ] + [ os.path.join(path3, script), ] + argv[2:]) elif len(argv) > 1 and argv[1].startswith('runserver'): if '_' in argv[1]: from pytigon.schserw import ROOT_PATH, DATA_PATH, PRJ_PATH, \ STATIC_APP_ROOT, MEDIA_ROOT, UPLOAD_PATH x = argv[1].split('_', 1) app = x[1] if not os.path.exists(PRJ_PATH) or not os.path.exists(DATA_PATH): from pytigon_lib.schtools.install_init import init init(app, ROOT_PATH, DATA_PATH, PRJ_PATH, STATIC_APP_ROOT, [MEDIA_ROOT, UPLOAD_PATH]) path3 = os.path.join(PRJ_PATH, app) os.chdir(path3) options = [] if not '-b' in argv[2:]: options = [ '-b', '0.0.0.0:8000', ] options.append('asgi:application') tmp = sys.argv sys.argv = [ '', ] + argv[2:] + options if platform_name() == 'Android': from daphne.cli import CommandLineInterface CommandLineInterface.entrypoint() else: from hypercorn.__main__ import main main() sys.argv = tmp os.chdir(base_path) elif len(argv) > 1 and (argv[1].endswith('.py') or argv[1][-4:-1] == ".py"): subprocess.run([ get_executable(), ] + argv[1:]) else: help = False if len(argv) > 1 and argv[1] == '--help': help = True try: if help: print("First form:") print("===========") from pytigon_gui.pytigon import main main() except SystemExit: if help: print("Second form:") print("============") print( "Manage pytigon application: pytigon manage_{{project_name}} options" ) print( " to see all options run pytigon manage_{{project_name}} --help" ) print("") print("Third option:") print("=============") print( "Run web server: pytigon runserver_{{project_name}} options" ) print( " to see all options run pytigon runserver_{{project_name}} --help" ) print("") print("The fourth option:") print("==================") print("Run python script: pytigon {{script_name}}.py") print(" run python script in pytigon enviroment") print("") print("The fifth option:") print("=================") print( "Run python script in project directory: pytigon run_{{project_name}}/{{script_name}}.py" ) print(" run python script in pytigon enviroment") print("")
def show_first_form(self): global STORAGE ip_tab = [] if netifaces: interfaces = netifaces.interfaces() for interface in interfaces: if interface[:2] in ("wl", "en", "et"): ifaddress = netifaces.ifaddresses(interface) if netifaces.AF_INET in ifaddress: inets = ifaddress[netifaces.AF_INET] for inet in inets: if "addr" in inet: addr = inet["addr"] if len(addr.split(".")) == 4: ip_tab.append(addr) else: try: ip_address = get_ip_address(b"wlan0") ip_tab.append(ip_address) except: pass if ip_tab: ip_address = ", ".join(ip_tab) else: ip_address = "-" label = Label( text=f"[size=18sp][color=88f][b]PYTIGON - select the application:[/b][/color][/size]\n[size=15sp][color=448](my ip addresses: {ip_address})[/b][/color][/size]", markup=True, halign="center", ) self.add_widget(label) if not check_permission(Permission.WRITE_EXTERNAL_STORAGE): ret = request_permissions(PERMISSION) print("python::pytigon::request_permissions", ret) init( "_schall", schserw_settings.ROOT_PATH, schserw_settings.DATA_PATH, schserw_settings.PRJ_PATH, schserw_settings.STATIC_ROOT, [schserw_settings.MEDIA_ROOT, schserw_settings.UPLOAD_PATH], ) base_apps_path = os.path.join(os.path.join(STORAGE, "pytigon"), "prj") l = [pos for pos in os.listdir(base_apps_path) if not pos.startswith("_")] apps = [] for prj in l: base_apps_path2 = os.path.join(base_apps_path, prj) try: x = __import__(prj + ".apps") if hasattr(x.apps, "PUBLIC") and x.apps.PUBLIC: apps.append(prj) except: print("Error importing module: ", prj + ".apps") if len(apps) > 1: if len(apps) > MAX_SEL_APP: dy = MAX_SEL_APP - 1 else: dy = len(apps) for pos in apps[:dy]: button = Button(id=pos, text=pos, size_hint=(1, 1)) button.bind(on_release=self.chose_callback) self.add_widget(button) if len(apps) > MAX_SEL_APP: spinner = Spinner( text="Other applications", values=apps[dy:], size_hint=(0.5, 1), pos_hint={ "center_x": 0.5, }, ) spinner.bind(text=self.spinner_callback) self.add_widget(spinner) else: if len(apps) > 0: self.on_app_chosen(apps[0]) else: self.on_app_chosen()