Added Control box to inputcfg
This commit is contained in:
parent
6fe38b9957
commit
3eda4c8636
1 changed files with 112 additions and 23 deletions
135
gui/inputcfg.py
135
gui/inputcfg.py
|
@ -5,7 +5,100 @@ pygtk.require('2.0')
|
|||
import gtk
|
||||
import cairo
|
||||
import goocanvas
|
||||
import pango
|
||||
|
||||
class Control:
|
||||
def __init__(self, root):
|
||||
self.title = "EvDev"
|
||||
self.in_ports = []
|
||||
self.out_ports = []
|
||||
|
||||
self.group = goocanvas.Group(parent=root)
|
||||
|
||||
self.mainbox = goocanvas.Rect(parent=self.group,
|
||||
radius_x=10, radius_y=10,
|
||||
width=200,
|
||||
stroke_color="black",
|
||||
fill_color="lightgrey",
|
||||
line_width=1)
|
||||
self.titlebox = goocanvas.Rect(parent=self.group,
|
||||
width=200-10, height=30-10,
|
||||
radius_x=5, radius_y=5,
|
||||
stroke_color="black",
|
||||
fill_color="black")
|
||||
self.title = goocanvas.Text(parent=root,
|
||||
antialias=cairo.ANTIALIAS_SUBPIXEL,
|
||||
text="EvDev",
|
||||
width=180,
|
||||
font="sans bold 12",
|
||||
x=100,y=5,
|
||||
anchor=gtk.ANCHOR_NORTH,
|
||||
alignment=pango.ALIGN_CENTER,
|
||||
fill_color="white")
|
||||
|
||||
self.add_in_port("btn0")
|
||||
self.add_in_port("btn1")
|
||||
|
||||
self.add_out_port("abs1")
|
||||
self.add_out_port("abs2")
|
||||
self.add_out_port("abs3")
|
||||
self.add_out_port("abs4")
|
||||
self.add_out_port("abs5")
|
||||
self.add_out_port("abs6")
|
||||
self.set_pos(100, 100)
|
||||
|
||||
def layout(self):
|
||||
height = 40 + max(len(self.in_ports), len(self.out_ports)) * 20
|
||||
self.mainbox.set_properties(height=height)
|
||||
|
||||
def add_in_port(self, name):
|
||||
in_port = goocanvas.Ellipse(parent=self.group,
|
||||
center_x=0, center_y=40,
|
||||
radius_x=5, radius_y=5,
|
||||
stroke_color="black",
|
||||
line_width=1,
|
||||
fill_color="red")
|
||||
in_port_title = goocanvas.Text(parent=self.group,
|
||||
antialias=cairo.ANTIALIAS_SUBPIXEL,
|
||||
text=name,
|
||||
font="sans 9",
|
||||
x=10,y=0,
|
||||
anchor=gtk.ANCHOR_WEST,
|
||||
alignment=pango.ALIGN_LEFT,
|
||||
fill_color="black")
|
||||
self.in_ports.append((in_port, in_port_title))
|
||||
self.layout()
|
||||
|
||||
def add_out_port(self, name):
|
||||
out_port = goocanvas.Ellipse(parent=self.group,
|
||||
center_x=0, center_y=40,
|
||||
radius_x=5, radius_y=5,
|
||||
stroke_color="black",
|
||||
line_width=1,
|
||||
fill_color="green")
|
||||
out_port_title = goocanvas.Text(parent=self.group,
|
||||
antialias=cairo.ANTIALIAS_SUBPIXEL,
|
||||
text=name,
|
||||
font="sans 9",
|
||||
x=190,y=0,
|
||||
anchor=gtk.ANCHOR_EAST,
|
||||
alignment=pango.ALIGN_RIGHT,
|
||||
fill_color="black")
|
||||
self.out_ports.append((out_port, out_port_title))
|
||||
self.layout()
|
||||
|
||||
def set_pos(self, x, y):
|
||||
self.mainbox.set_properties(x=x, y=y)
|
||||
self.titlebox.set_properties(x=x+5, y=y+5)
|
||||
self.title.set_properties(x=x+100, y=y+5)
|
||||
for i in range(len(self.in_ports)):
|
||||
self.in_ports[i][0].set_properties(center_x=x, center_y=y+40+20*i)
|
||||
self.in_ports[i][1].set_properties(x=x+10, y=y+40+20*i)
|
||||
for i in range(len(self.out_ports)):
|
||||
self.out_ports[i][0].set_properties(center_x=x+200, center_y=y+40+20*i)
|
||||
self.out_ports[i][1].set_properties(x=x+190, y=y+40+20*i)
|
||||
|
||||
|
||||
class InputCfg:
|
||||
def delete_event(self, widget, event, data=None):
|
||||
return False
|
||||
|
@ -13,10 +106,20 @@ class InputCfg:
|
|||
def destroy(self, widget, data=None):
|
||||
gtk.main_quit()
|
||||
|
||||
def click(self, item, target_item, event, *rest):
|
||||
print item, target_item, event, rest
|
||||
def button_down(self, item, event):
|
||||
self.drag = True
|
||||
self.motion(item, event)
|
||||
|
||||
def button_up(self, item, event):
|
||||
self.drag = False
|
||||
|
||||
def motion(self, item, event):
|
||||
if self.drag:
|
||||
self.control.set_pos(event.x, event.y)
|
||||
|
||||
def __init__(self):
|
||||
self.drag = False
|
||||
|
||||
# create a new window
|
||||
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
self.window.connect("delete_event", self.delete_event)
|
||||
|
@ -36,32 +139,18 @@ class InputCfg:
|
|||
|
||||
|
||||
root = self.canvas.get_root_item()
|
||||
ellipse = goocanvas.Ellipse(parent=root,
|
||||
center_x=300, center_y=300,
|
||||
radius_x=100, radius_y=100,
|
||||
stroke_color="black",
|
||||
fill_color="lightgrey")
|
||||
rect = goocanvas.Rect(parent=root,
|
||||
antialias=cairo.ANTIALIAS_SUBPIXEL,
|
||||
x=100, y=100,
|
||||
radius_x=10, radius_y=10,
|
||||
width=200, height=100,
|
||||
stroke_color="black",
|
||||
fill_color="lightgrey")
|
||||
text = goocanvas.Text(parent=root,
|
||||
antialias=cairo.ANTIALIAS_SUBPIXEL,
|
||||
text="FoobarItem Really Long Description",
|
||||
width=180,
|
||||
font="serif bold 10",
|
||||
x=110,y=110)
|
||||
|
||||
rect.connect("button-press-event", self.click)
|
||||
self.canvas.connect("button-press-event", self.button_down)
|
||||
self.canvas.connect("button-release-event", self.button_up)
|
||||
self.canvas.connect("motion-notify-event", self.motion)
|
||||
|
||||
self.control = Control(root)
|
||||
|
||||
def main(self):
|
||||
gtk.main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
inputcfg = InputCfg()
|
||||
inputcfg.main()
|
||||
|
||||
|
||||
# EOF #
|
||||
|
|
Loading…
Add table
Reference in a new issue