def clear_date_of_birth(profiles): """clear dob input""" language_dict = set_options.Options() language_dict.get_text_dict("sort_profiles") lang_dict = language_dict.widget_text_dictionary curent_date = get_date.get(0) sorted_profiles = list() age = 0 for prof in profiles: if prof["DATE_OF_BIRTH"] != "" and prof["DATE_OF_DEATH"] == "": age = curent_date['ViewedYear'] - int(prof["DATE_OF_BIRTH"][6:10]) # lower one year if month of birth is lower than actual month if (int(prof["DATE_OF_BIRTH"][3:5].strip('0')) > curent_date['ViewedMonth']): age -= 1 prof["DATE_OF_BIRTH"] = (prof["DATE_OF_BIRTH"] + "(" + str(age) + lang_dict["age"] + ")") sorted_profiles.append(prof) elif prof["DATE_OF_BIRTH"] != "" and prof["DATE_OF_DEATH"] != "": age = (int(prof["DATE_OF_DEATH"][6:10]) - int(prof["DATE_OF_BIRTH"][6:10])) prof["DATE_OF_BIRTH"] = (prof["DATE_OF_BIRTH"] + "(" + str(age) + lang_dict["age"] + ")") sorted_profiles.append(prof) else: sorted_profiles.append(prof) return sorted_profiles
def event_markers(self, month_counter, day): """ one oval per one TYPE of event, max being 6 """ date_dict = get_date.get(month_counter) event_types = process_calendar_data.event_types_per_day( str(date_dict['ViewedYear']) + "/" + str(date_dict['ViewedMonth']) + "/" + str(day)) y_1 = 2 y_2 = 12 counter = event_types["SUM"] while counter != 0: if event_types["PREGNANCY"] == 1: self.canvas.create_oval(5, y_1, 15, y_2, fill="hot pink") event_types["PREGNANCY"] = 0 elif event_types["MEDICINE"] == 1: self.canvas.create_oval(5, y_1, 15, y_2, fill="blue") event_types["MEDICINE"] = 0 elif event_types["MILKING"] == 1: self.canvas.create_oval(5, y_1, 15, y_2, fill="yellow") event_types["MILKING"] = 0 elif event_types["OTHER"] == 1: self.canvas.create_oval(5, y_1, 15, y_2, fill="green2") event_types["OTHER"] = 0 elif event_types["DELIVERY"] == 1: self.canvas.create_oval(5, y_1, 15, y_2, fill="red") event_types["DELIVERY"] = 0 elif event_types["WITHDRAWAL"] == 1: self.canvas.create_oval(5, y_1, 15, y_2, fill="black") event_types["WITHDRAWAL"] = 0 y_1 += 12 y_2 += 12 counter -= 1
def get_month_name(month_counter): """returns name of the month depending on month number""" language_dict = set_options.Options() language_dict.get_text_dict("process_calendar_data") lang_dict = language_dict.widget_text_dictionary date_dict = get_date.get(month_counter) if int(date_dict['ViewedMonth']) == 1: month_name = lang_dict["month1"] elif int(date_dict['ViewedMonth']) == 2: month_name = lang_dict["month2"] elif int(date_dict['ViewedMonth']) == 3: month_name = lang_dict["month3"] elif int(date_dict['ViewedMonth']) == 4: month_name = lang_dict["month4"] elif int(date_dict['ViewedMonth']) == 5: month_name = lang_dict["month5"] elif int(date_dict['ViewedMonth']) == 6: month_name = lang_dict["month6"] elif int(date_dict['ViewedMonth']) == 7: month_name = lang_dict["month7"] elif int(date_dict['ViewedMonth']) == 8: month_name = lang_dict["month8"] elif int(date_dict['ViewedMonth']) == 9: month_name = lang_dict["month9"] elif int(date_dict['ViewedMonth']) == 10: month_name = lang_dict["month10"] elif int(date_dict['ViewedMonth']) == 11: month_name = lang_dict["month11"] elif int(date_dict['ViewedMonth']) == 12: month_name = lang_dict["month12"] return month_name
def add_withdrawal(year, month, day, days_in_month, months_in_future): day_counter = 0 withdrawal_counter = 1 withdrawal_days_counter = date_dict['Input4'] while withdrawal_days_counter > 0: if day+withdrawal_counter <= days_in_month: container.write( str(year)+'/'+str(month)+'/' + str(day+withdrawal_counter)+'-' + str(date_dict['EventType'])+'-' + str(date_dict['Input1'])+'-' + str(date_dict['Input2']) + '-' + str(date_dict['Input3']-withdrawal_counter)+'-' + str(date_dict['Input4'])+'-' + str(date_dict['Input5'])+'-'+str(random_num)+'\n') withdrawal_counter += 1 withdrawal_days_counter -= 1 else: vase = get_date.get(months_in_future+1) container.write( str(vase['ViewedYear'])+'/' + str(vase['ViewedMonth']) + '/' + str(1+day_counter)+'-'+str(date_dict['EventType'])+'-'+ str(date_dict['Input1'])+'-' + str(date_dict['Input2'])+'-' + str(date_dict['Input3']-withdrawal_counter)+'-' + str(date_dict['Input4'])+'-' + str(date_dict['Input5'])+'-' + str(random_num)+'\n') day_counter += 1 withdrawal_counter += 1 withdrawal_days_counter -= 1
def __init__(self, parent, text, x_orient, y_orient, tab, month_counter): self.month_counter = month_counter date_dict = get_date.get(month_counter) day = int(text) button = tk.Button( parent, text=text, height=self.HEIGHT, width=self.WIDTH, font=self.FONT, relief=self.RELIEF, takefocus=self.FOCUS, command=lambda: single_day_view.add_event_window( month_counter, day, tab)) if date_dict['ViewedDay'] == day: button.configure(bg="#ffffff") button.place(x=x_orient, y=y_orient)
def __init__(self, tab, month_counter): """ pressing 'next month' reloads __init__ with mounth_counter as 1 and pressing 'prev month' reloads __init__ with mounth_counter as -1 you can go as far as you like in future or past """ date_dict = get_date.get(month_counter) language_dict = set_options.Options() language_dict.get_text_dict("calendar_tab") lang_dict = language_dict.widget_text_dictionary def next_month(): next_month = month_counter + 1 Calendar(tab, next_month) def previous_month(): prev_month = month_counter - 1 Calendar(tab, prev_month) calendar_frame = tk.Frame(tab, height=800, width=800) calendar_frame.place(x=0, y=0) month_name = process_calendar_data.get_month_name(month_counter) # "next month" and "previous month" buttons prev_month_bttn = tk.Button( calendar_frame, text="<", height=1, command=previous_month, width=1, font="Helvetica 25 bold", relief=tk.FLAT, takefocus=0) prev_month_bttn.place(x=160, y=10) next_month_bttn = tk.Button( calendar_frame, text=">", height=1, command=next_month, width=1, font="Helvetica 25 bold", relief=tk.FLAT, takefocus=0) next_month_bttn.place(x=600, y=10) month_label = tk.Label( calendar_frame, text=month_name + " " + str(date_dict['ViewedYear']), font="Helvetica 20") month_label.place(x=310, y=20) mo_label = tk.Label( calendar_frame, text=lang_dict["mo_label"], font="Helvetica 16") mo_label.place(x=70, y=60) tu_label = tk.Label( calendar_frame, text=lang_dict["tu_label"], font="Helvetica 16") tu_label.place(x=170, y=60) we_label = tk.Label( calendar_frame, text=lang_dict["we_label"], font="Helvetica 16") we_label.place(x=270, y=60) th_label = tk.Label( calendar_frame, text=lang_dict["th_label"], font="Helvetica 16") th_label.place(x=370, y=60) fr_label = tk.Label( calendar_frame, text=lang_dict["fr_label"], font="Helvetica 16") fr_label.place(x=470, y=60) sa_label = tk.Label( calendar_frame, text=lang_dict["sa_label"], font="Helvetica 16") sa_label.place(x=570, y=60) su_label = tk.Label( calendar_frame, text=lang_dict["su_label"], font="Helvetica 16") su_label.place(x=670, y=60) # define position of first day(button) on the calendar depending on # lang_dict['FirstDayOfTheViewedMonth'] - day of the week # given month starts with y_orient = 100 if int(date_dict['FirstDayOfTheViewedMonth']) == 0: x_orient = 60 counter = 1 elif int(date_dict['FirstDayOfTheViewedMonth']) == 1: x_orient = 160 counter = 2 elif int(date_dict['FirstDayOfTheViewedMonth']) == 2: x_orient = 260 counter = 3 elif int(date_dict['FirstDayOfTheViewedMonth']) == 3: x_orient = 360 counter = 4 elif int(date_dict['FirstDayOfTheViewedMonth']) == 4: x_orient = 460 counter = 5 elif int(date_dict['FirstDayOfTheViewedMonth']) == 5: x_orient = 560 counter = 6 elif int(date_dict['FirstDayOfTheViewedMonth']) == 6: x_orient = 660 counter = 7 # next 31 buttons serve as days in calendar # function below lets know which button triggered add_event_window day_1_button = CreateButton( calendar_frame, "01", x_orient, y_orient, tab, month_counter) day_1_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_1_canvas.event_markers(month_counter, 1) # using counter i make sure that no more than seven # buttons(days) are displayed in each row(week) counter += 1 # if to far right start from beginning if x_orient == 660: x_orient = 60 # if not to far right place next button right from last one else: x_orient = x_orient+100 # each row has 7 positions, if last button was placed on last position # in given row - display next button in row bellow if counter >= 8: y_orient = 200 day_2_button = CreateButton( calendar_frame, "02", x_orient, y_orient, tab, month_counter) day_2_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_2_canvas.event_markers(month_counter, 2) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 8: y_orient = 200 day_3_button = CreateButton( calendar_frame, "03", x_orient, y_orient, tab, month_counter) day_3_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_3_canvas.event_markers(month_counter, 3) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 8: y_orient = 200 day_4_button = CreateButton( calendar_frame, "04", x_orient, y_orient, tab, month_counter) day_4_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_4_canvas.event_markers(month_counter, 4) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 8: y_orient = 200 day_5_button = CreateButton( calendar_frame, "05", x_orient, y_orient, tab, month_counter) day_5_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_5_canvas.event_markers(month_counter, 5) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 8: y_orient = 200 day_6_button = CreateButton( calendar_frame, "06", x_orient, y_orient, tab, month_counter) day_6_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_6_canvas.event_markers(month_counter, 6) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 8: y_orient = 200 day_7_button = CreateButton( calendar_frame, "07", x_orient, y_orient, tab, month_counter) day_7_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_7_canvas.event_markers(month_counter, 7) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 8: y_orient = 200 day_8_button = CreateButton( calendar_frame, "08", x_orient, y_orient, tab, month_counter) day_8_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_8_canvas.event_markers(month_counter, 8) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 15: y_orient = 300 day_9_button = CreateButton( calendar_frame, "09", x_orient, y_orient, tab, month_counter) day_9_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_9_canvas.event_markers(month_counter, 9) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 15: y_orient = 300 day_10_button = CreateButton( calendar_frame, "10", x_orient, y_orient, tab, month_counter) day_10_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_10_canvas.event_markers(month_counter, 10) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 15: y_orient = 300 day_11_button = CreateButton( calendar_frame, "11", x_orient, y_orient, tab, month_counter) day_11_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_11_canvas.event_markers(month_counter, 11) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 15: y_orient = 300 day_12_button = CreateButton( calendar_frame, "12", x_orient, y_orient, tab, month_counter) day_12_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_12_canvas.event_markers(month_counter, 12) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 15: y_orient = 300 day_13_button = CreateButton( calendar_frame, "13", x_orient, y_orient, tab, month_counter) day_13_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_13_canvas.event_markers(month_counter, 13) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 15: y_orient = 300 day_14_button = CreateButton( calendar_frame, "14", x_orient, y_orient, tab, month_counter) day_14_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_14_canvas.event_markers(month_counter, 14) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 15: y_orient = 300 day_15_button = CreateButton( calendar_frame, "15", x_orient, y_orient, tab, month_counter) day_15_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_15_canvas.event_markers(month_counter, 15) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 22: y_orient = 400 day_16_button = CreateButton( calendar_frame, "16", x_orient, y_orient, tab, month_counter) day_16_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_16_canvas.event_markers(month_counter, 16) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 22: y_orient = 400 day_17_button = CreateButton( calendar_frame, "17", x_orient, y_orient, tab, month_counter) day_17_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_17_canvas.event_markers(month_counter, 17) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 22: y_orient = 400 day_18_button = CreateButton( calendar_frame, "18", x_orient, y_orient, tab, month_counter) day_18_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_18_canvas.event_markers(month_counter, 18) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 22: y_orient = 400 day_19_button = CreateButton( calendar_frame, "19", x_orient, y_orient, tab, month_counter) day_19_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_19_canvas.event_markers(month_counter, 19) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 22: y_orient = 400 day_20_button = CreateButton( calendar_frame, "20", x_orient, y_orient, tab, month_counter) day_20_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_20_canvas.event_markers(month_counter, 20) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 22: y_orient = 400 day_21_button = CreateButton( calendar_frame, "21", x_orient, y_orient, tab, month_counter) day_21_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_21_canvas.event_markers(month_counter, 21) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 22: y_orient = 400 day_22_button = CreateButton( calendar_frame, "22", x_orient, y_orient, tab, month_counter) day_22_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_22_canvas.event_markers(month_counter, 22) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 29: y_orient = 500 day_23_button = CreateButton( calendar_frame, "23", x_orient, y_orient, tab, month_counter) day_23_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_23_canvas.event_markers(month_counter, 23) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 29: y_orient = 500 day_24_button = CreateButton( calendar_frame, "24", x_orient, y_orient, tab, month_counter) day_24_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_24_canvas.event_markers(month_counter, 24) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 29: y_orient = 500 dahy_25_button = CreateButton( calendar_frame, "25", x_orient, y_orient, tab, month_counter) day_25_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_25_canvas.event_markers(month_counter, 25) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 29: y_orient = 500 day_26_button = CreateButton( calendar_frame, "26", x_orient, y_orient, tab, month_counter) day_26_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_26_canvas.event_markers(month_counter, 26) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 29: y_orient = 500 day_27_button = CreateButton( calendar_frame, "27", x_orient, y_orient, tab, month_counter) day_27_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_27_canvas.event_markers(month_counter, 27) counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 29: y_orient = 500 day_28_button = CreateButton( calendar_frame, "28", x_orient, y_orient, tab, month_counter) day_28_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_28_canvas.event_markers(month_counter, 28) if int(date_dict['DaysInViewedMonth']) >= 29: counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 29: y_orient = 500 day_29_button = CreateButton( calendar_frame, "29", x_orient, y_orient, tab, month_counter) day_29_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_29_canvas.event_markers(month_counter, 29) if int(date_dict['DaysInViewedMonth']) >= 30: counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 36: y_orient = 600 day_30_button = CreateButton( calendar_frame, "30", x_orient, y_orient, tab, month_counter) day_30_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_30_canvas.event_markers(month_counter, 30) if int(date_dict['DaysInViewedMonth']) >= 31: counter += 1 if x_orient == 660: x_orient = 60 else: x_orient = x_orient+100 if counter >= 36: y_orient = 600 day_31_button = CreateButton( calendar_frame, "31", x_orient, y_orient, tab, month_counter) day_31_canvas = CreateCanvas(calendar_frame, x_orient, y_orient) day_31_canvas.event_markers(month_counter, 31) counter += 1
def add_event_window(month_counter, day_of_the_event, tab): language_dict = set_options.Options() language_dict.get_text_dict("single_day_view") lang_dict = language_dict.widget_text_dictionary month_name = process_calendar_data.get_month_name(month_counter) date_dict = get_date.get(month_counter) date_dict['DayOfTheNewEvent'] = day_of_the_event date_dict['DistancefromToday'] = month_counter single_day_frame = tk.Frame() single_day_frame.grid( row=0, column=0, columnspan=50, rowspan=50, sticky="NESW") def add_pregnancy(): def save_event(): result = check_calendar_input.pregnancy_event( date_dict, add_mum.get(), add_dad.get()) if result == "success": pregnancy_window.destroy() single_day_frame.destroy() add_event_window( month_counter, day_of_the_event, tab) pregnancy_window = tk.Toplevel(height=230, width=320) mum_label = tk.Label( pregnancy_window, text=lang_dict["mum_label"], font="Helvetica 12") mum_label.place(x=10, y=50) dad_label = tk.Label( pregnancy_window, text=lang_dict["dad_label"], font="Helvetica 12") dad_label.place(x=10, y=100) add_mum = tk.Entry(pregnancy_window, width=20, font="Helvetica 12") add_mum.place(x=105, y=50) add_dad = tk.Entry(pregnancy_window, width=20, font="Helvetica 12") add_dad.place(x=105, y=100) save = tk.Button( pregnancy_window, text=lang_dict["save"], height=1, width=6, font="Helvetica 12", command=save_event) save.place(x=170, y=190) close = tk.Button( pregnancy_window, text=lang_dict["close"], height=1, width=6, font="Helvetica 12", command=pregnancy_window.destroy) close.place(x=243, y=190) def add_medicine(): def save_event(): result = check_calendar_input.medicine_event( date_dict, add_treated_goat.get(), add_medicine_entry.get(), add_dosing_period.get(), add_withdrawal_period.get(), add_note.get('1.0', 'end-1c')) if result == "success": medicine_window.destroy() single_day_frame.destroy() add_event_window( month_counter, day_of_the_event, tab) medicine_window = tk.Toplevel(single_day_frame, height=460, width=390) treated_goat = tk.Label( medicine_window, text=lang_dict["treated_goat"], font="Helvetica 12") treated_goat.place(x=10, y=10) add_treated_goat = tk.Entry( medicine_window, width=35, font="Heletica 12") add_treated_goat.place(x=10, y=35) medicine = tk.Label( medicine_window, text=lang_dict["medicine"], font="Helvetica 12") medicine.place(x=10, y=75) add_medicine_entry = tk.Entry( medicine_window, width=17, font="Helvetica 12") add_medicine_entry.place(x=170, y=75) dosing_period = tk.Label( medicine_window, text=lang_dict["dosing_period"], font="Helvetica 12") dosing_period.place(x=10, y=120) withdrawal_period = tk.Label( medicine_window, text=lang_dict["withdrawal_period"], font="Helvetica 12") withdrawal_period.place(x=10, y=170) note = tk.Label( medicine_window, text=lang_dict["note"], font="Helvetica 12") note.place(x=10, y=220) add_dosing_period = tk.Entry( medicine_window, width=5, font="Helvetica 12") add_dosing_period.place(x=275, y=120) add_withdrawal_period = tk.Entry( medicine_window, width=5, font="Helvetica 12") add_withdrawal_period.place(x=275, y=170) add_note = sc.ScrolledText( medicine_window, width=35, height=7, font="Helvetica 12") add_note.place(x=10, y=245) save = tk.Button( medicine_window, text=lang_dict["save"], height=1, width=6, font="Helvetica 12", command=save_event) save.place(x=240, y=420) close = tk.Button( medicine_window, text=lang_dict["close"], height=1, width=6, font="Helvetica 12", command=medicine_window.destroy) close.place(x=313, y=420) def add_milking(): def save_event(): result = check_calendar_input.milking_event( date_dict, addMilk.get()) if result == "success": milkingWindow.destroy() single_day_frame.destroy() add_event_window( month_counter, day_of_the_event, tab) milkingWindow = tk.Toplevel(single_day_frame, height=175, width=250) milking = tk.Label( milkingWindow, text=lang_dict["milking"], font="Helvetica 12") milking.place(x=10, y=50) addMilk = tk.Entry(milkingWindow, width=5, font="Helvetica 12") addMilk.place(x=180, y=50) save = tk.Button( milkingWindow, text=lang_dict["save"], height=1, width=6, font="Helvetica 12", command=save_event) save.place(x=100, y=135) close = tk.Button( milkingWindow, text=lang_dict["close"], height=1, width=6, font="Helvetica 12", command=milkingWindow.destroy) close.place(x=173, y=135) def add_other(): def save_event(): result = check_calendar_input.other_event( date_dict, addTitle.get(), add_note.get('1.0', 'end-1c')) if result == "success": other_window.destroy() single_day_frame.destroy() add_event_window( month_counter, day_of_the_event, tab) other_window = tk.Toplevel(single_day_frame, height=350, width=390) title = tk.Label( other_window, text=lang_dict["title"], font="Helvetica 12") title.place(x=10, y=50) note = tk.Label( other_window, text=lang_dict["note"], font="Helvetica 12") note.place(x=10, y=100) addTitle = tk.Entry(other_window, width=15, font="Helvetica 12") addTitle.place(x=200, y=50) add_note = sc.ScrolledText( other_window, width=35, height=7, font="Helvetica 12") add_note.place(x=10, y=125) save = tk.Button( other_window, text=lang_dict["save"], height=1, width=6, font="Helvetica 12", command=save_event) save.place(x=240, y=310) close = tk.Button( other_window, text=lang_dict["close"], height=1, width=6, font="Helvetica 12", command=other_window.destroy) close.place(x=313, y=310) def help_window(): other_window = tk.Toplevel(single_day_frame, height=100, width=420) advice = tk.Label( other_window, text=lang_dict["advice"], font="Helvetica 12") advice.place(x=10, y=20) # kills the day - view frame # displays reseted month view frame def backButton(): calendar_tab.Calendar(tab, month_counter) single_day_frame.destroy() a = (str(date_dict['ViewedYear']) + "/" + str(date_dict['ViewedMonth']) + "/" + str(day_of_the_event)) list__of_events = process_calendar_data.get_event(a) back = tk.Button( single_day_frame, text=lang_dict["back"], height=2, width=7, font="Helvetica 12", command=backButton) back.place(x=10, y=10) pregnancy = tk.Button( single_day_frame, text=lang_dict["pregnancy"], height=2, width=9, font="Helvetica 12", bg="hot pink", command=add_pregnancy) pregnancy.place(x=105, y=10) medicine_button = tk.Button( single_day_frame, text=lang_dict["medicine_button"], height=2, width=8, font="Helvetica 12", bg="blue", command=add_medicine) medicine_button.place(x=215, y=10) daily_milking = tk.Button( single_day_frame, text=lang_dict["daily_milking"], height=2, width=10, font="Helvetica 12", bg="yellow", command=add_milking) daily_milking.place(x=314, y=10) other = tk.Button( single_day_frame, text=lang_dict["other"], height=2, width=7, font="Helvetica 12", bg="green2", command=add_other) other.place(x=435, y=10) help_button = tk.Button( single_day_frame, text="?", height=1, width=2, font="Helvetica 12", command=help_window) help_button.place(x=530, y=28) date = tk.Label( single_day_frame, text=str(day_of_the_event) + " " + month_name + " " + str(date_dict['ViewedYear']), font="Helvetica 25 bold") date.place(x=280, y=100) def reset(): single_day_frame.destroy calendar_tab.Calendar(tab, month_counter) if list__of_events: def onFrameConfigure(canvas): '''Reset the scroll region to encompass the inner frame''' canvas.configure(scrollregion=canvas.bbox("all")) canvas_scrollregion = 100*len(list__of_events) canvas = tk.Canvas( single_day_frame, width=760, height=600, scrollregion=(0, 0, 0, canvas_scrollregion)) canvas.place(x=0, y=180) vbar = tk.Scrollbar( single_day_frame, orient=tk.VERTICAL, command=canvas.yview) vbar.place(x=750, y=180, height=600) canvas.config(yscrollcommand=vbar.set) on_canvas_frame = tk.Frame( canvas, width=696, height=canvas_scrollregion) on_canvas_frame.place(x=65, y=0) on_canvas_frame.bind( "<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas)) canvas.create_window((50, 0), window=on_canvas_frame, anchor="nw") event_numbers = [] for event in range(len(list__of_events)): single_event = list__of_events[event].split("-") event_numbers.append(single_event[len(single_event)-1]) def send(event): answer = messagebox.askquestion( lang_dict["messagebox"], lang_dict["messagebox1"], icon='warning') if answer == "yes": calculatedEvent = int(event.y/100) process_calendar_data.delete_event( event_numbers[calculatedEvent]) single_day_frame.destroy() add_event_window( month_counter, day_of_the_event, tab) on_canvas_frame.bind("<Button-3>", send) if single_event[1] == "OTHER": title = tk.Label( on_canvas_frame, text=single_event[2], font="Helvetica 12 bold") else: title = tk.Label( on_canvas_frame, text=single_event[1], font="Helvetica 12 bold") title.place(x=10, y=event*100+5) if single_event[1] == "PREGNANCY": canvas.create_oval( 10, event * 100 + 10, 30, event * 100 + 30, fill="hot pink") label = tk.Label( on_canvas_frame, text=lang_dict["mum_label"] + ": " + single_event[2], font="Helvetica 10") label.place(x=10, y=event * 100 + 30) label2 = tk.Label( on_canvas_frame, text=lang_dict["dad_label"] + ": " + single_event[3], font="Helvetica 10") label2.place(x=10, y=event*100+60) elif single_event[1] == "MEDICINE": canvas.create_oval( 10, event * 100 + 10, 30, event * 100 + 30, fill="blue") label = tk.Label( on_canvas_frame, text=lang_dict["label"] + single_event[2], font="Helvetica 10") label.place(x=100, y=event*100+5) label2 = tk.Label( on_canvas_frame, text=lang_dict["medicine_button"] + ": " + single_event[3], font="Helvetica 10") label2.place(x=10, y=event*100+30) # if not empty(0) place label if int(single_event[4]) != 0: # if 1 day - singular, if more - plural if int(single_event[4]) == 1: label3 = tk.Label( on_canvas_frame, text=lang_dict["label1"] + single_event[4] + lang_dict["label2"], font="Helvetica 10") else: label3 = tk.Label( on_canvas_frame, text=lang_dict["label1"] + single_event[4]+" days left.", font="Helvetica 10") label3.place(x=200, y=event * 100 + 30) # I don't want withdrawal period to be displayed on # "medicine" event, remove quotation marks to add this label5 = tk.Label( on_canvas_frame, text=single_event[6], font="Helvetica 10", wraplength=680, justify=tk.LEFT) label5.place(x=10, y=event*100+50) elif single_event[1] == "MILKING": canvas.create_oval( 10, event * 100 + 10, 30, event * 100 + 30, fill="yellow") label = tk.Label( on_canvas_frame, text=lang_dict["label3"] + single_event[2], font="Helvetica 10") label.place(x=10, y=event*100+30) elif single_event[1] == "OTHER": canvas.create_oval( 10, event * 100 + 10, 30, event * 100 + 30, fill="green2") label = tk.Label( on_canvas_frame, text=single_event[3], font="Helvetica 10", wraplength=670, justify=tk.LEFT) label.place(x=10, y=event * 100 + 30) elif single_event[1] == "DELIVERY": canvas.create_oval( 10, event * 100 + 10, 30, event * 100 + 30, fill="red") if single_event[3] != "": label = tk.Label( on_canvas_frame, text=lang_dict["label4"] + single_event[2] + " " + lang_dict["label5"] + single_event[3] + lang_dict["label6"], font="Helvetica 10") label.place(x=10, y=event*100+30) else: label = tk.Label( on_canvas_frame, text=lang_dict["label4"] + single_event[2] + lang_dict["label5"], font="Helvetica 10") label.place(x=10, y=event*100+30) elif single_event[1] == "WITHDRAWAL": canvas.create_oval( 10, event * 100 + 10, 30, event * 100 + 30, fill="black") label = tk.Label( on_canvas_frame, text=lang_dict["label"] + single_event[2], font="Helvetica 10") label.place(x=140, y=event*100+5) label2 = tk.Label( on_canvas_frame, text=lang_dict["label7"] + single_event[3], font="Helvetica 10") label2.place(x=10, y=event * 100 + 30) # if 1 day - singular, if more - plural if int(single_event[5]) > 1: label3 = tk.Label( on_canvas_frame, text=lang_dict["label8"] + single_event[5] + " days left.", font="Helvetica 10") else: label3 = tk.Label( on_canvas_frame, text=lang_dict["label8"] + single_event[5] + " day left.", font="Helvetica 10") label3.place(x=250, y=event*100+30) label4 = tk.Label( on_canvas_frame, text=single_event[6], font="Helvetica 10", wraplength=680, justify=tk.LEFT) label4.place(x=10, y=event*100+50)
def save_medicine(date_dict): """saves medicine event""" language_dict = set_options.Options() language_dict.get_text_dict("process_calendar_data") lang_dict = language_dict.widget_text_dictionary random_num = random.randint(1, 1000000) try: container = open("Calendar.txt", "a") dosing_days_counter = date_dict['Input3'] medicine_counter = 0 day_counter = 0 def add_withdrawal(year, month, day, days_in_month, months_in_future): day_counter = 0 withdrawal_counter = 1 withdrawal_days_counter = date_dict['Input4'] while withdrawal_days_counter > 0: if day+withdrawal_counter <= days_in_month: container.write( str(year)+'/'+str(month)+'/' + str(day+withdrawal_counter)+'-'+"WITHDRAWAL" + '-'+str(date_dict['Input1'])+'-' + str(date_dict['Input2'])+'-'+str(date_dict['Input3']) + '-'+str(date_dict['Input4'] + 1 - withdrawal_counter) + '-'+str(date_dict['Input5'])+'-'+str(random_num)+'\n') withdrawal_counter += 1 withdrawal_days_counter -= 1 else: vase = get_date.get(months_in_future+1) container.write( str(vase['ViewedYear'])+'/'+str(vase['ViewedMonth']) + '/'+str(1+day_counter)+'-'+"WITHDRAWAL"+'-' + str(date_dict['Input1'])+'-'+str(date_dict['Input2']) + '-'+str(date_dict['Input3'])+'-' + str(date_dict['Input4']+1-withdrawal_counter) + '-'+str(date_dict['Input5'])+'-'+str(random_num)+'\n') day_counter += 1 withdrawal_counter += 1 withdrawal_days_counter -= 1 while dosing_days_counter > 0: if(date_dict['DayOfTheNewEvent'] + medicine_counter <= date_dict['DaysInViewedMonth']): container.write( str(date_dict['ViewedYear'])+'/' + str(date_dict['ViewedMonth'])+'/' + str(date_dict['DayOfTheNewEvent']+medicine_counter) + '-'+"MEDICINE"+'-'+str(date_dict['Input1'])+'-' + str(date_dict['Input2'])+'-' + str(date_dict['Input3']-medicine_counter) + '-'+str(date_dict['Input4'])+'-' + str(date_dict['Input5'])+'-'+str(random_num)+'\n') if date_dict['Input4'] != 0 and dosing_days_counter == 1: add_withdrawal( date_dict['ViewedYear'], date_dict['ViewedMonth'], date_dict['DayOfTheNewEvent']+medicine_counter, date_dict['DaysInViewedMonth'], 0) medicine_counter += 1 dosing_days_counter -= 1 else: vase = get_date.get(1) container.write( str(vase['ViewedYear'])+'/'+str(vase['ViewedMonth'])+'/' + str(1+day_counter)+'-'+"MEDICINE"+'-' + str(date_dict['Input1'])+'-'+str(date_dict['Input2'])+'-' + str(date_dict['Input3']-medicine_counter)+'-' + str(date_dict['Input4'])+'-'+str(date_dict['Input5'])+'-' + str(random_num)+'\n') if date_dict['Input4'] != 0 and dosing_days_counter == 1: add_withdrawal( vase['ViewedYear'], vase['ViewedMonth'], 1 + day_counter, vase['DaysInViewedMonth'], 1) day_counter += 1 medicine_counter += 1 dosing_days_counter -= 1 def add_withdrawal(year, month, day, days_in_month, months_in_future): day_counter = 0 withdrawal_counter = 1 withdrawal_days_counter = date_dict['Input4'] while withdrawal_days_counter > 0: if day+withdrawal_counter <= days_in_month: container.write( str(year)+'/'+str(month)+'/' + str(day+withdrawal_counter)+'-' + str(date_dict['EventType'])+'-' + str(date_dict['Input1'])+'-' + str(date_dict['Input2']) + '-' + str(date_dict['Input3']-withdrawal_counter)+'-' + str(date_dict['Input4'])+'-' + str(date_dict['Input5'])+'-'+str(random_num)+'\n') withdrawal_counter += 1 withdrawal_days_counter -= 1 else: vase = get_date.get(months_in_future+1) container.write( str(vase['ViewedYear'])+'/' + str(vase['ViewedMonth']) + '/' + str(1+day_counter)+'-'+str(date_dict['EventType'])+'-'+ str(date_dict['Input1'])+'-' + str(date_dict['Input2'])+'-' + str(date_dict['Input3']-withdrawal_counter)+'-' + str(date_dict['Input4'])+'-' + str(date_dict['Input5'])+'-' + str(random_num)+'\n') day_counter += 1 withdrawal_counter += 1 withdrawal_days_counter -= 1 except IOError: messagebox.showinfo(lang_dict["messagebox3"], lang_dict["messagebox4"]) container.close() else: messagebox.showinfo(lang_dict["messagebox1"], lang_dict["messagebox5"]) container.close()
def save_pregnancy(date_dict): """saves pregnancy event""" language_dict = set_options.Options() language_dict.get_text_dict("process_calendar_data") lang_dict = language_dict.widget_text_dictionary random_num = random.randint(1, 1000000) try: container = open("Calendar.txt", "a") container.write(str(date_dict['ViewedYear'])+'/' + str(date_dict['ViewedMonth'])+'/' + str(date_dict['DayOfTheNewEvent'])+'-' + "PREGNANCY"+'-'+str(date_dict['Input1'])+'-' + str(date_dict['Input2'])+'-'+str(random_num)+'\n') # adds "DELIVERY" event 150 days after "PREGNANCY" event pregnancy_period = 150 pregnancy_period -= ( date_dict['DaysInViewedMonth'] - date_dict['DayOfTheNewEvent']) timer = 0 counter = date_dict['DistancefromToday'] while timer <= pregnancy_period: counter += 1 vase = get_date.get(counter) timer = vase['DaysInViewedMonth'] if timer == pregnancy_period: messagebox.showinfo( lang_dict["messagebox1"], lang_dict["messagebox2"] + str(vase['ViewedYear'])+'/'+str(vase['ViewedMonth'])+'/' + str(pregnancy_period)+".") container.write( str(vase['ViewedYear'])+'/'+str(vase['ViewedMonth'])+'/' + str(pregnancy_period)+'-'+"DELIVERY"+'-' + str(date_dict['Input1'])+'-'+str(date_dict['Input2']) + '-'+str(random_num)+'\n') return pregnancy_period -= timer if pregnancy_period < 0: messagebox.showinfo( lang_dict["messagebox1"], lang_dict["messagebox2"] + str(vase['ViewedYear'])+'/'+str(vase['ViewedMonth']) + '/'+str(pregnancy_period+timer)+".") container.write( str(vase['ViewedYear'])+'/' + str(vase['ViewedMonth']) + '/'+str(pregnancy_period+timer)+'-'+"DELIVERY"+'-' + str(date_dict['Input1'])+'-'+str(date_dict['Input2']) + '-'+str(random_num)+'\n') return if timer > pregnancy_period: if vase['ViewedMonth']+1 < 12: messagebox.showinfo( lang_dict["messagebox1"], lang_dict["messagebox2"] + str(vase['ViewedYear'])+'/' + str(vase['ViewedMonth']+1) + '/' + str(pregnancy_period) + ".") container.write( str(vase['ViewedYear'])+'/' + str(vase['ViewedMonth']+1)+'/' + str(pregnancy_period)+'-'+"DELIVERY"+'-' + str(date_dict['Input1'])+'-' + str(date_dict['Input2'])+'-' + str(random_num)+'\n') return else: messagebox.showinfo( lang_dict["messagebox1"], lang_dict["messagebox2"] + str(vase['ViewedYear']+1)+'/'+str(1)+'/' + str(pregnancy_period)+".") container.write( str(vase['ViewedYear'] + 1)+'/'+str(1)+'/' + str(pregnancy_period)+'-'+"DELIVERY"+'-' + str(date_dict['Input1'])+'-' + str(date_dict['Input2'])+'-' + str(random_num)+'\n') except IOError: messagebox.showinfo(lang_dict["messagebox3"], lang_dict["messagebox4"]) container.close() else: messagebox.showinfo(lang_dict["messagebox1"], lang_dict["messagebox5"]) container.close()
def age_of_goats(): """ extract age of goats based on their DoB and current date, send dictionary (key is age from 1-15 and value is number of goats with this age) to Main().agePyramidChart() """ # dictionary containing ages of goats, key is gender+age from 1 to 15 and # value is number of goats with this age age_dictionary = { 'm1': 0, 'm2': 0, 'm3': 0, 'm4': 0, 'm5': 0, 'm6': 0, 'm7': 0, 'm8': 0, 'm9': 0, 'm10': 0, 'm11': 0, 'm12': 0, 'm13': 0, 'm14': 0, 'm15': 0, 'f1': 0, 'f2': 0, 'f3': 0, 'f4': 0, 'f5': 0, 'f6': 0, 'f7': 0, 'f8': 0, 'f9': 0, 'f10': 0, 'f11': 0, 'f12': 0, 'f13': 0, 'f14': 0, 'f15': 0 } profiles = get_all_profiles() # get current date curent_date = get_date.get(0) # compare date of birth of goat with current date to determine its age age = 0 for prof in profiles: if prof["DATE_OF_BIRTH"] != "": age = curent_date['ViewedYear'] - int(prof["DATE_OF_BIRTH"][6:10]) # lower one year if month of birth is lower than actual month month_of_birth = int(prof["DATE_OF_BIRTH"][3:5].strip('0')) if month_of_birth > curent_date['ViewedMonth']: age -= 1 if prof["GENDER"] == "male": if age in (0, 1): age_dictionary['m1'] += 1 if age == 2: age_dictionary['m2'] += 1 if age == 3: age_dictionary['m3'] += 1 if age == 4: age_dictionary['m4'] += 1 if age == 5: age_dictionary['m5'] += 1 if age == 6: age_dictionary['m6'] += 1 if age == 7: age_dictionary['m7'] += 1 if age == 8: age_dictionary['m8'] += 1 if age == 9: age_dictionary['m9'] += 1 if age == 10: age_dictionary['m10'] += 1 if age == 11: age_dictionary['m11'] += 1 if age == 12: age_dictionary['m12'] += 1 if age == 13: age_dictionary['m13'] += 1 if age == 14: age_dictionary['m14'] += 1 if age >= 15: age_dictionary['m15'] += 1 else: if age in (0, 1): age_dictionary['f1'] += 1 if age == 2: age_dictionary['f2'] += 1 if age == 3: age_dictionary['f3'] += 1 if age == 4: age_dictionary['f4'] += 1 if age == 5: age_dictionary['f5'] += 1 if age == 6: age_dictionary['f6'] += 1 if age == 7: age_dictionary['f7'] += 1 if age == 8: age_dictionary['f8'] += 1 if age == 9: age_dictionary['f9'] += 1 if age == 10: age_dictionary['f10'] += 1 if age == 11: age_dictionary['f11'] += 1 if age == 12: age_dictionary['f12'] += 1 if age == 13: age_dictionary['f13'] += 1 if age == 14: age_dictionary['f14'] += 1 if age >= 15: age_dictionary['f15'] += 1 return age_dictionary