Commits

magik_cypress  committed 0fd1de6 Draft

first import

  • Participants

Comments (0)

Files changed (5)

+Showcase
+========
+
+Demonstrate all the possibilities of Kivy toolkit.
+
+Android
+-------
+
+You can copy/paste this directory into /sdcard/kivy/showcase in your
+android device.
+
+title=Showcase
+author=Kivy team
+orientation=portrait
+#:kivy 1.0
+#:import kivy kivy
+#:import application_cms main
+
+<Editor>:
+    content: content
+    canvas:
+        Color:
+            rgb: 1, 1, 1
+        Rectangle:
+            source: 'data/images/background.jpg'
+            size: self.size
+
+    BoxLayout:
+        orientation: 'vertical'
+
+        BoxLayout:
+            padding: 10
+            spacing: 10
+            size_hint: 1, None
+            pos_hint: {'top': 1}
+            height: 44
+            Image:
+                size_hint: None, None
+                size: 24, 24
+                source: 'data/logo/kivy-icon-24.png'
+            Label:
+                height: 24
+                text_size: self.width, None
+                color: (1, 1, 1, .8)
+                text: 'Kivy %s - Add content couchdb via couchdbkit' % kivy.__version__
+
+        FloatLayout:
+            id: content
+
+[Title@Label]
+    pos_hint: {'center_x': .5, 'y': .3}
+    text: ctx.text
+    font_size: 22
+
+[VSeparator@Widget]:
+	size_hint_x: None
+	width: 10
+	canvas:
+		Color:
+			rgba: .8, .8, .8, .3
+		Rectangle:
+			size: 1, self.height
+			pos: self.center_x, self.y
+
+[HSeparator@Label]:
+	size_hint_y: None
+	height: 45
+	text: ctx.text if 'text' in ctx else ''
+	text_size: self.size
+	valign: 'middle'
+	halign: 'center'
+	canvas.before:
+		Color:
+			rgba: .2, .2, .2, .8
+		Rectangle:
+			size: self.size
+			pos: self.pos
+
+<StandardWidgets>:
+    text_input_title: text_input_title
+    text_input_paragraph: text_input_paragraph
+	BoxLayout:
+		pos_hint: {'x': 0, 'y': 0}
+
+		BoxLayout:
+		    orientation: 'vertical'
+
+            HSeparator:
+                text: 'Add content'
+
+		    BoxLayout:
+		        orientation: 'vertical'
+		        padding: 2
+		        spacing: 2
+
+                TextInput:
+                    id: text_input_title
+                    text: 'Title'
+                    focus: 'True'
+                    size_hint_y: None
+                    height: 30
+
+                TextInput:
+                    id: text_input_paragraph
+                    text: 'Paragraph'
+
+                Button:
+                    text: 'Send'
+                    on_release: root.callback()
+                    height: 30
+import kivy
+kivy.require('1.1.3')
+
+from kivy.properties import NumericProperty
+from kivy.properties import ObjectProperty
+from kivy.app import App
+from kivy.uix.boxlayout import BoxLayout
+from kivy.uix.floatlayout import FloatLayout
+from kivy.uix.button import Button
+from kivy.uix.widget import Widget
+from kivy.clock import Clock
+from couchdbkit import Server
+import random
+import datetime
+import json
+
+
+class Editor(FloatLayout):
+    pass
+
+
+class StandardWidgets(FloatLayout):
+
+    value = NumericProperty(0)
+    text_input_title = ObjectProperty(None)
+    text_input_paragraph = ObjectProperty(None)
+
+    def __init__(self, **kwargs):
+        super(StandardWidgets, self).__init__(**kwargs)
+        Clock.schedule_interval(self.increment_value, 1 / 30.)
+
+    def increment_value(self, dt):
+        self.value += dt
+
+    def connect_server(self):
+        server = Server('http://admin:sekrit@127.0.0.1:5984/')
+        try:
+            self.db = server.get_or_create_db("greeting-kivy")
+        except:
+            self.db = server.get_db("greeting-kivy")
+
+        return self.db
+
+    def callback(self):
+        self.db = self.connect_server()
+        published = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
+        greeting = {
+            "title": self.text_input_title.text,
+            "paragraph": self.text_input_paragraph.text,
+            "published": published
+        }
+        self.db.save_doc(greeting)
+        print 'Data save'
+
+class EditorApp(App):
+
+    def build(self):
+        root = BoxLayout(orientation='horizontal', padding=20, spacing=20)
+
+        self.content = content = BoxLayout()
+        root.add_widget(content)
+        sc = Editor()
+        sc.content.add_widget(root)
+        self.content.add_widget(StandardWidgets())
+        return sc
+
+if __name__ in ('__main__', '__android__'):
+    EditorApp().run()

File main.pyc

Binary file added.