Merge branch 'master' of ssh://github.com/kivy/kivy

This commit is contained in:
Mathieu Virbel 2012-08-10 11:18:06 +02:00
commit e02fd0dba5
5 changed files with 67 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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 ``<PongGame>`` rule we have is a canvas block::
The first block inside the ``<PongGame>`` rule we have is a canvas block:
.. code-block:: kv
<PongGame>:
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
<PongGame>:
...
# ...
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
<PongBall>:
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
<PongGame>:
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?

View File

@ -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.