From d178f02c5baee2e3202d55ccf85a8cf45bed62aa Mon Sep 17 00:00:00 2001 From: Dominik Kozaczko Date: Thu, 9 Aug 2012 13:07:07 +0200 Subject: [PATCH 1/4] small corrections to docs --- doc/Makefile | 2 +- doc/sources/guide/other-frameworks.rst | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 571a0b883..de560f124 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -2,7 +2,7 @@ # # You can set these variables from the command line. -PYTHON = python +PYTHON = python2 SPHINXOPTS = -W #SPHINXOPTS = SPHINXBUILD = sphinx-build diff --git a/doc/sources/guide/other-frameworks.rst b/doc/sources/guide/other-frameworks.rst index 13eb7f9d9..164159769 100644 --- a/doc/sources/guide/other-frameworks.rst +++ b/doc/sources/guide/other-frameworks.rst @@ -13,13 +13,13 @@ Using Twisted inside Kivy install a twisted reactor that will run inside the kivy event loop. Any arguments or keyword arguments passed to this function will be - passed on the the threadedselect reactors interleave function, these + passed on the threadedselect reactors interleave function, these are the arguments one would usually pass to twisted's reactor.startRunning .. warning:: Unlike the default twisted reactor, the installed reactor will not handle any signals unnless you set the 'installSignalHandlers' keyword argument - to 1 explicitly. This is done to allow kivy to handle teh signals as + to 1 explicitly. This is done to allow kivy to handle the signals as usual, unless you specifically want the twisted reactor to handle the signals (e.g. SIGINT). @@ -27,14 +27,15 @@ Using Twisted inside Kivy The kivy examples include a small example for a twisted server and client. The server app has a simple twisted server running and log any messages. -The client app can send messages to teh server and will print its message +The client app can send messages to the server and will print its message and the repsonse it got. The examples are based mostly on simple Echo example from the twisted docs, which you can find here: + - http://twistedmatrix.com/documents/current/core/examples/simpleserv.py - http://twistedmatrix.com/documents/current/core/examples/simpleclient.py To try the example run echo_server_app.py first, and then launch -echo_client_app.py. The server will, reply with simple echo messages to +echo_client_app.py. The server will reply with simple echo messages to anything the client app sends, when you hit enter after typing something in the textbox. From e68d68d1ac4e71093262d513782edef34c6cadeb Mon Sep 17 00:00:00 2001 From: Dominik Kozaczko Date: Thu, 9 Aug 2012 13:20:14 +0200 Subject: [PATCH 2/4] README links to correct API doc location --- doc/README | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/README b/doc/README index 5af6ddb43..9f124bfcd 100644 --- a/doc/README +++ b/doc/README @@ -2,8 +2,7 @@ Kivy - Documentation ==================== You can access the API documentation on web : - * last released version : http://kivy.org/docs/api - * trunk version, updated nightly : http://kivy.org/docs/api-trunk/ + * last released version : http://kivy.org/docs/api-index.html How to build the documentation From d1eefab85171f162c2401d37127e6b4e1faf7adc Mon Sep 17 00:00:00 2001 From: Dominik Kozaczko Date: Thu, 9 Aug 2012 13:50:05 +0200 Subject: [PATCH 3/4] more corrections to docs --- doc/Makefile | 2 +- doc/sources/guide/designwithkv.rst | 9 ++++--- doc/sources/tutorials/pong.rst | 38 ++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index de560f124..571a0b883 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -2,7 +2,7 @@ # # You can set these variables from the command line. -PYTHON = python2 +PYTHON = python SPHINXOPTS = -W #SPHINXOPTS = SPHINXBUILD = sphinx-build diff --git a/doc/sources/guide/designwithkv.rst b/doc/sources/guide/designwithkv.rst index 0d1c34062..3291d3ae4 100644 --- a/doc/sources/guide/designwithkv.rst +++ b/doc/sources/guide/designwithkv.rst @@ -27,8 +27,9 @@ create the UI around the ``Controller`` class in a file named `controller.kv`, which will be loaded when we run the ``ControllerApp``. How this is done and what files are loaded is described in the :func:`kivy.app.App.load_kv` method. -.. include:: ../../../examples/guide/designwithkv/controller.kv - :literal: +.. literalinclude:: ../../../examples/guide/designwithkv/controller.kv + :language: kv + :linenos: One label and one button in a vertical ``BoxLayout``. Seems very simple. There are 3 things going on here: @@ -52,7 +53,9 @@ are 3 things going on here: the current widget. * You can use any id declared in the rule the same as ``root`` and - ``self``. For example, you could do this in the ``on_press()``:: + ``self``. For example, you could do this in the ``on_press()``: + + .. code-block:: kv Button: on_press: root.do_action(); my_custom_label.font_size = 18 diff --git a/doc/sources/tutorials/pong.rst b/doc/sources/tutorials/pong.rst index b7bbd3171..da76c9906 100644 --- a/doc/sources/tutorials/pong.rst +++ b/doc/sources/tutorials/pong.rst @@ -74,8 +74,9 @@ called ``pong.kv`` in the same directory that will be automatically loaded when the application is run. So create a new file called ``*pong.kv*`` and add the following contents. -.. include:: ../../../examples/tutorials/pong/steps/step2/pong.kv - :literal: +.. literalinclude:: ../../../examples/tutorials/pong/steps/step2/pong.kv + :language: kv + :linenos: If you run the app now, you should see a vertical bar in the middle, and two zeros where the player scores will be displayed. @@ -127,7 +128,9 @@ child widgets that will be automatically added, or a `canvas` section in which you can add Graphics instructions that define how the widget itself is rendered. -The first block inside the ```` rule we have is a canvas block:: +The first block inside the ```` rule we have is a canvas block: + +.. code-block:: kv : canvas: @@ -150,10 +153,12 @@ score once we have the logic for that implemented. But the labels already look good, since we set a bigger font_size, and positioned them relatively to the root widget. The ``root`` keyword can be used inside child block to refer back to the parent/root widget the rule applies to (``PongGame`` in this -case):: +case): + +.. code-block:: kv : - ... + # ... Label: font_size: 70 @@ -207,7 +212,9 @@ Here is the python code for the PongBall class:: self.pos = Vector(*self.velocity) + self.pos -And here is the kv rule used to draw the ball as a white circle:: +And here is the kv rule used to draw the ball as a white circle: + +.. code-block:: kv : size: 50, 50 @@ -232,8 +239,9 @@ Here is the entire updated python code and kv file for this step: :literal: pong.kv: - .. include:: ../../../examples/tutorials/pong/steps/step3/pong.kv - :literal: + .. literalinclude:: ../../../examples/tutorials/pong/steps/step3/pong.kv + :language: kv + :linenos: Adding ball animation @@ -308,7 +316,9 @@ inside the ``update`` method and even make it bounce of the edges:: self.ball.velocity_x *= -1 Don't forget to hook it up in the kv file, by giving the child widget an id -and setting the games property to that id:: +and setting the games property to that id: + +.. code-block:: kv : ball: pong_ball @@ -337,8 +347,9 @@ Here is the entire code for this step: :literal: pong.kv: - .. include:: ../../../examples/tutorials/pong/steps/step4/pong.kv - :literal: + .. literalinclude:: ../../../examples/tutorials/pong/steps/step4/pong.kv + :language: kv + :linenos: Connect input event ------------------- @@ -401,8 +412,9 @@ And here it is in context. Pretty much done: pong.kv: - .. include:: ../../../examples/tutorials/pong/steps/step5/pong.kv - :literal: + .. literalinclude:: ../../../examples/tutorials/pong/steps/step5/pong.kv + :language: kv + :linenos: Where to go now? From d0cdce6cc01e01b5ca8a5c7564b87f786c9547e5 Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Thu, 9 Aug 2012 13:52:46 -0500 Subject: [PATCH 4/4] uix.screenmanager.ScreenManager: * this fixes issue #634 * remove exception when new screen with same name as existing is added * instead warn when switching to a screen by name, and there are multiple * adds `screen_names` property, to get list of all screen names --- kivy/uix/screenmanager.py | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/kivy/uix/screenmanager.py b/kivy/uix/screenmanager.py index 2d451002c..6537269d7 100644 --- a/kivy/uix/screenmanager.py +++ b/kivy/uix/screenmanager.py @@ -115,9 +115,10 @@ __all__ = ('Screen', 'ScreenManager', 'ScreenManagerException', 'TransitionBase', 'ShaderTransition', 'SlideTransition', 'SwapTransition', 'FadeTransition', 'WipeTransition') +from kivy.logger import Logger from kivy.event import EventDispatcher from kivy.uix.floatlayout import FloatLayout -from kivy.properties import StringProperty, ObjectProperty, \ +from kivy.properties import StringProperty, ObjectProperty, AliasProperty, \ NumericProperty, ListProperty, OptionProperty, BooleanProperty from kivy.animation import Animation, AnimationTransition from kivy.uix.relativelayout import RelativeLayout @@ -560,21 +561,37 @@ class ScreenManager(FloatLayout): default to None, read-only. ''' + def _get_screen_names(self): + return [s.name for s in self.screens] + + screen_names = AliasProperty(_get_screen_names, None, bind=('screens',)) + '''List of the names of all the :class:`Screen` widgets added. The list + is read only. + + :data:`screens_names` is a :class:`~kivy.properties.AliasProperty`, + it is read-only and updated if the screen list changes, or the name + of a screen changes. + ''' + + def __init__(self, **kwargs): super(ScreenManager, self).__init__(**kwargs) self.bind(pos=self._update_pos) + def _screen_name_changed(self, screen, name): + self.property('screen_names').dispatch(self) + if screen == self.current_screen: + self.current = name + def add_widget(self, screen): if not isinstance(screen, Screen): raise ScreenManagerException( 'ScreenManager accept only Screen widget.') - if screen.name in [s.name for s in self.screens]: - raise ScreenManagerException( - 'Name %r already used' % screen.name) if screen.manager: raise ScreenManagerException( 'Screen already managed by another ScreenManager.') screen.manager = self + screen.bind(name=self._screen_name_changed) self.screens.append(screen) if self.current is None: self.current = screen.name @@ -592,6 +609,8 @@ class ScreenManager(FloatLayout): screen = self.get_screen(value) if not screen: return + if screen == self.current_screen: + return previous_screen = self.current_screen self.current_screen = screen @@ -608,9 +627,13 @@ class ScreenManager(FloatLayout): '''Return the screen widget associated to the name, or None if not found. ''' - for screen in self.screens: - if screen.name == name: - return screen + matches = [s for s in self.screens if s.name == name] + num_matches = len(matches) + if num_matches == 0: + raise ScreenManagerException('No Screen with name "%s".' % name) + if num_matches > 1: + Logger.warn('Multiple screens named "%s": %s' % (name, matches)) + return matches[0] def next(self): '''Return the name of the next screen from the screen list.