minor code reformatting
This commit is contained in:
parent
f07f5b23bc
commit
21896bea8e
@ -33,12 +33,14 @@ class SketchWidget:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# try double-buffered
|
# try double-buffered
|
||||||
self.glconfig = gtk.gdkgl.Config(mode = (gtk.gdkgl.MODE_RGB |
|
self.glconfig = gtk.gdkgl.Config(
|
||||||
|
mode = (gtk.gdkgl.MODE_RGB |
|
||||||
gtk.gdkgl.MODE_DOUBLE |
|
gtk.gdkgl.MODE_DOUBLE |
|
||||||
gtk.gdkgl.MODE_DEPTH))
|
gtk.gdkgl.MODE_DEPTH))
|
||||||
except gtk.gdkgl.NoMatches:
|
except gtk.gdkgl.NoMatches:
|
||||||
# try single-buffered
|
# try single-buffered
|
||||||
self.glconfig = gtk.gdkgl.Config(mode = (gtk.gdkgl.MODE_RGB |
|
self.glconfig = gtk.gdkgl.Config(
|
||||||
|
mode = (gtk.gdkgl.MODE_RGB |
|
||||||
gtk.gdkgl.MODE_DEPTH))
|
gtk.gdkgl.MODE_DEPTH))
|
||||||
|
|
||||||
self.widget = gtk.gtkgl.DrawingArea(self.glconfig)
|
self.widget = gtk.gtkgl.DrawingArea(self.glconfig)
|
||||||
@ -51,7 +53,8 @@ class SketchWidget:
|
|||||||
self.widget.connect('motion-notify-event', self.motion_event)
|
self.widget.connect('motion-notify-event', self.motion_event)
|
||||||
self.widget.connect('scroll-event', self.scroll_event)
|
self.widget.connect('scroll-event', self.scroll_event)
|
||||||
|
|
||||||
self.widget.add_events(gtk.gdk.POINTER_MOTION_MASK
|
self.widget.add_events(
|
||||||
|
gtk.gdk.POINTER_MOTION_MASK
|
||||||
| gtk.gdk.BUTTON_PRESS_MASK
|
| gtk.gdk.BUTTON_PRESS_MASK
|
||||||
| gtk.gdk.BUTTON_RELEASE_MASK
|
| gtk.gdk.BUTTON_RELEASE_MASK
|
||||||
| gtk.gdk.SCROLL_MASK)
|
| gtk.gdk.SCROLL_MASK)
|
||||||
@ -117,7 +120,8 @@ class SketchWidget:
|
|||||||
self.drawVertical(Vertical(self.drawingLine, 0,
|
self.drawVertical(Vertical(self.drawingLine, 0,
|
||||||
self.drawingLine, 1))
|
self.drawingLine, 1))
|
||||||
elif self.drawingLine.getPt(0)[1] == self.drawingLine.getPt(1)[1]:
|
elif self.drawingLine.getPt(0)[1] == self.drawingLine.getPt(1)[1]:
|
||||||
self.drawHorizontal(Horizontal(self.drawingLine, 0,
|
self.drawHorizontal(
|
||||||
|
Horizontal(self.drawingLine, 0,
|
||||||
self.drawingLine, 1))
|
self.drawingLine, 1))
|
||||||
|
|
||||||
if gldrawable.is_double_buffered():
|
if gldrawable.is_double_buffered():
|
||||||
@ -221,12 +225,14 @@ class SketchWidget:
|
|||||||
if self.drawingLine is not None:
|
if self.drawingLine is not None:
|
||||||
self.sketch.shapes.append(self.drawingLine)
|
self.sketch.shapes.append(self.drawingLine)
|
||||||
if self.drawingLine.getPt(0)[0] == self.drawingLine.getPt(1)[0]:
|
if self.drawingLine.getPt(0)[0] == self.drawingLine.getPt(1)[0]:
|
||||||
self.sketch.constraints.append(Vertical(self.drawingLine, 0,
|
self.sketch.constraints.append(
|
||||||
|
Vertical(self.drawingLine, 0,
|
||||||
|
self.drawingLine, 1))
|
||||||
|
elif (self.drawingLine.getPt(0)[1]
|
||||||
|
== self.drawingLine.getPt(1)[1]):
|
||||||
|
self.sketch.constraints.append(
|
||||||
|
Horizontal(self.drawingLine, 0,
|
||||||
self.drawingLine, 1))
|
self.drawingLine, 1))
|
||||||
elif self.drawingLine.getPt(0)[1] \
|
|
||||||
== self.drawingLine.getPt(1)[1]:
|
|
||||||
self.sketch.constraints.append(Horizontal(
|
|
||||||
self.drawingLine, 0, self.drawingLine, 1))
|
|
||||||
start = self.drawingLine.getPt(1)
|
start = self.drawingLine.getPt(1)
|
||||||
self.drawingLine = Line(start[0], start[1], start[0], start[1])
|
self.drawingLine = Line(start[0], start[1], start[0], start[1])
|
||||||
self.queue_redraw()
|
self.queue_redraw()
|
||||||
@ -258,13 +264,13 @@ class SketchWidget:
|
|||||||
angle *= 180.0 / math.pi
|
angle *= 180.0 / math.pi
|
||||||
def within(a, b, d): return abs(a - b) < d
|
def within(a, b, d): return abs(a - b) < d
|
||||||
def snaps_to(q): return within(angle, q, self.snap_angle)
|
def snaps_to(q): return within(angle, q, self.snap_angle)
|
||||||
if (snaps_to(-180) or snaps_to(180) or snaps_to(0)) \
|
if ((snaps_to(-180) or snaps_to(180) or snaps_to(0))
|
||||||
and within(start[1], this_pt[1],
|
and within(start[1], this_pt[1],
|
||||||
self.screenDistToDist(self.snap_dist)):
|
self.screenDistToDist(self.snap_dist))):
|
||||||
this_pt = (this_pt[0], start[1])
|
this_pt = (this_pt[0], start[1])
|
||||||
elif (snaps_to(-90) or snaps_to(90)) \
|
elif ((snaps_to(-90) or snaps_to(90))
|
||||||
and within(start[0], this_pt[0],
|
and within(start[0], this_pt[0],
|
||||||
self.screenDistToDist(self.snap_dist)):
|
self.screenDistToDist(self.snap_dist))):
|
||||||
this_pt = (start[0], this_pt[1])
|
this_pt = (start[0], this_pt[1])
|
||||||
self.drawingLine.setPt(1, this_pt)
|
self.drawingLine.setPt(1, this_pt)
|
||||||
self.queue_redraw()
|
self.queue_redraw()
|
||||||
@ -290,8 +296,7 @@ class SketchWidget:
|
|||||||
self.queue_redraw()
|
self.queue_redraw()
|
||||||
|
|
||||||
def queue_redraw(self):
|
def queue_redraw(self):
|
||||||
self.widget.queue_draw_area(0, 0,
|
self.widget.queue_draw_area(0, 0, *map(int, self.size))
|
||||||
int(self.size[0]), int(self.size[1]))
|
|
||||||
|
|
||||||
def drawShapes(self):
|
def drawShapes(self):
|
||||||
for shape in self.sketch:
|
for shape in self.sketch:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user