diff --git a/playerdb.kv b/playerdb.kv new file mode 100644 index 0000000..9250e1e --- /dev/null +++ b/playerdb.kv @@ -0,0 +1,51 @@ +# Reference studentdb.py +#: import main studentdb +#: import ListAdapter kivy.adapters.listadapter.ListAdapter +#: import ListItemButton kivy.uix.listview.ListItemButton + +PlayerDB: + +: + orientation: "vertical" + player_name_text_input: player_name + team_text_input: team + player_list: player_list_view + padding: 10 + spacing: 10 + + BoxLayout: + size_hint_y: None + height: "40dp" + + Label: + text: "Player Name" + TextInput: + id: player_name + Label: + text: "Team" + TextInput: + id: team + + BoxLayout: + size_hint_y: None + height: "40dp" + Button: + text: "Submit" + size_hint_x: 15 + on_press: root.submit_player() + Button: + text: "Delete" + size_hint_x: 15 + on_press: root.delete_player() + Button: + text: "Replace" + size_hint_x: 15 + on_press: root.replace_player() + + # Define starting data and point to the ListItemButton + # in the Python code + ListView: + id: player_list_view + adapter: + ListAdapter(data=["Doug Smith"], cls=main.PlayerListButton) + diff --git a/playerdb.py b/playerdb.py new file mode 100644 index 0000000..7ce3b1a --- /dev/null +++ b/playerdb.py @@ -0,0 +1,81 @@ +from kivy.app import App +from kivy.uix.boxlayout import BoxLayout +from kivy.properties import ObjectProperty +from kivy.uix.listview import ListItemButton +from tkinter import * +# from tkinter import tkk +import sqlite3 + +# class playerDB +# db_conn =0 +# cursor = 0 +# curr_player = 0 + + +class PlayerListButton(ListItemButton): + pass + +class PlayerDB(BoxLayout): + + # Connects the value in the TextInput widget to these + # fields + player_name_text_input = ObjectProperty() + team_text_input = ObjectProperty() + player_list = ObjectProperty() + + def submit_player(self): + + # Get the student name from the TextInputs + player_name = self.player_name_text_input.text + " " + self.team_text_input.text + + # Add the student to the ListView + self.player_list.adapter.data.extend([player_name]) + + # Reset the ListView + self.player_list._trigger_reset_populate() + + def delete_player(self, *args): + + # If a list item is selected + if self.player_list.adapter.selection: + + # Get the text from the item selected + selection = self.player_list.adapter.selection[0].text + + # Remove the matching item + self.player_list.adapter.data.remove(selection) + + # Reset the ListView + self.player_list._trigger_reset_populate() + + def replace_player(self, *args): + + # If a list item is selected + if self.player_list.adapter.selection: + + # Get the text from the item selected + selection = self.player_list.adapter.selection[0].text + + # Remove the matching item + self.player_list.adapter.data.remove(selection) + + # Get the student name from the TextInputs + player_name = self.player_name_text_input.text + " " + self.team_text_input.text + + # Add the updated data to the list + self.player_list.adapter.data.extend([player_name]) + + # Reset the ListView + self.player_list._trigger_reset_populate() + + + +class PlayerDBApp(App): + def build(self): + return PlayerDB() + + +dbApp = PlayerDBApp() + +dbApp.run() + \ No newline at end of file