Example #1
0
def main():
    win = gtk.Window()

    canvas = Canvas(units='mm', scale=10)
    canvas.set_size_request(800, 600)
    # canvas.set_bounds(0, 0, 120., 90.)
    root = canvas.get_root_item()

    win.connect("destroy", gtk.main_quit)
    win.connect("key-press-event", key_press, canvas)
    win.connect("motion-notify-event", motion_notify, canvas)
    win.connect("button-press-event", button_press)
    win.connect("button-release-event", button_release)

    #mf = MatFree(preset='nop')
    #mf = MatFree(preset='pyramids')
    mf = MatFree(preset='default')
    new_cut = mf.apply(cut)

    canvas.points = [None]
    canvas.arrows = []

    idx = 1
    for path in new_cut:
        for C in path:
            if 'attr' in C.__dict__ and 'sharp' in C.attr:
                Ellipse(parent=root,
                        center_x=C.x,
                        center_y=C.y,
                        radius_x=.25,
                        radius_y=.25,
                        fill_color_rgba=0xFF666644,
                        line_width=0.01)

            Ellipse(parent=root,
                    center_x=C.x,
                    center_y=C.y,
                    radius_x=.2,
                    radius_y=.2,
                    line_width=0.01)

        p = Points(path)
        poly = Polyline(parent=root,
                        points=p,
                        line_width=0.05,
                        stroke_color="black")

        jumpto = True
        for C in path:
            text = Text(parent=root, text=idx, font="4", fill_color="blue")
            idx += 1
            canvas.points.append(
                (C, jumpto))  # store to allow cursor movement.
            jumpto = False
            text.translate(C.x + random.uniform(-.1, 0),
                           C.y + random.uniform(-.1, 0))
            text.scale(.05, .05)

    if len(canvas.points) <= 1:
        rect = Rect(parent=root,
                    x=1,
                    y=1,
                    width=3,
                    height=2,
                    fill_color='#77ff77',
                    stroke_color='black',
                    line_width=.01)
        print "Dummy rectangle drawn. No points in canvas."
    else:
        cursor_p = Points([(-0.5, 0), (0, 0.5), (0.5, 0), (0, -0.5),
                           (-0.5, 0)])
        canvas.cursor = Polyline(parent=root,
                                 points=cursor_p,
                                 line_width=0.05,
                                 stroke_color="green",
                                 fill_color_rgba=0x77ff7777)
        canvas.cursor.translate(canvas.points[1][0].x, canvas.points[1][0].y)
        canvas.cursor_idx = 1

    # text = Text(parent=root, text="Hello World", font="12")
    # text.rotate(30,0,10)
    # text.scale(.05,.05)

    win.add(canvas)
    win.show_all()

    gtk.main()
def main ():
    win = gtk.Window()

    canvas = Canvas(units='mm', scale=10)
    canvas.set_size_request(800, 600)
    # canvas.set_bounds(0, 0, 120., 90.)
    root = canvas.get_root_item()

    win.connect("destroy", gtk.main_quit)
    win.connect("key-press-event", key_press, canvas)
    win.connect("motion-notify-event", motion_notify, canvas)
    win.connect("button-press-event", button_press)
    win.connect("button-release-event", button_release)

    #mf = MatFree(preset='nop')
    #mf = MatFree(preset='pyramids')
    mf = MatFree(preset='default')
    new_cut = mf.apply(cut)

    canvas.points = [ None ]
    canvas.arrows = [ ]

    idx = 1
    for path in new_cut:
      for C in path:
        if 'attr' in C.__dict__ and 'sharp' in C.attr:
          Ellipse(parent=root, center_x=C.x, center_y=C.y, radius_x=.25, radius_y=.25, fill_color_rgba = 0xFF666644, line_width = 0.01)
          

        Ellipse(parent=root, center_x=C.x, center_y=C.y, radius_x=.2, radius_y=.2, line_width = 0.01)

      p = Points(path)
      poly = Polyline(parent=root, points=p, line_width=0.05, stroke_color="black")

      jumpto = True
      for C in path:
        text = Text(parent=root, text=idx, font="4", fill_color="blue")
        idx += 1
        canvas.points.append((C,jumpto))         # store to allow cursor movement.
        jumpto = False
        text.translate(C.x+random.uniform(-.1,0), C.y+random.uniform(-.1,0))
        text.scale(.05,.05)
      
    
    if len(canvas.points) <= 1:
      rect = Rect(parent=root, x=1, y=1, width=3,  height=2,
                  fill_color = '#77ff77', stroke_color = 'black', line_width = .01)
      print "Dummy rectangle drawn. No points in canvas."
    else:
      cursor_p = Points([(-0.5,0),(0,0.5),(0.5,0),(0,-0.5),(-0.5,0)])
      canvas.cursor = Polyline(parent=root, points=cursor_p, line_width=0.05, stroke_color="green", fill_color_rgba=0x77ff7777)
      canvas.cursor.translate(canvas.points[1][0].x,canvas.points[1][0].y)
      canvas.cursor_idx = 1
    
    # text = Text(parent=root, text="Hello World", font="12")
    # text.rotate(30,0,10)
    # text.scale(.05,.05)
                    
    win.add(canvas)
    win.show_all()
                                
    gtk.main()