Exemple #1
0
    def show_time_picker(self):
        from datetime import datetime

        previous_time = datetime.strptime("03:20:00", '%H:%M:%S').time()
        time_dialog = MDTimePicker()
        time_dialog.set_time(previous_time)
        time_dialog.open()
Exemple #2
0
    def show_time_picker(self):
        today = datetime.today()

        time_dialog = MDTimePicker()
        time_dialog.set_time(time(hour=today.hour, minute=today.minute))
        time_dialog.bind(time=self.set_time)
        time_dialog.open()
Exemple #3
0
 def time_picker(self,obj):
     from datetime import datetime
     previous_time = datetime.strptime("16:20:00", '%H:%M:%S').time()
     picker=MDTimePicker()
     picker.set_time(previous_time)
     picker.bind(time=self.got_time)
     picker.open()
Exemple #4
0
 def show_time_picker(self):
     from datetime import datetime
     # Must be a datetime object
     now = datetime.now()
     time_dialog = MDTimePicker()
     time_dialog.set_time(now)
     time_dialog.bind(time=self.get_time)
     time_dialog.open()
Exemple #5
0
    def show_example_time_picker(self, military):
        time_dialog = MDTimePicker(military=military)
        time_dialog.bind(time=self.get_time_picker_date)

        if self.ids.time_picker_use_previous_time.active:
            try:
                time_dialog.set_time(self.previous_time)
            except AttributeError:
                pass
        time_dialog.open()
Exemple #6
0
    def show_time_picker(self):
        from datetime import datetime

        # Define default time
        default_time = datetime.strptime("4:20:00", '%H:%M:%S').time()

        time_dialog = MDTimePicker()
        # Set default Time
        time_dialog.set_time(default_time)
        time_dialog.bind(on_cancel=self.on_cancel, time=self.get_time)
        time_dialog.open()
Exemple #7
0
    def show_example_time_picker(self):
        from kivymd.uix.picker import MDTimePicker

        time_dialog = MDTimePicker()
        time_dialog.bind(time=self.get_time_picker_date)

        if self.ids.time_picker_use_previous_time.active:
            try:
                time_dialog.set_time(self.previous_time)
            except AttributeError:
                pass
        time_dialog.open()
Exemple #8
0
 def open_time_picker(self):
     """
     Opens up time picker dialog for selection of alarm time.
     """
     time_dialog = MDTimePicker()
     # getting the previous time text in the button
     previous_time = datetime.strptime(self.time_picker.text,
                                       '%H:%M').time()
     # setting the previous time in the dialog
     time_dialog.set_time(previous_time)
     # binds a method that sets the time chosen
     time_dialog.bind(time=self.get_time_picker_time)
     time_dialog.open()
Exemple #9
0
    def show_example_time_picker(self):
        """Show MDTimePicker from the screen Pickers."""

        from kivymd.uix.picker import MDTimePicker

        time_dialog = MDTimePicker(self.get_time_picker_date)

        if self.data["Pickers"][
                "object"].ids.time_picker_use_previous_time.active:
            try:
                time_dialog.set_time(self.previous_time)
            except AttributeError:
                pass
        time_dialog.open()
Exemple #10
0
        def change_reminder(self, *args):

            # sets default time for value of Reminder.text
            # if empty --> default time is now
            default_time = datetime.datetime.now() if self.text in [
                None, '', ' '
            ] else datetime.datetime.strptime(self.text, '%H:%M')

            # open MDTimePicker preset to default_time
            time_dialog = MDTimePicker()
            time_dialog.set_time(default_time)
            time_dialog.open()
            time_dialog.bind(on_dismiss=lambda *args: self.
                             update_reminder_time(time_dialog.time))
Exemple #11
0
        def add_reminder(self, *args):

            # sets default time to now
            default_time = datetime.datetime.now()

            # creates new Reminder with text of time from MDTimePicker
            def set_reminder_time(self, time, *args):
                if time not in [None, '', ' ']:
                    self.reminder_list_instance.add_widget(
                        self.root_instance.Reminder(text=f'{time:%H:%M}'))

            # open MDTimePicker set to default_time
            time_dialog = MDTimePicker()
            time_dialog.set_time(default_time)
            time_dialog.open()
            time_dialog.bind(on_dismiss=lambda *args: set_reminder_time(
                self, time_dialog.time))
Exemple #12
0
        def choose_due_time(self, date, *args):

            # define default_time from task.secondary_text (second part / time-part)
            due_time = '' if self.text in [None, '', ' '] else self.text.split(' ')[
                1]
            default_time = datetime.datetime.now() if due_time in [
                None, '', ' '] else datetime.datetime.strptime(due_time, '%H:%M')

            # setting Task.due_date to values from MDDatePicker and MDTimePicker
            def set_due_date_time(self, date, time, *args):
                if all([date != None, time != None]):
                    due_date_time = ' '.join(
                        [f'{date:%d.%m.%Y}', f'{time:%H:%M}'])
                    self.text = due_date_time

            # open MDTimePicker preset to default_time
            time_dialog = MDTimePicker()
            time_dialog.set_time(default_time)
            time_dialog.open()
            time_dialog.bind(
                on_dismiss=lambda *args: set_due_date_time(
                    self, date, time_dialog.time)
            )
Exemple #13
0
 def show_time_picker(self, id):
     self.current_button_id = id
     time_dialog = MDTimePicker()
     time_dialog.set_time(datetime.now())
     time_dialog.bind(on_save=self.on_save_time_picker, on_cancel=self.on_cancel_time_picker)
     time_dialog.open()
Exemple #14
0
 def show_time_picker(self):
     time_dialog = MDTimePicker()
     time_dialog.bind(time=self.get_time)
     previous_time = datetime.now()
     time_dialog.set_time(previous_time)
     time_dialog.open()
Exemple #15
0
 def show_time_picker(self):
     time_dialog = MDTimePicker()
     time_dialog.bind(time=self.get_timeFromPicker)
     time_dialog.set_time(datetime.now().time())
     time_dialog.open()
Exemple #16
0
class YalbApp(MDApp):
    title = "Yet Another LogBook"
    #    theme_cls = ThemeManager()
    previous_date = ObjectProperty()

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.time_dialog = MDTimePicker()
        self.previous_time = datetime.utcnow()

    def build(self):
        table = TV(
            size=(Window.size[0], Window.size[1]),
            pos_hint={
                'x': 0.0,
                'y': 0.0
            },
            do_scroll_x=True,
        )
        table.populate("log.db")
        #print(str(table))
        self.root.ids.sm.transition = NoTransition()
        self.root.ids.scr_second_box.add_widget(table)

        def _on_rotate(obj, *args):
            #print(*args)
            self.on_rotate(*args)

        Window.bind(on_rotate=_on_rotate)
        Window.bind(on_resize=_on_rotate)

        #scr2.add_widget(RV())
        print("Vsykuyu hernyu delat tut")

    def calculate_night_time(self, coords_departure, coords_arrival, takeoff,
                             landing):
        if landing < takeoff:
            landing += timedelta(days=1)

        departure_ap = ephem.Observer()
        departure_ap.lat = radians(coords_departure[0])
        departure_ap.lon = radians(coords_departure[1])
        arrival_ap = ephem.Observer()
        arrival_ap.lat = radians(coords_arrival[0])
        arrival_ap.lon = radians(coords_arrival[1])
        departure_ap.date = takeoff
        arrival_ap.date = takeoff + timedelta(
            days=(departure_ap.lon - arrival_ap.lon) / pi / 12.0)

        s = ephem.Sun()
        plane = ephem.Observer()
        plane.date = takeoff
        flight_time_minutes = int((landing - takeoff).total_seconds() // 60)
        print("ldgt-to in minutes:", flight_time_minutes, "HH:MM :",
              timedelta(hours=flight_time_minutes / 60.0))
        dlat = (arrival_ap.lat - departure_ap.lat) / flight_time_minutes
        dlon = (arrival_ap.lon - departure_ap.lon) / flight_time_minutes
        dt = timedelta(seconds=60)
        nt = 0
        for i in range(flight_time_minutes):
            plane.date = takeoff + dt * float(i + 0.5)
            plane.lat = departure_ap.lat + dlat * float(i)
            plane.lon = departure_ap.lon + dlon * float(i)
            try:
                if plane.next_rising(s) < plane.next_setting(s):
                    nt += 1
            except ephem.NeverUpError:
                nt += 1
            except ephem.AlwaysUpError:
                pass
        nt = timedelta(hours=nt / 60.0)
        return nt

    def new_leg(self):
        date = self.root.ids.date_picker_input.text
        flightno = self.root.ids.flight_no_item_input.text
        acno = self.root.ids.aircraft_id_item_input.text
        fromap = self.root.ids.from_item_input.text
        toap = self.root.ids.to_item_input.text
        ofbt = self.root.ids.offblock_item_input.text
        tot = self.root.ids.takeoff_item_input.text
        lt = self.root.ids.landing_item_input.text
        onbt = self.root.ids.onblock_item_input.text

        offblocktime = datetime.strptime(date + " " + ofbt, "%Y-%m-%d %H:%M")
        onblocktime = datetime.strptime(date + " " + onbt, "%Y-%m-%d %H:%M")
        takeofftime = datetime.strptime(date + " " + tot, "%Y-%m-%d %H:%M")
        landingtime = datetime.strptime(date + " " + lt, "%Y-%m-%d %H:%M")

        if offblocktime > onblocktime:  # Check next day
            onblocktime += timedelta(days=1)
        blktime = onblocktime - offblocktime

        if landingtime < takeofftime:  # Check next day
            landingtime += timedelta(days=1)
        flttime = landingtime - takeofftime

        #coords_departure = self.get_ap_coords(fromap)
        coords_departure = (51.8779638888889, -176.646030555556)
        #coords_arrival = self.get_ap_coords(toap)
        coords_arrival = (44.814998626709, 136.292007446289)
        takeoff = takeofftime
        landing = landingtime
        night_time = self.calculate_night_time(coords_departure,
                                               coords_arrival, takeoff,
                                               landing)

        connection = sqlite3.connect("log.db")
        print("db_connected debug")
        cursor = connection.cursor()
        print("cursor_connected debug")
        sql = "INSERT INTO log ('Date', 'FlightNumber', 'Aircraft', 'AirportDeparture', 'AirportArrival', 'OffBlock', 'TakeOff', 'Landing', 'OnBlock', 'FlightTime', 'BlockTime', 'NightTime')" \
              " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"
        data = (date, flightno, acno, fromap, toap, ofbt, tot, lt, onbt,
                str(flttime)[:-3], str(blktime)[:-3], str(night_time)[:-3])
        cursor.execute(sql, data)
        print("cursor_executedted debug")
        connection.commit()
        print("connection_commited debug")
        cursor.close()
        print("cursor_closed debug")
        if connection:
            connection.close()
        print("conecion_closed debug")

        print(blktime, flttime, night_time)
        print(date, flightno, acno, fromap, toap, ofbt, tot, lt, onbt)

    def get_id(self, instance):
        for id, widget in self.root.ids.items():
            if widget.__self__ == instance:
                return id

    def on_rotate(self, angle, *args):
        table = self.root.ids.scr_second.children[0].children[0]
        table.layout.width = max(Window.size[0], Window.size[1])

    def on_refresh(self):
        self.on_rotate(0)

    def get_time_picker_data(self, instance, time):
        name = self.get_id(instance)
        if not name:
            return
        self.root.ids[name + "_item_input"].text = str(time)[:-3]
        self.previous_time = time

    def show_time_picker(self, instance):
        self.time_dialog = MDTimePicker()
        self.time_dialog.bind(
            time=lambda x, time: self.get_time_picker_data(instance, time))
        try:
            self.time_dialog.set_time(self.previous_time)
        except AttributeError:
            pass
        self.time_dialog.open()

    def set_previous_date(self, date_obj):
        self.previous_date = date_obj
        self.root.ids.date_picker_input.text = str(date_obj)

    def show_date_picker(self):
        pd = self.previous_date
        try:
            MDDatePicker(self.set_previous_date, pd.year, pd.month,
                         pd.day).open()
        except AttributeError:
            MDDatePicker(self.set_previous_date).open()

    def screen_main(self):
        sm = self.root.ids.sm
        sm.switch_to(self.root.ids.scr_main)

    def scr_edit(self):
        sm = self.root.ids.sm
        sm.switch_to(self.root.ids.scr_edit)

    def screen_second(self):
        sm = self.root.ids.sm
        sm.switch_to(self.root.ids.scr_second)
        self.root.ids.ap.title = sm.current_screen.name

    def screen_debug(self):
        sm = self.root.ids.sm
        sm.switch_to(self.root.ids.scr_debug)
        self.root.ids.ap.title = sm.current_screen.name