Skip to content

Commit

Permalink
Add more wrapper classes to avoid using panda3d.lui directly
Browse files Browse the repository at this point in the history
  • Loading branch information
tobspr committed Mar 14, 2016
1 parent 1160e9d commit 69e0a23
Show file tree
Hide file tree
Showing 35 changed files with 166 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Builtin/LUIButton.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from panda3d.lui import LUIObject
from LUIObject import LUIObject
from LUILayouts import LUIHorizontalStretchedLayout
from LUILabel import LUILabel
from LUIInitialState import LUIInitialState
Expand Down
3 changes: 2 additions & 1 deletion Builtin/LUICheckbox.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

from __future__ import division

from panda3d.lui import LUIObject, LUISprite
from LUIObject import LUIObject
from LUISprite import LUISprite
from LUILabel import LUILabel
from LUIInitialState import LUIInitialState

Expand Down
2 changes: 1 addition & 1 deletion Builtin/LUIFormattedLabel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from panda3d.core import LVecBase2i
from panda3d.lui import LUIObject
from LUIObject import LUIObject
from LUILabel import LUILabel
from LUIInitialState import LUIInitialState

Expand Down
3 changes: 2 additions & 1 deletion Builtin/LUIFrame.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

from __future__ import print_function

from panda3d.lui import LUIObject, LUISprite
from LUIObject import LUIObject
from LUISprite import LUISprite
from LUILayouts import LUICornerLayout
from LUIInitialState import LUIInitialState
from LUIScrollableRegion import LUIScrollableRegion
Expand Down
18 changes: 18 additions & 0 deletions Builtin/LUIHorizontalLayout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
This is a wrapper file. It contains no actual implementation
"""

from panda3d.lui import LUIHorizontalLayout as _LUIHorizontalLayout
from LUIInitialState import LUIInitialState

__all__ = ["LUIHorizontalLayout"]

class LUIHorizontalLayout(_LUIHorizontalLayout):
""" This is a wrapper class for the C++ LUIHorizontalLayout class, to be able to
use it in a more convenient way """

def __init__(self, parent=None, spacing=0.0, **kwargs):
_LUIHorizontalLayout.__init__(self, parent, spacing)
LUIInitialState.init(self, kwargs)
12 changes: 10 additions & 2 deletions Builtin/LUIInitialState.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ class LUIInitialState:
def __init__(self):
raise Exception("LUIInitialState is a static class")

@staticmethod
def init(obj, kwargs):
__mappings = {
"x": "left",
"y": "top",
"w": "width",
"h": "height"
}

@classmethod
def init(cls, obj, kwargs):
""" Applies the keyword arguments as properties """
for arg_name, arg_val in kwargs.items():
arg_name = cls.__mappings.get(arg_name, arg_name)
if hasattr(obj, arg_name):
setattr(obj, arg_name, arg_val)
else:
Expand Down
3 changes: 2 additions & 1 deletion Builtin/LUIInputField.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from panda3d.lui import LUIObject, LUISprite
from LUIObject import LUIObject
from LUISprite import LUISprite
from LUILabel import LUILabel
from LUIInitialState import LUIInitialState
from LUILayouts import LUIHorizontalStretchedLayout
Expand Down
8 changes: 8 additions & 0 deletions Builtin/LUIInputHandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
This is a wrapper file. It contains no actual implementation
"""

from panda3d.lui import LUIInputHandler as __LUIInputHandler
LUIInputHandler = __LUIInputHandler
3 changes: 2 additions & 1 deletion Builtin/LUILabel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from panda3d.lui import LUIObject, LUIText
from panda3d.lui import LUIText
from LUIObject import LUIObject
from LUIInitialState import LUIInitialState

__all__ = ["LUILabel"]
Expand Down
4 changes: 3 additions & 1 deletion Builtin/LUILayouts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

from __future__ import print_function, division

from panda3d.lui import LUIObject, LUISprite, LUIHorizontalLayout
from LUIObject import LUIObject
from LUISprite import LUISprite
from LUIHorizontalLayout import LUIHorizontalLayout
from direct.directnotify.DirectNotify import DirectNotify

from LUIInitialState import LUIInitialState
Expand Down
10 changes: 5 additions & 5 deletions Builtin/LUIObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"""

from panda3d.lui import LUIObject as __LUIObject
from .LUIInitialState import LUIInitialState
from panda3d.lui import LUIObject as _LUIObject
from LUIInitialState import LUIInitialState

__all__ = ["LUIObject"]

class LUIObject(__LUIObject):
class LUIObject(_LUIObject):
""" This is a wrapper class for the C++ LUIObject class, to be able to
use it in a more convenient way """

def __init__(self, x=0, y=0, w=-1, h=-1, solid=False, **kwargs):
LUIObject.__init__(self, x, y, w, h, solid)
def __init__(self, *args, **kwargs):
_LUIObject.__init__(self, *args)
LUIInitialState.init(self, kwargs)
3 changes: 2 additions & 1 deletion Builtin/LUIProgressbar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from panda3d.lui import LUIObject, LUISprite
from LUIObject import LUIObject
from LUISprite import LUISprite

from LUILayouts import LUIHorizontalStretchedLayout
from LUILabel import LUILabel
Expand Down
3 changes: 2 additions & 1 deletion Builtin/LUIRadiobox.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

from __future__ import division

from panda3d.lui import LUIObject, LUISprite
from LUIObject import LUIObject
from LUISprite import LUISprite
from LUIInitialState import LUIInitialState
from LUILabel import LUILabel

Expand Down
2 changes: 1 addition & 1 deletion Builtin/LUIRadioboxGroup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from panda3d.lui import LUIObject
from LUIObject import LUIObject

class LUIRadioboxGroup(LUIObject):

Expand Down
8 changes: 8 additions & 0 deletions Builtin/LUIRegion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
This is a wrapper file. It contains no actual implementation
"""

from panda3d.lui import LUIRegion as __LUIRegion
LUIRegion = __LUIRegion
3 changes: 2 additions & 1 deletion Builtin/LUIScrollableRegion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from panda3d.lui import LUIObject, LUISprite
from LUIObject import LUIObject
from LUISprite import LUISprite
from LUIInitialState import LUIInitialState
from LUILayouts import LUIHorizontalStretchedLayout

Expand Down
3 changes: 2 additions & 1 deletion Builtin/LUISelectbox.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from panda3d.lui import LUIObject, LUISprite
from LUIObject import LUIObject
from LUISprite import LUISprite
from LUILabel import LUILabel
from LUILayouts import LUICornerLayout, LUIHorizontalStretchedLayout
from LUIInitialState import LUIInitialState
Expand Down
5 changes: 3 additions & 2 deletions Builtin/LUISkin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

from panda3d.lui import LUIFontPool, LUIAtlasPool
from panda3d.core import Filename
import os
from os.path import join

from panda3d.core import Filename
from panda3d.lui import LUIFontPool, LUIAtlasPool

class LUISkin:

""" Abstract class, each skin derives from this class """
Expand Down
3 changes: 2 additions & 1 deletion Builtin/LUISlider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from panda3d.lui import LUIObject, LUISprite
from LUIObject import LUIObject
from LUISprite import LUISprite
from LUIInitialState import LUIInitialState
from LUILayouts import LUIHorizontalStretchedLayout

Expand Down
18 changes: 18 additions & 0 deletions Builtin/LUISprite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
This is a wrapper file. It contains no actual implementation
"""

from panda3d.lui import LUISprite as _LUISprite
from LUIInitialState import LUIInitialState

__all__ = ["LUISprite"]

class LUISprite(_LUISprite):
""" This is a wrapper class for the C++ LUISprite class, to be able to
use it in a more convenient way """

def __init__(self, *args, **kwargs):
_LUISprite.__init__(self, *args)
LUIInitialState.init(self, kwargs)
4 changes: 3 additions & 1 deletion Builtin/LUISpriteButton.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from panda3d.lui import LUIObject, LUISprite

from LUIObject import LUIObject
from LUISprite import LUISprite
from LUILabel import LUILabel
from LUIInitialState import LUIInitialState

Expand Down
5 changes: 4 additions & 1 deletion Builtin/LUITabbedFrame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

from LUIFrame import LUIFrame
from LUILabel import LUILabel
from panda3d.lui import LUIVerticalLayout, LUIHorizontalLayout, LUIObject
from LUIObject import LUIObject
from LUIVerticalLayout import LUIVerticalLayout
from LUIHorizontalLayout import LUIHorizontalLayout

class LUITabbedFrame(LUIFrame):
def __init__(self, **kwargs):
Expand Down
18 changes: 18 additions & 0 deletions Builtin/LUIVerticalLayout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
This is a wrapper file. It contains no actual implementation
"""

from panda3d.lui import LUIVerticalLayout as _LUIVerticalLayout
from LUIInitialState import LUIInitialState

__all__ = ["LUIVerticalLayout"]

class LUIVerticalLayout(_LUIVerticalLayout):
""" This is a wrapper class for the C++ LUIVerticalLayout class, to be able to
use it in a more convenient way """

def __init__(self, parent=None, spacing=0.0, **kwargs):
_LUIVerticalLayout.__init__(self, parent, spacing)
LUIInitialState.init(self, kwargs)
9 changes: 4 additions & 5 deletions Demos/01_MinimalExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
import sys
sys.path.insert(0, "../Builtin")

# Load some required LUI classes
from panda3d.lui import LUIRegion, LUIInputHandler

# Load a builtin LUI class. When lui is included in panda, this will be
# from direct.luiwidgets.LUIButton import LUIButton
# Load some builtin LUI classes. When lui is included in panda, this will be
# from direct.lui.LUIButton import LUIButton
from LUIButton import LUIButton
from LUISkin import LUIDefaultSkin
from LUIRegion import LUIRegion
from LUIInputHandler import LUIInputHandler

# Setup panda, nothing special here
from panda3d.core import load_prc_file_data
Expand Down
7 changes: 5 additions & 2 deletions Demos/02_SimpleConsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
""")

# Imports
from panda3d.lui import LUIRegion, LUIObject, LUIInputHandler
from panda3d.lui import LUIVerticalLayout

from LUISkin import LUIDefaultSkin
from LUIFrame import LUIFrame
from LUILabel import LUILabel
from LUIInputField import LUIInputField
from LUIFormattedLabel import LUIFormattedLabel
from LUIScrollableRegion import LUIScrollableRegion
from LUIObject import LUIObject
from LUIRegion import LUIRegion
from LUIInputHandler import LUIInputHandler
from LUIVerticalLayout import LUIVerticalLayout

from Skins.Metro.LUIMetroSkin import LUIMetroSkin

Expand Down
2 changes: 1 addition & 1 deletion Demos/B_Button.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from DemoFramework import DemoFramework
from LUIButton import LUIButton
from panda3d.lui import LUIHorizontalLayout
from LUIHorizontalLayout import LUIHorizontalLayout

import random

Expand Down
4 changes: 2 additions & 2 deletions Demos/B_Frame.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


from DemoFramework import DemoFramework
from panda3d.lui import LUIVerticalLayout
from LUIVerticalLayout import LUIVerticalLayout
from LUIFrame import LUIFrame
from LUILabel import LUILabel
from LUIButton import LUIButton
from panda3d.lui import LUIObject
from LUIObject import LUIObject

import random

Expand Down
2 changes: 1 addition & 1 deletion Demos/B_Progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from LUIProgressbar import LUIProgressbar
from LUISlider import LUISlider
from LUILabel import LUILabel
from panda3d.lui import LUIVerticalLayout
from LUIVerticalLayout import LUIVerticalLayout

import random

Expand Down
2 changes: 1 addition & 1 deletion Demos/B_Radiobox.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from DemoFramework import DemoFramework
from LUIRadiobox import LUIRadiobox
from LUIRadioboxGroup import LUIRadioboxGroup
from panda3d.lui import LUIVerticalLayout
from LUIVerticalLayout import LUIVerticalLayout

import random

Expand Down
2 changes: 1 addition & 1 deletion Demos/B_Slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from DemoFramework import DemoFramework
from LUISlider import LUISlider
from LUILabel import LUILabel
from panda3d.lui import LUIVerticalLayout
from LUIVerticalLayout import LUIVerticalLayout

import random

Expand Down
6 changes: 5 additions & 1 deletion Demos/DemoFramework.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
sys.path.insert(0, "../Builtin")

from panda3d.core import *
from panda3d.lui import LUIRegion, LUIInputHandler, LUISprite, LUIObject, LUIVerticalLayout

from LUIRegion import LUIRegion
from LUIInputHandler import LUIInputHandler
from LUISprite import LUISprite
from LUIObject import LUIObject
from LUIVerticalLayout import LUIVerticalLayout
from LUILabel import LUILabel
from LUIFrame import LUIFrame

Expand Down
6 changes: 5 additions & 1 deletion Tests/Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
win-fixed-size #f
""")

from panda3d.lui import LUIRegion, LUIObject, LUIInputHandler, LUISprite, LUIVerticalLayout
from LUIRegion import LUIRegion
from LUIObject import LUIObject
from LUIInputHandler import LUIInputHandler
from LUISprite import LUISprite
from LUIVerticalLayout import LUIVerticalLayout
from LUISkin import LUIDefaultSkin
from LUIFrame import LUIFrame
from LUIFormattedLabel import LUIFormattedLabel
Expand Down
5 changes: 4 additions & 1 deletion Tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

import time
from functools import wraps
from panda3d.lui import LUIRegion, LUIObject, LUIInputHandler, LUISprite
from LUIRegion import LUIRegion
from LUIObject import LUIObject
from LUIInputHandler import LUIInputHandler
from LUISprite import LUISprite
from LUISkin import LUIDefaultSkin
from panda3d.lui import LUIVerticalLayout
from LUIFrame import LUIFrame
Expand Down
Loading

0 comments on commit 69e0a23

Please sign in to comment.