Ported a few changes to Linux

This commit is contained in:
Skyler Lehmkuhl 2013-01-18 13:00:05 -05:00
parent a0d193d994
commit 058b7a3143
6 changed files with 60 additions and 16 deletions

View File

@ -49,4 +49,11 @@ class Color(GColor):
except TypeError:
return m(None, None, None, None)
class ImageColor(object):
"""docstring for ImageColor"""
def __init__(self, red, green, blue, alpha = 1.0, image = False, im = ''):
super(ImageColor, self).__init__()
self.arg = arg
export(Color)

View File

@ -5,13 +5,14 @@
#--------------------------------------------------------------------
from math import sin, cos, pi, floor
from cairo import OPERATOR_OVER, OPERATOR_SOURCE, FILL_RULE_EVEN_ODD
from cairo import OPERATOR_OVER, OPERATOR_SOURCE, FILL_RULE_EVEN_ODD, ImageSurface, SurfacePattern
from GUI import export
from GUI.Geometry import sect_rect
from GUI.StdFonts import application_font
from GUI.StdColors import black, white
from GUI.GCanvases import Canvas as GCanvas
from GUI.GCanvasPaths import CanvasPaths as GCanvasPaths
import sys
deg = pi / 180
twopi = 2 * pi
@ -111,20 +112,36 @@ class Canvas(GCanvas, GCanvasPaths):
def newpath(self):
self._gtk_ctx.new_path()
self.minx = sys.maxint
self.miny = sys.maxint
self.maxx = -sys.maxint/2
self.maxy = -sys.maxint/2
def moveto(self, x, y):
self._gtk_ctx.move_to(x, y)
self.minx = min(self.minx, x)
self.miny = min(self.miny, y)
self.maxx = max(self.maxx, x)
self.maxy = max(self.maxy, y)
def rmoveto(self, x, y):
self._gtk_ctx.rel_move_to(x, y)
def lineto(self, x, y):
self.minx = min(self.minx, x)
self.miny = min(self.miny, y)
self.maxx = max(self.maxx, x)
self.maxy = max(self.maxy, y)
self._gtk_ctx.line_to(x, y)
def rlineto(self, x, y):
self._gtk_ctx.rel_line_to(x, y)
def curveto(self, p1, p2, p3):
self.minx = min(self.minx, p1[0], p2[0], p3[0])
self.miny = min(self.miny, p1[1], p2[1], p3[1])
self.maxx = max(self.maxx, p1[0], p2[0], p3[0])
self.maxy = max(self.maxy, p1[1], p2[1], p3[1])
self._gtk_ctx.curve_to(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1])
def rcurveto(self, p1, p2, p3):
@ -152,6 +169,15 @@ class Canvas(GCanvas, GCanvasPaths):
def fill(self):
ctx = self._gtk_ctx
#ctx.set_source_rgba(*self._state.fillcolor._rgba)
if self.fillcolor.image:
# surface =
ctx.set_source_pixbuf(self.fillcolor.image, 0, 0)
ctx.save()
print (self.maxx-self.minx)*1.0/self.fillcolor.image.get_width()
self._gtk_ctx.scale((self.maxx-self.minx)*1.0/self.fillcolor.image.get_width(), 1)
ctx.fill_preserve()
ctx.restore()
else:
ctx.set_source_color(self._state.fillcolor._gdk_color)
ctx.fill_preserve()

View File

@ -17,8 +17,13 @@ class Color(GColor):
_from_gdk_color = classmethod(_from_gdk_color)
def __init__(self, red, green, blue, alpha = 1.0):
# def __init__(self, red, green, blue, alpha = 1.0):
def __init__(self, red, green, blue, alpha = 1.0, image = False, im = ''):
self._rgba = (red, green, blue, alpha)
self.image = image
if image:
self.image = im._gdk_pixbuf
else:
gdk_color = gdk.Color()
gdk_color.red = int(red * 65535)
gdk_color.green = int(green * 65535)

View File

@ -1,5 +1,5 @@
Package: lightningbeam
Version: 1.0.0-alpha2
Version: 1.0.1-alpha2
Section: graphics
Priority: optional
Architecture: all

View File

@ -635,8 +635,10 @@ def import_to_stage(widget=None):
# im = svlgui.Image(thefile)
if svlgui.PLATFORM=="osx":
# sips is OSX's built-in image manipulation tool
os.system("sips -s format png "+thefile+" --out "+svlgui.SECURETEMPDIR+"/"+thefile.split("/")[-1])
thefile = svlgui.SECURETEMPDIR+"/"+thefile.split("/")[-1]
os.system("sips -s format png "+thefile+" --out "+svlgui.SECURETEMPDIR+"/"+".".join(thefile.split("/")[-1].split(".")[:-1])+".png")
elif "linux" in svlgui.PLATFORM:
os.system("convert "+thefile+" "+svlgui.SECURETEMPDIR+"/"+".".join(thefile.split("/")[-1].split(".")[:-1])+".png")
thefile = svlgui.SECURETEMPDIR+"/"+".".join(thefile.split("/")[-1].split(".")[:-1])+".png"
im = box(100,100,200,200,svlgui.Color(thefile))
print im.filled
im.onMouseDown = onMouseDownObj

View File

@ -337,6 +337,7 @@ if SYSTEM=="osx":
m.save_cmd.enabled = 1
m.save_as_cmd.enabled = 1
m.open_cmd.enabled = 1
m.new_cmd.enabled = 1
m.undo_cmd.enabled = 1
m.redo_cmd.enabled = 1
m.run_file.enabled = 1
@ -521,9 +522,9 @@ class Menu(Widget):
if top:
global menus
self.mb = GUI.MenuList()
tool_menu = GUI.Menu("Tools", [("Execute", "test_cmd")])
# tool_menu = GUI.Menu("Tools", [("Execute", "test_cmd")])
menus = basic_menus(exclude = print_cmds)
menus.append(tool_menu)
# menus.append(tool_menu)
elif SYSTEM=="html":
pass
# I need to figure out how the menus work here.
@ -568,7 +569,7 @@ def menufuncs(j):
#menu = GUI.Menu("Test", [("Run", 'run_file')])
menus.append(menu)
else:
cmds={"Save":"save_cmd", "Save As":"save_as_cmd", "Open":"open_cmd","About Lightningbeam...":"about_cmd",\
cmds={"New":"new_cmd", "Save":"save_cmd", "Save As":"save_as_cmd", "Open":"open_cmd","About Lightningbeam...":"about_cmd",\
"Preferences":"preferences_cmd", "Undo":"undo_cmd", "Redo":"redo_cmd"}
[setattr(app,cmds[k[0]],k[1]) for k in i if (k[0] in cmds)]
@ -1106,7 +1107,10 @@ class Canvas(Widget):
x, y = event.position
for i in self.objs:
try:
if event.button:
i._onMouseDrag(x, y, button={"left":1,"right":2,"middle":3}[event.button])
else:
i._onMouseDrag(x, y, button=None)
except:
traceback.print_exc()
self.invalidate_rect([0,0,self.extent[0],self.extent[1]])