-
Notifications
You must be signed in to change notification settings - Fork 0
/
main2.py
277 lines (218 loc) · 10.3 KB
/
main2.py
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen
# from kivy.lang import Builder
class Background(Widget):
def __init__(self, **kwargs):
#inserisco background
super().__init__(**kwargs)
with self.canvas:
self.rect = Rectangle(source='background.jpg', pos=self.pos, size=self.size)
self.bind(pos=self.update_rect, size=self.update_rect)
# Create a dictionary to store the login information
self.login_info = {'username': 'username', 'password': 'password'}
def update_rect(self, *args):
#prende dimensioni app e mette login di conseguenza
self.rect.pos = self.pos
self.rect.size = self.size
# Position the login elements
self.username_input.pos = (self.center_x - self.username_input.width/2, self.center_y + 50)
self.password_input.pos = (self.center_x - self.password_input.width/2, self.center_y - 50)
self.login_button.pos = (self.center_x - self.login_button.width/2, self.center_y - 150)
def on_size(self, *args):
self.update_rect()
def on_pos(self, *args):
self.update_rect()
def add_login_elements(self):
# Add a username TextInput to the background
self.username_input = TextInput(hint_text='Username', size_hint=(None, None), size=(200, 50))
self.add_widget(self.username_input)
# Add a password TextInput to the background
self.password_input = TextInput(hint_text='Password', password=True, size_hint=(None, None), size=(200, 50))
self.add_widget(self.password_input)
# Add a login Button to the background
self.login_button = Button(text='Login', size_hint=(None, None), size=(200, 50))
self.add_widget(self.login_button)
#Aggiunge risposta del login
self.login_button.bind(on_press=self.login)
def login(self, instance):
# Get the entered username and password
username = self.username_input.text
password = self.password_input.text
# Check if the entered login information is valid
if username == self.login_info['username'] and password == self.login_info['password']:
print('Login successful')
self.manager.current = 'second'
else:
print('Invalid login information')
def switch_to_second_screen(self, *args):
self.manager.current = 'second'
class FirstScreen(Screen):
# def __init__(self, **kwargs):
# super(FirstScreen, self).__init__(**kwargs)
# self.add_widget(Label(text='Welcome to the First Screen!'))
# button = Button(text='Go to Second Screen', size_hint=(None, None), size=(200, 50))
# button.bind(on_press=self.switch_to_second_screen)
# self.add_widget(button)
def __init__(self, **kwargs):
super().__init__(**kwargs)
# create an instance of Background
self.background = Background()
self.background.add_login_elements()
# add the background widget to the screen
self.add_widget(self.background)
class SecondScreen(Screen):
def __init__(self, **kwargs):
super(SecondScreen, self).__init__(**kwargs)
self.add_widget(Label(text='Welcome to the Second Screen!'))
# button = Button(text='Go back to First Screen', size_hint=(None, None), size=(200, 50))
# button.bind(on_press=self.switch_to_first_screen)
# self.add_widget(button)
# def switch_to_first_screen(self, *args):
# self.manager.current = 'first'
# class NewPage(Widget):
# def __init__(self, **kwargs):
# super().__init__(**kwargs)
# label = Label(text='Do you want to continue?', pos_hint={'center_x': 0.5, 'center_y': 0.6})
# self.add_widget(label)
# yes_button = Button(text='Yes', size_hint=(None, None), size=(200, 50), pos_hint={'center_x': 0.4, 'center_y': 0.4})
# no_button = Button(text='No', size_hint=(None, None), size=(200, 50), pos_hint={'center_x': 0.6, 'center_y': 0.4})
# yes_button.bind(on_press=self.on_yes)
# no_button.bind(on_press=self.on_no)
# self.add_widget(yes_button)
# self.add_widget(no_button)
def on_yes(self, instance):
print('Yes')
# Do something here
def on_no(self, instance):
print('No')
class MyScreenManager(ScreenManager):
pass
class MainApp(App):
def build(self):
self.icon="icon.png"
Window.icon = 'icon.png'
# background = Background()
# background.add_login_elements()
# return background
screen_manager = MyScreenManager()
screen_manager.add_widget(FirstScreen(name='first'))
screen_manager.add_widget(SecondScreen(name='second'))
return screen_manager
# layout = BoxLayout(orientation0"vertical")
if __name__=="__main__":
app = MainApp()
app.run()
# app = MainApp()
# app.run()
# class MainApp(App):
# def build(self):
# label = Label(text="Hdddd")
# return label
# from kivymd.app import MDApp
# from kivy.uix.carousel import Carousel
# from kivy.uix.image import Image
# from kivymd.theming import ThemeManager
# from kivymd.uix.card import MDCard
# from kivymd.uix.floatlayout import MDFloatLayout
# from kivymd.uix.textfield import MDTextField
# from kivymd.uix.label import MDLabel
# class MDFloatLayoutApp(MDApp):
# theme_cls = ThemeManager()
# def build(self):
# float_layout = MDFloatLayout()
# card = MDCard(size_hint=(.45, .8), pos_hint={"center_x": .5, "center_y": .5})
# float_layout.add_widget(card)
# label = MDLabel(text="Manage Closet",bold=True,pos_hint={"center_x": .88, "center_y": .8},font_style="H4")
# float_layout.add_widget(label)
# carousel = Carousel(direction='right')
# for i in range(4):
# layout = MDFloatLayout()
# text_field = MDTextField(id="username",hint_text="Username",size_hint_x=.8,pos_hint={"center_x": .5, "center_y": .48})
# layout.add_widget(text_field)
# carousel.add_widget(layout)
# card.add_widget(carousel)
# if __name__ == '__main__':
# MDFloatLayoutApp().run()
# from kivy.app import App
# from kivy.uix.screenmanager import ScreenManager, Screen
# # from kivy.uix.boxlayout import BoxLayout
# from kivy.uix.floatlayout import FloatLayout
# from kivy.uix.filechooser import FileChooserIconView
# from kivy.uix.button import Button
# from kivy.uix.label import Label
# from kivy.uix.textinput import TextInput
# from kivy.core.window import Window
# Window.size=(320,600)
# Window.clearcolor = (0.749019608, 1.0, 0.792156863, 1)
# class LoginScreen(Screen):
# def __init__(self, **kwargs):
# super().__init__(**kwargs)
# # Create a BoxLayout for the login form
# # self.form_container = BoxLayout(orientation="vertical", spacing=30, padding=30)
# self.form_container = FloatLayout()
# # Create the username TextInput
# self.username = TextInput(hint_text="Username", size_hint=(.6, .1), pos_hint={'x':.2, 'y':.8})
# self.form_container.add_widget(self.username)
# # Create the password TextInput
# self.password = TextInput(hint_text="Password", size_hint=(.6, .1), pos_hint={"x": .2, "y": .6}, password=True)
# self.form_container.add_widget(self.password)
# # Create the login button
# self.login_button = Button(text="Login", size_hint=(.6, .1), pos_hint={"x": .2, "y": .4})
# self.login_button.bind(on_release=self.login)
# self.form_container.add_widget(self.login_button)
# # Add the form_container to the screen
# self.add_widget(self.form_container)
# def login(self, instance):
# # Get the values of the username and password
# username = self.username.text
# password = self.password.text
# # Check if the username and password are valid
# if username == "admin" and password == "password":
# # Change to the upload screen
# self.manager.current = "upload"
# else:
# # Show an error message
# self.form_container.add_widget(Label(text="Incorrect username or password", font_size=20, color=(1, 0, 0, 1)))
# class UploadScreen(Screen):
# def __init__(self, **kwargs):
# super().__init__(**kwargs)
# # Create a BoxLayout for the upload form
# # self.form_container = BoxLayout(orientation="vertical", spacing=30, padding=30)
# self.form_container = FloatLayout()
# # Create a label for the upload form
# self.form_container.add_widget(Label(text="Upload a Picture:", size_hint=(.6, .1), pos_hint={'x':.2, 'y':.8}, bold=True))
# # Create the FileChooserIconView
# self.file_chooser = FileChooserIconView(path=".", size_hint=(.6, .1), pos_hint={'x':.2, 'y':.4})
# self.form_container.add_widget(self.file_chooser)
# # Create the Browse button
# # self.browse_button = Button(text="Browse", size_hint=(.6, .1), pos_hint={'x':.2, 'y':.6})
# # self.browse_button.bind(on_release=self.show_file_picker)
# # self.add_widget(self.browse_button)
# # Create the upload button
# # self.upload_button = Button(text="Upload", size_hint=(.6, .1), pos_hint={'x':.2, 'y':.4})
# # self.upload_button.bind(on_release=self.upload_picture)
# # self.form_container.add_widget(self.upload_button)
# # Add the form_container to the screen
# self.add_widget(self.form_container)
# def upload_picture(self, instance):
# # Get the selected file
# file = self.file_chooser
# class AppScreenManager(ScreenManager):
# def __init__(self, **kwargs):
# super().__init__(**kwargs)
# # Add the login and upload screens to the ScreenManager
# self.add_widget(LoginScreen(name="login"))
# self.add_widget(UploadScreen(name="upload"))
# class LoginUploadApp(App):
# def build(self):
# # Create an instance of the AppScreenManager
# return AppScreenManager()
# if __name__ == "__main__":
# LoginUploadApp().run()