Skip to content
Snippets Groups Projects
Commit f18a0793 authored by Egli Adrian (IT-SCI-API-PFI)'s avatar Egli Adrian (IT-SCI-API-PFI)
Browse files

editor : pilsvg -> svg are included in package and get load from python package path. support ok

parent ea37f651
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,12 @@ include LICENSE
include README.rst
include requirements_dev.txt
graft svg
graft env-data
recursive-include tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
......
......@@ -7,6 +7,7 @@ import numpy as np
import time
import io
import os
import site
def enable_windows_cairo_support():
if os.name=='nt':
......@@ -52,7 +53,7 @@ class PILGL(GraphicsLayer):
self.nPixCell = int(max(1,np.ceil(min(w,h))))
else:
self.nPixCell = 40
# Total grid size at native scale
self.widthPx = self.width * self.nPixCell + self.linewidth
self.heightPx = self.height * self.nPixCell + self.linewidth
......@@ -253,8 +254,17 @@ class PILSVG(PILGL):
self.agents_prev = []
def pilFromSvgFile(self, sfPath):
with open(sfPath, "r") as fIn:
bytesPNG = svg2png(file_obj=fIn, output_height=self.nPixCell, output_width=self.nPixCell)
try:
with open(sfPath, "r") as fIn:
bytesPNG = svg2png(file_obj=fIn, output_height=self.nPixCell, output_width=self.nPixCell)
except:
newList=''
for directory in site.getsitepackages():
x = [word for word in os.listdir(directory) if word.startswith('flatland')]
if len(x) > 0 :
newList = directory+'/'+x[0]
with open(newList+'/'+sfPath, "r") as fIn:
bytesPNG = svg2png(file_obj=fIn, output_height=self.nPixCell, output_width=self.nPixCell)
with io.BytesIO(bytesPNG) as fIn:
pil_img = Image.open(fIn)
pil_img.load()
......
%% Cell type:markdown id: tags:
# Rail Editor v0.2
%% Cell type:code id: tags:
``` python
%load_ext autoreload
%autoreload 2
```
%% Cell type:code id: tags:
``` python
import numpy as np
from numpy import array
import ipywidgets
import IPython
from IPython.core.display import display, HTML
```
%% Cell type:code id: tags:
``` python
display(HTML("<style>.container { width:95% !important; }</style>"))
```
%% Output
%% Cell type:code id: tags:
``` python
from flatland.utils.editor import EditorMVC, EditorModel, View, Controller
```
%% Output
cairo installed: OK
Traceback (most recent call last):
File "c:\users\u216993\appdata\local\programs\python\python36\lib\site-packages\IPython\core\interactiveshell.py", line 3291, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-cd594490df80>", line 1, in <module>
from flatland.utils.editor import EditorMVC, EditorModel, View, Controller
File "c:\users\u216993\appdata\local\programs\python\python36\lib\site-packages\flatland_rl-0.1.1-py3.6.egg\flatland\utils\editor.py", line 21, in <module>
import flatland.utils.rendertools as rt
File "c:\users\u216993\appdata\local\programs\python\python36\lib\site-packages\flatland_rl-0.1.1-py3.6.egg\flatland\utils\rendertools.py", line 7, in <module>
from flatland.utils.graphics_pil import PILGL, PILSVG
File "c:\users\u216993\appdata\local\programs\python\python36\lib\site-packages\flatland_rl-0.1.1-py3.6.egg\flatland\utils\graphics_pil.py", line 263
newList.append( [word for word in os.listdir(directory): if word.startswith('flatland')] )
^
SyntaxError: invalid syntax
%% Cell type:code id: tags:
``` python
mvc = EditorMVC(sGL="PIL" ) # sGL="PIL")
```
%% Output
%% Cell type:markdown id: tags:
## Instructions
- Drag to draw (improved dead-ends)
- Shift-Drag to erase rails (erasing dead ends not yet automated - drag right across them)
- ctrl-click to add agent
- direction chosen randomly to fit rail
- ctrl-shift-click to add target for last agent
- target can be moved by repeating
- to Resize the env (cannot preserve work):
- select "Regen" tab, set regen size slider, click regenerate.
- alt-click remove all rails from cell
%% Cell type:code id: tags:
``` python
mvc.view.display()
```
%% Output
%% Cell type:code id: tags:
``` python
mvc.view.wOutput.clear_output()
mvc.view.wOutput
```
%% Output
%% Cell type:code id: tags:
``` python
len(mvc.editor.env.agents), len(mvc.editor.env.agents_static)
```
%% Output
(0, 0)
......
......@@ -65,6 +65,14 @@ else:
except:
os.system("pip install pycairo==1.18.1")
def get_all_svg_files(directory='./svg/'):
ret = []
for f in os.listdir(directory):
ret.append(directory+f)
return ret
# Gather requirements from requirements_dev.txt
# TODO : We could potentially split up the test/dev dependencies later
install_reqs = []
......@@ -101,6 +109,7 @@ setup(
keywords='flatland',
name='flatland-rl',
packages=find_packages('.'),
data_files=[('svg', get_all_svg_files())],
setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment