working on tiles and plan editor
This commit is contained in:
@@ -9,34 +9,26 @@ class TileSelector(Gtk.Window):
|
|||||||
Gtk.Window.__init__(self)
|
Gtk.Window.__init__(self)
|
||||||
self.connect("destroy", Gtk.main_quit)
|
self.connect("destroy", Gtk.main_quit)
|
||||||
|
|
||||||
grid = Gtk.Grid()
|
self.grid = Gtk.Grid()
|
||||||
|
|
||||||
straight_h = StraigthH()
|
self.add_tile(StraightH,0,0)
|
||||||
straight_h.connect('button-press-event',self.select)
|
self.add_tile(StraightV,1,0)
|
||||||
|
self.add_tile(Diag_TL,0,1)
|
||||||
|
self.add_tile(Diag_TR,1,1)
|
||||||
|
self.add_tile(Diag_BR,2,1)
|
||||||
|
self.add_tile(Diag_BL,3,1)
|
||||||
|
self.add_tile(TO_BRL,0,2)
|
||||||
|
|
||||||
straight_v = StraigthV()
|
self.add(self.grid)
|
||||||
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()
|
self.show_all()
|
||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
|
||||||
|
def add_tile(self,tile_class,x,y):
|
||||||
|
tile = tile_class()
|
||||||
|
tile.connect('button-press-event',self.select)
|
||||||
|
self.grid.attach(tile,x,y,1,1)
|
||||||
|
|
||||||
def select(self,btn,evt):
|
def select(self,btn,evt):
|
||||||
self.tile = btn.__class__
|
self.tile = btn.__class__
|
||||||
self.hide()
|
self.hide()
|
||||||
|
|||||||
28
src/Tiles.py
28
src/Tiles.py
@@ -28,7 +28,7 @@ class Tile(Gtk.DrawingArea):
|
|||||||
def connects_left(self):
|
def connects_left(self):
|
||||||
return self.connections()[3]
|
return self.connections()[3]
|
||||||
|
|
||||||
class StraigthH(Tile):
|
class StraightH(Tile):
|
||||||
def draw(self,widget,cr):
|
def draw(self,widget,cr):
|
||||||
cr.set_source_rgb(0,0,0)
|
cr.set_source_rgb(0,0,0)
|
||||||
cr.rectangle(0,11,32,10)
|
cr.rectangle(0,11,32,10)
|
||||||
@@ -37,7 +37,7 @@ class StraigthH(Tile):
|
|||||||
def connections(self):
|
def connections(self):
|
||||||
return (False,True,False,True)
|
return (False,True,False,True)
|
||||||
|
|
||||||
class StraigthV(Tile):
|
class StraightV(Tile):
|
||||||
def draw(self,widget,cr):
|
def draw(self,widget,cr):
|
||||||
cr.set_source_rgb(0,0,0)
|
cr.set_source_rgb(0,0,0)
|
||||||
cr.rectangle(11,0,10,32)
|
cr.rectangle(11,0,10,32)
|
||||||
@@ -57,6 +57,18 @@ class Diag_TL(Tile):
|
|||||||
def connections(self):
|
def connections(self):
|
||||||
return (True,False,False,True)
|
return (True,False,False,True)
|
||||||
|
|
||||||
|
class Diag_TR(Tile):
|
||||||
|
def draw(self,widget,cr):
|
||||||
|
cr.set_source_rgb(0,0,0)
|
||||||
|
cr.set_line_width(7)
|
||||||
|
cr.move_to(12,-5)
|
||||||
|
cr.line_to(38,21)
|
||||||
|
cr.stroke()
|
||||||
|
|
||||||
|
def connections(self):
|
||||||
|
return (True,True,False,False)
|
||||||
|
|
||||||
|
|
||||||
class Diag_BR(Tile):
|
class Diag_BR(Tile):
|
||||||
def draw(self,widget,cr):
|
def draw(self,widget,cr):
|
||||||
cr.set_source_rgb(0,0,0)
|
cr.set_source_rgb(0,0,0)
|
||||||
@@ -68,6 +80,18 @@ class Diag_BR(Tile):
|
|||||||
def connections(self):
|
def connections(self):
|
||||||
return (False,True,True,False)
|
return (False,True,True,False)
|
||||||
|
|
||||||
|
class Diag_BL(Tile):
|
||||||
|
def draw(self,widget,cr):
|
||||||
|
cr.set_source_rgb(0,0,0)
|
||||||
|
cr.set_line_width(7)
|
||||||
|
cr.move_to(-5,11)
|
||||||
|
cr.line_to(21,37)
|
||||||
|
cr.stroke()
|
||||||
|
|
||||||
|
def connections(self):
|
||||||
|
return (False,False,True,True)
|
||||||
|
|
||||||
|
|
||||||
class TO_BRL(Tile):
|
class TO_BRL(Tile):
|
||||||
def draw(self,widget,cr):
|
def draw(self,widget,cr):
|
||||||
cr.set_source_rgb(0,0,0)
|
cr.set_source_rgb(0,0,0)
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ class TrackPlan(Gtk.Window):
|
|||||||
Gtk.main()
|
Gtk.main()
|
||||||
|
|
||||||
def select_tile(self,widget,connections):
|
def select_tile(self,widget,connections):
|
||||||
print 'Button at ({},{}) pressed'.format(widget.x, widget.y)
|
#print 'Button at ({},{}) pressed'.format(widget.x, widget.y)
|
||||||
tileSelector = TileSelector(connections)
|
tileSelector = TileSelector(connections)
|
||||||
tile = tileSelector.tile()
|
tile = tileSelector.tile()
|
||||||
self.putTile(tile,widget.x,widget.y)
|
self.putTile(tile,widget.x,widget.y)
|
||||||
widget.destroy()
|
widget.destroy()
|
||||||
|
|
||||||
def putButton(self,x,y,connections):
|
def putButton(self,x,y,connections):
|
||||||
print 'putButton({},{})'.format(x,y)
|
#print 'putButton({},{})'.format(x,y)
|
||||||
btn = Gtk.Button('?')
|
btn = Gtk.Button('?')
|
||||||
btn.x = x
|
btn.x = x
|
||||||
btn.y = y
|
btn.y = y
|
||||||
@@ -35,7 +35,7 @@ class TrackPlan(Gtk.Window):
|
|||||||
btn.show()
|
btn.show()
|
||||||
|
|
||||||
def putTile(self,tile,x,y):
|
def putTile(self,tile,x,y):
|
||||||
print 'putTile({},{})'.format(x,y)
|
#print 'putTile({},{})'.format(x,y)
|
||||||
tile.x = x
|
tile.x = x
|
||||||
tile.y = y
|
tile.y = y
|
||||||
self.grid.attach(tile,x,y,1,1)
|
self.grid.attach(tile,x,y,1,1)
|
||||||
@@ -57,4 +57,8 @@ class TrackPlan(Gtk.Window):
|
|||||||
bottom = self.grid.get_child_at(x,y+1)
|
bottom = self.grid.get_child_at(x,y+1)
|
||||||
if bottom == None:
|
if bottom == None:
|
||||||
self.putButton(x,y+1,tile.connections())
|
self.putButton(x,y+1,tile.connections())
|
||||||
|
|
||||||
|
self.save()
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
print 'Saving plan not implemented'
|
||||||
@@ -36,7 +36,7 @@ class web4rail_server:
|
|||||||
conn.send(plan+"\n")
|
conn.send(plan+"\n")
|
||||||
|
|
||||||
def select_system(self,conn):
|
def select_system(self,conn):
|
||||||
path='/tmp/srichter/mops/'
|
path='/'
|
||||||
conn.send("Welcome to the Web2Rail server. Please select a SYSTEM first:\n");
|
conn.send("Welcome to the Web2Rail server. Please select a SYSTEM first:\n");
|
||||||
while True:
|
while True:
|
||||||
conn.send('current dir: '+path+"\n")
|
conn.send('current dir: '+path+"\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user