Esempio n. 1
0
def image_cb(filename):
    if filename.endswith('.png'):
        img = Fl.PNG_Image(filename).asRGBA()
    elif filename.endswith('.jpg'):
        img = Fl.JPEG_Image(filename).asRGBA()
    else:
        return None

    return img.w(), img.h(), memoryview(img)
Esempio n. 2
0
def deadViewer(filename = None):
    try:
        WIDTH, HEIGHT = 600,700
        window = Fl.Double_Window(WIDTH, HEIGHT)
        menu = Fl.Menu_Bar(0,0,WIDTH,30)

        widget = GLWidget(10,40, WIDTH - 20, HEIGHT - 50)
        
        menu.add("&File",0,None,None,Fl.SUBMENU)
        menu.add("File/&Open", 0, widget.openFile, None, Fl.MENU_DIVIDER)
        menu.add("File/&Quit", 0, lambda widget,data: Fl.exit())
        
        window.end()
        window.resizable(widget)
        window.show()
        widget.show()
        if not filename is None:
            widget.openFile(filename=filename)
        Fl.run()
            
    finally:
        vg.DestroyContextSH()
Esempio n. 3
0
    def __init__(self, svg=None, width=500, height=500):
        try:
            WIDTH, HEIGHT = width, height
            super(Viewer, self).__init__(WIDTH, HEIGHT)
            menu = Fl.Menu_Bar(0, 0, WIDTH, 30)

            widget = GLWidget(10, 40, WIDTH - 20, HEIGHT - 50)

            menu.add("&File", 0, None, None, Fl.SUBMENU)
            menu.add("File/&Open", 0, widget.openFile, None, Fl.MENU_DIVIDER)
            menu.add("File/&Quit", 0, lambda widget, data: Fl.exit())

            self.end()
            self.resizable(widget)
            self.show()
            widget.show()
            if not svg is None:
                widget.openFile(filename=svg)
            Fl.run()

        finally:
            vg.DestroyContextSH()
Esempio n. 4
0
def deadViewer(filename=None):
    try:
        WIDTH, HEIGHT = 600, 700
        window = Fl.Double_Window(WIDTH, HEIGHT)
        menu = Fl.Menu_Bar(0, 0, WIDTH, 30)

        widget = GLWidget(10, 40, WIDTH - 20, HEIGHT - 50)

        menu.add("&File", 0, None, None, Fl.SUBMENU)
        menu.add("File/&Open", 0, widget.openFile, None, Fl.MENU_DIVIDER)
        menu.add("File/&Quit", 0, lambda widget, data: Fl.exit())

        window.end()
        window.resizable(widget)
        window.show()
        widget.show()
        if not filename is None:
            widget.openFile(filename=filename)
        Fl.run()

    finally:
        vg.DestroyContextSH()
Esempio n. 5
0
def filecb(widget, data):
    native = Fl.Native_File_Chooser()
    native.set_title("Pick a file")
    native.set_filter('''Text\t*.txt
                        C Files\t*.{cxx,h,c}
                        Apps\t*.{app}\n''')
    ret = native.show()
    if ret == -1:
        print 'Error ', native.errmsg()
    elif ret == 1:
        print 'Cancel'
    else:
        print native.filename()
Esempio n. 6
0
    def __init__(self, svg=None, width=500, height=500 ):
        try:
            WIDTH, HEIGHT = width, height
            super(Viewer,self).__init__(WIDTH,HEIGHT)
            menu = Fl.Menu_Bar(0,0,WIDTH,30)

            widget = GLWidget(10,40, WIDTH - 20, HEIGHT - 50)
            
            menu.add("&File",0,None,None,Fl.SUBMENU)
            menu.add("File/&Open", 0, widget.openFile, None, Fl.MENU_DIVIDER)
            menu.add("File/&Quit", 0, lambda widget,data: Fl.exit())
            
            self.end()
            self.resizable(widget)
            self.show()
            widget.show()
            if not svg is None:
                widget.openFile( filename = svg )
            Fl.run()
                
        finally:
            vg.DestroyContextSH()
Esempio n. 7
0
    def openFile(self, widget=None, filename=None):
        if filename is None:
            native = Fl.Native_File_Chooser()
            native.title("Select SVG file")
            native.filter('SVG\t*.svg')
            ret = native.show()
            if ret == -1 or ret == 1:
                return

            filename = native.filename()

        xmltree = readFile(filename)
        self.renderer = Renderer(xmltree, imageprovider=image_cb)

        if isinstance(filename, basestring):
            name = os.path.split(filename)[-1]
        else:
            name = 'unamed.svg'

        self.updateScale()
        self.redraw()
Esempio n. 8
0
    def handle(self, event):
        if event == Fl.FOCUS:
            self.redraw()
            return 1
        elif event == Fl.MOUSEWHEEL:
            self.scale *= 1 + .1 * Fl.event_dy()
            self.redraw()
            return 1
        elif event == Fl.PUSH:
            if Fl.event_button() == Fl.MIDDLE_MOUSE:
                self.mouse_x = Fl.event_x()
                self.mouse_y = Fl.event_y()
            return 1

        elif event == Fl.RELEASE:
            self.mouse_x = None
            self.mouse_y = None
            return 0

        elif event == Fl.DRAG:
            if Fl.event_button() == Fl.MIDDLE_MOUSE:
                if not self.mouse_x is None:
                    dx = Fl.event_x() - self.mouse_x
                    dy = Fl.event_y() - self.mouse_y

                    mat = vg.GetMatrix()
                    sx, sy = mat[0], mat[4]

                    self.dx -= dx / sx
                    self.dy += dy / sy

                    self.mouse_x += dx
                    self.mouse_y += dy

                    self.redraw()
                    return 1

        return 0
Esempio n. 9
0
 def handle(self, event):
     if event == Fl.FOCUS:
         self.redraw()
         return 1   
     elif event == Fl.MOUSEWHEEL:
         self.scale *= 1 + .1*Fl.event_dy()
         self.redraw()
         return 1
     elif event == Fl.PUSH:
         if Fl.event_button() == Fl.MIDDLE_MOUSE:
             self.mouse_x = Fl.event_x()
             self.mouse_y = Fl.event_y()
         return 1
     
     elif event == Fl.RELEASE:
         self.mouse_x = None
         self.mouse_y = None
         return 0
         
     elif event == Fl.DRAG:
         if Fl.event_button() == Fl.MIDDLE_MOUSE:
             if not self.mouse_x is None:
                 dx = Fl.event_x() - self.mouse_x
                 dy = Fl.event_y() - self.mouse_y
                 
                 mat = vg.GetMatrix()
                 sx, sy = mat[0], mat[4]
                 
                 self.dx -= dx/sx
                 self.dy += dy/sy
                 
                 self.mouse_x += dx
                 self.mouse_y += dy
                 
                 self.redraw()
                 return 1
         
     return 0
Esempio n. 10
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl


def tree_cb(widget, data):
    print 'cb', widget.callback_reason()


window = Fl.Double_Window(320, 365, 'Tree')

tree = Fl.Tree(5, 5, 310, 355)
tree.showroot(0)
tree.callback(tree_cb)
tree.begin()
tree.add("Flintstones/Fred")
tree.add("Flintstones/Wilma")
tree.add("Flintstones/Pebbles")
tree.add("Simpsons/Homer")
tree.add("Simpsons/Marge")
tree.add("Simpsons/Bart")
tree.add("Simpsons/Lisa")
tree.end()

window.end()
window.show()
Fl.run()
Esempio n. 11
0
 def draw(self):
     Fl.color(Fl.BLACK)
     
     Fl.begin_line()
     Fl.vertex(10,10)
     Fl.vertex(380,400)
     Fl.end_line()
     
     Fl.begin_line()
     Fl.vertex(10,400)
     Fl.vertex(380,10)
     Fl.end_line()
Esempio n. 12
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl

window = Fl.Window(320, 320)
b1 = Fl.Button(10, 10, 300, 300)
image1 = Fl.PNG_Image('sudoku-128.png')
b1.image(image1)
window.end()
window.show()
Fl.run()
Esempio n. 13
0
  <rect x="100" y="100" width="400" height="200" rx="50"
        fill="green" />

  <g transform="translate(700 210) rotate(-30)">
    <rect x="0" y="0" width="400" height="200" rx="50"
          fill="none" stroke="purple" stroke-width="30" />
  </g>
</svg>
""")

    renderer = Renderer(xmltree)

    import svgplotlib.FLTK as Fl

    WIDTH, HEIGHT = 600, 700
    window = Fl.Window(WIDTH, HEIGHT)

    width, height = renderer.width, renderer.height

    widget = Fl.Button(10, 10, width, height)

    pixels = vg.PixelBuffer(width, height)
    ctx = vg.CreateOffScreenSH()
    vg.StartOffScreenSH(ctx, width, height)

    vg.Setfv(vg.CLEAR_COLOR, 4, [1., 1., 1., 1.])
    vg.Clear(0, 0, width, height)

    # center on bounding box
    box = renderer.bounds
    scale = min(width / box.width, height / box.height)
Esempio n. 14
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl

Fl.alert('Dialog tests!')
print Fl.choice('Select button', 'Yes', 'No')
print Fl.input('Enter text', 'text line')
Fl.message('Welcome again!')
Esempio n. 15
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl

window = Fl.Window(400, 420)

image1 = Fl.PNG_Image('sudoku-128.png')


def cb(self, data, name):
    print 'name = ', name
    return image1


widget = Fl.Help_View(10, 10, 380, 400)
widget.value('''<b>Testing</b>
<img src="angry.gif"/>''')
widget.callback(cb, 'testing')
window.end()
window.show()
Fl.run()
Esempio n. 16
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl


def beepcb(widget, data):
    print 'beep'


def exitcb(widget, data):
    Fl.exit()


window = Fl.Window(320, 65, 'Buttons')
b1 = Fl.Button(20, 20, 80, 25, "&Beep")
b1.callback(beepcb)
b3 = Fl.Button(220, 20, 80, 25, "E&xit")
b3.callback(exitcb)
window.end()
window.show()
Fl.run()
Esempio n. 17
0
    def draw(self):
        Fl.color(Fl.BLACK)

        Fl.begin_line()
        Fl.vertex(10, 10)
        Fl.vertex(380, 400)
        Fl.end_line()

        Fl.begin_line()
        Fl.vertex(10, 400)
        Fl.vertex(380, 10)
        Fl.end_line()
Esempio n. 18
0
# -*- coding: utf-8 -*-
import sys

sys.path.append('..')
import svgplotlib.FLTK as Fl


def cb(widget, data):
    print 'called'
    print widget, data


WIDTH = 700

window = Fl.Window(WIDTH, 400)
menubar = Fl.Menu_Bar(0, 0, WIDTH, 30)
menubar.add("&File", 0, None, None, Fl.SUBMENU)
menubar.add("File/Exit1", 0, cb, 'test1')
menubar.add("File/Exit2", 0, cb, 'test2')

button = Fl.Menu_Button(10, 50, WIDTH / 2, 30, 'Menu Button')
button.add("Exit1", 0, cb, 'test1')
button.add("Exit2", 0, cb, 'test2')

choice = Fl.Choice(WIDTH / 4, 100, WIDTH / 2, 30, 'Choice Button')
first = choice.add("Exit1", 0, cb, 'test1')
choice.add("Exit2", 0, cb, 'test2')
choice.value(first)

window.end()
window.show()
Esempio n. 19
0
def exitcb(widget, data):
    Fl.exit()
Esempio n. 20
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl

def filecb(widget, data):
    native = Fl.Native_File_Chooser()
    native.set_title("Pick a file")
    native.set_filter('''Text\t*.txt
                        C Files\t*.{cxx,h,c}
                        Apps\t*.{app}\n''')
    ret = native.show()
    if ret == -1:
        print 'Error ', native.errmsg()
    elif ret == 1:
        print 'Cancel'
    else:
        print native.filename()
                
def exitcb(widget, data):
    Fl.exit()
    
window = Fl.Window(320,65)
b1 = Fl.Button(20, 20, 80, 25, "&Select file")
b1.callback(filecb)
b3 = Fl.Button(220,20, 80, 25, "E&xit")
b3.callback(exitcb)
window.end()
window.show()
Fl.run()
Esempio n. 21
0
    
    pixels = vg.PixelBuffer(width,height)
    ctx = vg.CreateOffScreenSH()
    vg.StartOffScreenSH(ctx, width, height)
    
    vg.Setfv(vg.CLEAR_COLOR, 4, [1.,1.,1.,1.])
    vg.Clear(0, 0, width, height)
    
    # center on bounding box
    box = renderer.bounds
    scale = min(width/box.width, height/box.height)
    
    vg.Seti(vg.MATRIX_MODE, vg.MATRIX_PATH_USER_TO_SURFACE)
    vg.LoadIdentity()
    
    vg.Scale(scale, scale)
    vg.Translate(0., 1.5*box.height)
    vg.Scale(1., -1.)
    vg.Translate(-box.minx, -box.miny + .5*box.height)
    
    renderer.render()
    vg.EndOffScreenSH(ctx, pixels)
    vg.DestroyOffScreenSH(ctx)
    
    img = Fl.RGB_Image(width,height, 4, 0, pixels)
    
    widget.set_image(img)
    window.show()
    Fl.run()

Esempio n. 22
0
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl

import Common.Graphics.GL as gl

class TestWidget(Fl.Gl_Window):
    def __init__(self, X, Y, W, H, L = ''):
        Fl.Gl_Window.__init__(self, X, Y, W, H, L)
        
    def draw(self):
        gl.Disable(gl.LIGHTING)
        gl.ShadeModel(gl.FLAT)
        gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE)
        gl.LineWidth(2)
        gl.Color4d(1.,0.,0.,1.)
        
        gl.Begin(gl.LINES)
        gl.Vertex3d(-1.,-1.,-1.)
        gl.Vertex3d(1.,1.,1.)
        gl.End()

window = Fl.Window(400,420)
widget = TestWidget(10,10,380,400)
window.end()
window.resizable(widget)
window.show()
widget.show()
widget.redraw()
Fl.run()
Esempio n. 23
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl

window = Fl.Window(400, 420)

buffer = Fl.Text_Buffer()
print buffer.length()
buffer.append('testing')
print buffer.length()

widget = Fl.Text_Display(10, 10, 380, 400)
widget.buffer(buffer)

window.end()
window.show()
Fl.run()
Esempio n. 24
0
def exitcb(widget, data):
    Fl.exit()
Esempio n. 25
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl

window = Fl.Window(400, 420)

output = Fl.Output(100, 20, 200, 30, "Fl_Output")
output.value('single text line')

moutput = Fl.Multiline_Output(100, 60, 200, 70, "Fl_Multiline_Output")
moutput.value('first text line\nsecond text line')

window.end()
window.show()
Fl.run()
Esempio n. 26
0
# -*- coding: utf-8 -*-
import sys
sys.path.append('..')
import svgplotlib.FLTK as Fl


def cb(widget, data):
    print 'CB: ', widget.get_label(), widget.get_value()


window = Fl.Window(400, 420)
input = []
y = 10
input.append(Fl.Input(70, y, 300, 30, "Normal:"))
y += 35
input.append(Fl.Float_Input(70, y, 300, 30, "Float:"))
y += 35
input.append(Fl.Int_Input(70, y, 300, 30, "Int:"))
y += 35
input.append(Fl.Multiline_Input(70, y, 300, 100, "&Multiline:"))
y += 35

for widget in input:
    widget.callback(cb)

window.end()
window.show()
Fl.run()