コード例 #1
0
ファイル: mtimeslot.py プロジェクト: gihankarunarathne/NTM
    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)
        )
コード例 #2
0
ファイル: ntmgui.py プロジェクト: gihankarunarathne/NTM
    def set_report_total(self, rep_res):
        template = '''<html><head><title>''' + _("Daily Traffic Report") + '''</title>
        </head>
        <body><p><h2 align="center">''' + _("Report - Total") + '''</h2></p>
        <p align="center">
        <table class="bordered" style="border-collapse: collapse; border: 1px solid #a0a0a0; margin: 10px 0px 10px 0px;"><tbody>
        <tr><th rowspan="1" colspan="2" style="border: 1px solid #a0a0a0;">''' + _("Traffic") + '''</th></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Days with traffic") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{0}</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Total") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{1:.2f} MB</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Received") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{2:.2f} MB</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Transmitted") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{3:.2f} MB</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Max in one day") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{4:.2f} MB</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Min in one day") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{5:.2f} MB</td></tr>
        </tbody></table>
        </p>
        <p align="center">
        <table class="bordered" style="border-collapse: collapse; border: 1px solid #a0a0a0; margin: 10px 0px 10px 0px;"><tbody>
        <tr><th rowspan="1" colspan="2" style="border: 1px solid #a0a0a0;">''' + _("Sessions") + '''</th></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("N. sessions") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{6}</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Total time") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{7}</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Max session length") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{8}</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _("Min session length") + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{9}</td></tr>
        </tbody></table>
        </p>
        </body></html>
        '''
        mbytes = 1.0 / (1024.0 * 1024.0)
        data = template.format(rep_res[2], mbytes*(rep_res[3]+rep_res[4]), mbytes*rep_res[3],
                    mbytes*rep_res[4], mbytes*rep_res[5], mbytes*rep_res[6], rep_res[7],
                    ntmtools.format_time(rep_res[8]), ntmtools.format_time(rep_res[9]), ntmtools.format_time(rep_res[10]))

        self.view_rep.load_html_string(data, "file:///")
コード例 #3
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
    def check_limit(self):
        ntmtools.dbg_msg("MTime.check_limit")

        if (not self.active): return

        if ( (self.used_sec + self.this_slot_sec) >= self.total_sec):
            if (self.last_state == 1) and (not self.disc_msgDialog):
                self.disc_msgDialog = True
                last_day = ntmtools.get_last_day(self.first_day, self.period_length, self.custom_days)
                if self.auto_disconnect:
                    msg = _('Time Limit Reached') + ', {0}. '.format(ntmtools.format_time(self.total_sec)) + _('Disconnection is done!!\nPeriod: {0} to {1}').format(self.first_day.isoformat(), last_day.isoformat())
                    if self.disconnect_handler != None:
                        self.disconnect_handler()
                    showDialog = True
                else:
                    msg = _('Time Limit Reached') + ', {0}.\n'.format(ntmtools.format_time(self.total_sec)) + _('Period: {0} to {1}').format(self.first_day.isoformat(), last_day.isoformat())
                    showDialog = not self.dialog_showed

                if showDialog:
                    dialog = gtk.Dialog(
                        _("NTM - Message"), None,
                         gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                         (gtk.STOCK_OK, gtk.RESPONSE_OK)
                    )
                    icon = gtk.Window().render_icon(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
                    dialog.set_icon(icon)
                    label = gtk.Label(msg)
                    label.set_padding(8, 8)
                    dialog.vbox.pack_start(label)
                    dialog.show_all()
                    result = dialog.run()
                    dialog.destroy()
                    self.dialog_showed = True
                self.disc_msgDialog = False
コード例 #4
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
    def check_limit(self):
        ntmtools.dbg_msg("MTime.check_limit")

        if (not self.active): return

        if ((self.used_sec + self.this_slot_sec) >= self.total_sec):
            if (self.last_state == 1) and (not self.disc_msgDialog):
                self.disc_msgDialog = True
                last_day = ntmtools.get_last_day(self.first_day,
                                                 self.period_length,
                                                 self.custom_days)
                if self.auto_disconnect:
                    msg = _('Time Limit Reached') + ', {0}. '.format(
                        ntmtools.format_time(self.total_sec)
                    ) + _(
                        'Disconnection is done!!\nPeriod: {0} to {1}').format(
                            self.first_day.isoformat(), last_day.isoformat())
                    if self.disconnect_handler != None:
                        self.disconnect_handler()
                    showDialog = True
                else:
                    msg = _('Time Limit Reached') + ', {0}.\n'.format(
                        ntmtools.format_time(
                            self.total_sec)) + _('Period: {0} to {1}').format(
                                self.first_day.isoformat(),
                                last_day.isoformat())
                    showDialog = not self.dialog_showed

                if showDialog:
                    dialog = gtk.Dialog(
                        _("NTM - Message"), None,
                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                        (gtk.STOCK_OK, gtk.RESPONSE_OK))
                    icon = gtk.Window().render_icon(gtk.STOCK_DIALOG_WARNING,
                                                    gtk.ICON_SIZE_DIALOG)
                    dialog.set_icon(icon)
                    label = gtk.Label(msg)
                    label.set_padding(8, 8)
                    dialog.vbox.pack_start(label)
                    dialog.show_all()
                    result = dialog.run()
                    dialog.destroy()
                    self.dialog_showed = True
                self.disc_msgDialog = False
コード例 #5
0
ファイル: mtimeslot.py プロジェクト: gihankarunarathne/NTM
    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))
コード例 #6
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
 def gui_pref_total_time_hclicked(self, data = None):
     result = self.gui_time_len_dialog.run()
     if result == 1: # OK
         hour = self.gui_time_len_dialog_hour.get_value()
         minute = self.gui_time_len_dialog_minute.get_value()
         second = self.gui_time_len_dialog_second.get_value()
         self.temp_gui_total_sec = int(round(second + minute*60 + hour*60*60))
         if (self.temp_gui_total_sec == 0):
             self.ntm.ntmgui.show_dialog(_("NTM - Warning!"), _("The total time must be > 0 sec. Default value is 1h"))
             self.temp_gui_total_sec = 1*60*60
         self.gui_pref_total_time.set_label(ntmtools.format_time(self.temp_gui_total_sec))
     self.gui_time_len_dialog.hide()
コード例 #7
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
    def update_preferences_gui(self):
        if self.gtkb == None:
            print("MMTime.update_preferences_gui(*): Gui not builded.\n")
            return

        self.gui_pref_time_active.set_active(self.active)
        self.gui_pref_total_time.set_label(ntmtools.format_time(self.total_sec))
        self.gui_pref_auto_disconnect.set_active(self.auto_disconnect)

        self.gui_pref_period_length.set_active(self.period_length)
        self.gui_pref_days.set_value(self.custom_days)
        self.gui_pref_first_day.set_label(self.first_day.isoformat())
        self.temp_gui_pref_first_day  = self.first_day
        self.gui_pref_period_autoupdate.set_active(self.period_autoupdate)
コード例 #8
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
    def update_preferences_gui(self):
        if self.gtkb == None:
            print("MMTime.update_preferences_gui(*): Gui not builded.\n")
            return

        self.gui_pref_time_active.set_active(self.active)
        self.gui_pref_total_time.set_label(ntmtools.format_time(
            self.total_sec))
        self.gui_pref_auto_disconnect.set_active(self.auto_disconnect)

        self.gui_pref_period_length.set_active(self.period_length)
        self.gui_pref_days.set_value(self.custom_days)
        self.gui_pref_first_day.set_label(self.first_day.isoformat())
        self.temp_gui_pref_first_day = self.first_day
        self.gui_pref_period_autoupdate.set_active(self.period_autoupdate)
コード例 #9
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
 def gui_pref_total_time_hclicked(self, data=None):
     result = self.gui_time_len_dialog.run()
     if result == 1:  # OK
         hour = self.gui_time_len_dialog_hour.get_value()
         minute = self.gui_time_len_dialog_minute.get_value()
         second = self.gui_time_len_dialog_second.get_value()
         self.temp_gui_total_sec = int(
             round(second + minute * 60 + hour * 60 * 60))
         if (self.temp_gui_total_sec == 0):
             self.ntm.ntmgui.show_dialog(
                 _("NTM - Warning!"),
                 _("The total time must be > 0 sec. Default value is 1h"))
             self.temp_gui_total_sec = 1 * 60 * 60
         self.gui_pref_total_time.set_label(
             ntmtools.format_time(self.temp_gui_total_sec))
     self.gui_time_len_dialog.hide()
コード例 #10
0
ファイル: ntmgui.py プロジェクト: gihankarunarathne/NTM
    def set_report_total(self, rep_res):
        template = '''<html><head><title>''' + _(
            "Daily Traffic Report"
        ) + '''</title>
        </head>
        <body><p><h2 align="center">''' + _("Report - Total") + '''</h2></p>
        <p align="center">
        <table class="bordered" style="border-collapse: collapse; border: 1px solid #a0a0a0; margin: 10px 0px 10px 0px;"><tbody>
        <tr><th rowspan="1" colspan="2" style="border: 1px solid #a0a0a0;">''' + _(
            "Traffic"
        ) + '''</th></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Days with traffic"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{0}</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Total"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{1:.2f} MB</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Received"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{2:.2f} MB</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Transmitted"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{3:.2f} MB</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Max in one day"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{4:.2f} MB</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Min in one day"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{5:.2f} MB</td></tr>
        </tbody></table>
        </p>
        <p align="center">
        <table class="bordered" style="border-collapse: collapse; border: 1px solid #a0a0a0; margin: 10px 0px 10px 0px;"><tbody>
        <tr><th rowspan="1" colspan="2" style="border: 1px solid #a0a0a0;">''' + _(
            "Sessions"
        ) + '''</th></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "N. sessions"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{6}</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Total time"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{7}</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Max session length"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{8}</td></tr>
        <tr><td style="border: 1px solid #a0a0a0;">''' + _(
            "Min session length"
        ) + '''</td><td style="border: 1px solid #a0a0a0; text-align: right;">{9}</td></tr>
        </tbody></table>
        </p>
        </body></html>
        '''
        mbytes = 1.0 / (1024.0 * 1024.0)
        data = template.format(rep_res[2], mbytes * (rep_res[3] + rep_res[4]),
                               mbytes * rep_res[3], mbytes * rep_res[4],
                               mbytes * rep_res[5], mbytes * rep_res[6],
                               rep_res[7], ntmtools.format_time(rep_res[8]),
                               ntmtools.format_time(rep_res[9]),
                               ntmtools.format_time(rep_res[10]))

        self.view_rep.load_html_string(data, "file:///")
コード例 #11
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
 def get_short_message(self):
     total_used_sec = self.used_sec + self.this_slot_sec
     return "{0}".format(ntmtools.format_time(total_used_sec))
コード例 #12
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
 def get_summary_message(self):
     total_used_sec = self.used_sec + self.this_slot_sec
     return _("Used {0} of {1}").format(
         ntmtools.format_time(total_used_sec),
         ntmtools.format_time(self.total_sec))
コード例 #13
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
 def get_short_message(self):
     total_used_sec = self.used_sec + self.this_slot_sec
     return "{0}".format(ntmtools.format_time(total_used_sec))
コード例 #14
0
ファイル: mtime.py プロジェクト: gihankarunarathne/NTM
 def get_summary_message(self):
     total_used_sec = self.used_sec + self.this_slot_sec
     return _("Used {0} of {1}").format(ntmtools.format_time(total_used_sec), ntmtools.format_time(self.total_sec))