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.scrollview import ScrollView
- from kivy.uix.label import Label
- from kivy.config import Config
- from kivy.graphics import Color, Rectangle
- from kivy.lang import Builder
- from kivy.properties import ObjectProperty
- from kivy.properties import StringProperty
- from kivy.properties import BooleanProperty
- import kivy.utils
- Config.set('graphics', 'resizable', '0')
- Config.set('graphics', 'width', '540')
- Config.set('graphics', 'height', '960')
- Config.set('graphics', 'right', 1)
- Config.set('graphics', 'top', 1)
- Builder.load_file("coinbar.kv")
- Builder.load_file("imagebutton.kv")
- class ImageButton(ButtonBehavior,Image):
- instance = StringProperty()
- am_i_selected = BooleanProperty()
- def __init__(self,**kwargs):
- super(ImageButton, self).__init__(**kwargs)
- # ---------- sets the image source ----------
- def on_instance(self, *args):
- pass
- if self.instance == "noteskeeper":
- self.am_i_selected = True
- else:
- self.am_i_selected = False
- #print(self.instance)
- #print(self.am_i_selected)
- # ---------- on_press behavior of the coins ----------
- def select_coin(self):
- print(self.instance)
- # ---------- NotesKeeper is selected at App start ----------
- selected = self.parent.coinbar_selected
- print(selected)
- if not self.am_i_selected:
- self.parent.ids[selected].am_i_selected = False
- self.parent.ids[selected].source = "cents/unselected/" + self.parent.ids[selected].instance + ".png"
- self.am_i_selected = True
- self.source = "cents/selected/" + self.instance + ".png"
- self.parent.coinbar_selected = self.instance
- return
- if self.am_i_selected:
- if self.instance == "noteskeeper":
- return
- else:
- self.am_i_selected = False
- self.source = "cents/unselected/" + self.instance + ".png"
- # ---------- CoinBar ----------
- class CoinBar(GridLayout):
- def __init__(self,**kwargs):
- super(CoinBar, self).__init__(**kwargs)
- self.coinbar_selected = "noteskeeper"
- # ---------- Sets 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
- # ---------- CatBar ----------
- class CatBar(GridLayout):
- cats = ["Reminder", "Idea", "Funny", "Well written"]
- def __init__(self,**kwargs):
- self.rows = 1
- super(CatBar, self).__init__(**kwargs)
- # ---------- creates the cats ----------
- for cat in self.cats:
- new_cat = ImageButton(instance=cat)
- self.add_widget(new_cat)
- # ---------- Previews ----------
- 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)
- # ---------- NotesKeeperPreview ----------
- 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
- # ---------- ButtonBar ----------
- 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)
- # ---------- the buttons created at App startup ----------
- self.b1 = Label()
- self.b2 = Label()
- self.b3 = Label()
- self.b4 = Label()
- # ---------- add_cat adds a new cat in the cat bar together with a note for that cat ----------
- self.add_cat = ImageButton(instance="add_cat")
- self.add_cat.on_press = self.plus_cat
- # ---------- save_thought opens the NoteKeeping Widget for you to save a note in ----------
- self.save_thought = ImageButton(instance="save_thought")
- self.save_thought.on_press = self.plus_thought
- 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)
- # ---------- future function to add a cat to the category bar ----------
- def plus_cat(self):
- 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
- # ---------- MainScreen ----------
- 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)
- # ---------- App Start ----------
- 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