more work on Kivy
This commit is contained in:
parent
f40c99472d
commit
e7de822f42
12
kt.py
12
kt.py
|
|
@ -9,16 +9,18 @@ from kivy.graphics import Color, Ellipse, Line
|
||||||
|
|
||||||
Builder.load_file("lightningbeam.kv")
|
Builder.load_file("lightningbeam.kv")
|
||||||
|
|
||||||
class Lightningbeam(TabbedPanel):
|
class LightningbeamPanel(TabbedPanel):
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class KivyCanvas(Widget):
|
||||||
|
def on_touch_down(self, touch):
|
||||||
|
print touch.button
|
||||||
|
|
||||||
class MyPaintApp(App):
|
class LightningbeamApp(App):
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
return Lightningbeam()
|
return LightningbeamPanel()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
MyPaintApp().run()
|
LightningbeamApp().run()
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
#:kivy 1.0
|
#:kivy 1.0
|
||||||
#:import ActionScriptLexer pygments.lexers.ActionScriptLexer
|
#:import ActionScriptLexer pygments.lexers.ActionScriptLexer
|
||||||
|
|
||||||
<Lightningbeam>:
|
<KivyCanvas>:
|
||||||
|
|
||||||
|
|
||||||
|
<LightningbeamPanel>:
|
||||||
do_default_tab: False
|
do_default_tab: False
|
||||||
TabbedPanelItem:
|
TabbedPanelItem:
|
||||||
text: 'Drawing'
|
text: 'Drawing'
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
orientation: "vertical"
|
orientation: "vertical"
|
||||||
|
KivyCanvas:
|
||||||
|
|
||||||
TabbedPanelItem:
|
TabbedPanelItem:
|
||||||
text: 'Tools'
|
text: 'Tools'
|
||||||
|
|
@ -25,7 +29,7 @@
|
||||||
Button:
|
Button:
|
||||||
text: "Ellipse"
|
text: "Ellipse"
|
||||||
Button:
|
Button:
|
||||||
text: "Painbrush"
|
text: "Paintbrush"
|
||||||
TabbedPanelItem:
|
TabbedPanelItem:
|
||||||
text: 'ActionScript'
|
text: 'ActionScript'
|
||||||
CodeInput:
|
CodeInput:
|
||||||
|
|
|
||||||
|
|
@ -569,6 +569,8 @@ if svlgui.SYSTEM == "gtk":
|
||||||
MainWindow = lightningbeam_windows.MainWindow()
|
MainWindow = lightningbeam_windows.MainWindow()
|
||||||
elif svlgui.SYSTEM=="osx":
|
elif svlgui.SYSTEM=="osx":
|
||||||
MainWindow = lightningbeam_windows.MainWindowOSX()
|
MainWindow = lightningbeam_windows.MainWindowOSX()
|
||||||
|
elif svlgui.SYSTEM=="kivy":
|
||||||
|
MainWindow = lightningbeam_windows.MainWindowKivy()
|
||||||
elif svlgui.SYSTEM=="html":
|
elif svlgui.SYSTEM=="html":
|
||||||
MainWindow = lightningbeam_windows.MainWindowHTML()
|
MainWindow = lightningbeam_windows.MainWindowHTML()
|
||||||
elif svlgui.SYSTEM=="pyglet":
|
elif svlgui.SYSTEM=="pyglet":
|
||||||
|
|
|
||||||
|
|
@ -438,7 +438,10 @@ class MainWindowHTML:
|
||||||
[self.stage,self.toolbox._int(),self.scriptwindow._int(),self.timelinebox._int()+2,0,"nsew", "hv"] )
|
[self.stage,self.toolbox._int(),self.scriptwindow._int(),self.timelinebox._int()+2,0,"nsew", "hv"] )
|
||||||
self.window.add(self.frame)
|
self.window.add(self.frame)
|
||||||
|
|
||||||
|
class MainWindowKivy:
|
||||||
|
def __init__(self):
|
||||||
|
from kivy.lang import Builder
|
||||||
|
Builder.load_file("lightningbeam.kv")
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
a = MainWindow()
|
a = MainWindow()
|
||||||
|
|
|
||||||
60
svlgui.py
60
svlgui.py
|
|
@ -136,6 +136,8 @@ class Color (object):
|
||||||
retval = "var "+self.val.split('/')[-1].replace(' ','_').replace('.','_')+" = new Image();\n"
|
retval = "var "+self.val.split('/')[-1].replace(' ','_').replace('.','_')+" = new Image();\n"
|
||||||
retval = retval+self.val.split('/')[-1].replace(' ','_').replace('.','_')+".src = \""+self.val.split("/")[-1]+"\";\n"
|
retval = retval+self.val.split('/')[-1].replace(' ','_').replace('.','_')+".src = \""+self.val.split("/")[-1]+"\";\n"
|
||||||
return retval
|
return retval
|
||||||
|
def print_json(self):
|
||||||
|
return {'type':'Color','arguments':{'val':self.val}}
|
||||||
def rgb2hex(r, g, b, a=1):
|
def rgb2hex(r, g, b, a=1):
|
||||||
r=hex(int(r*255)).split("x")[1].zfill(2)
|
r=hex(int(r*255)).split("x")[1].zfill(2)
|
||||||
g=hex(int(g*255)).split("x")[1].zfill(2)
|
g=hex(int(g*255)).split("x")[1].zfill(2)
|
||||||
|
|
@ -203,6 +205,7 @@ if sys.platform=="linux2":
|
||||||
import pickle
|
import pickle
|
||||||
import tarfile
|
import tarfile
|
||||||
import tempfile
|
import tempfile
|
||||||
|
'''
|
||||||
import GUI # Using PyGUI. Experimental.
|
import GUI # Using PyGUI. Experimental.
|
||||||
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
from GUI import Window as OSXWindow, Button as OSXButton, Image as OSXImage
|
||||||
from GUI import Frame as OSXFrame, Color as OSXColor, Grid as OSXGrid, CheckBox as OSXCheckBox
|
from GUI import Frame as OSXFrame, Color as OSXColor, Grid as OSXGrid, CheckBox as OSXCheckBox
|
||||||
|
|
@ -220,7 +223,16 @@ if sys.platform=="linux2":
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import Image as PILImage
|
import Image as PILImage
|
||||||
from GUI.Geometry import offset_rect, rect_sized
|
SYSTEM="osx"
|
||||||
|
from GUI.Geometry import offset_rect, rect_sized'''
|
||||||
|
|
||||||
|
from kivy.app import App # Using Kivy. Very experimental.
|
||||||
|
from kivy.uix.widget import Widget
|
||||||
|
from kivy.uix.codeinput import CodeInput
|
||||||
|
from kivy.uix.tabbedpanel import TabbedPanel
|
||||||
|
from kivy.uix.button import Button
|
||||||
|
from kivy.graphics import Color, Ellipse, Line
|
||||||
|
SYSTEM="kivy"
|
||||||
|
|
||||||
#If we can import this, we are in the install directory. Mangle media paths accordingly.
|
#If we can import this, we are in the install directory. Mangle media paths accordingly.
|
||||||
try:
|
try:
|
||||||
|
|
@ -228,7 +240,6 @@ if sys.platform=="linux2":
|
||||||
except:
|
except:
|
||||||
media_path = ""
|
media_path = ""
|
||||||
#app = GUI.application()
|
#app = GUI.application()
|
||||||
SYSTEM="osx"
|
|
||||||
TEMPDIR = "/tmp"
|
TEMPDIR = "/tmp"
|
||||||
FONT = u'Times New Roman'
|
FONT = u'Times New Roman'
|
||||||
'''
|
'''
|
||||||
|
|
@ -379,6 +390,31 @@ if SYSTEM=="osx":
|
||||||
|
|
||||||
|
|
||||||
app = Lightningbeam()
|
app = Lightningbeam()
|
||||||
|
elif SYSTEM=="kivy":
|
||||||
|
class Lightningbeam(App):
|
||||||
|
def build(self):
|
||||||
|
return LightningbeamPanel()
|
||||||
|
class LightningbeamPanel(TabbedPanel):
|
||||||
|
pass
|
||||||
|
class KivyCanvas(Widget):
|
||||||
|
def draw(self):
|
||||||
|
with self.canvas:
|
||||||
|
for i in self.objs:
|
||||||
|
try:
|
||||||
|
i.draw(None)
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
def on_touch_down(self, touch):
|
||||||
|
x, y = touch.x, touch.y
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
for i in self.objs:
|
||||||
|
i._onMouseDown(x,y,button=touch.button, clicks=(3 if touch.is_triple_click else (2 if touch.is_double_click else 1)))
|
||||||
|
except ObjectDeletedError:
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
self.draw()
|
||||||
elif SYSTEM=="html":
|
elif SYSTEM=="html":
|
||||||
app = ""
|
app = ""
|
||||||
|
|
||||||
|
|
@ -1153,6 +1189,9 @@ class Canvas(Widget):
|
||||||
pass
|
pass
|
||||||
self.canvas = OSXCanvas(extent = (width, height), scrolling = 'hv')
|
self.canvas = OSXCanvas(extent = (width, height), scrolling = 'hv')
|
||||||
self.canvas.objs = self.objs
|
self.canvas.objs = self.objs
|
||||||
|
elif SYSTEM=="kivy":
|
||||||
|
|
||||||
|
self.canvas = KivyCanvas()
|
||||||
elif SYSTEM=="html":
|
elif SYSTEM=="html":
|
||||||
global ids
|
global ids
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -1185,6 +1224,8 @@ class Canvas(Widget):
|
||||||
def draw(self):
|
def draw(self):
|
||||||
if SYSTEM=="gtk":
|
if SYSTEM=="gtk":
|
||||||
self.expose_event(self.canvas, "draw_event", self.objs)
|
self.expose_event(self.canvas, "draw_event", self.objs)
|
||||||
|
elif SYSTEM=="kivy":
|
||||||
|
self.canvas.draw()
|
||||||
elif SYSTEM in ["osx", "android"]:
|
elif SYSTEM in ["osx", "android"]:
|
||||||
self.canvas.invalidate_rect((0,0,self.canvas.extent[0],self.canvas.extent[1]))
|
self.canvas.invalidate_rect((0,0,self.canvas.extent[0],self.canvas.extent[1]))
|
||||||
elif SYSTEM=="html":
|
elif SYSTEM=="html":
|
||||||
|
|
@ -1192,6 +1233,8 @@ class Canvas(Widget):
|
||||||
def is_focused(self):
|
def is_focused(self):
|
||||||
if SYSTEM=="osx":
|
if SYSTEM=="osx":
|
||||||
return self.canvas.is_target()
|
return self.canvas.is_target()
|
||||||
|
else:
|
||||||
|
return false
|
||||||
def add(self, obj, x, y):
|
def add(self, obj, x, y):
|
||||||
obj.x = x
|
obj.x = x
|
||||||
obj.y = y
|
obj.y = y
|
||||||
|
|
@ -1493,6 +1536,8 @@ class Image(object):
|
||||||
pass
|
pass
|
||||||
def print_sc(self):
|
def print_sc(self):
|
||||||
return ".png "+self.name+" \""+self.path+"\"\n"
|
return ".png "+self.name+" \""+self.path+"\"\n"
|
||||||
|
def print_json(self):
|
||||||
|
return {'type':'Image','arguments':{'image':self.image,'x':self.x,'y':self.y,'animated':self.animated,'canvas':None,'htiles':self.htiles,'vtiles':self.vtiles,'skipl':false}}
|
||||||
|
|
||||||
class Shape (object):
|
class Shape (object):
|
||||||
def __init__(self,x=0,y=0,rotation=0,fillcolor=None,linecolor=None):
|
def __init__(self,x=0,y=0,rotation=0,fillcolor=None,linecolor=None):
|
||||||
|
|
@ -1638,6 +1683,10 @@ class Shape (object):
|
||||||
else:
|
else:
|
||||||
cr.stroke()
|
cr.stroke()
|
||||||
cr.grestore()
|
cr.grestore()
|
||||||
|
elif SYSTEM=="kivy":
|
||||||
|
Color(1, 1, 0)
|
||||||
|
d = 30.
|
||||||
|
Ellipse(pos=(self.x - d / 2, self.y - d / 2), size=(d, d))
|
||||||
elif SYSTEM=="html":
|
elif SYSTEM=="html":
|
||||||
tb = ""
|
tb = ""
|
||||||
tb+="cr.save()\n"
|
tb+="cr.save()\n"
|
||||||
|
|
@ -1768,6 +1817,13 @@ class Shape (object):
|
||||||
retval += self.name+".fill = \""+self.fillcolor.rgb+"\";\n"+self.name+".line = \""+self.linecolor.rgb+"\";\n"
|
retval += self.name+".fill = \""+self.fillcolor.rgb+"\";\n"+self.name+".line = \""+self.linecolor.rgb+"\";\n"
|
||||||
retval += self.name+".filled = "+str(self.filled).lower()+";\n"
|
retval += self.name+".filled = "+str(self.filled).lower()+";\n"
|
||||||
return retval
|
return retval
|
||||||
|
def print_json(self):
|
||||||
|
return {'type':'Shape','arguments':{'x':self.x,
|
||||||
|
'y':self.y,
|
||||||
|
'rotation':self.rotation,
|
||||||
|
'linecolor':self.linecolor.print_json(),
|
||||||
|
'fillcolor':self.fillcolor.print_json()},
|
||||||
|
'properties':{'shapedata':self.shapedata}}
|
||||||
|
|
||||||
class Text (object):
|
class Text (object):
|
||||||
def __init__(self,text="",x=0,y=0):
|
def __init__(self,text="",x=0,y=0):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue