Skip to content

Commit ff18e6f

Browse files
authored
Merge pull request #131 from keremkaynak3/master
TwelveB
2 parents b5d3301 + 0b3db6a commit ff18e6f

File tree

2 files changed

+323
-0
lines changed

2 files changed

+323
-0
lines changed

Projects/TwelveB/registered.db

32 KB
Binary file not shown.

Projects/TwelveB/twelveB.py

Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
import wx
2+
import sqlite3
3+
4+
class NotionApp(wx.Frame):
5+
def __init__(self, user_id, *args, **kwargs):
6+
super(NotionApp, self).__init__(*args, **kwargs)
7+
self.dark_mode = self.load_dark_mode_state()
8+
self.init_ui()
9+
self.conn = sqlite3.connect("registered.db")
10+
self.create_tables()
11+
self.user_id = user_id # Oturum açmış kullanıcı ID'si burada saklanıyor
12+
self.show_notes()
13+
14+
def load_dark_mode_state(self):
15+
try:
16+
with open("dark_mode.txt", "r") as file:
17+
return file.read().strip() == "True"
18+
except FileNotFoundError:
19+
return False
20+
21+
def toggle_dark_mode(self, event):
22+
self.dark_mode = not self.dark_mode
23+
self.apply_dark_mode()
24+
self.save_dark_mode_state_to_db()
25+
26+
def save_dark_mode_state_to_db(self):
27+
cursor = self.conn.cursor()
28+
cursor.execute("UPDATE settings SET dark_mode = ? WHERE id = 1", (int(self.dark_mode),))
29+
self.conn.commit()
30+
31+
def create_tables(self):
32+
cursor = self.conn.cursor()
33+
cursor.execute('''
34+
CREATE TABLE IF NOT EXISTS users (
35+
id INTEGER PRIMARY KEY AUTOINCREMENT,
36+
username TEXT NOT NULL,
37+
password TEXT NOT NULL
38+
)
39+
''')
40+
41+
cursor.execute('''
42+
CREATE TABLE IF NOT EXISTS notes (
43+
id INTEGER PRIMARY KEY AUTOINCREMENT,
44+
user_id INTEGER,
45+
note TEXT,
46+
checked INTEGER DEFAULT 0,
47+
FOREIGN KEY(user_id) REFERENCES users(id)
48+
)
49+
''')
50+
51+
cursor.execute('''
52+
CREATE TABLE IF NOT EXISTS settings (
53+
id INTEGER PRIMARY KEY,
54+
dark_mode INTEGER
55+
)
56+
''')
57+
self.conn.commit()
58+
59+
def init_ui(self):
60+
self.SetTitle("Welcome to TwelveB")
61+
self.SetSize((500, 400))
62+
63+
panel = wx.Panel(self)
64+
vbox = wx.BoxSizer(wx.VERTICAL)
65+
66+
self.listbox = wx.CheckListBox(panel)
67+
vbox.Add(self.listbox, proportion=1, flag=wx.EXPAND | wx.ALL, border=15)
68+
69+
hbox = wx.BoxSizer(wx.HORIZONTAL)
70+
self.text_ctrl = wx.TextCtrl(panel)
71+
hbox.Add(self.text_ctrl, proportion=1, flag=wx.EXPAND)
72+
add_button = wx.Button(panel, label="Ekle")
73+
add_button.Bind(wx.EVT_BUTTON, self.on_add)
74+
hbox.Add(add_button, flag=wx.LEFT, border=5)
75+
vbox.Add(hbox, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=15)
76+
77+
delete_button = wx.Button(panel, label="Sil")
78+
delete_button.Bind(wx.EVT_BUTTON, self.on_delete)
79+
vbox.Add(delete_button, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=15)
80+
81+
edit_button = wx.Button(panel, label="Düzenle")
82+
edit_button.Bind(wx.EVT_BUTTON, self.on_edit)
83+
vbox.Add(edit_button, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=15)
84+
85+
exit_button = wx.Button(panel, label="Hesap Değiştir")
86+
exit_button.Bind(wx.EVT_BUTTON, self.on_exit)
87+
vbox.Add(exit_button, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=15)
88+
89+
dark_mode_button = wx.Button(panel, label="Dark Mode")
90+
dark_mode_button.Bind(wx.EVT_BUTTON, self.toggle_dark_mode)
91+
vbox.Add(dark_mode_button, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=15)
92+
93+
panel.SetSizer(vbox)
94+
95+
self.Bind(wx.EVT_CHECKLISTBOX, self.on_check)
96+
97+
def apply_dark_mode(self):
98+
# Dark mode aktifse arayüz renklerini değiştir
99+
if self.dark_mode:
100+
self.SetBackgroundColour(wx.Colour(25, 25, 25)) # Arka plan rengini değiştir
101+
self.listbox.SetBackgroundColour(wx.Colour(25, 25, 25)) # Liste kutusunun arka plan rengini değiştir
102+
self.listbox.SetForegroundColour(wx.Colour(500, 500, 500)) # Liste kutusunun metin rengini değiştir
103+
else:
104+
self.SetBackgroundColour(wx.NullColour) # Arka plan rengini varsayılana ayarla
105+
self.listbox.SetBackgroundColour(wx.NullColour) # Liste kutusunun arka plan rengini varsayılana ayarla
106+
self.listbox.SetForegroundColour(wx.NullColour) # Liste kutusunun metin rengini varsayılana ayarla
107+
108+
self.Refresh() # Arayüzün yenilenmesini sağla
109+
110+
def show_notes(self):
111+
cursor = self.conn.cursor()
112+
cursor.execute("SELECT note, checked FROM notes WHERE user_id=?", (self.user_id,))
113+
notes = cursor.fetchall()
114+
115+
self.listbox.Clear()
116+
for note, checked in notes:
117+
self.listbox.Append(note)
118+
if checked:
119+
self.listbox.Check(self.listbox.GetCount() - 1)
120+
121+
def get_current_user_id(self):
122+
return self.user_id
123+
124+
def on_add(self, event):
125+
item = self.text_ctrl.GetValue()
126+
if item:
127+
user_id = self.get_current_user_id() # Kullanıcının ID'sini almak için bir yol bulunmalıdır
128+
self.add_note(user_id, item) # Önce veritabanına ekleyin
129+
self.show_notes() # Notları tekrar yükleyin
130+
self.text_ctrl.Clear()
131+
132+
def on_edit(self, event):
133+
selection = self.listbox.GetSelection()
134+
if selection != wx.NOT_FOUND:
135+
current_note = self.listbox.GetString(selection)
136+
dialog = wx.TextEntryDialog(self, "Notu Düzenle:", "Not Düzenleme")
137+
dialog.SetValue(current_note) # Varsayılan değeri ayarla
138+
if dialog.ShowModal() == wx.ID_OK:
139+
new_note = dialog.GetValue()
140+
if new_note and new_note != current_note:
141+
self.edit_note(current_note, new_note)
142+
self.show_notes()
143+
dialog.Destroy()
144+
145+
def edit_note(self, current_note, new_note):
146+
cursor = self.conn.cursor()
147+
cursor.execute("UPDATE notes SET note=? WHERE user_id=? AND note=?", (new_note, self.user_id, current_note))
148+
self.conn.commit()
149+
150+
def add_note(self, user_id, note):
151+
cursor = self.conn.cursor()
152+
cursor.execute("INSERT INTO notes (user_id, note, checked) VALUES (?, ?, 0)", (user_id, note))
153+
self.conn.commit()
154+
print("Not kaydedildi:", note)
155+
156+
def on_delete(self, event):
157+
selection = self.listbox.GetSelection()
158+
if selection != wx.NOT_FOUND:
159+
note = self.listbox.GetString(selection)
160+
self.delete_note(note)
161+
self.show_notes()
162+
163+
def delete_note(self, note):
164+
cursor = self.conn.cursor()
165+
cursor.execute("DELETE FROM notes WHERE user_id=? AND note=?", (self.user_id, note))
166+
self.conn.commit()
167+
168+
def on_exit(self, event):
169+
self.Close(True) # Uygulamayı kapat
170+
app = wx.GetApp()
171+
login_dialog = LoginDialog(None)
172+
login_dialog.ShowModal()
173+
174+
def on_check(self, event):
175+
index = event.GetInt()
176+
note = self.listbox.GetString(index)
177+
checked = self.listbox.IsChecked(index)
178+
179+
cursor = self.conn.cursor()
180+
cursor.execute("UPDATE notes SET checked=? WHERE user_id=? AND note=?", (int(checked), self.user_id, note))
181+
self.conn.commit()
182+
print(f"Updated note '{note}' to {'checked' if checked else 'unchecked'}.")
183+
184+
class LoginDialog(wx.Dialog):
185+
def __init__(self, *args, **kwargs):
186+
super(LoginDialog, self).__init__(*args, **kwargs)
187+
self.init_ui()
188+
189+
def init_ui(self):
190+
self.SetTitle("Giriş Yap")
191+
self.SetSize((400, 400))
192+
193+
panel = wx.Panel(self)
194+
vbox = wx.BoxSizer(wx.VERTICAL)
195+
196+
username_label = wx.StaticText(panel, label="Kullanıcı Adı:")
197+
vbox.Add(username_label, flag=wx.LEFT | wx.TOP, border=10)
198+
self.username_textctrl = wx.TextCtrl(panel)
199+
vbox.Add(self.username_textctrl, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
200+
201+
password_label = wx.StaticText(panel, label="Şifre:")
202+
vbox.Add(password_label, flag=wx.LEFT | wx.TOP, border=10)
203+
self.password_textctrl = wx.TextCtrl(panel, style=wx.TE_PASSWORD)
204+
vbox.Add(self.password_textctrl, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
205+
206+
login_button = wx.Button(panel, label="Giriş Yap")
207+
login_button.Bind(wx.EVT_BUTTON, self.on_login)
208+
vbox.Add(login_button, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
209+
210+
forgot_button = wx.Button(panel, label="Şifremi Unuttum")
211+
forgot_button.Bind(wx.EVT_BUTTON, self.on_forgot_password)
212+
vbox.Add(forgot_button, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
213+
214+
register_button = wx.Button(panel, label="Kayıt Ol")
215+
register_button.Bind(wx.EVT_BUTTON, self.on_register)
216+
vbox.Add(register_button, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.TOP, border=10)
217+
218+
exit_application_button = wx.Button(panel, label="Uygulamayı Kapat")
219+
exit_application_button.Bind(wx.EVT_BUTTON, self.on_exit_application)
220+
vbox.Add(exit_application_button, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10)
221+
222+
panel.SetSizer(vbox)
223+
224+
def on_exit_application(self, event):
225+
self.Destroy() # Uygulama penceresini kapat
226+
app = wx.GetApp()
227+
app.ExitMainLoop() # Uygulamanın çalışmasını durdur
228+
229+
def on_forgot_password(self, event):
230+
username = wx.GetTextFromUser("Lütfen kullanıcı adınızı girin:", "Şifremi Unuttum")
231+
if username:
232+
conn = sqlite3.connect("registered.db")
233+
cursor = conn.cursor()
234+
cursor.execute("SELECT password FROM users WHERE username=?", (username,))
235+
user = cursor.fetchone()
236+
if user:
237+
wx.MessageBox(f"Şifreniz: {user[0]}", "Şifreniz", wx.OK | wx.ICON_INFORMATION)
238+
else:
239+
wx.MessageBox("Kullanıcı adı bulunamadı!", "Hata", wx.OK | wx.ICON_ERROR)
240+
241+
def on_register(self, event):
242+
register_dialog = RegisterDialog(None)
243+
if register_dialog.ShowModal() == wx.ID_OK:
244+
wx.MessageBox("Kayıt başarıyla tamamlandı! Lütfen giriş yapın.", "Başarılı", wx.OK | wx.ICON_INFORMATION)
245+
246+
def on_login(self, event):
247+
def login(username, password):
248+
conn = sqlite3.connect("registered.db")
249+
cursor = conn.cursor()
250+
cursor.execute("SELECT id FROM users WHERE username=? AND password=?", (username, password))
251+
user = cursor.fetchone()
252+
conn.close()
253+
254+
if user:
255+
return user[0]
256+
else:
257+
return None
258+
259+
username = self.username_textctrl.GetValue()
260+
password = self.password_textctrl.GetValue()
261+
user_id = login(username, password)
262+
if user_id is not None:
263+
app = wx.GetApp()
264+
app.frame = NotionApp(user_id, None)
265+
app.frame.show_notes() # Kullanıcının notlarını göster
266+
app.frame.Show()
267+
self.Destroy()
268+
else:
269+
wx.MessageBox("Kullanıcı adı veya şifre yanlış!", "Hata", wx.OK | wx.ICON_ERROR)
270+
self.username_textctrl.Clear()
271+
self.password_textctrl.Clear()
272+
273+
def on_register(self, event):
274+
register_dialog = RegisterDialog(None)
275+
if register_dialog.ShowModal() == wx.ID_OK:
276+
wx.MessageBox("Kayıt başarıyla tamamlandı! Lütfen giriş yapın.", "Başarılı", wx.OK | wx.ICON_INFORMATION)
277+
278+
class RegisterDialog(wx.Dialog):
279+
def __init__(self, *args, **kwargs):
280+
super(RegisterDialog, self).__init__(*args, **kwargs)
281+
self.init_ui()
282+
283+
def init_ui(self):
284+
self.SetTitle("Kayıt Ol")
285+
self.SetSize((350, 200))
286+
287+
panel = wx.Panel(self)
288+
vbox = wx.BoxSizer(wx.VERTICAL)
289+
290+
username_label = wx.StaticText(panel, label="Kullanıcı Adı:")
291+
vbox.Add(username_label, flag=wx.LEFT | wx.TOP, border=10)
292+
self.username_textctrl = wx.TextCtrl(panel)
293+
vbox.Add(self.username_textctrl, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
294+
295+
password_label = wx.StaticText(panel, label="Şifre:")
296+
vbox.Add(password_label, flag=wx.LEFT | wx.TOP, border=10)
297+
self.password_textctrl = wx.TextCtrl(panel, style=wx.TE_PASSWORD)
298+
vbox.Add(self.password_textctrl, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=10)
299+
300+
register_button = wx.Button(panel, label="Kayıt Ol")
301+
register_button.Bind(wx.EVT_BUTTON, self.on_register)
302+
vbox.Add(register_button, flag=wx.EXPAND | wx.ALL, border=10)
303+
304+
panel.SetSizer(vbox)
305+
306+
def on_register(self, event):
307+
username = self.username_textctrl.GetValue()
308+
password = self.password_textctrl.GetValue()
309+
if username and password:
310+
conn = sqlite3.connect("registered.db") # Veritabanı burada açılıyor
311+
cursor = conn.cursor()
312+
cursor.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, password))
313+
conn.commit()
314+
conn.close() # Veritabanı burada kapanıyor
315+
self.EndModal(wx.ID_OK)
316+
else:
317+
wx.MessageBox("Kullanıcı adı ve şifre boş bırakılamaz!", "Hata", wx.OK | wx.ICON_ERROR)
318+
319+
if __name__ == "__main__":
320+
app = wx.App()
321+
login_dialog = LoginDialog(None)
322+
login_dialog.ShowModal()
323+
app.MainLoop()

0 commit comments

Comments
 (0)