Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, x, y, color, batch, id):
if id:
self.id_counter = max(self.id_counter, id)
self.id = self.id_counter
else:
Element.id_counter += 1
self.id = self.id_counter
self.x, self.y = x, y
self.w, self.h = 70, 30
self.cw, self.ch = self.w // 2, self.h // 2
self.offset = 20
self.put_size = 5
self.pin_color = color_select(color)
self.color = color
self.draw_color = color
self.er_color = (230, 20, 20)
self.active = True
self.batch = batch
self.graphics = dict(inputs=dict(), outputs=dict(), connections=list(),
error=None, base=Quad(self.batch))
self.x, self.y = x, y
self.w, self.h = 70, 30
self.cw, self.ch = self.w // 2, self.h // 2
self.offset = 20
self.put_size = 5
self.pin_color = color_select(color)
self.color = color
self.draw_color = color
self.er_color = (230, 20, 20)
self.active = True
self.batch = batch
self.graphics = dict(inputs=dict(), outputs=dict(), connections=list(),
error=None, base=Quad(self.batch))
self.er_label = pyglet.text.Label('error', font_name=font,
bold=True, font_size=12,
color=self.er_color + (255,),
anchor_x='right', anchor_y='center')
self.inputs = ()
self.outputs = ()
self.in_labels = []
self.connected_to = []
self.out_labels = []
self.child = []
self.selected = False # 714848
self.selectedInput = {'name': 'none', 'pos': 0}
self.selectedOutput = {'name': 'none', 'pos': 0}
self.hover = False
self.problem = False
def render_base(self):
# Render for base
if not self.active and not self.hover:
return False
gr = self.graphics
self.cw, self.ch = self.w // 2, self.h // 2
if self.problem:
if not gr['error']:
gr['error'] = Quad(self.batch, True)
gr['error'].redraw(self.x, self.y, self.cw + self.put_size,
self.ch + self.put_size,
(190, 20, 20))
elif gr['error']:
gr['error'].id.delete()
gr['error'] = None
gr['base'].redraw(self.x, self.y, self.cw, self.ch,
self.draw_color)
self.pin_color = color_select(self.draw_color)
for input in self.put_pos(self.inputs):
put_name = self.selectedInput['name']
self.id = self.id_counter
self.x, self.y = x, y
self.w, self.h = 70, 30
self.cw, self.ch = self.w // 2, self.h // 2
self.offset = 20
self.put_size = 5
self.pin_color = color_select(color)
self.color = color
self.draw_color = color
self.er_color = (230, 20, 20)
self.active = True
self.batch = batch
self.graphics = dict(inputs=dict(), outputs=dict(), connections=list(),
error=None, base=Quad(self.batch))
self.er_label = pyglet.text.Label('error', font_name=font,
bold=True, font_size=12,
color=self.er_color + (255,),
anchor_x='right', anchor_y='center')
self.inputs = ()
self.outputs = ()
self.in_labels = []
self.connected_to = []
self.out_labels = []
self.child = []
self.selected = False # 714848
self.selectedInput = {'name': 'none', 'pos': 0}
self.selectedOutput = {'name': 'none', 'pos': 0}
self.hover = False
def serialize(self, nodes, anchor=(0, 0)):
buff = []
buff.append({'version': Serializer.version})
for node in nodes:
if isinstance(node, Node):
buff.append(OrderedDict({'type': 'node',
'x': node.x - anchor[0],
'y': node.y - anchor[1],
'size': node.editor_size,
'color': node.color,
'code': node.code.split('\n'),
'connects': node.get_con_id(),
'id': node.id}))
elif isinstance(node, Field):
buff.append(OrderedDict({'type': 'field',
'x': node.x - anchor[0],
'y': node.y - anchor[1],
'size': (node.w, node.h),
'code': node.document.text.split('\n'),
'connects': node.get_con_id(),
'id': node.id}))
elif isinstance(node, Sub):
buff.append(OrderedDict({'type': 'sub',
'x': node.x - anchor[0],
'y': node.y - anchor[1],
'size': node.editor_size,
'color': node.color,
'code': node.code,
'connects': node.get_con_id(),
'id': node.id}))
def serialize(self, nodes, anchor=(0, 0)):
buff = []
buff.append({'version': Serializer.version})
for node in nodes:
if isinstance(node, Node):
buff.append(OrderedDict({'type': 'node',
'x': node.x - anchor[0],
'y': node.y - anchor[1],
'size': node.editor_size,
'color': node.color,
'code': node.code.split('\n'),
'connects': node.get_con_id(),
'id': node.id}))
elif isinstance(node, Field):
buff.append(OrderedDict({'type': 'field',
'x': node.x - anchor[0],
'y': node.y - anchor[1],
'size': (node.w, node.h),
'code': node.document.text.split('\n'),
'connects': node.get_con_id(),
'id': node.id}))
'x': node.x - anchor[0],
'y': node.y - anchor[1],
'size': node.editor_size,
'color': node.color,
'code': node.code.split('\n'),
'connects': node.get_con_id(),
'id': node.id}))
elif isinstance(node, Field):
buff.append(OrderedDict({'type': 'field',
'x': node.x - anchor[0],
'y': node.y - anchor[1],
'size': (node.w, node.h),
'code': node.document.text.split('\n'),
'connects': node.get_con_id(),
'id': node.id}))
elif isinstance(node, Sub):
buff.append(OrderedDict({'type': 'sub',
'x': node.x - anchor[0],
'y': node.y - anchor[1],
'size': node.editor_size,
'color': node.color,
'code': node.code,
'connects': node.get_con_id(),
'id': node.id}))
return json.dumps(buff, indent=4)
def create_window():
config = pyglet.gl.Config(double_buffer=True, depth_size=0,
stencil_size=0, aux_buffers=0,
samples=1)
try:
window = PynoWindow(config, filename='.auto-saved.pn')
except:
# if config is crashed run more default one
print('Runnig using default config...')
window = PynoWindow(pyglet.gl.Config(), filename='.auto-saved.pn')
return window
import pyglet
from pyno import window
# import profile
if __name__ == '__main__':
print('Loading...')
config = pyglet.gl.Config(double_buffer=True, depth_size=0,
stencil_size=0, aux_buffers=0,
samples=1)
try:
pwindow = window.PynoWindow(config, filename='.auto-saved.pn')
except:
# if config is crashed run more default one
pwindow = window.PynoWindow(pyglet.gl.Config(), filename='.auto-saved.pn')
pyglet.options['debug_gl'] = False # performance boost?
# profile.run('pyglet.app.run()', sort=1)
pyglet.app.run()
def new_code(self, code):
# New code, search for in/outputs
if self.code == code:
return
self.problem = False
self.code = code
self.name = code.strip()
self.label.text = self.name + ' →'
try:
pwin = window.PynoWindow(pyglet.gl.Config(),
caption='→ ' + self.name)
pwin.load_pyno(self.code)
if self.pwindow:
self.pwindow.close()
del self.pwindow
self.pwindow = pwin
except Exception as ex:
self.problem = ex # abusing since this resolves in most cases like "True"
self.er_label.text = repr(ex)
return
# window visibility handeled in window.py
self.pwindow.nodes_update()
inputs, outputs = [], []