예제 #1
0
    def update_main_gui(self):
        if self.gtkb == None:
            print("MMTime.update_main_gui(): Gui not builded.\n")
            return

        total_used_sec = self.used_sec + self.this_slot_sec
        (h, m, s) = ntmtools.sec_to_hms(total_used_sec)
        out_str = """<span color='#900000'>{0}h{1}'<small>{2}"</small></span>""".format(
            h, m, s)
        self.gui_main_used_sec.set_markup(out_str)

        time_diff = self.total_sec - total_used_sec
        if (time_diff < 0):
            time_diff = -time_diff
            sign = "-"
        else:
            sign = ""
        (h, m, s) = ntmtools.sec_to_hms(time_diff)
        out_str = """<span color='#009000'>{0}{1}h{2}'<small>{3}"</small></span>""".format(
            sign, h, m, s)
        self.gui_main_left_sec.set_markup(out_str)

        (h, m, s) = ntmtools.sec_to_hms(self.total_sec)
        out_str = """{0}h{1}'<small>{2}"</small>""".format(h, m, s)
        self.gui_main_total_sec.set_markup(out_str)

        total_used_sec = self.used_sec + self.this_slot_sec
        if self.total_sec == 0:
            print _("Warning! mtime.py: total sec is 0.")
            per = 100.0
        else:
            per = 100.0 * total_used_sec / self.total_sec

        last_day = ntmtools.get_last_day(self.first_day, self.period_length,
                                         self.custom_days)

        if self.now != None:
            period_len_total = ntmtools.timedelta2sec(
                ntmtools.date_to_datetime_end(last_day) -
                ntmtools.date_to_datetime_start(self.first_day))
            period_len_used = ntmtools.timedelta2sec(
                self.now - ntmtools.date_to_datetime_start(self.first_day))
            if period_len_used != 0:
                estimate = total_used_sec * period_len_total / period_len_used
                (h, m, s) = ntmtools.sec_to_hms(estimate)
                estimate_str = '''{0}h{1}'{2}"'''.format(h, m, s)
            else:
                estimate_str = "--"
        else:
            estimate_str = "--"

        text = "<b>" + _("Time") + "</b>"
        text += """ <small>({0:.1f}%) [{1}]</small>""".format(
            per, estimate_str)
        self.gui_time_topLabel.set_markup(text)
        #self.gui_time_topLabel.set_markup("""<small>({0:.1f}%) [{1}]</small>""".format(per, estimate_str))

        self.gui_main_period.set_markup(
            "<small><small>" + _("Period") +
            ": {0} - {1}</small></small>".format(self.first_day, last_day))
예제 #2
0
    def update_period(self, timestamp):
        last_day = ntmtools.get_last_day(self.first_day, self.period_length,
                                         self.custom_days)
        date_timestamp = timestamp.date()
        if (date_timestamp < self.first_day):
            return False

        if self.period_autoupdate:
            ch = False
            while date_timestamp > last_day:
                self.first_day = last_day + datetime.timedelta(1)
                last_day = ntmtools.get_last_day(self.first_day,
                                                 self.period_length,
                                                 self.custom_days)
                ch = True

            if ch:
                ntmtools.set_db_var(self.db_conn, "time_slot.first_day",
                                    self.first_day.isoformat())
                ret = MTimeSlot.load_sessions(
                    self.db_conn,
                    ntmtools.date_to_datetime_start(self.first_day),
                    ntmtools.date_to_datetime_end(last_day), self.slotLength)
                self.slotsUsed = ret[0]
                self.tsTime = ret[1]

            return True
        else:
            return (date_timestamp <= last_day)
예제 #3
0
    def update_main_gui(self):
        if self.gtkb == None:
            print("MTimeSlot.update_main_gui() - Gui not builded.\n")
            return

        self.gui_main_slots_used.set_text(str(self.slotsUsed))
        self.gui_main_slots_left.set_text(str(self.totalSlots - self.slotsUsed))
        self.gui_main_slots_total.set_text(str(self.totalSlots))

        self.gui_main_thisSlot_timeUsed.set_text(ntmtools.format_time(self.tsTime))
        secLeft = self.slotLength - self.tsTime
        self.gui_main_thisSlot_timeLeft.set_text(ntmtools.format_time(secLeft))
        self.gui_main_thisSlot_timeTotal.set_text(ntmtools.format_time(self.slotLength))

        totalSec = self.totalSlots * self.slotLength
        per = 100.0 * (self.slotsUsed * self.slotLength - secLeft) / totalSec

        last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)

        if self.now != None:
            period_len_total = ntmtools.timedelta2sec(ntmtools.date_to_datetime_end(last_day) - ntmtools.date_to_datetime_start(self.first_day))
            period_len_used = ntmtools.timedelta2sec(self.now - ntmtools.date_to_datetime_start(self.first_day))
            if period_len_used != 0:
                estimate = self.slotsUsed * period_len_total / period_len_used
                estimate_str = '{0}sl.'.format(int(round(estimate)))
            else: estimate_str = "--"
        else: estimate_str = "--"

        text = "<b>" + _("Time Slot") + "</b>"
        text += " <small>({0:.1f}%) [{1}]</small>".format(per, estimate_str)
        self.gui_timeslot_topLabel.set_markup(text)

        self.gui_main_period.set_markup(
            "<small><small>" + _("Period") + ": {0} - {1}</small></small>".format(self.first_day, last_day)
        )
예제 #4
0
    def update_period(self, timestamp):
        last_day = ntmtools.get_last_day(self.first_day, self.period_length,
                                         self.custom_days)
        date_timestamp = timestamp.date()
        if (date_timestamp < self.first_day):
            return False

        if self.period_autoupdate:
            ch = False
            while date_timestamp > last_day:
                self.first_day = last_day + datetime.timedelta(1)
                last_day = ntmtools.get_last_day(self.first_day,
                                                 self.period_length,
                                                 self.custom_days)
                ch = True

            if ch:
                ntmtools.set_db_var(self.db_conn, "time.first_day",
                                    self.first_day.isoformat())
                last_day = ntmtools.get_last_day(self.first_day,
                                                 self.period_length,
                                                 self.custom_days)
                self.used_sec = MTime.load_time_used(
                    self.ntm.db_conn,
                    ntmtools.date_to_datetime_start(self.first_day),
                    ntmtools.date_to_datetime_end(last_day))
                self.connStartTime = timestamp
                self.this_slot_sec = 0

            return True
        else:
            return (date_timestamp <= last_day)
예제 #5
0
    def update_h(self, timestamp, session_start, update_interval,
                 last_rec_traffic, last_tra_traffic, conn_state):
        ntmtools.dbg_msg("MTime.update_h - conn_state:{0}".format(conn_state))

        if (not self.active): return

        self.now = timestamp
        if not self.update_period(session_start): return

        if (self.last_state == 0):
            if (conn_state == 1):  # offline -> online
                self.dialog_showed = False
                last_day = ntmtools.get_last_day(self.first_day,
                                                 self.period_length,
                                                 self.custom_days)
                self.used_sec = MTime.load_time_used(
                    self.ntm.db_conn,
                    ntmtools.date_to_datetime_start(self.first_day),
                    ntmtools.date_to_datetime_end(last_day))
                self.connStartTime = timestamp
                self.this_slot_sec = 0
        else:  # last_state is online
            self.this_slot_sec = ntmtools.timedelta2sec(self.now -
                                                        self.connStartTime)
            if (conn_state == 0):  # online -> offline
                pass

        self.last_state = conn_state
        self.update_main_gui()

        if self.logUpdate:
            print('Time: {0} of {1}\n'.format(
                self.used_sec + self.this_slot_sec, self.total_sec))

        self.check_limit()
예제 #6
0
파일: mtime.py 프로젝트: lgtl/ntm
    def update_h(self, timestamp, session_start, update_interval, last_rec_traffic, last_tra_traffic, conn_state):
        if (not self.active): return

        self.now = timestamp
        if not self.update_period(session_start): return

        if (self.last_state == 0):
            if (conn_state == 1): # offline -> online
                last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
                self.used_sec = MTime.loadTimeUsed(self.ntm.db_conn, ntmtools.date_to_datetime_start(self.first_day), ntmtools.date_to_datetime_end(last_day))
                self.connStartTime = timestamp
                self.this_slot_sec = 0
        else: # last_state is online
            self.this_slot_sec = ntmtools.timedelta2sec(self.now - self.connStartTime)
            if (conn_state == 0): # online -> offline
                pass

        self.last_state = conn_state
        self.update_main_gui()

        if self.logUpdate:
            print('Time: {0} of {1}\n'.
                format( self.used_sec + self.this_slot_sec, self.total_sec)
            )

        self.check_limit()
예제 #7
0
 def reload_time_used(self):
     last_day = ntmtools.get_last_day(self.first_day, self.period_length,
                                      self.custom_days)
     used_sec = MTime.load_time_used(
         self.db_conn, ntmtools.date_to_datetime_start(self.first_day),
         ntmtools.date_to_datetime_end(last_day))
     self.used_sec = used_sec
     self.update_main_gui()
예제 #8
0
 def reload_sessions(self):
     last_day = ntmtools.get_last_day(self.first_day, self.period_length,
                                      self.custom_days)
     ret = MTimeSlot.load_sessions(
         self.db_conn, ntmtools.date_to_datetime_start(self.first_day),
         ntmtools.date_to_datetime_end(last_day), self.slotLength)
     self.slotsUsed = ret[0]
     self.tsTime = ret[1]
     self.update_main_gui()
예제 #9
0
    def update_main_gui(self):
        if self.gtkb == None:
            print("MTimeSlot.update_main_gui() - Gui not builded.\n")
            return

        self.gui_main_slots_used.set_text(str(self.slotsUsed))
        self.gui_main_slots_left.set_text(str(self.totalSlots -
                                              self.slotsUsed))
        self.gui_main_slots_total.set_text(str(self.totalSlots))

        self.gui_main_thisSlot_timeUsed.set_text(
            ntmtools.format_time(self.tsTime))
        secLeft = self.slotLength - self.tsTime
        self.gui_main_thisSlot_timeLeft.set_text(ntmtools.format_time(secLeft))
        self.gui_main_thisSlot_timeTotal.set_text(
            ntmtools.format_time(self.slotLength))

        totalSec = self.totalSlots * self.slotLength
        per = 100.0 * (self.slotsUsed * self.slotLength - secLeft) / totalSec

        last_day = ntmtools.get_last_day(self.first_day, self.period_length,
                                         self.custom_days)

        if self.now != None:
            period_len_total = ntmtools.timedelta2sec(
                ntmtools.date_to_datetime_end(last_day) -
                ntmtools.date_to_datetime_start(self.first_day))
            period_len_used = ntmtools.timedelta2sec(
                self.now - ntmtools.date_to_datetime_start(self.first_day))
            if period_len_used != 0:
                estimate = self.slotsUsed * period_len_total / period_len_used
                estimate_str = '{0}sl.'.format(int(round(estimate)))
            else:
                estimate_str = "--"
        else:
            estimate_str = "--"

        text = "<b>" + _("Time Slot") + "</b>"
        text += " <small>({0:.1f}%) [{1}]</small>".format(per, estimate_str)
        self.gui_timeslot_topLabel.set_markup(text)

        self.gui_main_period.set_markup(
            "<small><small>" + _("Period") +
            ": {0} - {1}</small></small>".format(self.first_day, last_day))
예제 #10
0
파일: mtimeslot.py 프로젝트: lgtl/ntm
    def setPreferences(self, active, totalSlots, slotLength, auto_disconnect, period_length, custom_days, first_day, period_autoupdate):
        update_timeslot = False
        if (self.active != active):
            self.active = active
            ntmtools.setDBVar(self.db_conn, "time_slot.active", ntmtools.boolToStrInt(active))
            update_timeslot = True

        if (self.totalSlots != totalSlots):
            self.totalSlots = totalSlots
            ntmtools.setDBVar(self.db_conn, "time_slot.total_slots", str(int(totalSlots)))

        if (self.slotLength != slotLength):
            self.slotLength = slotLength
            ntmtools.setDBVar(self.db_conn, "time_slot.slot_length", str(int(slotLength)))
            update_timeslot = True

        if (self.auto_disconnect != auto_disconnect):
            self.auto_disconnect = auto_disconnect
            ntmtools.setDBVar(self.db_conn, "time_slot.auto_disconnect", ntmtools.boolToStrInt(auto_disconnect))
            update_timeslot = True

        if (self.period_length != period_length):
            self.period_length = period_length
            ntmtools.setDBVar(self.db_conn, "time_slot.period_length", str(int(period_length)))
            update_timeslot = True

        if (self.custom_days != custom_days):
            self.custom_days = custom_days
            ntmtools.setDBVar(self.db_conn, "time_slot.custom_days", str(int(custom_days)))
            if (period_length == 0): update_timeslot = True

        if (self.first_day != first_day):
            self.first_day = first_day
            ntmtools.setDBVar(self.db_conn, "time_slot.first_day", first_day.isoformat())
            update_timeslot = True

        if (self.period_autoupdate != period_autoupdate):
            self.period_autoupdate = period_autoupdate
            ntmtools.setDBVar(self.db_conn, "time_slot.period_autoupdate", ntmtools.boolToStrInt(period_autoupdate))
            if self.period_autoupdate:
                self.update_period(self.now)
                update_timeslot = True

        if (update_timeslot):
            last_day = ntmtools.get_last_day(first_day, period_length, custom_days)
            ret = MTimeSlot.loadSessions(self.db_conn, ntmtools.date_to_datetime_start(first_day), ntmtools.date_to_datetime_end(last_day), slotLength)
            self.slotsUsed = ret[0]
            self.tsTime = ret[1]

        if self.active:
            self.gui_main.show()
            self.update_main_gui()
            self.check_limit()
        else:
            self.gui_main.hide()
예제 #11
0
    def set_preferences(self, active, total_sec, auto_disconnect, period_length, custom_days, first_day, period_autoupdate):

        self.dialog_showed = False

        update_time = False
        if (self.active != active):
            self.active = active
            ntmtools.set_db_var(self.db_conn, "time.active", ntmtools.bool_to_str_int(active))
            update_time = True

        if (self.total_sec != total_sec):
            self.total_sec = total_sec
            ntmtools.set_db_var(self.db_conn, "time.total_sec", str(total_sec))

        if (self.auto_disconnect != auto_disconnect):
            self.auto_disconnect = auto_disconnect
            ntmtools.set_db_var(self.db_conn, "time.auto_disconnect", ntmtools.bool_to_str_int(auto_disconnect))

        if (self.period_length != period_length):
            self.period_length = period_length
            ntmtools.set_db_var(self.db_conn, "time.period_length", str(int(period_length)))
            update_time = True

        if (self.custom_days != custom_days):
            self.custom_days = custom_days
            ntmtools.set_db_var(self.db_conn, "time.custom_days", str(int(custom_days)))
            #if (period_length == 0): update_timeslot = True
            update_time = True

        if (self.first_day != first_day):
            self.first_day = first_day
            ntmtools.set_db_var(self.db_conn, "time.first_day", first_day.isoformat())
            update_time = True

        if (self.period_autoupdate != period_autoupdate):
            self.period_autoupdate = period_autoupdate
            ntmtools.set_db_var(self.db_conn, "time.period_autoupdate", ntmtools.bool_to_str_int(period_autoupdate))
            update_time = True

        if (update_time):
            if self.period_autoupdate:
                self.update_period(self.now)
            else:
                last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
                self.used_sec = MTime.load_time_used(self.db_conn, ntmtools.date_to_datetime_start(self.first_day), ntmtools.date_to_datetime_end(last_day))

        if self.active:
            self.gui_main.show()
            self.update_main_gui()
            self.check_limit()
        else:
            self.gui_main.hide()
예제 #12
0
    def update_main_gui(self):
        if self.gtkb == None:
            print("MMTime.update_main_gui(): Gui not builded.\n")
            return

        total_used_sec = self.used_sec + self.this_slot_sec
        (h, m, s) = ntmtools.sec_to_hms(total_used_sec)
        out_str = """<span color='#900000'>{0}h{1}'<small>{2}"</small></span>""".format(h, m, s)
        self.gui_main_used_sec.set_markup(out_str)

        time_diff = self.total_sec - total_used_sec
        if (time_diff < 0):
            time_diff = -time_diff            
            sign = "-"
        else:
            sign = ""
        (h, m, s) = ntmtools.sec_to_hms(time_diff)
        out_str = """<span color='#009000'>{0}{1}h{2}'<small>{3}"</small></span>""".format(sign, h, m, s)
        self.gui_main_left_sec.set_markup(out_str)

        (h, m, s) = ntmtools.sec_to_hms(self.total_sec)
        out_str = """{0}h{1}'<small>{2}"</small>""".format(h, m, s)
        self.gui_main_total_sec.set_markup(out_str)

        total_used_sec = self.used_sec + self.this_slot_sec
        if self.total_sec == 0:
            print _("Warning! mtime.py: total sec is 0.")
            per = 100.0
        else: per = 100.0 * total_used_sec / self.total_sec

        last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)

        if self.now != None:
            period_len_total = ntmtools.timedelta2sec(ntmtools.date_to_datetime_end(last_day) - ntmtools.date_to_datetime_start(self.first_day))
            period_len_used = ntmtools.timedelta2sec(self.now - ntmtools.date_to_datetime_start(self.first_day))
            if period_len_used != 0:
                estimate = total_used_sec * period_len_total / period_len_used
                (h, m, s) = ntmtools.sec_to_hms(estimate)
                estimate_str = '''{0}h{1}'{2}"'''.format(h, m, s)
            else: estimate_str = "--"
        else: estimate_str = "--"

        text = "<b>" + _("Time") + "</b>"
        text += """ <small>({0:.1f}%) [{1}]</small>""".format(per, estimate_str)
        self.gui_time_topLabel.set_markup(text)
        #self.gui_time_topLabel.set_markup("""<small>({0:.1f}%) [{1}]</small>""".format(per, estimate_str))
        
        self.gui_main_period.set_markup("<small><small>" + _("Period") + ": {0} - {1}</small></small>".format(self.first_day, last_day))
예제 #13
0
    def update_period(self, timestamp):
        last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
        date_timestamp = timestamp.date()
        if (date_timestamp < self.first_day):
            return False

        if self.period_autoupdate:
            ch = False
            while date_timestamp > last_day:
                self.first_day = last_day + datetime.timedelta(1)
                last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
                ch = True

            if ch:
                ntmtools.set_db_var(self.db_conn, "time_slot.first_day", self.first_day.isoformat())
                ret = MTimeSlot.load_sessions(self.db_conn, ntmtools.date_to_datetime_start(self.first_day), ntmtools.date_to_datetime_end(last_day), self.slotLength)
                self.slotsUsed = ret[0]
                self.tsTime = ret[1]

            return True
        else:
            return (date_timestamp <= last_day)
예제 #14
0
파일: mtime.py 프로젝트: lgtl/ntm
    def update_period(self, timestamp):
        last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
        date_timestamp = timestamp.date()
        if (date_timestamp < self.first_day):
            return False

        if self.period_autoupdate:
            ch = False
            while date_timestamp > last_day:
                self.first_day = last_day + datetime.timedelta(1)
                last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
                ch = True

            if ch:
                ntmtools.setDBVar(self.db_conn, "time.first_day", self.first_day.isoformat())
                last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
                self.used_sec = MTime.loadTimeUsed(self.ntm.db_conn, ntmtools.date_to_datetime_start(self.first_day), ntmtools.date_to_datetime_end(last_day))
                self.connStartTime = timestamp
                self.this_slot_sec = 0

            return True
        else:
            return (date_timestamp <= last_day)
예제 #15
0
파일: mtraffic.py 프로젝트: lgtl/ntm
    def update_main_gui(self):
        # print("mtraffic.update_main_gui(self)")
        if self.gtkb == None:
            print("MTraffic.update_main_gui(*): Gui not builded.\n")
            return

        mbyte = (1024.0*1024.0)
        traf_tot = (self.rec_traffic + self.tra_traffic)

        per = 100.0 * traf_tot / self.traffic_limit

        self.gui_main_left.set_text("{0:.3f}".format((self.traffic_limit - traf_tot)/mbyte))
        self.gui_main_used.set_text("{0:.3f}".format(traf_tot/mbyte))
        self.gui_main_in.set_text("{0:.3f}".format(self.rec_traffic / mbyte))
        self.gui_main_out.set_text("{0:.3f}".format(self.tra_traffic / mbyte))

        self.gui_main_total.set_text("{0:.0f}".format(self.traffic_limit/mbyte))

        if self.last_speed != None:
            while self.last_speed > self.bwu_max_speed:
                self.bwu_max_speed = self.bwu_max_speed + 10.0
            self.gui_main_bwu.speed = self.last_speed
            self.gui_main_bwu.max_speed = self.bwu_max_speed
            self.gui_main_bwu.queue_draw()

        last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)

        if self.now != None:
            period_len_total = ntmtools.timedelta2sec(ntmtools.date_to_datetime_end(last_day) - ntmtools.date_to_datetime_start(self.first_day))
            period_len_used = ntmtools.timedelta2sec(self.now - ntmtools.date_to_datetime_start(self.first_day))
            if period_len_used != 0: estimate_str = ntmtools.formatBytes(traf_tot * period_len_total / period_len_used)
            else: estimate_str = "--"
        else: estimate_str = "--"

        self.gui_main_per.set_markup("<small>({0:.1f}%) [{1}]</small>".format(per, estimate_str))

        self.gui_main_period.set_markup("<small><small>" + _("Period") + ": {0} - {1}</small></small>".format(self.first_day, last_day))
예제 #16
0
 def reload_sessions(self):
     last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
     ret = MTimeSlot.load_sessions(self.db_conn, ntmtools.date_to_datetime_start(self.first_day), ntmtools.date_to_datetime_end(last_day), self.slotLength)
     self.slotsUsed = ret[0]
     self.tsTime = ret[1]
     self.update_main_gui()
예제 #17
0
파일: mtime.py 프로젝트: lgtl/ntm
    def makeFromDb(ntm):
        conn = ntm.db_conn

        val_str = ntmtools.readDBVar(conn, "time.active")
        try:
            active = (ntmtools.strToInt(val_str, 1) != 0)
        except:
            ntmtools.dbgMsg(_("Wrong value for the param") + " 'time.active' " + _("or is not stored. Default value") + " 'True'")
            active = True
            ntmtools.setDBVar(conn, "time.active", "1")

        val_str = ntmtools.readDBVar(conn, "time.total_sec")
        try:
            total_sec = ntmtools.strToInt(val_str, 30*60*60) # 30h
        except:
            ntmtools.dbgMsg(_("Wrong value for the param") + " 'time.total_sec' " + _("or is not stored. Default value") + " '30h'")
            total_sec = 30*60*60
            ntmtools.setDBVar(conn, "time.total_sec", total_sec)

        val_str = ntmtools.readDBVar(conn, "time.auto_disconnect")
        try:
            auto_disconnect = (ntmtools.strToInt(val_str, 1) != 0)
        except:
            ntmtools.dbgMsg(_("Wrong value for the param") + " 'time.auto_disconnect' " + _("or is not stored. Default value") + " '" +_("True") + "'")
            auto_disconnect = True
            ntmtools.setDBVar(conn, "time.auto_disconnect", "1")


        val_str = ntmtools.readDBVar(conn, "time.period_length")
        try:
            period_length = int(val_str)
        except:
            ntmtools.dbgMsg(_("Wrong value for the param") + " 'time.period_length' " + _("or is not stored. Default value") + " '" + _("Month") + "'")
            period_length = 3  # 3 -> Month
            ntmtools.setDBVar(conn, "time.period_length", str(int(period_length)))

        val_str = ntmtools.readDBVar(conn, "time.custom_days")
        try:
            custom_days = int(val_str)
        except:
            ntmtools.dbgMsg(_("Wrong value for the param") + " 'time.custom_days' " + _("or is not stored. Default value") + " '30'")
            custom_days = 30
            ntmtools.setDBVar(conn, "time.custom_days", str(int(custom_days)))

        val_str = ntmtools.readDBVar(conn, "time.first_day")
        try:
            first_day = ntmtools.strToDate(val_str)
        except:
            ntmtools.dbgMsg(_("Wrong value for the param") + " 'time.first_day' " + _("or is not stored. Default value") + " '2009-10-01'")
            first_day = datetime.date(2009, 10, 01)
            ntmtools.setDBVar(conn, "time.first_day", first_day)

        val_str = ntmtools.readDBVar(conn, "time.period_autoupdate")
        try:
            period_autoupdate = (ntmtools.strToInt(val_str, 1) != 0)
        except:
            ntmtools.dbgMsg(_("Wrong value for the param") + " 'time.period_autoupdate' " + _("or is not stored. Default value") + " '" + _("True") + "'")
            period_autoupdate = True
            ntmtools.setDBVar(conn, "time.period_autoupdate", "1")


        last_day = ntmtools.get_last_day(first_day, period_length, custom_days)
        used_sec = MTime.loadTimeUsed(conn, ntmtools.date_to_datetime_start(first_day), ntmtools.date_to_datetime_end(last_day))

        return MTime(ntm, active, used_sec, total_sec, auto_disconnect, period_length, custom_days, first_day, period_autoupdate)
예제 #18
0
    def make_from_db(ntm):
        conn = ntm.db_conn

        val_str = ntmtools.read_db_var(conn, "time_slot.active")
        try:
            active = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time_slot.active' " +
                _("or is not stored. Default value") + " '" + _("True") + "'")
            active = True
            ntmtools.set_db_var(conn, "time_slot.active", "1")

        val_str = ntmtools.read_db_var(conn, "time_slot.total_slots")
        try:
            total_slots = ntmtools.str_to_int(val_str, 200)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time_slot.total_slots' " +
                _("or is not stored. Default value") + " '200'")
            total_slots = 200
            ntmtools.set_db_var(conn, "time_slot.total_slots", total_slots)

        val_str = ntmtools.read_db_var(conn, "time_slot.slot_length")
        try:
            slot_length = ntmtools.str_to_int(val_str, 15 * 60)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time_slot.slot_length' " +
                _("or is not stored. Default value") + " 15'")
            slot_length = 15 * 60
            ntmtools.set_db_var(conn, "time_slot.slot_length", slot_length)

        val_str = ntmtools.read_db_var(conn, "time_slot.auto_disconnect")
        try:
            auto_disconnect = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'time_slot.auto_disconnect' " +
                _("or is not stored. Default value") + " '" + _("True") + "'")
            auto_disconnect = True
            ntmtools.set_db_var(conn, "time_slot.auto_disconnect", "1")

        val_str = ntmtools.read_db_var(conn, "time_slot.period_length")
        try:
            period_length = int(val_str)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'time_slot.period_length' " +
                _("or is not stored. Default value") + " '" + _("Month") + "'")
            period_length = 3  # 3 -> Month
            ntmtools.set_db_var(conn, "time_slot.period_length",
                                str(int(period_length)))

        val_str = ntmtools.read_db_var(conn, "time_slot.custom_days")
        try:
            custom_days = int(val_str)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time_slot.custom_days' " +
                _("or is not stored. Default value") + " 30")
            custom_days = 30
            ntmtools.set_db_var(conn, "time_slot.custom_days",
                                str(int(custom_days)))

        val_str = ntmtools.read_db_var(conn, "time_slot.first_day")
        try:
            first_day = ntmtools.str_to_date(val_str)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time_slot.first_day' " +
                _("or is not stored. Default value") + " '2009-10-01'")
            first_day = datetime.date(2009, 10, 01)
            ntmtools.set_db_var(conn, "time_slot.first_day", first_day)

        val_str = ntmtools.read_db_var(conn, "time_slot.period_autoupdate")
        try:
            period_autoupdate = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'time_slot.period_autoupdate' " +
                _("or is not stored. Default value") + " '" + _("True") + "'")
            period_autoupdate = True
            ntmtools.set_db_var(conn, "time_slot.period_autoupdate", "1")

        val_str = ntmtools.read_db_var(conn, "time_slot.alert.active")
        try:
            alert_active = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time_slot.alert.active' " +
                _("or is not stored. Default value") + " '" + _("True") + "'")
            alert_active = True
            ntmtools.set_db_var(conn, "time_slot.alert.active", "1")

        val_str = ntmtools.read_db_var(conn, "time_slot.alert.predate")
        try:
            alert_predate = int(val_str)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") +
                " 'time_slot.alert.predate' " +
                _("or is not stored. Default value") + ' 30"')
            alert_predate = 30
            ntmtools.set_db_var(conn, "time_slot.alert.predate",
                                str(int(alert_predate)))

        last_day = ntmtools.get_last_day(first_day, period_length, custom_days)
        ret = MTimeSlot.load_sessions(
            conn, ntmtools.date_to_datetime_start(first_day),
            ntmtools.date_to_datetime_end(last_day), slot_length)
        slots_used = ret[0]
        ts_time = ret[1]

        return MTimeSlot(ntm, active, slots_used, total_slots, ts_time,
                         slot_length, auto_disconnect, period_length,
                         custom_days, first_day, period_autoupdate,
                         alert_active, alert_predate)
예제 #19
0
파일: mtime.py 프로젝트: lgtl/ntm
 def reloadTimeUsed(self):
     last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
     used_sec = MTime.loadTimeUsed(self.db_conn, ntmtools.date_to_datetime_start(self.first_day), ntmtools.date_to_datetime_end(last_day))
     self.used_sec = used_sec
     self.update_main_gui()
예제 #20
0
    def set_preferences(self, active, totalSlots, slotLength, auto_disconnect,
                        period_length, custom_days, first_day,
                        period_autoupdate, alert_active, alert_predate):
        self.dialog_showed = False

        update_timeslot = False
        if (self.active != active):
            self.active = active
            ntmtools.set_db_var(self.db_conn, "time_slot.active",
                                ntmtools.bool_to_str_int(active))
            update_timeslot = True

        if (self.totalSlots != totalSlots):
            self.totalSlots = totalSlots
            ntmtools.set_db_var(self.db_conn, "time_slot.total_slots",
                                str(int(totalSlots)))

        if (self.slotLength != slotLength):
            self.slotLength = slotLength
            ntmtools.set_db_var(self.db_conn, "time_slot.slot_length",
                                str(int(slotLength)))
            update_timeslot = True

        if (self.auto_disconnect != auto_disconnect):
            self.auto_disconnect = auto_disconnect
            ntmtools.set_db_var(self.db_conn, "time_slot.auto_disconnect",
                                ntmtools.bool_to_str_int(auto_disconnect))
            update_timeslot = True

        if (self.period_length != period_length):
            self.period_length = period_length
            ntmtools.set_db_var(self.db_conn, "time_slot.period_length",
                                str(int(period_length)))
            update_timeslot = True

        if (self.custom_days != custom_days):
            self.custom_days = custom_days
            ntmtools.set_db_var(self.db_conn, "time_slot.custom_days",
                                str(int(custom_days)))
            if (period_length == 0): update_timeslot = True

        if (self.first_day != first_day):
            self.first_day = first_day
            ntmtools.set_db_var(self.db_conn, "time_slot.first_day",
                                first_day.isoformat())
            update_timeslot = True

        if (self.period_autoupdate != period_autoupdate):
            self.period_autoupdate = period_autoupdate
            ntmtools.set_db_var(self.db_conn, "time_slot.period_autoupdate",
                                ntmtools.bool_to_str_int(period_autoupdate))
            if self.period_autoupdate:
                self.update_period(self.now)
                update_timeslot = True

        if (update_timeslot):
            last_day = ntmtools.get_last_day(first_day, period_length,
                                             custom_days)
            ret = MTimeSlot.load_sessions(
                self.db_conn, ntmtools.date_to_datetime_start(first_day),
                ntmtools.date_to_datetime_end(last_day), slotLength)
            self.slotsUsed = ret[0]
            self.tsTime = ret[1]

        if (self.alert_active != alert_active):
            self.alert_active = alert_active
            ntmtools.set_db_var(self.db_conn, "time_slot.alert.active",
                                ntmtools.bool_to_str_int(alert_active))

        if (self.alert_predate != alert_predate):
            self.alert_predate = alert_predate
            ntmtools.set_db_var(self.db_conn, "time_slot.alert.predate",
                                str(int(alert_predate)))
            if self.notify_ok:
                self.notifyalert_predate = pynotify.Notification(
                    _("NTM - Time Slot"), "{0} ".format(self.alert_predate) +
                    _("seconds before timeslot end!"))

        if self.active:
            self.gui_main.show()
            self.update_main_gui()
            self.check_limit()
        else:
            self.gui_main.hide()
예제 #21
0
    def set_preferences(self, active, totalSlots, slotLength, auto_disconnect, period_length, 
                        custom_days, first_day, period_autoupdate,
                        alert_active, alert_predate
                       ):
        self.dialog_showed = False

        update_timeslot = False
        if (self.active != active):
            self.active = active
            ntmtools.set_db_var(self.db_conn, "time_slot.active", ntmtools.bool_to_str_int(active))
            update_timeslot = True

        if (self.totalSlots != totalSlots):
            self.totalSlots = totalSlots
            ntmtools.set_db_var(self.db_conn, "time_slot.total_slots", str(int(totalSlots)))

        if (self.slotLength != slotLength):
            self.slotLength = slotLength
            ntmtools.set_db_var(self.db_conn, "time_slot.slot_length", str(int(slotLength)))
            update_timeslot = True

        if (self.auto_disconnect != auto_disconnect):
            self.auto_disconnect = auto_disconnect
            ntmtools.set_db_var(self.db_conn, "time_slot.auto_disconnect", ntmtools.bool_to_str_int(auto_disconnect))
            update_timeslot = True

        if (self.period_length != period_length):
            self.period_length = period_length
            ntmtools.set_db_var(self.db_conn, "time_slot.period_length", str(int(period_length)))
            update_timeslot = True

        if (self.custom_days != custom_days):
            self.custom_days = custom_days
            ntmtools.set_db_var(self.db_conn, "time_slot.custom_days", str(int(custom_days)))
            if (period_length == 0): update_timeslot = True

        if (self.first_day != first_day):
            self.first_day = first_day
            ntmtools.set_db_var(self.db_conn, "time_slot.first_day", first_day.isoformat())
            update_timeslot = True

        if (self.period_autoupdate != period_autoupdate):
            self.period_autoupdate = period_autoupdate
            ntmtools.set_db_var(self.db_conn, "time_slot.period_autoupdate", ntmtools.bool_to_str_int(period_autoupdate))
            if self.period_autoupdate:
                self.update_period(self.now)
                update_timeslot = True

        if (update_timeslot):
            last_day = ntmtools.get_last_day(first_day, period_length, custom_days)
            ret = MTimeSlot.load_sessions(self.db_conn, ntmtools.date_to_datetime_start(first_day), ntmtools.date_to_datetime_end(last_day), slotLength)
            self.slotsUsed = ret[0]
            self.tsTime = ret[1]



        if (self.alert_active != alert_active):
            self.alert_active = alert_active
            ntmtools.set_db_var(self.db_conn, "time_slot.alert.active", ntmtools.bool_to_str_int(alert_active))

        if (self.alert_predate != alert_predate):
            self.alert_predate = alert_predate
            ntmtools.set_db_var(self.db_conn, "time_slot.alert.predate", str(int(alert_predate)))
            if self.notify_ok:
                self.notifyalert_predate = pynotify.Notification (_("NTM - Time Slot"), "{0} ".format(self.alert_predate) + _("seconds before timeslot end!"))



        if self.active:
            self.gui_main.show()
            self.update_main_gui()
            self.check_limit()
        else:
            self.gui_main.hide()
예제 #22
0
    def set_preferences(self, active, total_sec, auto_disconnect,
                        period_length, custom_days, first_day,
                        period_autoupdate):

        self.dialog_showed = False

        update_time = False
        if (self.active != active):
            self.active = active
            ntmtools.set_db_var(self.db_conn, "time.active",
                                ntmtools.bool_to_str_int(active))
            update_time = True

        if (self.total_sec != total_sec):
            self.total_sec = total_sec
            ntmtools.set_db_var(self.db_conn, "time.total_sec", str(total_sec))

        if (self.auto_disconnect != auto_disconnect):
            self.auto_disconnect = auto_disconnect
            ntmtools.set_db_var(self.db_conn, "time.auto_disconnect",
                                ntmtools.bool_to_str_int(auto_disconnect))

        if (self.period_length != period_length):
            self.period_length = period_length
            ntmtools.set_db_var(self.db_conn, "time.period_length",
                                str(int(period_length)))
            update_time = True

        if (self.custom_days != custom_days):
            self.custom_days = custom_days
            ntmtools.set_db_var(self.db_conn, "time.custom_days",
                                str(int(custom_days)))
            #if (period_length == 0): update_timeslot = True
            update_time = True

        if (self.first_day != first_day):
            self.first_day = first_day
            ntmtools.set_db_var(self.db_conn, "time.first_day",
                                first_day.isoformat())
            update_time = True

        if (self.period_autoupdate != period_autoupdate):
            self.period_autoupdate = period_autoupdate
            ntmtools.set_db_var(self.db_conn, "time.period_autoupdate",
                                ntmtools.bool_to_str_int(period_autoupdate))
            update_time = True

        if (update_time):
            if self.period_autoupdate:
                self.update_period(self.now)
            else:
                last_day = ntmtools.get_last_day(self.first_day,
                                                 self.period_length,
                                                 self.custom_days)
                self.used_sec = MTime.load_time_used(
                    self.db_conn,
                    ntmtools.date_to_datetime_start(self.first_day),
                    ntmtools.date_to_datetime_end(last_day))

        if self.active:
            self.gui_main.show()
            self.update_main_gui()
            self.check_limit()
        else:
            self.gui_main.hide()
예제 #23
0
    def make_from_db(ntm):
        conn = ntm.db_conn

        val_str = ntmtools.read_db_var(conn, "time.active")
        try:
            active = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time.active' " +
                _("or is not stored. Default value") + " 'True'")
            active = True
            ntmtools.set_db_var(conn, "time.active", "1")

        val_str = ntmtools.read_db_var(conn, "time.total_sec")
        try:
            total_sec = ntmtools.str_to_int(val_str, 30 * 60 * 60)  # 30h
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time.total_sec' " +
                _("or is not stored. Default value") + " '30h'")
            total_sec = 30 * 60 * 60
            ntmtools.set_db_var(conn, "time.total_sec", total_sec)

        val_str = ntmtools.read_db_var(conn, "time.auto_disconnect")
        try:
            auto_disconnect = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time.auto_disconnect' " +
                _("or is not stored. Default value") + " '" + _("True") + "'")
            auto_disconnect = True
            ntmtools.set_db_var(conn, "time.auto_disconnect", "1")

        val_str = ntmtools.read_db_var(conn, "time.period_length")
        try:
            period_length = int(val_str)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time.period_length' " +
                _("or is not stored. Default value") + " '" + _("Month") + "'")
            period_length = 3  # 3 -> Month
            ntmtools.set_db_var(conn, "time.period_length",
                                str(int(period_length)))

        val_str = ntmtools.read_db_var(conn, "time.custom_days")
        try:
            custom_days = int(val_str)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time.custom_days' " +
                _("or is not stored. Default value") + " '30'")
            custom_days = 30
            ntmtools.set_db_var(conn, "time.custom_days",
                                str(int(custom_days)))

        val_str = ntmtools.read_db_var(conn, "time.first_day")
        try:
            first_day = ntmtools.str_to_date(val_str)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time.first_day' " +
                _("or is not stored. Default value") + " '2009-10-01'")
            first_day = datetime.date(2009, 10, 01)
            ntmtools.set_db_var(conn, "time.first_day", first_day)

        val_str = ntmtools.read_db_var(conn, "time.period_autoupdate")
        try:
            period_autoupdate = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(
                _("Wrong value for the param") + " 'time.period_autoupdate' " +
                _("or is not stored. Default value") + " '" + _("True") + "'")
            period_autoupdate = True
            ntmtools.set_db_var(conn, "time.period_autoupdate", "1")

        last_day = ntmtools.get_last_day(first_day, period_length, custom_days)
        used_sec = MTime.load_time_used(
            conn, ntmtools.date_to_datetime_start(first_day),
            ntmtools.date_to_datetime_end(last_day))

        return MTime(ntm, active, used_sec, total_sec, auto_disconnect,
                     period_length, custom_days, first_day, period_autoupdate)
예제 #24
0
    def make_from_db(ntm):
        conn = ntm.db_conn

        val_str = ntmtools.read_db_var(conn, "time_slot.active")
        try:
            active = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.active' " + _("or is not stored. Default value") + " '" + _("True") + "'")
            active = True
            ntmtools.set_db_var(conn, "time_slot.active", "1")

        val_str = ntmtools.read_db_var(conn, "time_slot.total_slots")
        try:
            total_slots = ntmtools.str_to_int(val_str, 200)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.total_slots' " + _("or is not stored. Default value") + " '200'")
            total_slots = 200
            ntmtools.set_db_var(conn, "time_slot.total_slots", total_slots)

        val_str = ntmtools.read_db_var(conn, "time_slot.slot_length")
        try:
            slot_length = ntmtools.str_to_int(val_str, 15*60)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.slot_length' " + _("or is not stored. Default value") + " 15'")
            slot_length = 15*60
            ntmtools.set_db_var(conn, "time_slot.slot_length", slot_length)

        val_str = ntmtools.read_db_var(conn, "time_slot.auto_disconnect")
        try:
            auto_disconnect = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.auto_disconnect' " + _("or is not stored. Default value") + " '" + _("True") + "'")
            auto_disconnect = True
            ntmtools.set_db_var(conn, "time_slot.auto_disconnect", "1")


        val_str = ntmtools.read_db_var(conn, "time_slot.period_length")
        try:
            period_length = int(val_str)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.period_length' " + _("or is not stored. Default value") + " '" + _("Month") + "'")
            period_length = 3  # 3 -> Month
            ntmtools.set_db_var(conn, "time_slot.period_length", str(int(period_length)))

        val_str = ntmtools.read_db_var(conn, "time_slot.custom_days")
        try:
            custom_days = int(val_str)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.custom_days' " + _("or is not stored. Default value") + " 30")
            custom_days = 30
            ntmtools.set_db_var(conn, "time_slot.custom_days", str(int(custom_days)))

        val_str = ntmtools.read_db_var(conn, "time_slot.first_day")
        try:
            first_day = ntmtools.str_to_date(val_str)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.first_day' " + _("or is not stored. Default value") + " '2009-10-01'")
            first_day = datetime.date(2009, 10, 01)
            ntmtools.set_db_var(conn, "time_slot.first_day", first_day)

        val_str = ntmtools.read_db_var(conn, "time_slot.period_autoupdate")
        try:
            period_autoupdate = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.period_autoupdate' " + _("or is not stored. Default value") + " '" + _("True") + "'")
            period_autoupdate = True
            ntmtools.set_db_var(conn, "time_slot.period_autoupdate", "1")

        val_str = ntmtools.read_db_var(conn, "time_slot.alert.active")
        try:
            alert_active = (ntmtools.str_to_int(val_str, 1) != 0)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.alert.active' " + _("or is not stored. Default value") + " '" + _("True") + "'")
            alert_active = True
            ntmtools.set_db_var(conn, "time_slot.alert.active", "1")

        val_str = ntmtools.read_db_var(conn, "time_slot.alert.predate")
        try:
            alert_predate = int(val_str)
        except:
            ntmtools.dbg_msg(_("Wrong value for the param") + " 'time_slot.alert.predate' " + _("or is not stored. Default value") + ' 30"')
            alert_predate = 30
            ntmtools.set_db_var(conn, "time_slot.alert.predate", str(int(alert_predate)))

        last_day = ntmtools.get_last_day(first_day, period_length, custom_days)
        ret = MTimeSlot.load_sessions(conn, ntmtools.date_to_datetime_start(first_day), ntmtools.date_to_datetime_end(last_day), slot_length)
        slots_used  = ret[0]
        ts_time = ret[1]

        return MTimeSlot(ntm, active, slots_used, total_slots, ts_time, slot_length, auto_disconnect, period_length, custom_days, first_day, period_autoupdate, alert_active, alert_predate)
예제 #25
0
    def update_main_gui(self):
        ntmtools.dbg_msg("MTraffic.update_main_gui")
        if self.gtkb == None:
            ntmtools.dbg_msg("MTraffic.update_main_gui : Gui not builded.\n",
                             100)
            return

        mbyte = (1024.0 * 1024.0)
        traf_tot = (self.rec_traffic + self.tra_traffic)

        per = 100.0 * traf_tot / self.traffic_limit

        self.gui_main_left.set_text("{0:.3f}".format(
            (self.traffic_limit - traf_tot) / mbyte))
        self.gui_main_left.set_tooltip_text("{0} bytes".format(
            int(self.traffic_limit - traf_tot)))

        self.gui_main_used.set_text("{0:.3f}".format(traf_tot / mbyte))
        self.gui_main_used.set_tooltip_text("{0} bytes".format(int(traf_tot)))

        self.gui_main_in.set_text("{0:.3f}".format(self.rec_traffic / mbyte))
        self.gui_main_in.set_tooltip_text("{0} bytes".format(
            int(self.rec_traffic)))

        self.gui_main_out.set_text("{0:.3f}".format(self.tra_traffic / mbyte))
        self.gui_main_out.set_tooltip_text("{0} bytes".format(
            int(self.tra_traffic)))

        self.gui_main_total.set_text("{0:.0f}".format(self.traffic_limit /
                                                      mbyte))
        self.gui_main_total.set_tooltip_text("{0} bytes".format(
            int(self.traffic_limit)))

        if self.last_speed != None:
            while self.last_speed > self.bwu_max_speed:
                self.bwu_max_speed = self.bwu_max_speed + 10.0
            self.gui_main_bwu.speed = self.last_speed
            self.gui_main_bwu.max_speed = self.bwu_max_speed
            self.gui_main_bwu.queue_draw()

        last_day = ntmtools.get_last_day(self.first_day, self.period_length,
                                         self.custom_days)

        if self.now != None:
            period_len_total = ntmtools.timedelta2sec(
                ntmtools.date_to_datetime_end(last_day) -
                ntmtools.date_to_datetime_start(self.first_day))
            period_len_used = ntmtools.timedelta2sec(
                self.now - ntmtools.date_to_datetime_start(self.first_day))
            if period_len_used != 0:
                estimate_str = ntmtools.format_bytes(
                    traf_tot * period_len_total / period_len_used)
            else:
                estimate_str = "--"
        else:
            estimate_str = "--"

        if self.gui_expander.get_expanded():
            text = "<b>{0}</b> <small>({1:.1f}%) [{2}]</small>".format(
                _("Traffic"), per, estimate_str)
        else:
            text = "<b>{0}</b> {1}<small> ({2:.1f}%)</small>".format(
                _("Traffic"), ntmtools.format_bytes(traf_tot), per)

        self.gui_main_top_label.set_markup(text)

        self.gui_main_period.set_markup(
            "<small><small>" + _("Period") +
            ": {0} - {1}</small></small>".format(self.first_day, last_day))