-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
166 lines (129 loc) · 5.16 KB
/
main.py
File metadata and controls
166 lines (129 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#coding: utf-8
import kivy
import sqlite3
kivy.require('1.9.1')
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.core.window import Window
from kivy.config import Config
from kivy.lang import Builder
from kivy.uix.textinput import TextInput
from kivy.uix.actionbar import ActionItem
from kivy.uix.gridlayout import GridLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.popup import Popup
global sm, playlist
playlist ='oi'
Builder.load_file('pyfy.kv')
class Play(Screen):
global sm, playlist
def listar_dados(self, playlist):
sm.get_screen('play').ids.grid_play.clear_widgets()
conn = sqlite3.connect('banco.db')
cursor = conn.cursor()
cursor.execute(f'''SELECT id, nome, artista, genero FROM {playlist};''')
for i in cursor:
label = f'{i[1]}\nArtista: {i[2]}\nGênero: {i[3]}'
btl = Button(text=label, disabled=True)
bt = Button(text=f'Excluir', id=str(i[0]), on_press=self.excluir_musica)
bt2= Button(text=f'Editar', id=str(i[0]))
box = BoxLayout(orientation='vertical')
box2 = BoxLayout(orientation='vertical', size_hint=(.2,1))
box2.add_widget(bt)
box2.add_widget(bt2)
box.add_widget(btl)
box3 = BoxLayout(orientation='horizontal')
box3.add_widget(box)
box3.add_widget(box2)
sm.get_screen('play').ids.grid_play.add_widget(box3)
sm.get_screen('addmusica').ids.nome_action.title = ''
sm.current = 'play'
conn.close()
def detalhes_play(self, instance):
sm.get_screen('play').ids.grid_play.clear_widgets()
sm.get_screen('play').ids.nome_playlist.text = instance.text
self.listar_dados(instance.text)
def add_musica(self):
nomeplaylist = sm.get_screen('play').ids.nome_playlist.text
sm.get_screen('addmusica').ids.nome_action.title = nomeplaylist
sm.current='addmusica'
def excluir_musica(self, instance):
id=instance.id
playlist = sm.get_screen('play').ids.nome_playlist.text
conn = sqlite3.connect('banco.db')
cursor = conn.cursor()
cursor.execute(f"""DELETE FROM {playlist} WHERE id = ?""", (id,))
conn.commit()
print('deu bom')
sm.get_screen('play').ids.grid_play.clear_widgets()
self.listar_dados(playlist)
conn.close()
class AddMusica(Screen):
def add(self):
play = Play()
conn = sqlite3.connect('banco.db')
cursor = conn.cursor()
playlist = sm.get_screen('addmusica').ids.nome_action.title
nome = sm.get_screen('addmusica').ids.nome_musica.text
artista = sm.get_screen('addmusica').ids.nome_artista.text
genero = sm.get_screen('addmusica').ids.nome_genero.text
dados = (nome, artista, genero)
cursor.execute(f"""INSERT INTO {playlist}(nome, artista, genero)VALUES (?, ?, ?)""", dados)
conn.commit()
play.listar_dados(playlist)
print('----------------------------------------\nMúsica inserida com sucesso!\n----------------------------------------')
conn.close()
class Playlists(Screen):
global sm
def __init__(self, **kwargs):
super(Playlists, self).__init__(**kwargs)
def listar_playlists():
play = Play()
sm.get_screen('playlists').ids.grid.clear_widgets()
conn = sqlite3.connect('banco.db')
cursor = conn.cursor()
cursor.execute('''SELECT name FROM sqlite_master WHERE type ='table' AND name NOT LIKE 'sqlite_%';''')
for i in cursor:
bt = Button(text=i[0], on_press=play.detalhes_play)
sm.get_screen('playlists').ids.grid.add_widget(bt)
sm.current='playlists'
conn.close()
class Login(Screen):
global sm
def __init__(self, **kwargs):
super(Login, self).__init__(**kwargs)
self.playlists = Playlists
def iniciarDB(self):
self.playlists.listar_playlists()
class AddPlay(Screen):
def __init__(self, **kwargs):
super(AddPlay, self).__init__(**kwargs)
self.playlists = Playlists
def criar_play(self, playlist):
conn = sqlite3.connect('banco.db')
cursor = conn.cursor()
cursor.execute(f"""
CREATE TABLE {playlist} (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
nome VARCHAR (30) NOT NULL,
artista VARCHAR (30) NOT NULL,
genero VARCHAR (30) NOT NULL
);
""")
print(f'Playlist {playlist} criada com sucesso.')
self.playlists.listar_playlists()
conn.close()
class PyfyApp(App):
def build(self):
global sm
sm = ScreenManager(transition=NoTransition())
sm.add_widget(Login(name='login'))
sm.add_widget(Playlists(name='playlists'))
sm.add_widget(AddPlay(name='addplay'))
sm.add_widget(Play(name='play'))
sm.add_widget(AddMusica(name='addmusica'))
return sm
Window.clearcolor = (1, 1, 1, 1)
PyfyApp().run()