Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from kivy.app import App
- from kivy.uix.button import ButtonBehavior
- from kivy.uix.image import Image
- from kivy.uix.gridlayout import GridLayout
- from kivy.uix.floatlayout import FloatLayout
- from kivy.uix.scrollview import ScrollView
- from kivy.uix.label import Label
- from kivy.config import Config
- from kivy.graphics import Color, Rectangle
- from kivy.uix.widget import Widget
- from kivy.lang import Builder
- from kivy.properties import ObjectProperty
- import kivy.utils
- Config.set('graphics', 'resizable', '0')
- Config.set('graphics', 'width', '540')
- Config.set('graphics', 'height', '940')
- Config.set('graphics', 'right', 1)
- Config.set('graphics', 'top', 1)
- Builder.load_file("coinbar.kv")
- class ImageButton(ButtonBehavior,Image):
- def __init__(self, instance="", is_selected="",**kwargs):
- # ---------- Attributes of the ImageButtons, sets the source for the image ----------
- self.am_i_selected = ""
- self.instance = instance
- unselected = "cents/Unselected/"
- selected = "cents/Selected/"
- png = ".png"
- if is_selected == "yes":
- source = selected + instance + png
- self.am_i_selected = "yes"
- else:
- source = unselected + instance + png
- self.am_i_selected = "no"
- # ---------- passes the source to the Image super class ----------
- super(ImageButton, self).__init__(**kwargs)
- super(ImageButton, self).__init__(source=source)
- # ---------- on_press behavior of the coins ----------
- def select_coin(self):
- selected = self.parent.coinbar_selected
- Noteskeeper = self.parent.children[0]
- TwoCentsPreview = self.parent.children[1]
- TwoCents = self.parent.children[2]
- MyCents = self.parent.children[3]
- if self.am_i_selected == "no":
- Noteskeeper.source = "cents/unselected/" + selected + ".png"
- self.am_i_selected = "yes"
- self.source = "cents/selected/" + self.instance + ".png"
- self.parent.coinbar_selected = self.instance
- return
- if self.am_i_selected == "yes":
- self.am_i_selected = "no"
- self.source = "cents/unselected/" + self.instance + ".png"
- class CoinBar(GridLayout):
- # ---------- CoinBar ----------
- def __init__(self,**kwargs):
- super(CoinBar, self).__init__(**kwargs)
- # ---------- NotesKeeper Coin ----------
- self.coinbar_selected = "NotesKeeper"
- # ---------- TwoCentsPreview Coin ----------
- TwoCentsPreview = ImageButton(instance="TwoCentsPreview", is_selected="no")
- TwoCentsPreview.pos_hint = {"top": 1, "right": .5}
- TwoCentsPreview.on_press = TwoCentsPreview.select_coin
- # ---------- TwoCents Coin ----------
- TwoCents = ImageButton(instance="TwoCents", is_selected="no")
- TwoCents.pos_hint = {"top": 1, "right": .75}
- TwoCents.on_press = TwoCents.select_coin
- # ---------- MyCents Coin ----------
- MyCents = ImageButton(instance="MyCents", is_selected="no")
- MyCents.pos_hint = {"top": 1, "right": 1}
- MyCents.id = "MyCents"
- MyCents.on_press = MyCents.select_coin
- print(self.ids)
- # ---------- Setting the CoinBar Background color to white ----------
- with self.canvas.before:
- Color(rgb=(kivy.utils.get_color_from_hex("ffffff")))
- self.rect = Rectangle(size=self.size, pos=self.pos)
- self.bind(pos=self.update_bind_background, size=self.update_bind_background)
- def update_bind_background(self, *args):
- self.rect.pos = self.pos
- self.rect.size = self.size
- #def build(self):
- # return coinbar_kv
- class CatBar(GridLayout):
- def __init__(self,**kwargs):
- self.rows = 1
- Cats = ["Reminder", "Idea", "Funny", "well written"]
- super(CatBar, self).__init__(**kwargs)
- for number, cat in enumerate(Cats):
- number = ImageButton("Cat","no")
- self.add_widget(number)
- class Previews(ScrollView):
- def __init__(self,**kwargs):
- super(Previews, self).__init__(**kwargs)
- # ---------- Middle Grid ----------
- noteskeeper_previews = NotesKeeperPreview()
- noteskeeper_previews.cols = 1
- x = ImageButton()
- x.source = "cents/NotesKeeper.png"
- noteskeeper_previews.add_widget(x)
- # ----------- creation of the Previews ----------
- self.twocent_previews = GridLayout()
- self.twocent_previews.cols = 1
- self.add_widget(noteskeeper_previews)
- class NotesKeeperPreview(GridLayout):
- def __init__(self, **kwargs):
- super().__init__()
- with self.canvas.before:
- Color(rgb=(kivy.utils.get_color_from_hex("ffffff")))
- self.rect = Rectangle(size=self.size, pos=self.pos)
- self.bind(pos=self.update_bind_background, size=self.update_bind_background)
- def update_bind_background(self, *args):
- self.rect.pos = self.pos
- self.rect.size = self.size
- class ButtonBar(GridLayout):
- def __init__(self, **kwargs):
- super(ButtonBar, self).__init__(**kwargs)
- self.rows = 1
- # ---------- sets background of the Button Bar to white ----------
- with self.canvas.before:
- Color(rgb=(kivy.utils.get_color_from_hex("ffffff")))
- self.rect = Rectangle(size=self.size, pos=self.pos)
- self.bind(pos=self.update_bind_background, size=self.update_bind_background)
- self.b1 = Label()
- self.b2 = Label()
- self.b3 = Label()
- self.b4 = Label()
- self.add_cat = ImageButton(instance="add_cat", is_selected="no")
- self.add_cat.on_press = self.show_options
- self.save_thought = ImageButton(instance="save_thought", is_selected="no")
- self.b3 = self.add_cat
- self.b4 = self.save_thought
- self.add_buttons()
- # ---------- adds b1,b2,b3,b4 to the ButtonBar GridLayout ----------
- def add_buttons(self):
- self.add_widget(self.b1)
- self.add_widget(self.b2)
- self.add_widget(self.b3)
- self.add_widget(self.b4)
- # ---------- test function to see what i can access ----------
- def show_options(self):
- print(self.parent.ids.coin_bar.ids)
- # ---------- future function to add a cat to the category bar ----------
- def plus_cat(self, test):
- print("This adds a cat")
- # ---------- future function to add a thought to the previews ----------
- def plus_thought(self):
- print("this saves a thought")
- # ---------- binds the background size and position of the background rectangle to the button bar size/pos ----------
- def update_bind_background(self, *args):
- self.rect.pos = self.pos
- self.rect.size = self.size
- class MainScreen(GridLayout):
- # ---------- Root of the main.kv grid. Has the coin_bar, cat_bar, previews and button_bar as children ----------
- def __init__(self,**kwargs):
- super(MainScreen, self).__init__(**kwargs)
- class MainApp(App):
- def __init__(self,**kwargs):
- super(MainApp, self).__init__(**kwargs)
- def build(self):
- return MainScreen()
- MainApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement