From 4107ea1f0b76ddf89b8e445bae252a75c4d02e0f Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Wed, 3 Nov 2010 17:37:48 -0400 Subject: [PATCH] fixes to be able to import window + use runTouchApp --- kivy/base.py | 47 ++++---- kivy/core/audio/__init__.py | 4 +- kivy/core/gl/__init__.py | 2 +- kivy/core/video/video_gstreamer.py | 2 +- kivy/core/window/__init__.py | 36 +++--- kivy/core/window/default.py | 10 -- kivy/core/window/window_pygame.py | 17 +-- kivy/graphics/__init__.py | 2 +- kivy/input/providers/mouse.py | 9 +- kivy/loader.py | 2 +- kivy/modules/touchinfo.py | 2 +- kivy/tools/benchmark.py | 2 +- kivy/tools/tests/.init.py.swp | Bin 16384 -> 0 bytes kivy/tools/tests/test_baseobject.py | 61 ---------- kivy/tools/tests/test_css.py | 47 -------- kivy/tools/tests/test_layout.py | 129 -------------------- kivy/tools/tests/test_properties.py~ | 85 -------------- kivy/tools/tests/test_textarea.py | 170 --------------------------- kivy/tools/tests/test_textinput.py | 19 --- kivy/tools/tests/test_widget.py | 101 ---------------- 20 files changed, 59 insertions(+), 688 deletions(-) delete mode 100644 kivy/core/window/default.py delete mode 100644 kivy/tools/tests/.init.py.swp delete mode 100644 kivy/tools/tests/test_baseobject.py delete mode 100644 kivy/tools/tests/test_css.py delete mode 100644 kivy/tools/tests/test_layout.py delete mode 100644 kivy/tools/tests/test_properties.py~ delete mode 100644 kivy/tools/tests/test_textarea.py delete mode 100644 kivy/tools/tests/test_textinput.py delete mode 100644 kivy/tools/tests/test_widget.py diff --git a/kivy/base.py b/kivy/base.py index 46129b56f..0a3916742 100644 --- a/kivy/base.py +++ b/kivy/base.py @@ -3,7 +3,7 @@ Base: Main event loop, provider creation, window management... ''' __all__ = ( - 'EventLoop', 'Window', + 'EventLoop', 'runTouchApp', 'stopTouchApp', 'getCurrentTouches', ) @@ -19,7 +19,6 @@ from kivy.input import TouchFactory, kivy_postproc_modules # private vars EventLoop = None -Window = None def getCurrentTouches(): '''Return the list of all current touches @@ -37,6 +36,12 @@ class EventLoopBase(object): self.status = 'idle' self.input_providers = [] self.event_listeners = [] + self.window = None + + def set_window(self, window): + '''Set the window used for event loop + ''' + self.window = window def add_input_provider(self, provider): '''Add a new input provider to listen for touch event @@ -110,11 +115,11 @@ class EventLoopBase(object): if not touch.grab_exclusive_class: for listener in self.event_listeners: if event == 'down': - listener.dispatch_event('on_touch_down', touch) + listener.dispatch('on_touch_down', touch) elif event == 'move': - listener.dispatch_event('on_touch_move', touch) + listener.dispatch('on_touch_move', touch) elif event == 'up': - listener.dispatch_event('on_touch_up', touch) + listener.dispatch('on_touch_up', touch) # dispatch grabbed touch touch.grab_state = True @@ -153,12 +158,12 @@ class EventLoopBase(object): if event == 'down': # don't dispatch again touch in on_touch_down # a down event are nearly uniq here. - # wid.dispatch_event('on_touch_down', touch) + # wid.dispatch('on_touch_down', touch) pass elif event == 'move': - wid.dispatch_event('on_touch_move', touch) + wid.dispatch('on_touch_move', touch) elif event == 'up': - wid.dispatch_event('on_touch_up', touch) + wid.dispatch('on_touch_up', touch) touch.grab_current = None @@ -202,11 +207,10 @@ class EventLoopBase(object): # read and dispatch input from providers self.dispatch_input() - if kivy_window: - kivy_window.dispatch_events() - kivy_window.dispatch_event('on_update') - kivy_window.dispatch_event('on_draw') - kivy_window.dispatch_event('on_flip') + window = self.window + if window: + window.dispatch('on_draw') + window.dispatch('on_flip') # don't loop if we don't have listeners ! if len(self.event_listeners) == 0: @@ -224,8 +228,8 @@ class EventLoopBase(object): def exit(self): '''Close the main loop, and close the window''' self.close() - if kivy_window: - kivy_window.close() + if self.window: + self.window.close() #: EventLoop instance EventLoop = EventLoopBase() @@ -275,11 +279,6 @@ def runTouchApp(widget=None, slave=False): # Ok, we got one widget, and we are not in slave mode # so, user don't create the window, let's create it for him ! - ### Not needed, since we always create window ?! - #if not slave and widget: - # global kivy_window - # from ui.window import MTWindow - # kivy_window = MTWindow() # Instance all configured input for key, value in Config.items('input'): @@ -306,8 +305,8 @@ def runTouchApp(widget=None, slave=False): EventLoop.add_postproc_module(mod) # add main widget - if widget and getWindow(): - getWindow().add_widget(widget) + if widget and EventLoop.window: + EventLoop.window.add_widget(widget) # start event loop Logger.info('Base: Start application main loop') @@ -329,10 +328,10 @@ def runTouchApp(widget=None, slave=False): # ourself (previous behavior.) # try: - if kivy_window is None: + if EventLoop.window is None: _run_mainloop() else: - kivy_window.mainloop() + EventLoop.window.mainloop() finally: stopTouchApp() diff --git a/kivy/core/audio/__init__.py b/kivy/core/audio/__init__.py index 39b54c5c0..27e6945cc 100644 --- a/kivy/core/audio/__init__.py +++ b/kivy/core/audio/__init__.py @@ -103,9 +103,9 @@ class Sound(EventDispatcher): return self._status = x if x == 'stop': - self.dispatch_event('on_stop') + self.dispatch('on_stop') elif x == 'play': - self.dispatch_event('on_play') + self.dispatch('on_play') else: assert('unknown status %s' % x) status = property(_get_status, diff --git a/kivy/core/gl/__init__.py b/kivy/core/gl/__init__.py index 46e805a2f..1d020e547 100644 --- a/kivy/core/gl/__init__.py +++ b/kivy/core/gl/__init__.py @@ -17,7 +17,7 @@ if gl_check.lower() in ['0', 'false', 'no']: # To be able to use our GL provider, we must have a window # Automaticly import window auto to ensure the default window creation -import kivy.core.window.default +import kivy.core.window # Display the current OpenGL version version = glGetString(GL_VERSION) diff --git a/kivy/core/video/video_gstreamer.py b/kivy/core/video/video_gstreamer.py index 12d9e0773..a05aaa437 100644 --- a/kivy/core/video/video_gstreamer.py +++ b/kivy/core/video/video_gstreamer.py @@ -48,7 +48,7 @@ class VideoGStreamer(VideoBase): # reset to start for next play self._pipeline.seek_simple( gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, 0) - self.dispatch_event('on_eos') + self.dispatch('on_eos') super(VideoGStreamer, self)._do_eos() def stop(self): diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py index 0c90664cc..039eb39d0 100644 --- a/kivy/core/window/__init__.py +++ b/kivy/core/window/__init__.py @@ -79,7 +79,6 @@ class WindowBase(EventDispatcher): self.register_event_type('on_flip') self.register_event_type('on_rotate') self.register_event_type('on_draw') - self.register_event_type('on_update') self.register_event_type('on_resize') self.register_event_type('on_close') self.register_event_type('on_touch_down') @@ -92,8 +91,8 @@ class WindowBase(EventDispatcher): self.register_event_type('on_key_down') self.register_event_type('on_key_up') - #self.children = SafeList() - #self.parent = self + self.children = [] + self.parent = self #self.visible = True # add view @@ -160,6 +159,7 @@ class WindowBase(EventDispatcher): # attach modules + listener event Modules.register_window(self) + EventLoop.set_window(self) EventLoop.add_event_listener(self) # mark as initialized @@ -185,10 +185,6 @@ class WindowBase(EventDispatcher): '''Flip between buffers''' pass - def dispatch_events(self): - '''Dispatch all events from windows''' - pass - def _get_modifiers(self): return self._modifiers modifiers = property(_get_modifiers) @@ -202,7 +198,7 @@ class WindowBase(EventDispatcher): def _set_size(self, size): if super(WindowBase, self)._set_size(size): Logger.debug('Window: Resize window to %s' % str(self.size)) - self.dispatch_event('on_resize', *size) + self.dispatch('on_resize', *size) return True return False size = property(_get_size, _set_size, @@ -264,13 +260,6 @@ class WindowBase(EventDispatcher): def get_parent_layout(self): return None - def on_update(self): - '''Event called when window are update the widget tree. - (Usually before on_draw call.) - ''' - for w in self.children[:]: - w.dispatch_event('on_update') - def on_draw(self): '''Event called when window we are drawing window. This function are cleaning the buffer with bg-color css, @@ -281,14 +270,14 @@ class WindowBase(EventDispatcher): # then, draw childrens for w in self.children[:]: - w.dispatch_event('on_draw') + w.dispatch('on_draw') def on_touch_down(self, touch): '''Event called when a touch is down''' w, h = self.system_size touch.scale_for_screen(w, h, rotation=self._rotation) for w in reversed(self.children[:]): - if w.dispatch_event('on_touch_down', touch): + if w.dispatch('on_touch_down', touch): return True def on_touch_move(self, touch): @@ -296,7 +285,7 @@ class WindowBase(EventDispatcher): w, h = self.system_size touch.scale_for_screen(w, h, rotation=self._rotation) for w in reversed(self.children[:]): - if w.dispatch_event('on_touch_move', touch): + if w.dispatch('on_touch_move', touch): return True def on_touch_up(self, touch): @@ -304,7 +293,7 @@ class WindowBase(EventDispatcher): w, h = self.system_size touch.scale_for_screen(w, h, rotation=self._rotation) for w in reversed(self.children[:]): - if w.dispatch_event('on_touch_up', touch): + if w.dispatch('on_touch_up', touch): return True def on_resize(self, width, height): @@ -312,6 +301,9 @@ class WindowBase(EventDispatcher): self.update_viewport() def update_viewport(self): + # XXX FIXME + from kivy.core.gl import * + width, height = self.system_size w2 = width / 2. h2 = height / 2. @@ -357,8 +349,8 @@ class WindowBase(EventDispatcher): if x not in (0, 90, 180, 270): raise ValueError('can rotate only 0,90,180,270 degrees') self._rotation = x - self.dispatch_event('on_resize', *self.size) - self.dispatch_event('on_rotate', x) + self.dispatch('on_resize', *self.size) + self.dispatch('on_rotate', x) rotation = property(_get_rotation, _set_rotation, 'Get/set the window content rotation. Can be one of ' '0, 90, 180, 270 degrees.') @@ -411,5 +403,5 @@ class WindowBase(EventDispatcher): # Load the appropriate provider Window = core_select_lib('window', ( ('pygame', 'window_pygame', 'WindowPygame'), -)) +))() diff --git a/kivy/core/window/default.py b/kivy/core/window/default.py deleted file mode 100644 index 36fd06fef..000000000 --- a/kivy/core/window/default.py +++ /dev/null @@ -1,10 +0,0 @@ -''' -Default: create the default window if not exist -''' - -from kivy.core.window import Window -from kivy import kivy_configure - -Window() - -kivy_configure() diff --git a/kivy/core/window/window_pygame.py b/kivy/core/window/window_pygame.py index 92eeac57c..fa7968c33 100644 --- a/kivy/core/window/window_pygame.py +++ b/kivy/core/window/window_pygame.py @@ -76,8 +76,9 @@ class WindowPygame(WindowBase): pygame.key.set_repeat(repeat_delay, int(1000. / repeat_rate)) # set window icon before calling set_mode - icon = pygame.image.load(Config.get('graphics', 'window_icon')) - pygame.display.set_icon(icon) + # XXX FIXME + #icon = pygame.image.load(Config.get('graphics', 'window_icon')) + #pygame.display.set_icon(icon) # init ourself size + setmode # before calling on_resize @@ -171,7 +172,7 @@ class WindowPygame(WindowBase): if event.buttons == (0, 0, 0): continue x, y = event.pos - self.dispatch_event('on_mouse_move', x, y, self.modifiers) + self.dispatch('on_mouse_move', x, y, self.modifiers) # mouse action elif event.type in (pygame.MOUSEBUTTONDOWN, @@ -186,22 +187,22 @@ class WindowPygame(WindowBase): eventname = 'on_mouse_down' if event.type == pygame.MOUSEBUTTONUP: eventname = 'on_mouse_up' - self.dispatch_event(eventname, x, y, btn, self.modifiers) + self.dispatch(eventname, x, y, btn, self.modifiers) # keyboard action elif event.type in (pygame.KEYDOWN, pygame.KEYUP): self._pygame_update_modifiers(event.mod) # atm, don't handle keyup if event.type == pygame.KEYUP: - self.dispatch_event('on_key_up', event.key, + self.dispatch('on_key_up', event.key, event.scancode) continue # don't dispatch more key if down event is accepted - if self.dispatch_event('on_key_down', event.key, + if self.dispatch('on_key_down', event.key, event.scancode, event.unicode): continue - self.dispatch_event('on_keyboard', event.key, + self.dispatch('on_keyboard', event.key, event.scancode, event.unicode) # video resize @@ -219,7 +220,7 @@ class WindowPygame(WindowBase): def mainloop(self): # don't known why, but pygame required a resize event # for opengl, before mainloop... window reinit ? - self.dispatch_event('on_resize', *self.size) + self.dispatch('on_resize', *self.size) while not EventLoop.quit: try: diff --git a/kivy/graphics/__init__.py b/kivy/graphics/__init__.py index 252114297..0992cf653 100644 --- a/kivy/graphics/__init__.py +++ b/kivy/graphics/__init__.py @@ -9,5 +9,5 @@ Kivy. We hardly ask you to use theses class ! .. seealso:: Read the full documentation at :mod:`kivy.c_ext.c_graphics` ''' -from kivy.c_ext.graphics import Canvas +from kivy.c_ext.graphics import * diff --git a/kivy/input/providers/mouse.py b/kivy/input/providers/mouse.py index 79a4e52a2..2a7b3824d 100644 --- a/kivy/input/providers/mouse.py +++ b/kivy/input/providers/mouse.py @@ -143,14 +143,15 @@ class MouseTouchProvider(TouchProvider): def update(self, dispatch_fn): '''Update the mouse provider (pop event from the queue)''' if not self.window: - from kivy.base import getWindow - self.window = getWindow() + from kivy.core.window import Window + self.window = Window if self.window: - self.window.push_handlers( - on_mouse_move=self.on_mouse_motion, + Window.bind(on_mouse_move=self.on_mouse_motion) + ''', on_mouse_down=self.on_mouse_press, on_mouse_up=self.on_mouse_release ) + ''' if not self.window: return try: diff --git a/kivy/loader.py b/kivy/loader.py index 9e740398f..b5a09a8e0 100644 --- a/kivy/loader.py +++ b/kivy/loader.py @@ -193,7 +193,7 @@ class LoaderBase(object): # got one client to update client.image = image client.loaded = True - client.dispatch_event('on_load') + client.dispatch('on_load') self._client.remove((c_filename, client)) def image(self, filename, load_callback=None, post_callback=None): diff --git a/kivy/modules/touchinfo.py b/kivy/modules/touchinfo.py index 18f0263a0..629920453 100644 --- a/kivy/modules/touchinfo.py +++ b/kivy/modules/touchinfo.py @@ -39,7 +39,7 @@ class TouchInfos(MTWidget): self.bubbles[uid] = bubble bubble.pos = touch.pos bubble.label = info(touch) - bubble.dispatch_event('on_draw') + bubble.dispatch('on_draw') alive = [x.uid for x in current] for uid in bubbles.keys()[:]: diff --git a/kivy/tools/benchmark.py b/kivy/tools/benchmark.py index b0f79162c..1168a8c82 100644 --- a/kivy/tools/benchmark.py +++ b/kivy/tools/benchmark.py @@ -58,7 +58,7 @@ class bench_widget_dispatch: def run(self): root = self.root for x in xrange(1000): - root.dispatch_event('on_update') + root.dispatch('on_update') class bench_graphx_line: '''Graphx: draw lines (5000 x/y) 1000 times''' diff --git a/kivy/tools/tests/.init.py.swp b/kivy/tools/tests/.init.py.swp deleted file mode 100644 index 468d761beae19e293d9bee606209c4cc981d5b1b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3O^h5z6~`-y9X=B*kR#wiInmNR>zVPcmk?NGjiP*M6=NH+b_Bzy)iYDG)3~R* z>8jZeNBDpcQiKRdfW!^^!Ud!N3MgDSMB;{mkw6KT2yp`ff&;>E2>f4F*L2P9WGs{m zk*cMiXQr#(t5^SeRoz{^?yX$f{3L&%eVXAo#@LI$zj5}LM~~h1voA2F5|z{GTOF5^ zo&A;?YZr^^UL}X8`uRYdB9l`}NF`4tS)$s-{vtzP<`wV?yg3CXYS{YNU2N_2>dJlh zp5X6$@5MLg&s%#1yaHYUuYgy;E8rFI3U~#)0&h75RB=1|52C&uJPmHExC5W>2Un}# z`0$5Uz$@St@CtYZyaHYUuYgy;E8rFI3U~#)0&h_T;sIml5&L=C0Kofy+5`C2dl-8O z{0LkJ*T7f69{3daFt`UC2X}yf-_6*+z;D5~fdnPE1lphlj)2$hV(bR^33wi)U<*76 z9tKCiKiJ9e%;@z$@T+@Kun5v*09n{cVi>8e9V@ z_$c@w_yG9po#+dA5j+Q;0R!+LxEuWKD13tNfG>k9pa){G4E}rsaf6q^3*cFhgU3Mw zyoQaMpMtC45zquD!7=a`jOk0@``|jb2EGO|Z~@Smx4}K&IB*W`978t!QGdg!VXF8B zm;16Em)kp?)h}qkNaEQ6f1N2FxvXEO$iN%cXEjwPkhw4ebV^H`#WrIM;Ui{9LPx zGTs*Jyx3QxJmb}$;_yyhs3gy1mp?d6QYFeWwXsMc&mOAsFfe@#8ui#v<2jVcc9JsB zIzbefw!6?eSbZZerp`h)w(AESxxv^vm7`%^nn2MTSq-1fIE2&Lf~qNvFa&5SNT$;oYPTTt>(dPSM{g_P|Jd4c&j<5|bi38Wf`vJ6Of zxBljZN2j$R+H|0`d`ONu-r3}!DB5v>)&?Z(bjS`kv*#(#=DE_rA*83jI5i~CG&c1# zPsT-FDkp4RcOZs(#lR90rST-|kLIi-2WEQ_ODP6TK8&I8V0OfKebkXs=G#Rm=ypE7 z-fh&{lR>Z~*Oz3#mv}g9RgE2t?qBcLHr48|)LOe=@})J&ZAkRpgr%J^8;v;!L1x`k zP*GLCR?0Y=U)hueb>(fLVx>w_%~^Y$j79-m(VW7!Nh)Ng>QwC`ip=0dkrlrdHIhPU z@sezq+hV6B-9={<=TxbNuSx)wjDh3nbP0(fx)fpX#&MEGQ2%5{f)p0m_6W4+4{a-S7Hfv4pe#B%wv&|y5Ntx-NW+9o*eOig<%>U`IH7UomVGslt z^o2L(rH~WcnBZ!rMuN+JDMW^1EfpodDG#*@sI0756waaY;4wYngIdYMB28x#T0xXC)w0XKEWM_b|pjoVSMPXs7dQe)Sr~4$gq-8i!yAqcj9zHU(lpU zCA0Qpj?lnXDN{A#o^mp13)#VAtxQ6mQBMp44NBt?PQFb;n0>a`@@(&L4^@3?^V}onpE7l}(}^;di|In9LomN0J?gtjHpqA9hC&17R?YIrsU1a_ zQFIZ*-8tnEZVUCNRbu*E_Z7 z{)y-LSHTP5yFh_+;5fJmU%vof2hV~L_ykx6)Xs;1KfD570k42pz$@St@CtYZyaHYU zufYGC0`zQ5NBv|?zXYCb3v388`awsv(RJnwe+(~CBp&Q(=W40FHaxJ~RaxQzjdms5 z^iSB}Ej+*CeZ%aNz42V_N-f%~X11pN#KS+mLc?n&dWXjG9z_4dmKYuhX;ZJ>3$P~i zNgF>&HZgmpZUOw!UYxa_c{zd?8cOe29DEH#FITJui7`m@mN6c$UDsx>`0#eHej7I{ zI+@K45#d#vq@C8)?Qq&c`jpm9q-}|p4bCoj ziZRAUK$_qU3c7B0tnl60!O_D$n+&r_;FzIW(5_#hq1Q8oD0O-~Q$%qTu^P3}I1PVj JUlldje*wLDLxunV diff --git a/kivy/tools/tests/test_baseobject.py b/kivy/tools/tests/test_baseobject.py deleted file mode 100644 index f8815eae3..000000000 --- a/kivy/tools/tests/test_baseobject.py +++ /dev/null @@ -1,61 +0,0 @@ -''' -BaseObject -''' - -from init import test, import_kivy_no_window - -def unittest_defaults(): - import_kivy_no_window() - from kivy import BaseObject - a = BaseObject() - test(a.x == 0) - test(a.y == 0) - test(a.width == 0) - test(a.height == 0) - test(a.pos == (0, 0)) - test(a.size == (0, 0)) - - # test every accessor - a.x = 2 - test(a.x == 2) - test(a.pos == (2, 0)) - test(a.center == (2, 0)) - - a.y = 2 - test(a.y == 2) - test(a.pos == (2, 2)) - test(a.center == (2, 2)) - - a.pos = (0, 0) - test(a.x == 0) - test(a.y == 0) - test(a.pos == (0, 0)) - test(a.center == (0, 0)) - - a.width = 2 - test(a.width == 2) - test(a.size == (2, 0)) - test(a.center == (1, 0)) - - a.height = 2 - test(a.height == 2) - test(a.size == (2, 2)) - test(a.center == (1, 1)) - - a.size = (0, 0) - test(a.width == 0) - test(a.height == 0) - test(a.size == (0, 0)) - test(a.center == (0, 0)) - - a.center = (5, 5) - test(a.x == 5) - test(a.y == 5) - test(a.pos == (5, 5)) - test(a.width == 0) - test(a.height == 0) - test(a.size == (0, 0)) - - a.size = (20, 20) - test(a.center == (15, 15)) - diff --git a/kivy/tools/tests/test_css.py b/kivy/tools/tests/test_css.py deleted file mode 100644 index 60ce2b669..000000000 --- a/kivy/tools/tests/test_css.py +++ /dev/null @@ -1,47 +0,0 @@ -''' -Css styling basic tests -''' - -from init import test, import_kivy_no_window - -def unittest_css(): - import_kivy_no_window() - from kivy import MTWidget, Label - from kivy import css_add_sheet - css_add_sheet(''' - .style { - bg-color: rgba(255, 255, 255, 255); - } - #my { bg-color : rgba(255, 0, 255, 0);} - ''') - w = MTWidget(cls='style') - x = MTWidget(id='my',cls='style') - test(w.style['bg-color'] == [1.0 ,1.0 ,1.0 ,1.0]) - test(x.style['bg-color'] == [1.0 ,0.0 ,1.0 ,0.0]) - x.style['bg-color'] = [0, 0, 0, 0] - test(x.style['bg-color'] == [0 ,0 ,0 ,0]) - -def unittest_css_label(): - import_kivy_no_window() - from kivy import MTLabel, css_add_sheet - css_add_sheet(''' - .style { - color: rgba(0, 255, 0, 255); - } - ''') - l = MTLabel(label='test', cls='style') - test(l.style['color'] == [0.0, 1.0, 0.0, 1.0]) - -def unittest_css_multiclass(): - import_kivy_no_window() - from kivy import MTLabel, css_add_sheet - css_add_sheet(''' - .test1 { - font-color : rgba(255,255,255,255); - } - .test2 { - font-size: 24; - } - ''') - l = MTLabel(label = 'test', cls=('test1', 'test2')) - test(l.style['font-size'] == 24) diff --git a/kivy/tools/tests/test_layout.py b/kivy/tools/tests/test_layout.py deleted file mode 100644 index df6c45c4d..000000000 --- a/kivy/tools/tests/test_layout.py +++ /dev/null @@ -1,129 +0,0 @@ -''' -Layout -''' - -from init import test, import_kivy_no_window - -def unittest_boxlayout_horizontal(): - _test_boxlayout('horizontal') - -def unittest_boxlayout_vertical(): - _test_boxlayout('vertical') - -def _test_boxlayout(orientation): - import_kivy_no_window() - from kivy import MTBoxLayout, MTWidget - - # note: this test act always if orientation - # is a horizontal one. use sw() around pos or size - # to ensure that the swap is done. - - def sw(tpl): - tpl = tuple(map(int, tpl)) - if orientation == 'vertical': - return tpl[1], tpl[0] - return tpl - - - # note: default spacing is 1 - # default padding is 0 - - # default add - m = MTBoxLayout(orientation=orientation) - for x in xrange(10): - m.add_widget(MTWidget(size=(10,10))) - test(sw(m.size) == (109, 10)) - - # - # spacing to 10 - # - m = MTBoxLayout(orientation=orientation, spacing=10) - for x in xrange(10): - m.add_widget(MTWidget(size=(10,10))) - test(sw(m.size) == (190, 10)) - - # - # padding to 10 - # - m = MTBoxLayout(orientation=orientation, padding=10, spacing=0) - for x in xrange(10): - m.add_widget(MTWidget(size=(10,10))) - m.do_layout() - - # size should be 10 (number of widget) * width (10) + 2 * padding - test(sw(m.size) == (120, 30)) - for x in xrange(10): - if orientation == 'vertical': - test(sw(m.children[x].pos) == (10 + x * 10, 10)) - else: - test(sw(m.children[x].pos) == (10 + (9 - x) * 10, 10)) - - - # - # testing size_hint with padding - # - m = MTBoxLayout(orientation=orientation, padding=10, spacing=0, - size_hint=(None, None), size=(500, 500)) - m.add_widget(MTWidget(size_hint=(1, 1))) - m.do_layout() - test(sw(m.size) == (500, 500)) - test(sw(m.children[0].size) == (480, 480)) - - # - # testing size_hint with spacing - # - m = MTBoxLayout(orientation=orientation, spacing=10, - size_hint=(None, None), size=(500, 500)) - m.add_widget(MTWidget(size_hint=(1, 1))) - m.do_layout() - - # only one should have no impact - test(sw(m.size) == (500, 500)) - test(sw(m.children[0].size) == (500, 500)) - - # add a second widget - m.add_widget(MTWidget(size_hint=(1, 1))) - m.do_layout() - - # now, we should see difference - test(sw(m.size) == (500, 500)) - test(sw(m.children[0].size) == (245, 500)) - test(sw(m.children[1].size) == (245, 500)) - - - # - # testing with padding + spacing - # - m = MTBoxLayout(orientation=orientation, spacing=10, padding=10) - for x in xrange(10): - m.add_widget(MTWidget(size=(10,10))) - m.do_layout() - - test(sw(m.size) == (210, 30)) - for x in xrange(10): - if orientation == 'vertical': - test(sw(m.children[x].pos) == (10 + x * 20, 10)) - else: - test(sw(m.children[x].pos) == (10 + (9 - x) * 20, 10)) - - - # - # testing with padding + spacing + size_hint - # - m = MTBoxLayout(orientation=orientation, spacing=10, padding=10, - size_hint=(None, None), size=(500, 500)) - m.add_widget(MTWidget(size_hint=(1, 1))) - m.add_widget(MTWidget(size_hint=(1, 1))) - m.do_layout() - - # now, we should see difference - test(sw(m.size) == (500, 500)) - test(sw(m.children[0].size) == (235, 480)) - test(sw(m.children[1].size) == (235, 480)) - if orientation == 'vertical': - test(sw(m.children[0].pos) == (10, 10)) - test(sw(m.children[1].pos) == (255, 10)) - else: - test(sw(m.children[0].pos) == (255, 10)) - test(sw(m.children[1].pos) == (10, 10)) - diff --git a/kivy/tools/tests/test_properties.py~ b/kivy/tools/tests/test_properties.py~ deleted file mode 100644 index d0f3e9c8c..000000000 --- a/kivy/tools/tests/test_properties.py~ +++ /dev/null @@ -1,85 +0,0 @@ -''' -New properties -''' - -from init import test, import_kivy_no_window - -def unittest_property(): - import_kivy_no_window() - from kivy.c_ext.c_properties import Property - - a = Property(-1) - test(a.get() == -1) - a.set(0) - test(a.get() == 0) - a.set(1) - test(a.get() == 1) - -def unittest_property_observer(): - import_kivy_no_window() - from kivy.c_ext.c_properties import Property - - a = Property(-1) - test(a.get() == -1) - global observe_called - observe_called = 0 - def observe(value): - global observe_called - observe_called = 1 - a.bind(observe) - - a.set(0) - test(a.get() == 0) - test(observe_called == 1) - observe_called = 0 - a.set(0) - test(a.get() == 0) - test(observe_called == 0) - a.set(1) - test(a.get() == 1) - test(observe_called == 1) - -def unittest_property_stringcheck(): - import_kivy_no_window() - from kivy.c_ext.c_properties import StringProperty - - a = StringProperty('') - test(a.get() == '') - a.set('hello') - test(a.get() == 'hello') - - try: - a.set(88) # number shouldn't be accepted - test('string accept number, fail.' == 0) - except ValueError: - test('string dont accept number') - -def unittest_property_numericcheck(): - import_kivy_no_window() - from kivy.c_ext.c_properties import NumericProperty - - a = NumericProperty(0) - test(a.get() == 0) - a.set(99) - test(a.get() == 99) - - try: - a.set('') # string shouldn't be accepted - test('number accept string, fail.' == 0) - except ValueError: - test('number dont accept string') - -def unittest_property_propertynone(): - import_kivy_no_window() - from kivy.c_ext.c_properties import NumericProperty - - a = NumericProperty(0, allownone=True) - test(a.get() == 0) - try: - a.set(None) - test(a.get() == None) - except ValueError, e: - print e - test('none not accepted' == 0) - a.set(1) - test(a.get() == 1) diff --git a/kivy/tools/tests/test_textarea.py b/kivy/tools/tests/test_textarea.py deleted file mode 100644 index 2d3738fd8..000000000 --- a/kivy/tools/tests/test_textarea.py +++ /dev/null @@ -1,170 +0,0 @@ -''' -Test usage of MTTextArea widget -''' - -from init import test, import_kivy_window - -def instance(**kwargs): - ''' Individual test framework''' - import_kivy_window() - from kivy import MTTextArea - from kivy import css_add_sheet, css_reload - try: - return MTTextArea(**kwargs) - except: - return None - -def unittest_mttextarea_cursor(): - t = instance() - test(t is not None) - if t is None: - return - - test(t.cursor == (0, 0)) - test(t.cursor_index == 0) - - t.value = 'abc\ndef\nghi' - test(len(t.value) == 11) - test(t.cursor == (3, 2)) - test(t.cursor_index == 11) - - # test some cursor position from text index - test(t.get_cursor_from_index(0) == (0, 0)) - test(t.get_cursor_from_index(1) == (1, 0)) - test(t.get_cursor_from_index(2) == (2, 0)) - test(t.get_cursor_from_index(3) == (3, 0)) - test(t.get_cursor_from_index(4) == (0, 1)) - test(t.get_cursor_from_index(5) == (1, 1)) - test(t.get_cursor_from_index(6) == (2, 1)) - test(t.get_cursor_from_index(7) == (3, 1)) - test(t.get_cursor_from_index(8) == (0, 2)) - test(t.get_cursor_from_index(9) == (1, 2)) - test(t.get_cursor_from_index(10) == (2, 2)) - test(t.get_cursor_from_index(11) == (3, 2)) - - # now, set the cursor, and check the index - t.cursor = (0, 0) - test(t.cursor_index == 0) - t.cursor = (1, 0) - test(t.cursor_index == 1) - t.cursor = (2, 0) - test(t.cursor_index == 2) - t.cursor = (3, 0) - test(t.cursor_index == 3) - t.cursor = (0, 1) - test(t.cursor_index == 4) - t.cursor = (1, 1) - test(t.cursor_index == 5) - t.cursor = (2, 1) - test(t.cursor_index == 6) - t.cursor = (3, 1) - test(t.cursor_index == 7) - t.cursor = (0, 2) - test(t.cursor_index == 8) - t.cursor = (1, 2) - test(t.cursor_index == 9) - t.cursor = (2, 2) - test(t.cursor_index == 10) - t.cursor = (3, 2) - test(t.cursor_index == 11) - - # test bounds - test(t.get_cursor_from_index(-1) == (0, 0)) - test(t.get_cursor_from_index(-100) == (0, 0)) - print t.get_cursor_from_index(12) - test(t.get_cursor_from_index(12) == (3, 2)) - test(t.get_cursor_from_index(100) == (3, 2)) - - -def unittest_mttextarea_basics(): - '''Test driver''' - - # Test defaults - t = instance() - test(t is not None) - if t is None: return - test(t.height == 100) - test(t.width == 100) - test(t.value == '') - test(len(t.lines) == 1) - - # Test operations with a single line in widget - tline1 = 'This is a single line' - t.value = tline1 - test(tline1 == t.value) - test(len(t.lines) == 3) - test(t.height == 100) - test(t.width == 100) - - # Replace text with an empty string - t.value = '' - test(t.value == '') - test(len(t.lines) == 1) - test(t.height == 100) - test(t.width == 100) - - # Now lets put in a string of 12 lines and see what happens - tline2 = ['', 'Line 1', ('Line 2 which is rather long and should overflow' - ' horizontally ........................'), - 'Line 3', 'Line 4', 'Line 5 ', 'Line 6', ' Line 7', - 'Line 8', '', 'Line 10', ''] - tline2b = '\n'.join(tline2) - t.value = tline2b - # Among other things, make sure leading and trailing white space - # are not lost - test(tline2b == t.value) - test(len(t.lines) == 21) - test(t.height == 100) - test(t.width == 100) - - # Lets replace line 8 - '''This is now deprecated. - lt1 = 'Replacement text for line 8' - tline2[7] = lt1 - tline2c = '\n'.join(tline2) - t.set_line_text(7, lt1) - test(tline2c == t.value) - test(len(t.lines) == 12) - test(t.height == 100) - test(t.width == 100) - ''' - - # Test full auto-sizing - del t - t = instance(autosize=True) - test(t is not None) - if t is None: return - - # Test defaults - test(int(t.height) == 25) - test(int(t.width) == 1) - test(t.value == '') - test(len(t._glyph_size) == 0) - test(len(t.lines) == 1) - - # Test operations with a single line in widget - # This test assumes the default font and Pygame as text manager running - # on Ubuntu 10.04. - # Other text managers may give slightly different results for dimensions - # and different fonts could cause larger variations - t.value = tline1 - test(tline1 == t.value) - test(len(t.lines) == 1) - test(int(t.height) == 25) - test(int(t.width) == 203) - - # Replace text with an empty string - t.value = '' - test(t.value == '') - test(len(t.lines) == 1) - test(int(t.height) == 25) - test(int(t.width) == 1) - - # Now lets put in a string of 12 lines and see what happens - t.value = tline2b - # Among other things, make sure leading and trailing white space - # are not lost - test(tline2b == t.value) - test(len(t.lines) == 12) - test(int(t.height) == 322) - test(int(t.width) == 809) diff --git a/kivy/tools/tests/test_textinput.py b/kivy/tools/tests/test_textinput.py deleted file mode 100644 index 395050140..000000000 --- a/kivy/tools/tests/test_textinput.py +++ /dev/null @@ -1,19 +0,0 @@ -''' -test usage of MTTextInput widget -''' - -from init import test, import_kivy_window - -def instance(): - import_kivy_window() - from kivy import MTTextInput - from kivy import css_add_sheet, css_reload - try: - t = MTTextInput() - return True - except: - return False - -def unittest_mttextinput(): - test(instance()) - diff --git a/kivy/tools/tests/test_widget.py b/kivy/tools/tests/test_widget.py deleted file mode 100644 index 4f1d91208..000000000 --- a/kivy/tools/tests/test_widget.py +++ /dev/null @@ -1,101 +0,0 @@ -''' -Widgets -''' - -from init import test, import_kivy_no_window - -def unittest_defaults(): - import_kivy_no_window() - from kivy import MTWidget - w = MTWidget() - test(w.x == 0) - test(w.y == 0) - test(w.width == 100) - test(w.height == 100) - test(w.visible == True) - test(w.draw_children == True) - test(w.cls == '') - -def unittest_visible_methods(): - import_kivy_no_window() - from kivy import MTWidget - w = MTWidget() - w.hide() - test(w.visible == False) - w.show() - test(w.visible == True) - -def unittest_visible_events(): - import_kivy_no_window() - from kivy import MTWidget - - global on_update_called - on_update_called = 0 - - def on_update(): - global on_update_called - on_update_called += 1 - - # by default, visible is True - w = MTWidget() - w.connect('on_draw', on_draw) - w.dispatch_event('on_draw') - test(on_draw_called == 1) - - # make it invisible - w.visible = False - w.dispatch_event('on_draw') - test(on_draw_called == 1) - - # make it visible - w.visible = True - w.dispatch_event('on_draw') - test(on_draw_called == 2) - - # create a new widget, visible default to False - on_draw_called = 0 - w = MTWidget(visible=False) - try: - # XXX FIXME unable to connect to default on_draw - # since it's not yet register. - w.connect('on_draw', on_draw) - except: - pass - w.dispatch_event('on_draw') - test(on_draw_called == 0) - - w.visible = True - w.connect('on_draw', on_draw) - w.dispatch_event('on_draw') - test(on_draw_called == 1) - -def unittest_coordinate_transform(): - import_kivy_no_window() - from kivy import MTWidget - - # child 2 inside child 1 inside child0 - child0 = MTWidget(pos=(100, 100)) - child1 = MTWidget(pos=(200, 200)) - child2 = MTWidget(pos=(300, 300)) - - child0.add_widget(child1) - child1.add_widget(child2) - - test(child0.pos == (100, 100)) - test(child1.pos == (200, 200)) - test(child2.pos == (300, 300)) - - # screen coordinate is default - test(child0.to_local(*child1.pos) == (200, 200)) - - # using the relative attribute, - # we should have relative coordinate - test(child0.to_local(*child1.pos, relative=True) == (100, 100)) - test(child1.to_local(*child2.pos, relative=True) == (100, 100)) - - # screen coordinate 400,400 is 100,100 in relative coordinate from child2 - test(child2.to_widget(400, 400, relative=True) == (100, 100)) - - # 100, 100 relative coordinate from child2 is 400, 400 in screen coordinate - test(child2.to_window(100, 100, relative=True) == (400, 400)) -