Commits

Kevin Luikens committed 49416e9

fixed my plugin loading bug.

Comments (0)

Files changed (14)

desktop/desktop-multi.py

 from OpenGL.GL import glTranslatef
 
 plugins = MTPlugins(plugin_paths=[
-    os.path.join(os.path.dirname(__file__), '.', 'apps'),
-    os.path.join(os.path.dirname(__file__), '.', 'games')
+    os.path.join(os.path.dirname(__file__), '..', 'apps'),
+    os.path.join(os.path.dirname(__file__), '..', 'games')
 ])
 plugins.search_plugins()
 

games/mole/mccann.jpg

Added
New image

games/mole/mole.py

 class CircleDrawer( MTWidget ):
     '''Draw a circle at the position of all touches.'''
     
-    def draw( self ):
+    def draw(self):
         set_color( 1, 0, 0 )
         for touch in getCurrentTouches():
             drawCircle( touch.pos, 50 )
 
 class GameMenu( MTBoxLayout ):
     
-    def __init__( self, window, **kwargs ):
+    def __init__(self, window, **kwargs):
         kwargs.setdefault('size_hint', (None, None) )
-        super( GameMenu, self ).__init__( **kwargs )
+        super( GameMenu, self ).__init__(**kwargs)
         self.window = window
         self.trial_num = 0
     
     
-class MainUI( MTBoxLayout ):
-    xml = '''
-        <MTBoxLayout>
-            <MTButton label="1" id='"btn1"' />
-            <MTButton label="2" id='"btn2"' />
-            <MTButton label="3" id='"btn3"' />
-        </MTBoxLayout>
-        '''
+class Mole( MTButtonMatrix ):
     
-    def __init__(self, **kwargs):
-        super(MainUI, self).__init_(**kwargs)
-        xml = XMLWidget( xml=MainUI.xml )
-        xml.autoconnect(self)
-        self.add_widget(xml.root)
+    def __init__(self,**kwargs):
+        kwargs.setdefault('matrix_size', (3, 3))
+        super(TTTGame, self).__init__(**kwargs)
+        #TODO
+        #self.player_images = (MTWidget(),MTSvg(filename='cross.svg'),MTSvg(filename='circle.svg') )
+        self.player = 1
+        self.done = False
+        self.testpoint = (0,0)
     
-    def on_btn2_press(self, *largs):
-        print 'my button 2 was pressed'
+    def restart(self):
+        self.done = False
+        self.player = 1
+        self.testpoint = (0,0)
+        self.reset()
+    
+    # def show_winner(self, text):
+    #     popup = MoleWinner(game=self,text=text)
+    #     self.get_parent_window().add_widget(popup)
+
+def pymt_plugin_activate(w,ctx):
+    ctx.game = Mole( size = w.size )
+    w.add_widget( ctx.game )
+
+def pymt_plugin_deactivate(w, ctx):
+    w.remove_widget( ctx.game )
 
 if __name__ == '__main__':
-    layout = MTBoxLayout( orientation='horizontal' )
-    button1 = MTButton( label='BTN1' )
-    button2 = MTButton( label='BTN2' )
-    layout.add_widget( button1 )
-    layout.add_widget( button2 )
-    
-    
-    widget = MTWidget()
-    @widget.event
-    def on_draw():
-        print 'on_draw() called from my widget'
-    
-    button = MTButton()
-    #button = MTButton()
-    
-    @button.event
-    def on_press(*largs):
-        print 'my button is pressed, arguments are', largs
-    
-    @button.event
-    def on_release(*largs):
-        print 'my button is released, arguments are', largs
-    
-    def my_onpress_callback(*largs):
-        print 'my button is pressed, arguments are', largs
-    button.connect('on_press', my_onpress_callback)
-    layout.add_widget( button )
-    
-    #getWindow().add_widget( layout )
-    
     w = MTWindow()
     ctx = MTContext()
-    
-    pymt_plugin_activate(w,ctx)
-    runTouchApp( GameMenu() )
-    pymt_plugin_deactivate(w,ctx)
+    pymt_plugin_activate(w, ctx)
+    runTouchApp()
+    pymt_plugin_deactivate(w, ctx)

widgets/image.jpg

Added
New image

widgets/kinetic.py

+from pymt import *
+
+def print_me(*largs):
+	print 'CLICKED ON', largs[0].label
+
+mms = MTWindow()
+w = MTScatterWidget(size=(500, 500))
+mms.add_widget(w)
+
+# uncomment if you want a horizontal kinetic list
+#k = MTKineticList(pos=(20, 20), size=(400, 400), h_limit=2, w_limit=0, do_x=True, do_y=False)
+k = MTKineticList(pos=(50,50), size=(400, 400), w_limit=3)
+w.add_widget(k)
+
+d = range(0, 20)
+for x in d:
+    item = MTKineticItem(label=str(x),deletable=True)
+    item.push_handlers(on_press=curry(print_me, item))
+    k.add_widget(item)
+
+runTouchApp()

widgets/kineticimage.py

+from pymt import *
+import glob, os
+
+k = MTKineticList(size=getWindow().size, friction=1, do_x=True,
+                  h_limit=4, do_y=False, title=None, deletable=False,
+                  searchable=False, w_limit=0)
+
+# search file in image directory
+pattern = os.path.join(os.path.dirname(__file__), 'images', '*.png')
+for x in xrange(10):
+    for filename in glob.glob(pattern):
+        item = MTKineticImage(image=Loader.image(filename))
+        k.add_widget(item)
+
+runTouchApp(k)

widgets/label_fade.py

+from pymt import *
+
+w = getWindow()
+m = MTLabel(label='Welcome', pos=w.center, color=(1., 0, 0, 1.), font_size=12., anchor_x='center', anchor_y='middle')
+m.do(Animation(duration=5, color=(0, 1., 0, 0), font_size=88.))
+
+runTouchApp(m)

widgets/labelanchor.py

+from pymt import *
+
+layout = MTGridLayout(cols=3)
+
+size = (200, 200)
+text = 'Hello World\nAnchor X: %s\nAnchor Y: %s'
+style = {'bg-color': (0, .2, 0, 1), 'draw-background': 1}
+
+for anchor_x in ('left', 'center', 'right'):
+    for anchor_y in ('top', 'middle', 'bottom'):
+        label = MTLabel(label=text % (anchor_x, anchor_y), size=size,
+                anchor_x=anchor_x, anchor_y=anchor_y,
+                halign=anchor_x, valign=anchor_y,
+                style=style)
+        layout.add_widget(label)
+
+runTouchApp(layout)

widgets/modalpopup.py

+from pymt import *
+
+m = MTWindow()
+
+# create a simple popup
+p = MTModalPopup(title='Hello World', content='I hope you will like it !')
+m.add_widget(p)
+
+runTouchApp()
+

widgets/modalwindow.py

+from pymt import *
+
+m = MTWindow()
+
+# a back button, you will be unable to click on him
+# cause the modal window will take all events
+back = MTButton(label='Try to click me', pos=(200, 200))
+
+# create a modal window
+mw = MTModalWindow()
+
+# add a button to close modal window
+mb = MTButton(label='Close Modal')
+@mb.event
+def on_press(*largs):
+	global mw
+	m.remove_widget(mw)
+mw.add_widget(mb)
+
+# add back button
+m.add_widget(back)
+
+# add modal window
+m.add_widget(mw)
+
+runTouchApp()

widgets/multiplescatter.py

+from pymt import *
+
+class MyWidget(MTWidget):
+	def __init__(self, **kwargs):
+		super(MyWidget, self).__init__(**kwargs)
+
+	def on_draw(self):
+		for w in self.children:
+			w.dispatch_event('on_draw')
+		c = self.children[-1].children[-1]
+		cwinpos = c.to_window(*c.pos)
+		set_color(0, 1, 0, 1)
+		drawLine((0, 0, cwinpos[0], cwinpos[1]))
+
+		set_color(0, 0, 1, 1)
+		drawLine((0, 0, c.x, c.y))
+
+w = MTWindow()
+root = MyWidget()
+s1 = MTScatterWidget(style={'bg-color': (1, 0, 0, 1)}, size=(200, 200))
+s2 = MTScatterWidget(style={'bg-color': (1, 1, 0, 1)})
+s1.add_widget(s2)
+root.add_widget(s1)
+w.add_widget(root)
+print ''
+print 'Blue line represent the (0, 0) -> scatter.pos (invalid in this case)'
+print 'Green line represent the (0, 0) -> scatter position for window (valid)'
+print ''
+runTouchApp()
+from pymt import *
+
+m = MTWindow()
+
+p = MTPopup(title='Example with kinetic', label_submit='Select')
+k = MTKineticList(size=(400, 300), searchable=False, deletable=False, title=None)
+k.add_widget(MTKineticItem(label='test1'))
+k.add_widget(MTKineticItem(label='test2'))
+k.add_widget(MTKineticItem(label='blehlazkdjalzidj'))
+k.add_widget(MTKineticItem(label='blehlazkdjalzidj'))
+k.add_widget(MTKineticItem(label='blehlazkdjalzidj'))
+k.add_widget(MTKineticItem(label='blehlazkdjalzidj'))
+p.add_widget(k)
+m.add_widget(p)
+
+runTouchApp()

widgets/stencil.py

+# Just a test with stacking stencil.
+# InnerWindow use stencil for clipping content draw
+# And Kinetic too.
+
+# Scatter plane is here to test that stacking with different matrix
+# transformation will work too.
+
+from pymt import *
+
+mms = MTWindow()
+w = MTInnerWindow(size=(600, 600))
+mms.add_widget(w)
+
+p = MTScatterPlane()
+k = MTKineticList(pos=(20, 20), size=(400, 400), w_limit=3)
+p.add_widget(k)
+w.add_widget(p)
+
+d = range(0, 10)
+for x in d:
+    item = MTKineticItem(label=str(x))
+    k.add_widget(item)
+
+runTouchApp()

widgets/stencilcontainer.py

+from pymt import *
+sb = MTStencilContainer(size=(200, 200))
+s = MTStencilContainer(size=(50, 50))
+s.add_widget(MTLabel(label="XXXXXXXXXX", pos=(100, 100), font_size=16))
+s.add_widget(MTLabel(label="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX", pos=(150, 50), font_size=16))
+s.add_widget(MTLabel(label="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX", pos=(100, 150), font_size=16))
+s.add_widget(MTLabel(label="XXXXXXXXXXXXXXXXXXXXXXXXXXXXX", pos=(0, 0), font_size=16))
+sb.add_widget(s)
+w = MTWindow()
+w.add_widget(sb)
+runTouchApp()
+