Added a logger for more maintainable and configurable debug messages.
Fixed a bug with context setting so that all children are updated on context update.
This commit is contained in:
parent
76be0b0d23
commit
49a630e8ac
5 changed files with 28 additions and 6 deletions
1
jgui/logger/__init__.py
Normal file
1
jgui/logger/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from jgui.logger.logger import *
|
||||||
6
jgui/logger/logger.py
Normal file
6
jgui/logger/logger.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
from jgui.settings import DEBUG
|
||||||
|
|
||||||
|
def log(*args):
|
||||||
|
if DEBUG:
|
||||||
|
print(*args)
|
||||||
1
jgui/settings.py
Normal file
1
jgui/settings.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
DEBUG=True
|
||||||
|
|
@ -4,6 +4,7 @@ import pangocairo as pc
|
||||||
import math
|
import math
|
||||||
from .structures import Size, Position, Rectangle, Color, BorderRadius, Padding
|
from .structures import Size, Position, Rectangle, Color, BorderRadius, Padding
|
||||||
from ..events.events import WindowEventSource
|
from ..events.events import WindowEventSource
|
||||||
|
from ..logger import log
|
||||||
|
|
||||||
debug = True
|
debug = True
|
||||||
|
|
||||||
|
|
@ -289,7 +290,7 @@ class Window(WindowEventSource, WindowSurface):
|
||||||
|
|
||||||
position = Position.from_value(kwargs.pop('position', Position()))
|
position = Position.from_value(kwargs.pop('position', Position()))
|
||||||
size = Size.from_value(kwargs.pop('size', Size()))
|
size = Size.from_value(kwargs.pop('size', Size()))
|
||||||
self.context = kwargs.pop('context', None)
|
self._context = kwargs.pop('context', None)
|
||||||
self.min_size = Size.from_value(kwargs.pop('min_size', Size(1,1)))
|
self.min_size = Size.from_value(kwargs.pop('min_size', Size(1,1)))
|
||||||
self.max_size = Size.from_value(kwargs.pop('max_size', Size(-1,-1)))
|
self.max_size = Size.from_value(kwargs.pop('max_size', Size(-1,-1)))
|
||||||
self.corner_handle_size = Size.from_value(kwargs.pop('corner_handle_size', Size(20, 20)))
|
self.corner_handle_size = Size.from_value(kwargs.pop('corner_handle_size', Size(20, 20)))
|
||||||
|
|
@ -318,6 +319,7 @@ class Window(WindowEventSource, WindowSurface):
|
||||||
self.accept('mouse-move', self.process_mouse_move)
|
self.accept('mouse-move', self.process_mouse_move)
|
||||||
self.size = size
|
self.size = size
|
||||||
self.position = position
|
self.position = position
|
||||||
|
self.context = self._context
|
||||||
self.resizable = kwargs.pop('resizable', self._resizable)
|
self.resizable = kwargs.pop('resizable', self._resizable)
|
||||||
self.draggable = kwargs.pop('draggable', self._draggable)
|
self.draggable = kwargs.pop('draggable', self._draggable)
|
||||||
|
|
||||||
|
|
@ -638,7 +640,7 @@ class Window(WindowEventSource, WindowSurface):
|
||||||
|
|
||||||
def inject_mouse_down(self, button):
|
def inject_mouse_down(self, button):
|
||||||
if self.mouse_inside():
|
if self.mouse_inside():
|
||||||
print button, self.name
|
log(button, self.name)
|
||||||
self.mouse_inputs[button] = True
|
self.mouse_inputs[button] = True
|
||||||
self.mouse_down = True
|
self.mouse_down = True
|
||||||
self.grab_focus()
|
self.grab_focus()
|
||||||
|
|
@ -651,7 +653,7 @@ class Window(WindowEventSource, WindowSurface):
|
||||||
|
|
||||||
def inject_mouse_up(self, button):
|
def inject_mouse_up(self, button):
|
||||||
if self.mouse_held() and self.mouse_inputs[button]:
|
if self.mouse_held() and self.mouse_inputs[button]:
|
||||||
print button+'-up', self.name
|
log(button+'-up', self.name)
|
||||||
self.mouse_down = False
|
self.mouse_down = False
|
||||||
self.mouse_inputs[button] = False
|
self.mouse_inputs[button] = False
|
||||||
self.dispatch('{}-up'.format(button), self, self.mouse_pos)
|
self.dispatch('{}-up'.format(button), self, self.mouse_pos)
|
||||||
|
|
@ -694,7 +696,7 @@ class Window(WindowEventSource, WindowSurface):
|
||||||
|
|
||||||
def release_focus(self):
|
def release_focus(self):
|
||||||
if self.focused:
|
if self.focused:
|
||||||
print 'released', self.name
|
log('released', self.name)
|
||||||
self.focused = False
|
self.focused = False
|
||||||
self.mouse_down = False
|
self.mouse_down = False
|
||||||
#clear events that may have been triggered
|
#clear events that may have been triggered
|
||||||
|
|
@ -764,16 +766,26 @@ class Window(WindowEventSource, WindowSurface):
|
||||||
if not self.mouse_held():
|
if not self.mouse_held():
|
||||||
if mouse_focus:
|
if mouse_focus:
|
||||||
if not self.mouse_in:
|
if not self.mouse_in:
|
||||||
print 'mouse-enter', self.name
|
log('mouse-enter', self.name)
|
||||||
self.dispatch('mouse-enter', self)
|
self.dispatch('mouse-enter', self)
|
||||||
self.dispatch('hover', self)
|
self.dispatch('hover', self)
|
||||||
self.mouse_in = True
|
self.mouse_in = True
|
||||||
else:
|
else:
|
||||||
if self.mouse_in:
|
if self.mouse_in:
|
||||||
print 'mouse-leave', self.name
|
log('mouse-leave', self.name)
|
||||||
self.dispatch('mouse-leave', self)
|
self.dispatch('mouse-leave', self)
|
||||||
self.mouse_in = False
|
self.mouse_in = False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def context(self):
|
||||||
|
return self._context
|
||||||
|
|
||||||
|
@context.setter
|
||||||
|
def context(self, context):
|
||||||
|
self._context = context
|
||||||
|
for child in self.children:
|
||||||
|
child.context = self._context
|
||||||
|
|
||||||
def add_child(self, child_window):
|
def add_child(self, child_window):
|
||||||
if child_window not in self.children:
|
if child_window not in self.children:
|
||||||
child_window.parent = self
|
child_window.parent = self
|
||||||
|
|
|
||||||
2
test.py
2
test.py
|
|
@ -64,6 +64,8 @@ class Test(ShowBase):
|
||||||
if width != self.width or height != self.height:
|
if width != self.width or height != self.height:
|
||||||
self.width, self.height = width, height
|
self.width, self.height = width, height
|
||||||
cairoTexture = Texture()
|
cairoTexture = Texture()
|
||||||
|
cairoTexture.setMagfilter(Texture.FTNearest)
|
||||||
|
cairoTexture.setMinfilter(Texture.FTNearest)
|
||||||
cairoTexture.setXSize(self.width)
|
cairoTexture.setXSize(self.width)
|
||||||
cairoTexture.setYSize(self.height)
|
cairoTexture.setYSize(self.height)
|
||||||
cairoTexture.setFormat(cairoTexture.FRgba8)
|
cairoTexture.setFormat(cairoTexture.FRgba8)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue