Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 KB | None | 0 0
  1. import kivy
  2.  
  3. from kivy.app import App
  4. from kivy.lang import Builder
  5. from kivy.uix.button import Button
  6. from kivy.uix.label import Label
  7. from kivy.uix.gridlayout import GridLayout
  8. from kivy.uix.textinput import TextInput
  9. from kivy.properties import ObjectProperty
  10. from kivy.uix.screenmanager import ScreenManager, Screen
  11. from kivy.uix.behaviors.focus import FocusBehavior
  12. from kivy.factory import Factory
  13. from kivy.uix.widget import Widget
  14.  
  15.  
  16.  
  17.  
  18. # You can create your kv code in the Python file
  19. Builder.load_string("""
  20. <KeypadTextInput@TextInput>:
  21. keypad: None
  22. on_focus: root.keypad._on_focus(*args)
  23. <Idle>:
  24. BoxLayout:
  25. Button:
  26. text: "Delivery"
  27. on_press:
  28. # You can define the duration of the change
  29. # and the direction of the slide
  30. root.manager.transition.direction = 'right'
  31. root.manager.transition.duration = 1
  32. root.manager.current = 'LockBox'
  33. Button:
  34. text: "Collect"
  35. on_press:
  36. # You can define the duration of the change
  37. # and the direction of the slide
  38. root.manager.transition.direction = 'left'
  39. root.manager.transition.duration = 1
  40. root.manager.current = 'BoxPin'
  41. <Collecting>:
  42. BoxLayout:
  43. Label:
  44. text: ""
  45. on_press:
  46.  
  47. root.manager.transition.direction = 'right'
  48. root.manager.transition.duration = 1
  49. root.manager.current = 'LockBox'
  50. Button:
  51. text: "Collect"
  52. on_press:
  53. # You can define the duration of the change
  54. # and the direction of the slide
  55. root.manager.transition.direction = 'left'
  56. root.manager.transition.duration = 1
  57. root.manager.current = 'BoxPin'
  58.  
  59. <LockBox>:
  60. GridLayout:
  61. cols:3
  62. rows:2
  63. spacing: 10
  64. padding: 10
  65. Label:
  66. text: "Please select lock box size "
  67. halign: 'center'
  68. valign: 'top'
  69. Button:
  70. text: "SMALL"
  71. on_press:
  72. root.manager.transition.direction = 'right'
  73. root.manager.current = 'UnitPin'
  74. Button:
  75. text: "MEDIUM"
  76. on_press:
  77. root.manager.transition.direction = 'right'
  78. root.manager.current = 'UnitPin'
  79. Button:
  80. text: "LARGE"
  81. on_press:
  82. root.manager.transition.direction = 'right'
  83. root.manager.current = 'UnitPin'
  84. <BoxPin>:
  85.  
  86. FloatLayout:
  87. Button:
  88. text: 'Back'
  89. color: 1.0, 0.6, 0.0, 1
  90. font_size: 20
  91. size_hint_x: 0.250
  92. size_hint_y: 0.150
  93. pos_hint: {'x': 0.025, 'y': 0.03}
  94. on_release:
  95. root.manager.transition.direction = 'right'
  96. root.manager.current = 'Idle'
  97. Button:
  98. id: startStopButton
  99. text: 'Unlock'
  100. color: 1.0, 0.6, 0.0, 1
  101. size_hint_x: 0.250
  102. size_hint_y: 0.150
  103. pos_hint: {'x': 0.725, 'y': 0.03}
  104. on_release:
  105. root.startStop()
  106.  
  107. Label:
  108. text: "Enter Locker Number and SMS code"
  109. color: 1.0, 0.6, 0.0, 1
  110. font_size: 20
  111. pos_hint: {'x': -.265,'y':.35}
  112.  
  113. Label:
  114. text: "Locker No."
  115. color: 1.0, 0.6, 0.0, 1
  116. font_size: 20
  117. pos_hint: {'x': -.42, 'y':.1}
  118.  
  119. Label:
  120. text: "SMS Code"
  121. color: 1.0, 0.6, 0.0, 1
  122. font_size: 20
  123. pos_hint: {'x': -.42, 'y': -.15}
  124.  
  125.  
  126. FloatLayout:
  127.  
  128.  
  129. KeypadTextInput:
  130. keypad: keypad
  131. color: 1.0, .6, 0, 1
  132. font_size: 20
  133. size_hint_x: .275
  134. size_hint_y: .15
  135. pos_hint: {'x': .15,'y': .525}
  136. KeypadTextInput:
  137. keypad: keypad
  138. color: 1.0, 0.6, 0.0, 1
  139. font_size: 20
  140. size_hint_x: .275
  141. size_hint_y: .15
  142. pos_hint: {'x': .15,'y': .275}
  143. Keypad:
  144. id: keypad
  145. cols: 3
  146. rows: 4
  147. spacing: 10
  148. pos_hint: {'x': .475,'y': .25}
  149. size_hint: (.5,.7)
  150.  
  151. ############################################################################################
  152.  
  153. <UnitPin>:
  154.  
  155. FloatLayout:
  156. Button:
  157. text: 'Back'
  158. color: 1.0, 0.6, 0.0, 1
  159. font_size: 20
  160. size_hint_x: 0.250
  161. size_hint_y: 0.150
  162. pos_hint: {'x': 0.025, 'y': 0.03}
  163. on_release:
  164. root.manager.transition.direction = 'left'
  165. root.manager.current = 'Idle'
  166. Button:
  167. id: unitSelector
  168. text: 'Select'
  169. color: 1.0, 0.6, 0.0, 1
  170. size_hint_x: 0.250
  171. size_hint_y: 0.150
  172. pos_hint: {'x': 0.725, 'y': 0.03}
  173. on_release:
  174. root.startStop()
  175. Button:
  176. id: Scanner
  177. text: 'Scan'
  178. size_hint_x: 0.4
  179. size_hint_y: 0.15
  180. pos_hint:{'x': 0.3,'y': 0.03}
  181. on_release:
  182. #root.polarity()
  183.  
  184. Label:
  185. text: "Enter Unit Number"
  186. color: 1.0, 0.6, 0.0, 1
  187. font_size: 20
  188. pos_hint: {'x': -.265,'y':.35}
  189.  
  190. Label:
  191. text: "Unit No."
  192. color: 1.0, 0.6, 0.0, 1
  193. font_size: 20
  194. pos_hint: {'x': -.42, 'y':.1}
  195.  
  196. Label:
  197. text: "Bar Code"
  198. color: 1.0, 0.6, 0.0, 1
  199. font_size: 20
  200. pos_hint: {'x': -.42, 'y': -.15}
  201.  
  202.  
  203. FloatLayout:
  204.  
  205.  
  206. KeypadTextInput:
  207. keypad: keypad
  208. color: 1.0, .6, 0, 1
  209. font_size: 20
  210. size_hint_x: .275
  211. size_hint_y: .15
  212. pos_hint: {'x': .15,'y': .525}
  213. KeypadTextInput:
  214. keypad: keypad
  215. color: 1.0, 0.6, 0.0, 1
  216. font_size: 20
  217. size_hint_x: .275
  218. size_hint_y: .15
  219. pos_hint: {'x': .15,'y': .275}
  220. Keypad:
  221. id: keypad
  222. cols: 3
  223. rows: 4
  224. spacing: 10
  225. pos_hint: {'x': .475,'y': .25}
  226. size_hint: (.5,.7)
  227.  
  228.  
  229. """)
  230.  
  231.  
  232. # Create a class for all screens in which you can include
  233. # helpful methods specific to that screen
  234. class Idle(Screen):
  235. pass
  236.  
  237.  
  238.  
  239.  
  240.  
  241. class LockBox(Screen):
  242. pass
  243.  
  244.  
  245. class UnitPin(Screen):
  246. pass
  247.  
  248. class BoxPin(Screen):
  249. LockerNo_input = ObjectProperty()
  250. PinNo_input = ObjectProperty()
  251. pass
  252.  
  253.  
  254. class BoxPin(Screen):
  255.  
  256. def startStop(self):
  257. if self.ids.startStopButton.text == "Start":
  258. self.ids.startStopButton.text = "Stop"
  259. else:
  260. self.ids.startStopButton.text = "Start"
  261.  
  262. def polarity(self):
  263. if self.ids.polButton.text == "Polarity +":
  264. self.ids.polButton.text = "Polarity -"
  265. else:
  266. self.ids.polButton.text = "Polarity +"
  267.  
  268.  
  269. class KeypadButton(Button):
  270.  
  271. def on_touch_down(self, touch):
  272. if self.collide_point(*touch.pos):
  273. FocusBehavior.ignored_touch.append(touch)
  274. return super(KeypadButton, self).on_touch_down(touch)
  275.  
  276. class Keypad(GridLayout):
  277. target = ObjectProperty(None, allownone=True)
  278.  
  279. def __init__(self, **kwargs):
  280. super(Keypad, self).__init__(**kwargs)
  281. self.cols = 3
  282. for x in list(range(1, 10)) + ['<-', 0, 'Enter']:
  283. btn = KeypadButton(text=str(x), on_release=self._on_release)
  284. self.add_widget(btn)
  285.  
  286. def _on_focus(self, value, ti):
  287. self.target = value and ti
  288.  
  289. def _on_release(self, instance, *largs):
  290. if self.target:
  291. if instance.text == 'Enter':
  292. print("Enter: {}".format(self.target.text))
  293. self.target.text = ''
  294. elif instance.text == '<-':
  295. if self.target.text:
  296. self.target.text = self.target.text[:-1]
  297. #else:
  298. #self.target.text += str(instance.text)
  299. print(self.target.text)
  300. elif self.target == None:
  301. print('none')
  302. else:
  303. print(instance.text)
  304.  
  305. # The ScreenManager controls moving between screens
  306. screen_manager = ScreenManager()
  307.  
  308. # Add the screens to the manager and then supply a name
  309. # that is used to switch screens
  310. screen_manager.add_widget(Idle(name="Idle"))
  311.  
  312. screen_manager.add_widget(LockBox(name="LockBox"))
  313.  
  314. screen_manager.add_widget(BoxPin(name="BoxPin"))
  315. screen_manager.add_widget(UnitPin(name="UnitPin"))
  316.  
  317.  
  318. class Dlocker(App):
  319.  
  320. global dbHost
  321. global dbName
  322. global dbUser
  323. global dbPass
  324.  
  325. dbHost = 'localhost'
  326. dbName = 'DB_GAP'
  327. dbUser = 'Gaptech'
  328. dbPass = 'dlocker'
  329.  
  330.  
  331. def build(self):
  332. return screen_manager
  333.  
  334.  
  335. dlocker = Dlocker()
  336. dlocker.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement