Advertisement
SeriAce

Untitled

Apr 1st, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 KB | None | 0 0
  1. from kivy.app import App
  2. from kivy.uix.button import ButtonBehavior
  3. from kivy.uix.image import Image
  4. from kivy.uix.gridlayout import GridLayout
  5. from kivy.uix.floatlayout import FloatLayout
  6. from kivy.uix.scrollview import ScrollView
  7. from kivy.uix.label import Label
  8. from kivy.config import Config
  9. from kivy.graphics import Color, Rectangle
  10. from kivy.uix.widget import Widget
  11. from kivy.lang import Builder
  12. from kivy.properties import ObjectProperty
  13. import kivy.utils
  14.  
  15. Config.set('graphics', 'resizable', '0')
  16. Config.set('graphics', 'width', '540')
  17. Config.set('graphics', 'height', '940')
  18. Config.set('graphics', 'right', 1)
  19. Config.set('graphics', 'top', 1)
  20.  
  21. Builder.load_file("coinbar.kv")
  22.  
  23.  
  24. class ImageButton(ButtonBehavior,Image):
  25. def __init__(self, instance="", is_selected="",**kwargs):
  26. # ---------- Attributes of the ImageButtons, sets the source for the image ----------
  27. self.am_i_selected = ""
  28. self.instance = instance
  29. unselected = "cents/Unselected/"
  30. selected = "cents/Selected/"
  31. png = ".png"
  32. if is_selected == "yes":
  33. source = selected + instance + png
  34. self.am_i_selected = "yes"
  35. else:
  36. source = unselected + instance + png
  37. self.am_i_selected = "no"
  38. # ---------- passes the source to the Image super class ----------
  39. super(ImageButton, self).__init__(**kwargs)
  40. super(ImageButton, self).__init__(source=source)
  41.  
  42. # ---------- on_press behavior of the coins ----------
  43. def select_coin(self):
  44. selected = self.parent.coinbar_selected
  45. Noteskeeper = self.parent.children[0]
  46. TwoCentsPreview = self.parent.children[1]
  47. TwoCents = self.parent.children[2]
  48. MyCents = self.parent.children[3]
  49. if self.am_i_selected == "no":
  50. Noteskeeper.source = "cents/unselected/" + selected + ".png"
  51. self.am_i_selected = "yes"
  52. self.source = "cents/selected/" + self.instance + ".png"
  53. self.parent.coinbar_selected = self.instance
  54.  
  55. return
  56. if self.am_i_selected == "yes":
  57. self.am_i_selected = "no"
  58. self.source = "cents/unselected/" + self.instance + ".png"
  59.  
  60. class CoinBar(GridLayout):
  61. # ---------- CoinBar ----------
  62. def __init__(self,**kwargs):
  63. super(CoinBar, self).__init__(**kwargs)
  64. # ---------- NotesKeeper Coin ----------
  65. self.coinbar_selected = "NotesKeeper"
  66. # ---------- TwoCentsPreview Coin ----------
  67. TwoCentsPreview = ImageButton(instance="TwoCentsPreview", is_selected="no")
  68. TwoCentsPreview.pos_hint = {"top": 1, "right": .5}
  69. TwoCentsPreview.on_press = TwoCentsPreview.select_coin
  70.  
  71. # ---------- TwoCents Coin ----------
  72. TwoCents = ImageButton(instance="TwoCents", is_selected="no")
  73. TwoCents.pos_hint = {"top": 1, "right": .75}
  74. TwoCents.on_press = TwoCents.select_coin
  75.  
  76. # ---------- MyCents Coin ----------
  77. MyCents = ImageButton(instance="MyCents", is_selected="no")
  78. MyCents.pos_hint = {"top": 1, "right": 1}
  79. MyCents.id = "MyCents"
  80. MyCents.on_press = MyCents.select_coin
  81. print(self.ids)
  82. # ---------- Setting the CoinBar Background color to white ----------
  83. with self.canvas.before:
  84. Color(rgb=(kivy.utils.get_color_from_hex("ffffff")))
  85. self.rect = Rectangle(size=self.size, pos=self.pos)
  86. self.bind(pos=self.update_bind_background, size=self.update_bind_background)
  87. def update_bind_background(self, *args):
  88. self.rect.pos = self.pos
  89. self.rect.size = self.size
  90.  
  91. #def build(self):
  92. # return coinbar_kv
  93.  
  94.  
  95. class CatBar(GridLayout):
  96. def __init__(self,**kwargs):
  97. self.rows = 1
  98. Cats = ["Reminder", "Idea", "Funny", "well written"]
  99. super(CatBar, self).__init__(**kwargs)
  100. for number, cat in enumerate(Cats):
  101. number = ImageButton("Cat","no")
  102. self.add_widget(number)
  103.  
  104. class Previews(ScrollView):
  105. def __init__(self,**kwargs):
  106. super(Previews, self).__init__(**kwargs)
  107. # ---------- Middle Grid ----------
  108. noteskeeper_previews = NotesKeeperPreview()
  109. noteskeeper_previews.cols = 1
  110. x = ImageButton()
  111. x.source = "cents/NotesKeeper.png"
  112. noteskeeper_previews.add_widget(x)
  113.  
  114. # ----------- creation of the Previews ----------
  115. self.twocent_previews = GridLayout()
  116. self.twocent_previews.cols = 1
  117.  
  118.  
  119. self.add_widget(noteskeeper_previews)
  120.  
  121. class NotesKeeperPreview(GridLayout):
  122. def __init__(self, **kwargs):
  123. super().__init__()
  124. with self.canvas.before:
  125. Color(rgb=(kivy.utils.get_color_from_hex("ffffff")))
  126. self.rect = Rectangle(size=self.size, pos=self.pos)
  127. self.bind(pos=self.update_bind_background, size=self.update_bind_background)
  128.  
  129. def update_bind_background(self, *args):
  130. self.rect.pos = self.pos
  131. self.rect.size = self.size
  132.  
  133. class ButtonBar(GridLayout):
  134. def __init__(self, **kwargs):
  135. super(ButtonBar, self).__init__(**kwargs)
  136. self.rows = 1
  137. # ---------- sets background of the Button Bar to white ----------
  138. with self.canvas.before:
  139. Color(rgb=(kivy.utils.get_color_from_hex("ffffff")))
  140. self.rect = Rectangle(size=self.size, pos=self.pos)
  141. self.bind(pos=self.update_bind_background, size=self.update_bind_background)
  142. self.b1 = Label()
  143. self.b2 = Label()
  144. self.b3 = Label()
  145. self.b4 = Label()
  146.  
  147. self.add_cat = ImageButton(instance="add_cat", is_selected="no")
  148. self.add_cat.on_press = self.show_options
  149. self.save_thought = ImageButton(instance="save_thought", is_selected="no")
  150.  
  151. self.b3 = self.add_cat
  152. self.b4 = self.save_thought
  153. self.add_buttons()
  154. # ---------- adds b1,b2,b3,b4 to the ButtonBar GridLayout ----------
  155. def add_buttons(self):
  156. self.add_widget(self.b1)
  157. self.add_widget(self.b2)
  158. self.add_widget(self.b3)
  159. self.add_widget(self.b4)
  160.  
  161. # ---------- test function to see what i can access ----------
  162. def show_options(self):
  163. print(self.parent.ids.coin_bar.ids)
  164.  
  165.  
  166. # ---------- future function to add a cat to the category bar ----------
  167. def plus_cat(self, test):
  168. print("This adds a cat")
  169.  
  170. # ---------- future function to add a thought to the previews ----------
  171. def plus_thought(self):
  172. print("this saves a thought")
  173.  
  174. # ---------- binds the background size and position of the background rectangle to the button bar size/pos ----------
  175. def update_bind_background(self, *args):
  176. self.rect.pos = self.pos
  177. self.rect.size = self.size
  178.  
  179. class MainScreen(GridLayout):
  180. # ---------- Root of the main.kv grid. Has the coin_bar, cat_bar, previews and button_bar as children ----------
  181. def __init__(self,**kwargs):
  182. super(MainScreen, self).__init__(**kwargs)
  183.  
  184.  
  185. class MainApp(App):
  186. def __init__(self,**kwargs):
  187. super(MainApp, self).__init__(**kwargs)
  188.  
  189. def build(self):
  190. return MainScreen()
  191.  
  192.  
  193. MainApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement