working on plan editor
This commit is contained in:
43
src/TileSelector.py
Normal file
43
src/TileSelector.py
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/python
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from Tiles import *
|
||||
|
||||
class TileSelector(Gtk.Window):
|
||||
def __init__(self,connection):
|
||||
Gtk.Window.__init__(self)
|
||||
self.connect("destroy", Gtk.main_quit)
|
||||
|
||||
grid = Gtk.Grid()
|
||||
|
||||
straight_h = StraigthH()
|
||||
straight_h.connect('button-press-event',self.select)
|
||||
|
||||
straight_v = StraigthV()
|
||||
straight_v.connect('button-press-event',self.select)
|
||||
|
||||
diag_tl = Diag_TL()
|
||||
diag_tl.connect('button-press-event',self.select)
|
||||
|
||||
diag_br = Diag_BR()
|
||||
diag_br.connect('button-press-event',self.select)
|
||||
|
||||
to_brl = TO_BRL()
|
||||
to_brl.connect('button-press-event',self.select)
|
||||
|
||||
grid.attach(straight_h,0,0,1,1)
|
||||
grid.attach(straight_v,1,0,1,1)
|
||||
grid.attach(diag_tl,0,1,1,1)
|
||||
grid.attach(diag_br,1,1,1,1)
|
||||
grid.attach(to_brl,1,2,1,1)
|
||||
|
||||
self.add(grid)
|
||||
|
||||
self.show_all()
|
||||
Gtk.main()
|
||||
|
||||
def select(self,btn,evt):
|
||||
self.tile = btn.__class__
|
||||
self.hide()
|
||||
Gtk.main_quit()
|
||||
82
src/Tiles.py
Normal file
82
src/Tiles.py
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/usr/bin/python
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gdk, Gtk
|
||||
|
||||
class Tile(Gtk.DrawingArea):
|
||||
def __init__(self):
|
||||
Gtk.DrawingArea.__init__(self)
|
||||
self.connect('draw',self.draw)
|
||||
self.set_size_request(32, 32)
|
||||
self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
|
||||
|
||||
def draw(self,widget,canvas):
|
||||
pass
|
||||
|
||||
def connections(self):
|
||||
return (False,False,False,False)
|
||||
|
||||
def connects_up(self):
|
||||
return self.connections()[0]
|
||||
|
||||
def connects_down(self):
|
||||
return self.connections()[2]
|
||||
|
||||
def connects_right(self):
|
||||
return self.connections()[1]
|
||||
|
||||
def connects_left(self):
|
||||
return self.connections()[3]
|
||||
|
||||
class StraigthH(Tile):
|
||||
def draw(self,widget,cr):
|
||||
cr.set_source_rgb(0,0,0)
|
||||
cr.rectangle(0,11,32,10)
|
||||
cr.fill()
|
||||
|
||||
def connections(self):
|
||||
return (False,True,False,True)
|
||||
|
||||
class StraigthV(Tile):
|
||||
def draw(self,widget,cr):
|
||||
cr.set_source_rgb(0,0,0)
|
||||
cr.rectangle(11,0,10,32)
|
||||
cr.fill()
|
||||
|
||||
def connections(self):
|
||||
return (True,False,True,False)
|
||||
|
||||
class Diag_TL(Tile):
|
||||
def draw(self,widget,cr):
|
||||
cr.set_source_rgb(0,0,0)
|
||||
cr.set_line_width(7)
|
||||
cr.move_to(-5,21)
|
||||
cr.line_to(21,-5)
|
||||
cr.stroke()
|
||||
|
||||
def connections(self):
|
||||
return (True,False,False,True)
|
||||
|
||||
class Diag_BR(Tile):
|
||||
def draw(self,widget,cr):
|
||||
cr.set_source_rgb(0,0,0)
|
||||
cr.set_line_width(7)
|
||||
cr.move_to(12,37)
|
||||
cr.line_to(37,12)
|
||||
cr.stroke()
|
||||
|
||||
def connections(self):
|
||||
return (False,True,True,False)
|
||||
|
||||
class TO_BRL(Tile):
|
||||
def draw(self,widget,cr):
|
||||
cr.set_source_rgb(0,0,0)
|
||||
cr.set_line_width(7)
|
||||
cr.move_to(12,37)
|
||||
cr.line_to(37,12)
|
||||
cr.stroke()
|
||||
cr.rectangle(0,11,32,10)
|
||||
cr.fill()
|
||||
|
||||
def connections(self):
|
||||
return (False,True,True,True)
|
||||
60
src/TrackPlan.py
Normal file
60
src/TrackPlan.py
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/python
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from TileSelector import *
|
||||
|
||||
class TrackPlan(Gtk.Window):
|
||||
def __init__(self,json):
|
||||
Gtk.Window.__init__(self)
|
||||
self.connect("delete-event", Gtk.main_quit)
|
||||
|
||||
self.grid = Gtk.Grid()
|
||||
|
||||
self.putButton(0,0,None)
|
||||
|
||||
self.add(self.grid)
|
||||
|
||||
self.show_all()
|
||||
Gtk.main()
|
||||
|
||||
def select_tile(self,widget,connections):
|
||||
print 'Button at ({},{}) pressed'.format(widget.x, widget.y)
|
||||
tileSelector = TileSelector(connections)
|
||||
tile = tileSelector.tile()
|
||||
self.putTile(tile,widget.x,widget.y)
|
||||
widget.destroy()
|
||||
|
||||
def putButton(self,x,y,connections):
|
||||
print 'putButton({},{})'.format(x,y)
|
||||
btn = Gtk.Button('?')
|
||||
btn.x = x
|
||||
btn.y = y
|
||||
btn.connect('clicked',self.select_tile,connections)
|
||||
self.grid.attach(btn,x,y,1,1)
|
||||
btn.show()
|
||||
|
||||
def putTile(self,tile,x,y):
|
||||
print 'putTile({},{})'.format(x,y)
|
||||
tile.x = x
|
||||
tile.y = y
|
||||
self.grid.attach(tile,x,y,1,1)
|
||||
tile.show()
|
||||
|
||||
if tile.connects_left():
|
||||
left = self.grid.get_child_at(x-1,y)
|
||||
if left == None:
|
||||
self.putButton(x-1,y,tile.connections())
|
||||
if tile.connects_right():
|
||||
right = self.grid.get_child_at(x+1,y)
|
||||
if right == None:
|
||||
self.putButton(x+1,y,tile.connections())
|
||||
if tile.connects_up():
|
||||
top = self.grid.get_child_at(x,y-1)
|
||||
if top == None:
|
||||
self.putButton(x,y-1,tile.connections())
|
||||
if tile.connects_down():
|
||||
bottom = self.grid.get_child_at(x,y+1)
|
||||
if bottom == None:
|
||||
self.putButton(x,y+1,tile.connections())
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import socket
|
||||
from ConnectDialog import *
|
||||
from FileDialog import *
|
||||
from TrackPlan import *
|
||||
from YesNoDialog import *
|
||||
|
||||
def readline(socket):
|
||||
@@ -47,6 +48,11 @@ if conn_dlg.port != None:
|
||||
|
||||
client_sock.send(file_dialog.dir+"\n")
|
||||
continue
|
||||
|
||||
if line == 'PLAN:':
|
||||
json = client.next()
|
||||
plan = TrackPlan(json)
|
||||
continue
|
||||
|
||||
if 'does not exist. Create' in line:
|
||||
dir = line.split('does not exist')[0].strip()
|
||||
|
||||
@@ -28,12 +28,15 @@ class web4rail_server:
|
||||
os.mkdir(path, 0755)
|
||||
file = open(path+'/plan.json', 'w+')
|
||||
|
||||
def load_system(self,path):
|
||||
def load_system(self,path,conn):
|
||||
print 'loading system from '+path
|
||||
|
||||
with open(path+'/plan.json', 'r') as plan_file:
|
||||
plan=plan_file.read()
|
||||
conn.send("PLAN:\n")
|
||||
conn.send(plan+"\n")
|
||||
|
||||
def select_system(self,conn):
|
||||
path='/'
|
||||
path='/tmp/srichter/mops/'
|
||||
conn.send("Welcome to the Web2Rail server. Please select a SYSTEM first:\n");
|
||||
while True:
|
||||
conn.send('current dir: '+path+"\n")
|
||||
@@ -49,7 +52,6 @@ class web4rail_server:
|
||||
break
|
||||
path += entry+'/'
|
||||
else:
|
||||
print entry
|
||||
conn.send(path+entry+' does not exist. Create (yes/no/abort)?\n')
|
||||
input = conn.recv(1024).strip()
|
||||
if input == 'yes':
|
||||
@@ -64,7 +66,7 @@ class web4rail_server:
|
||||
if path == None:
|
||||
return
|
||||
|
||||
self.load_system(path)
|
||||
self.load_system(path,conn)
|
||||
|
||||
|
||||
def start(self):
|
||||
|
||||
Reference in New Issue
Block a user