Skip to content

Commit ce38688

Browse files
author
Tom De Smedt
committed
Small bug fixes for text() and canvas.fps.
1 parent f8c33b1 commit ce38688

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

nodebox/graphics/context.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ def complement(clr):
435435
""" Returns the color opposite on the color wheel.
436436
The complementary color contrasts with the given color.
437437
"""
438+
if not isinstance(clr, Color):
439+
clr = Color(clr)
438440
return clr.rotate(180)
439441

440442
def analog(clr, angle=20, d=0.1):
@@ -2092,7 +2094,7 @@ def label(str="", width=None, height=None, **kwargs):
20922094
# FormattedDocument allows individual styling of characters - see Text.style().
20932095
label = pyglet.text.Label(batch=_label_batch)
20942096
label.begin_update()
2095-
label.document = pyglet.text.document.FormattedDocument(str)
2097+
label.document = pyglet.text.document.FormattedDocument(str or " ")
20962098
label.width = width
20972099
label.height = height
20982100
label.font_name = fontname
@@ -2104,6 +2106,9 @@ def label(str="", width=None, height=None, **kwargs):
21042106
label.set_style("align", align)
21052107
label.set_style("line_spacing", lineheight * fontsize)
21062108
label.color = [int(ch*255) for ch in fill]
2109+
if str == "":
2110+
# Empty string "" does not set properties so we used " " first.
2111+
label.text = str
21072112
label.end_update()
21082113
return label
21092114

@@ -3479,8 +3484,8 @@ def __init__(self, width=640, height=480, name="NodeBox for OpenGL", resizable=F
34793484
EventHandler.__init__(self)
34803485
self.profiler = Profiler(self)
34813486
self._window = pyglet.window.Window(**window)
3482-
self._fps = None # Frames per second.
3483-
self._frame = 60 # The current frame.
3487+
self._fps = 60 # Frames per second.
3488+
self._frame = 0 # The current frame.
34843489
self._elapsed = 0 # dt = time elapsed since last frame.
34853490
self._active = False # Application is running?
34863491
self.paused = False # Pause animation?
@@ -3905,7 +3910,6 @@ def run(self, draw=None, setup=None, update=None, stop=None):
39053910
self.set_method(update, name="update")
39063911
if isinstance(stop, FunctionType):
39073912
self.set_method(stop, name="stop")
3908-
self._frame += 1
39093913
self._setup()
39103914
self.fps = self._fps # Schedule the _update and _draw events.
39113915
pyglet.app.run()

0 commit comments

Comments
 (0)