class MainWindow(BoxLayout): def __init__(self, **kwargs): super().__init__(**kwargs) self.db = Database() self.init_view() # def init_view(self): # all_tasks = self.db.get_task() # scroll_parent = Window # tw = self.ids.today_wrapper # uw = self.ids.upcoming_wrapper # for t in all_tasks: # checkin, date1 = t[2], t[2] # if self.clear_date(date1): # task = Today() # task.rooms = t[1] # task.date1 = date1 # task.checkin = checkin # task.checkout, task.date2 = t[3], t[3] # task.room_type = t[4] # task.NumOfAdults = t[5] # task.NumOfChild = t[6] # task.size_hint = (None, 1) # task.size = [scroll_parent.width / 2.4, 45] # tw.add_widget(task) # else: # task = Upcoming() # task.rooms = t[1] # task.checkin = ''.join(date1) # task.checkin = checkin # task.checkout, task.date2 = t[3], t[3] # task.room_type = t[4] # task.NumOfAdults = t[5] # task.NumOfChild = t[6] # task.size_hint = (1, None) # task.height = dp(100) # uw.add_widget(task) def init_view(self): all_tasks = self.db.get_task() scroll_parent = Window tw = self.ids.today_wrapper for t in all_tasks: task = Today() task.rooms = t[1] task.checkin,task.date1 = t[2],t[3] print(task.checkin,task.date1) task.checkout, task.date2 = t[4], t[5] print(task.checkout, task.date2) # task.checkout = t[3] task.room_type = t[6] # task.checkin, task.date1 = t[2], t[3] # print(task.checkin, task.date1) task.NumOfAdults = t[7] task.NumOfChild = t[8] task.size_hint = (None, 1) # task.size = [100,200] task.size = [scroll_parent.width / 2.4, 45] itask = Today() itask.rooms = t[1] itask.room_type = t[6] itask.checkin, itask.date1 = t[2], t[3] itask.size_hint = (None, None) itask.size = [scroll_parent.width / 2.4, round(scroll_parent.height / 3)] tw.add_widget(task) self.ids.all_today.add_widget(itask) def clear_date(self, date: str): today = datetime.today() _date = date.split('/') print("date = ", _date) if len(_date) < 3: _date = date.split('-') date_ = [int(x) for x in reversed(_date)] print(date_) task_date = datetime(date_[0], date_[1], date_[2]) x = abs((today - task_date).days) print(x) if x == 0: return True else: return False def get_update(self,inst): nt = NewTask() nt.ids.task_rooms.text = inst.rooms nt.ids.task_checkin.text = inst.date1 nt.ids.task_date1.text = inst.checkin nt.ids.task_checkout.text = inst.date2 nt.ids.task_date2.text = inst.checkout nt.ids.task_room_type.text = inst.room_type nt.ids.task_adults.text = inst.NumOfAdults nt.ids.task_child.text = inst.NumOfChild nt.ids.submit_wrapper.clear_widgets() submit = Button(text='Update Reserve',background_normal='', background_color=rgba('#0e5174')) submit.bind(on_release=lambda x:self.update_task(nt,inst)) nt.ids.submit_wrapper.add_widget(submit) nt.open() def update_task(self,task_data,task): xtask = [ task_data.ids.task_rooms.text, task_data.ids.task_date1.text, task_data.ids.task_checkin.text, task_data.ids.task_date2.text, task_data.ids.task_checkout.text, task_data.ids.task_room_type.text, task_data.ids.task_adults.text, task_data.ids.task_child.text, task_data.ids.submit_wrapper.clear_widgets() ] error = None for t in xtask: if t is not None: if len(t)<1: t.hint_text = 'Field required' t.hint_text_color = [1,0,0,1] error = True if error: pass else: # xtask = [xtask[0],''.join(xtask[1:]),task.rooms] if self.db.update_task(xtask): task.rooms = task_data.ids.task_rooms.text task.date1 = task_data.ids.task_checkin.text task.checkin = task_data.ids.task_date1.text task.date2 = task_data.ids.task_checkout.text task.checkout = task_data.ids.task_date2.text task.room_type = task_data.ids.task_room_type.text task.NumOfAdults = task_data.ids.task_adults.text task.NumOfChild = task_data.ids.task_child.text task_data.dismiss() def delete_task(self, task: Today): rooms = task.rooms if self.db.delete_task(rooms): task.parent.remove_widget(task) def add_new(self): nt = NewTask() nt.open() def add_task(self, mv, xtask: tuple): error = False scroll_parent = self.ids.scroll_parent tw = self.ids.today_wrapper for t in xtask: if len(t.text) < 1: t.hint_text = 'Field required' t.hint_text_color = [1, 0, 0, 1] error = True if error: pass else: task = Today() task.rooms = xtask[0].text task.checkin = xtask[2].text task.date1 = xtask[1].text task.checkout = xtask[4].text task.date2 = xtask[3].text task.room_type = xtask[5].text task.NumOfAdults = xtask[6].text task.NumOfChild = xtask[7].text task.size_hint = (None, None) task.size = [scroll_parent.width / 2.4, scroll_parent.height - (.1 * scroll_parent.height)] # add tasks1 to db # checkin_date = ''.join([xtask[1].text, xtask[2].text]) # checkout_date = ''.join([xtask[3].text, xtask[4].text]) task_ = ( xtask[0].text, xtask[1].text, xtask[2].text, xtask[3].text, xtask[4].text, xtask[5].text, xtask[6].text, xtask[7].text) if self.db.add_task(task_): tw.add_widget(task) mv.dismiss() # check if we have enough tasks to show # if len(tw.children)>1: # for child in tw.children: # if type(child) == NewButton: # tw.remove_widget(child) # break def add_user(self,username,password): if len(username.text)<3 or len(password.text)<6: pass else: user = (username.text,password.text) if self.db.add_user(user): self.ids.scrn_mngr.current = 'scrn_signin' def auth_user(self, username, password): uname = username.text upass = password.text if self.db.auth_user((uname,upass)): self.ids.scrn_mngr.current = 'scrn_main' username.text='' password.text=''
class MainWindow(BoxLayout): def __init__(self, **kw): super().__init__(**kw) self.db = Database() self.init_view() def init_view(self): all_tasks = self.db.get_tasks() scroll_parent = Window tw = self.ids.today_wrapper uw = self.ids.upcoming for t in all_tasks: date, time = t[2].rsplit(' ', 1) if self.clean_date(date): task = Today() task.og_name = t[1] task.name = t[1].upper() task.time = time task.date = date task.size_hint = (None, 1) task.size = [scroll_parent.width / 2.4, 45] itask = Today() itask.og_name = t[1] itask.name = t[1].upper() itask.time = time itask.date = date itask.size_hint = (None, None) itask.size = [ scroll_parent.width / 2.4, round(scroll_parent.height / 4) ] tw.add_widget(task) self.ids.all_today.add_widget(itask) else: task = Upcoming() task.name = t[1].upper() task.og_name = t[1] task.time = ' '.join([date, time]) task.date = date task.size_hint = (1, None) task.height = dp(100) itask = Upcoming() itask.name = t[1].upper() itask.og_name = t[1] itask.time = ' '.join([date, time]) itask.date = date itask.size_hint = (1, None) itask.height = dp(100) uw.add_widget(task) self.ids.all_upcoming.add_widget(itask) # task.size = [100, 200] if len(tw.children) > 1: for child in tw.children: if type(child) == NewButton: tw.remove_widget(child) def clean_date(self, date: str): today = datetime.today() _date = date.split('/') if len(_date) < 3: _date = date.split('-') date_ = [int(x) for x in reversed(_date)] task_date = datetime(date_[0], date_[1], date_[2]) x = abs((today - task_date).days) if x == 0: return True else: return False def get_update(self, inst): nt = NewTask() nt.ids.task_name.text = inst.name nt.ids.task_time.text = inst.time nt.ids.task_date.text = inst.date nt.ids.submit_wrapper.clear_widgets() submit = Button(text='Update Task', background_normal='', background_color=rgba('#0e5174')) submit.bind(on_release=lambda x: self.update_task(nt, inst)) nt.ids.submit_wrapper.add_widget(submit) nt.open() def update_task(self, task_data, task): error = False xtask = [ task_data.ids.task_name.text, task_data.ids.task_date.text, task_data.ids.task_time.text ] for t in xtask: if len(t) < 3: t.hint_text = 'Field required' t.hint.text_color = [1, 0, 0, 1] error = True if error: pass else: xtask = [xtask[0], ' '.join(xtask[1:]), task.og_name] if self.db.update_task(xtask): task.name = task_data.ids.task_name.text task.date = task_data.ids.task_date.text task.time = task_data.ids.task_time.text task_data.dismiss() def delete_task(self, task: Today): name = task.name if self.db.delete_task(name): task.parent.remove_widget(task) def add_new(self): nt = NewTask() nt.open() def add_task(self, mv, xtask: tuple): error = False scroll_parent = self.ids.scroll_parent tw = self.ids.today_wrapper uw = self.ids.upcoming for t in xtask: if len(t.text) < 3: t.hint_text = 'Field required' t.hint.text_color = [1, 0, 0, 1] error = True if error: pass else: date = ' '.join([xtask[1].text, xtask[2].text]) task_ = (xtask[0].text, date) if self.clean_date(xtask[1].text): task = Today() task.og_name = xtask[0].text task.name = xtask[0].text.upper() task.time = xtask[2].text task.date = xtask[1].text task.size_hint = (None, None) task.size = [ scroll_parent.width / 2.4, scroll_parent.height * .9 ] if self.db.add_task(task_): tw.add_widget(task) else: task = Upcoming() task.og_name = xtask[0].text task.name = xtask[0].text.upper() task.time = xtask[2].text task.date = xtask[1].text task.size_hint = (1, None) task.height = dp(100) if self.db.add_task(task_): uw.add_widget(task) # add task to db mv.dismiss() # check if we have enough tasks to show if len(tw.children) > 1: for child in tw.children: if type(child) == NewButton: tw.remove_widget(child) def add_user(self, username, password): if len(username.text) < 3 or len(password.text) < 6: pass else: user = (username.text, password.text) if self.db.add_user(user): self.ids.scrn_mngr.current = 'scrn_signin' def auth_user(self, username, password): uname = username.text upass = password.text if self.db.auth_user((uname, upass)): self.ids.scrn_mngr.current = 'scrn_main' username.text = '' password.text = ''
class MainWindow (BoxLayout): def __init__(self, **kw): super().__init__(**kw) self.db = Database() self.ring_sound = SoundLoader.load('ring_ring.mp3') self.init_view() def my_callback(self, dt): all_tasks = self.db.get_tasks() uw = self.ids.upcoming for t in all_tasks: date, time = t[2].rsplit(' ', 1) date_object = datetime.strptime(date[2:]+" "+time, '%y-%m-%d %H:%M:%S') # print(date_object, datetime.today()) if date_object < datetime.today(): print("deleting a task") print(t) self.ring_sound.play() self.db.delete_task_by_time(t[2]) for child in uw.children: if child.date == date and child.time == time: uw.remove_widget(child) else: pass def init_view(self): all_tasks = self.db.get_tasks() scroll_parent = Window tw = self.ids.today_wrapper uw = self.ids.upcoming # self.background_thread() Clock.schedule_interval(self.my_callback, 5) for t in all_tasks: date, time = t[2].rsplit(' ', 1) date_object = datetime.strptime(date[2:]+" "+time, '%y-%m-%d %H:%M:%S') task = Upcoming() task.name = t[1] task.og_name = t[1] task.time = time task.date = date task.size_hint = (1, None) task.height = dp(100) itask = Upcoming() itask.name = t[1] itask.og_name = t[1] itask.time = time itask.date = date itask.size_hint = (1, None) itask.height = dp(100) uw.add_widget(task) self.ids.all_upcoming.add_widget(itask) # task.size = [100, 200] if len(tw.children) > 1: for child in tw.children: if type(child) == NewButton: tw.remove_widget(child) def clean_date(self, date: str): today = datetime.today() _date = date.split('/') if len(_date) < 3: _date = date.split('-') date_ = [int(x) for x in reversed(_date)] # Change this later task_date = today # task_date = datetime(date_[0], date_[1], date_[2]) x = abs((today - task_date).days) if x == 0: return True else: return False def get_update(self, inst): nt = NewTask() nt.ids.task_name.text = inst.name nt.ids.task_time.text = inst.time # nt.ids.task_date.text = inst.date nt.ids.submit_wrapper.clear_widgets() submit = Button(text='Update Task', background_normal='', background_color=rgba('#0e5174')) submit.bind(on_release=lambda x: self.update_task(nt, inst)) nt.ids.submit_wrapper.add_widget(submit) nt.open() def update_task(self, task_data, task): error = False xtask = [ task_data.ids.task_name.text, # task_data.ids.task_date.text, task_data.ids.task_time.text ] for t in xtask: if len(t) < 3: t.hint_text = 'Field required' t.hint.text_color = [1, 0, 0, 1] error = True if error: pass else: # Change this later # xtask = [xtask[0], ' '.join(xtask[1:]), task.og_name] xtask = [xtask[0], ' '.join(xtask[1:]), task.og_name] if self.db.update_task(xtask): task.name = task_data.ids.task_name.text # Change this later # task.date = task_data.ids.task_date.text task.date = str(datetime.today()).split(" ")[0] task.time = task_data.ids.task_time.text task_data.dismiss() def delete_task(self, task: Today): date = task.date + " " + task.time # if self.db.delete_task(name): print(date) if self.db.delete_task_by_time(date): task.parent.remove_widget(task) def add_new(self): nt = NewTask() nt.open() def add_task(self, mv, xtask: tuple): error = False scroll_parent = self.ids.scroll_parent tw = self.ids.today_wrapper uw = self.ids.upcoming for t in xtask: if len(t.text) < 3: t.hint_text = 'Field required' # t.hint.text_color = [1, 0, 0, 1] # Change this later # error = True if error: pass else: # Change this later # date = ' '.join([xtask[1].text, xtask[2].text]) date = xtask[1].text task_ = (xtask[0].text, date) # Change this later task = Upcoming() task.og_name = xtask[0].text task.date = str(datetime.today()).split(' ')[0] task.name = xtask[0].text # Change this later # task.time = xtask[2].text # task.date = xtask[1].text task.time = xtask[1].text task.size_hint = (1, None) task.height = dp(100) if self.db.add_task(task_): uw.add_widget(task) # if self.clean_date(xtask[1].text): # task = Today() # task.og_name = xtask[0].text # task.name = xtask[0].text.upper() # task.time = xtask[2].text # task.date = xtask[1].text # task.size_hint = (None, None) # task.size = [scroll_parent.width / # 2.4, scroll_parent.height * .9] # if self.db.add_task(task_): # tw.add_widget(task) # else: # task = Upcoming() # task.og_name = xtask[0].text # task.name = xtask[0].text.upper() # task.time = xtask[2].text # task.date = xtask[1].text # task.size_hint = (1, None) # task.height = dp(100) # if self.db.add_task(task_): # uw.add_widget(task) # add task to db mv.dismiss() # check if we have enough tasks to show if len(tw.children) > 1: for child in tw.children: if type(child) == NewButton: tw.remove_widget(child) def add_user(self, username, password): if len(username.text) < 3 or len(password.text) < 6: pass else: user = (username.text, password.text) if self.db.add_user(user): self.ids.scrn_mngr.current = 'scrn_main' def auth_user(self, username, password): uname = username.text upass = password.text if self.db.auth_user((uname, upass)): self.ids.scrn_mngr.current = 'scrn_main' username.text = '' password.text = ''