Table of Contents
Preface V
Author's Biography XV
1 Introduction of Python 1
1.1 Wht Python 1
1.1.1 Drawbacks of Python 1
1.2 History of Python 2
1.3 Major features of Python 2
1.3.1 What is new in upcoming Python 3.8 3
1.4 Market demand 7
1.5 Why Python in mobile app development? 9
1.6 Python versions 11
1.7 Architecture of python application 11
1.8 System requirement 13
1.9 Installation of python in various platform 13
Installation in widows 13
Installation in Linux 13
Installation in Mac 14
1.10 Creating First Hello World app 14
1.10.1 Basic operations in python prompt 17
1.11 Anatomy of Python program 17
1.12 IDLE 18
1.13 User input 18
1.14 Installing external modules using pip 18
Summary 19
Key terms 20
Review questions 20
Exercise 21
2 Python basics 24
2.1 Variables 24
2.2 Data types 26
2.2.1 Booleans 28
2.2.2 Integer 28
2.2.3 Float 28
2.2.4 String 28
2.2.5 None 29
2.3 Block indentation 29
2.4 Math calculations 30
2.5 Operators 31
2.6 String operations 31
2.7 Indexing 32
2.8 Slicing 33
2.9 Concatenation 33
2.10 Single-line and multiline comments 33
2.11 Functions 34
2.11.1 Built-in functions 34
2.11.2 User-defined functions 35
2.11.3 Function with argument 36
2.11.4 Flow of execution 36
2.11.5 Default values 36
2.12 Return value 37
2.13 Type-casting 38
2.14 Disassembler 38
2.15 Lambda keyword 39
Summary 40
Key terms 40
Review questions 41
Exercise 41
3 Conditions and loops 45
3.1 If and else and conditional statements 45
3.1.1 Nested if-else 47
3.2 Loops 48
3.2.1 For loop 48
3.2.2 While loop 49
3.3 Break and continue statement 49
3.4 Collections 50
3.4.1 Tuples 51
3.4.2 Lists 52
3.4.3 Sets 54
3.4.4 Frozen sets 55
3.4.5 Byte 56
3.4.6 Byte array 56
3.4.7 String 57
3.4.8 Dictionaries 58
3.4.9 Arrays 60
3.5 Date and time 61
Summary 61
Key terms 62
Review questions 62
Exercise 62
4 Object-oriented programming (OOP) 65
4.1 Object-oriented programming (OOP) 65
4.2 Class-65
4.3 Object 66
4.4 Functions 66
4.5 Abstraction 68
4.5.1 Abstract class 69
4.5.2 Interface 70
4.6 Polymorphism 73
4.6.1 Overloading 75
4.6.2 Overriding 76
4.7 Encapsulation 78
4.8 Inheritance 79
4.9 Access modifier/specifier 80
4.10 Decorator 81
4.10.1 @classmethod decorator 82
4.10.2 @staticmethod decorator 83
Summary 83
Key terms 84
Review questions 84
Exercise 85
5 Standard libraries 88
5.1 File operations using native 88
5.1.1 Writing file 89
5.2 OS module 89
5.3 Exception handling 91
5.3.1 User-defined exceptions 92
5.4 Import standard Python modules and packages 92
5.4.1 Creating a module 93
5.4.2 Packages 93
5.5 Regulat expression 95
5.6 Math module 97
5.6.1 Writing documentation for module 98
5.7 JSON 99
5.8 SQLite 101
5.9 SQLAIchemy 103
Summary 104
Key terms 104
Review questions 105
Exercise 106
6 Getting started with Kivy 109
6.1 Why cross-platform? 109
6.2 What is Kivy 109
6.3 Why Python in mobile app 109
6.4 Kivy architecture 110
6.5 Python developed mobile apps 113
6.6 History of Kivy 114
6.7 Why not Cordova 114
6.8 Kivy versions 114
6.9 How it is different from the cross-platform app framework 114
6.10 System requirement 115
6.11 Installation of Kivy 115
6.11.1 Installation in Windows? 115
6.11.2 Installation in Mac OS? 115
6.11.3 Installation in Linux? 116
6.11.4 What are Wheels and pip? 117
6.11.5 Cython installation in Linux? 118
6.11.6 Verifying installation 118
6.12 Creating the First Hello World App 118
6.12.1 Event handling in Kivy 119
6.12.2 Event dispatcher 119
6.12.3 Main loop 119
6.12.4 Custom events 120
6.13 Anatomy of Kivy 121
6.13.1 Running Kivy application 122
6.13.2 Listing and uninstalling Kivy 124
Summary 125
Key terms 126
Review questions 126
Exercise 127
7 Kivy basics 130
17.1 Configuring environment 130
17.2 Configure Kivy and how to import Kivy library 140
17.3 First app 142
7.3.1 Widgets 145
7.3.2 Custom widgets 146
7.4 Orientation horizontal and vertical 147
7.4.1 Size-hint, pos_hint 149
7.4.2 Pos_hint 152
7.4.3 FileChooser 154
7.5 Super, padding,__init__, add_widget 158
7.5.1 Super 158
7.5.2 __init__ 159
7.5.3 Add_widget 161
Summary 162
Key terms 163
Review questions 163
Exercise 164
8 Layouts 167
8.1 What is the layout 167
8.2 Box layout 167
8.3 Float layout 170
8.4 Anchor layout 175
8.5 Grid layout 178
8.6 Relative layout 181
8.7 Stack layout 184
8.8 Page layout 184
Summary 186
Key terms 186
Review questions 186
Exercise 187
9 Designing user interfaces 190
9.1 What is UI (user interface) components 190
9.2 Buttons 190
9.3 Labels 193
9.4 ListView 196
9.4.1 RecyclerView 197
9.5 Image 201
9.6 Events and properties 202
9.7 Fonts and their properties 204
9.8 Popup menu 204
9.9 TextInput 206
9.10 ScrollView 207
9.11 Kivy clock 208
Summary 209
Key terms 210
Review questions 210
Exercise 210
10 UX widgets 213
10.1 ActionBar and slider 213
10.2 Checkbox and text on window 215
10.2.1 Toggle button 219
10.2.2 TreeView 222
10.3 Radio/checkbox button and label management 224
10.4 ProgressBar and carousel 228
Kivy clock 230
10.4.1 Custom ProgressBar 231
10.4.2 Carousel layout 234
10.4.3 Scatter 237
10.5 Canvas 239
10.6 AsyncImage 241
10.7 Spinner 243
10.8 Accordion 244
10.9 Switching between two screens 245
Summary 247
Key terms 249
Review questions 250
Exercise 250
11 Graphics handling 253
11.1 Graphics 253
11.2 Interacting with another framework 256
11.3 Modules 260
11.4 Network support 261
11.5 Storage tool 262
11.6 Rotate clock and rotate speed 264
11.7 Triggered events 266
11.8 Animations 268
11.9 Audio 270
11.10 Video 271
Annotation 276
Summary 276
Key terms 278
Review questions 279
Exercise 279
12 Packaging app for various platforms 282
12.1 Adding behaviour with mixin class 282
12.1.1 Packaging application 284
12.1.2 Testing application with android device 285
12.1.3 Packaging for android 291
12.1.4 Plyer 303
12.2 Building an android APK on OS X 304
12.3 Package licensing 305
12.4 Packaging application using Kivy launcher 305
12.5 External libraries 306
12.6 Python application testing 306
12.7 Release on the market 311
12.8 Kivy application testing 311
Summary 311
Key terms 313
Review questions 314
Exercise 314
13 Sample project 318
13.1 Introduction of git 318
13.2 Implementation of git 318
13.3 Sample project 1 320
Sample project 2 324
13.4 Kivy catalog 327
13.5 Creating my own screen 335
13.6 Project game 336
Bibliography 341
Index 343