Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
Change no-args to look for gridlabd-editor (#977)
Browse files Browse the repository at this point in the history
* Change no-args to look for gridlabd-editor

* Add no args popup

* Update cmdarg.cpp

* Update gridlabd-editor.py

* Update gridlabd-editor.py

* Update gridlabd-editor.py

Co-authored-by: Alyona Teyber <Ivanova.alyona5@gmail.com>
  • Loading branch information
David P. Chassin and aivanova5 committed Aug 24, 2021
1 parent 1fbe54b commit e1f94c6
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 32 deletions.
42 changes: 10 additions & 32 deletions gldcore/cmdarg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,42 +247,20 @@ DEPRECATED static int help(void *main, int argc, const char *argv[]);

STATUS GldCmdarg::no_cmdargs(void)
{
char htmlfile[1024];
if ( global_autostartgui && find_file("gridlabd.htm",NULL,R_OK,htmlfile,sizeof(htmlfile)-1)!=NULL )
char guiname[1024] = "gridlabd-editor.py";
char guipath[1024];
if ( find_file(guiname,NULL,R_OK,guipath,sizeof(guipath)) )
{
char cmd[4096];

/* enter server mode and wait */
#ifdef WIN32
if ( htmlfile[1]!=':' )
{
snprintf(htmlfile,sizeof(htmlfile)-1,"%s\\gridlabd.htm", global_workdir);
}
output_message("opening html page '%s'", htmlfile);
snprintf(cmd,sizeof(cmd)-1,"start %s file:///%s", global_browser, htmlfile);
#elif defined(MACOSX)
snprintf(cmd,sizeof(cmd)-1,"open -a %s %s", global_browser, htmlfile);
#else
snprintf(cmd,sizeof(cmd)-1,"%s '%s' & ps -p $! >/dev/null", global_browser, htmlfile);
#endif
IN_MYCONTEXT output_verbose("Starting browser using command [%s]", cmd);
if (my_instance->subcommand("%s",cmd)!=0)
{
output_error("unable to start browser");
return FAILED;
}
else
{
IN_MYCONTEXT output_verbose("starting interface");
}
strcpy(global_environment,"server");
global_mainloopstate = MLS_PAUSED;
char command[2048];
snprintf(command,sizeof(command),"/usr/local/bin/python3 %s &",guipath);
system(command);
return SUCCESS;
}
else
output_error("default html file '%s' not found (workdir='%s')", "gridlabd.htm",global_workdir);

return SUCCESS;
{
output_error("%s not found",guiname);
return FAILED;
}
}

DEPRECATED static int copyright(void *main, int argc, const char *argv[])
Expand Down
2 changes: 2 additions & 0 deletions python_extras/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ dist_pkgdata_DATA += python_extras/example/tstat_init.py
dist_pkgdata_DATA += python_extras/volt_dump/meter_record.py
dist_pkgdata_DATA += python_extras/volt_dump/voltdump.py
dist_pkgdata_DATA += python_extras/metar2glm.py
dist_pkgdata_DATA += python_extras/gridlabd-editor.py
dist_pkgdata_DATA += python_extras/gridlabd-editor.png
Binary file added python_extras/gridlabd-editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions python_extras/gridlabd-editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""Copyright (C) 2021 Regents of the Leland Stanford Junior University
See https://www.gridlabd.us/ for license, acknowledgments, credits, manuals, documentation, and tutorials.
"""

#
# Python modules
#
import sys, os
import json
import subprocess

#
# Console output
#
def stdout(*msg,file=sys.stdout):
print(*msg,file=file)

def stderr(*msg,file=sys.stderr):
print(*msg,file=file)

#
# GridLAB-D link
#
result = subprocess.run("/usr/local/bin/gridlabd --version=json".split(),capture_output=True)
if not result:
stderr("ERROR: GridLAB-D is not installed on this system")
quit(-1)
info = json.loads(result.stdout)
# print(info.keys())
version = info['version']
build = info['build_number']
branch = info['branch']
system = info['system']

#
# No GUI on linux yet
#
if os.uname().sysname == "Linux":
stderr("ERROR: no GUI support on linux systems")
quit(1)

#
# Tkinter module
#
try:
import tkinter as tk
from tkinter import *
from tkinter.font import Font
from tkinter import Menu, messagebox, filedialog, simpledialog, ttk
except Exception as err:
if os.uname().sysname == 'Darwin':
stderr(f"ERROR: {err}. Did you remember to run 'brew install python-tk'?",file=sys.stderr)
else:
stderr(f"ERROR: {err}. Did you remember to install tkinter support?",file=sys.stderr)
quit(-1)

try:
from PIL import Image, ImageTk
except Exception as err:
if os.uname().sysname == 'Darwin':
stderr(f"ERROR: {err}. Did you remember to run 'brew install pillow'?",file=sys.stderr)
else:
stderr(f"ERROR: {err}. Did you remember to install pillow support?",file=sys.stderr)
quit(-1)

def TODO(msg="function not implemented yet",context=None):
if not context:
context = sys._getframe(1).f_code.co_name
root.output(f"TODO [{context}]: {msg}")

#
# Platform specifics
#
if sys.platform == "darwin":
try:
from Foundation import NSBundle
except:
import pip
pip.main(["install","pyobjc"])
from Foundation import NSBundle
bundle = NSBundle.mainBundle()
if bundle:
info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
if info and info['CFBundleName'] == 'Python':
info['CFBundleName'] = "GridLAB-D"
info['CFBundleExecutable'] = "GridLAB-D"
info['CFBundleShortVersionString'] = f"{version}"
info['CFBundleVersion'] = f"{build} {branch}"
info['NSHumanReadableCopyright'] = __doc__

#
# Main app startup
#
if __name__ == "__main__":
root = Tk()
root.withdraw()
try:
ico = Image.open(__file__.replace(".py",".png"))
photo = ImageTk.PhotoImage(ico)
root.wm_iconphoto(True, photo)
except Exception as err:
print("EXCEPTION:",err)
messagebox.showinfo("Welcome",
f"HiPAS GridLAB-D\n{version}-{build} ({branch}) {system}\n\n{__doc__}")

0 comments on commit e1f94c6

Please sign in to comment.