5 changed files with 198 additions and 5 deletions
@ -0,0 +1,43 @@
@@ -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() |
@ -0,0 +1,82 @@
@@ -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) |
@ -0,0 +1,60 @@
@@ -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()) |
||||
|
Loading…
Reference in new issue