def __init_reference_volume(self, is_roaming): if not is_roaming: self._monthly_limits = self._conf.get_monthly_limits(is_roaming) monthly_limits = self._monthly_limits combobox = self.ref_data_combobox hbox = self.ref_data_other_hbox else: self._monthly_ro_limits = self._conf.get_monthly_limits(is_roaming) monthly_limits = self._monthly_ro_limits combobox = self.ref_ro_data_combobox hbox = self.ref_ro_data_other_hbox model = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING) for limit in monthly_limits: if limit == -1: model.append([-1, _("Other")]) else: limit_str = format_to_maximun_unit_one_decimal( int(limit) * 1024, "GB", "MB", "KB") model.append([limit, limit_str]) combobox.set_model(model) cell = gtk.CellRendererText() combobox.pack_start(cell, True) combobox.add_attribute(cell, 'text', 1) default_limit = self._conf.get_default_selected_monthly_limit( is_roaming) index = monthly_limits.index(default_limit) combobox.set_active(index) if default_limit == -1: hbox.show_all() else: hbox.hide()
def __on_traffic_data_changed(self, traffic_manager, data_used, data_used_roaming, data_limit, billing_period): data_limit_string = format_to_maximun_unit_one_decimal( data_limit, "GB", "MB", "KB", "Bytes") data_used_string = format_to_maximun_unit_one_decimal( data_used, "GB", "MB", "KB", "Bytes") period_end_string = billing_period[1].strftime('%d/%m/%Y') period_start_string = billing_period[0].strftime('%d/%m/%Y') # -- Set the available data to zero if used higher than limit data_available = 0 if (data_used > data_limit) else (data_limit - data_used) data_available_string = format_to_maximun_unit_one_decimal( data_available, "GB", "MB", "KB", "Bytes") try: fraction = int((data_used * 10.0) / data_limit) if fraction > 10: fraction = 10 elif fraction < 0: fraction = 0 except: fraction = 0 if tgcm.country_support == 'uk': description = _("Data purchased: %s\nYou've used: %s\nData available until %s: %s") % \ (data_limit_string, data_used_string, period_end_string, data_available_string) elif tgcm.country_support == 'es': description = _("Consumed data since %s: %s") % \ (period_start_string, data_used_string) else: description = _("Data purchased: %s\nConsumed data: %s\nAvailable data until %s: %s") % \ (data_limit_string, data_used_string, period_end_string, data_available_string) self.set_var("str.user.data.available", "") self.set_var("str.user.data.available.data", "%s" % (data_available_string)) self.set_var("str.user.data.used.data", "%s" % (data_used_string)) self.set_var("user.data.used", fraction) self.set_var("user.data.description", description) self.set_var("str.user.data.limit.data", data_limit_string)
def __on_traffic_data_changed(self, traffic_manager, data_used, data_used_roaming, data_limit, billing_period): data_limit_string = format_to_maximun_unit_one_decimal(data_limit,"GB","MB","KB","Bytes") data_used_string = format_to_maximun_unit_one_decimal(data_used,"GB","MB","KB","Bytes") period_end_string = billing_period[1].strftime('%d/%m/%Y') period_start_string = billing_period[0].strftime('%d/%m/%Y') # -- Set the available data to zero if used higher than limit data_available = 0 if (data_used > data_limit) else (data_limit - data_used) data_available_string = format_to_maximun_unit_one_decimal(data_available,"GB","MB","KB","Bytes") try: fraction = int ((data_used * 10.0) / data_limit) if fraction > 10: fraction = 10 elif fraction < 0: fraction = 0 except: fraction = 0 if tgcm.country_support == 'uk': description = _("Data purchased: %s\nYou've used: %s\nData available until %s: %s") % \ (data_limit_string, data_used_string, period_end_string, data_available_string) elif tgcm.country_support == 'es': description = _("Consumed data since %s: %s") % \ (period_start_string, data_used_string) else: description = _("Data purchased: %s\nConsumed data: %s\nAvailable data until %s: %s") % \ (data_limit_string, data_used_string, period_end_string, data_available_string) self.set_var("str.user.data.available", "") self.set_var("str.user.data.available.data", "%s" % (data_available_string)) self.set_var("str.user.data.used.data", "%s" % (data_used_string)) self.set_var("user.data.used", fraction) self.set_var("user.data.description", description) self.set_var("str.user.data.limit.data", data_limit_string);
def __update_labels(self, monthly_limit, is_roaming): if not is_roaming: alert_widgets = self._alert_labels else: alert_widgets = self._alert_roaming_labels for i in range(0, 4): checkbutton = alert_widgets[i] alert = self._alerts[i] avail_data = monthly_limit * alert * 1024 / 100.0 percent = str(alert) data = format_to_maximun_unit_one_decimal(avail_data, "GB", "MB", "KB") checkbutton.set_label(self._alert_text % { 'percent': percent, 'data': data })
def draw(self, widget, event): ctx=widget.window.cairo_create() # cairo context object ctx.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) ctx.clip() rc=self.get_allocation() is_uk=tgcm.country_support=='uk' # YLabel (MBytes) text="MBytes" ctx.save() ext=ctx.text_extents(text) ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) ctx.set_font_size(10.0) ctx.move_to(20, rc.height/2) ctx.rotate(3 * math.pi / 2) ctx.set_source_rgb(0,0,0) ctx.show_text(text) ctx.restore() ctx.stroke() max_data=1.0 for d in xrange(len(self.values)): if d>=self.pos and d-self.pos<self.vis_cols: # scale graph to visible values for d2 in xrange(2): max_data=max(max_data, self.values[d][0][d2]) ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(10.0) if is_uk: ext2=ctx.text_extents(_("Billing")) ext3=ctx.text_extents(_("period")) ext4=ctx.text_extents(_("Data used (MB)")) colors=[ [ [[0.4,0.4,0.4],[0.4,0.4,0.6],[0.4,0.4,1.0]], [[0.8,0.2,0.2],[0.8,0.2,0.2],[1.0,0.313,0.313]] ], [ [[0.0,0.0,0.2],[0.0,0.0,0.4],[0.2,0.2,1.0]], [[0.6,0.0,0.0],[0.6,0.0,0.0],[0.8,0.0,0.0]] ] ] if not self.conf.is_last_imsi_seen_valid(): monthly_limit = self.conf.get_default_selected_monthly_limit(is_roaming = False) else: imsi = self.conf.get_last_imsi_seen() monthly_limit = self.conf.get_imsi_based_selected_monthly_limit(imsi, is_roaming = False) if monthly_limit == -1: monthly_limit = self.conf.get_imsi_based_other_monthly_limit(imsi, is_roaming = False) alert_mb = monthly_limit # Show the monthly allowance bar if necessary if self.conf.is_alerts_available() and (max_data > 0) and \ (alert_mb > 0) and (alert_mb < max_data): text=_("Transference limit") # Calculate the size of the graph box. It is necessary to consider some additional # space on the right for the "Monthly allowance" mark ext=ctx.text_extents(text) barras=Rect(50,15,rc.width-ext[2],rc.height-50) # Draw the monthly allowance legend and mark ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(10.0) ext0=ctx.font_extents() ctx.move_to(rc.width-ext[2], barras.bottom-(barras.bottom-barras.top)*alert_mb/max_data-ext0[1]) # descent ctx.set_source_rgb(0,0,0) ctx.show_text(text) ctx.stroke() paint=True for xx in xrange(barras.left, rc.width, 10): if paint: yy=barras.bottom-(barras.bottom-barras.top)*alert_mb/max_data ctx.set_source_rgb(0.6,0.6,0.8) self.fill_rect(ctx, Rect(xx,yy,xx+10,yy+1)) paint=not paint else: # Calculate the size of the graph box. As we have not reached the monthly data allowance, # it's not necessary to reserve space for it barras=Rect(50,15,rc.width-15,rc.height-50) if is_uk: # Seems that UK uses a custom graph box size barras=Rect(10+max(20,ext4[2]/2),15,rc.width-ext[2],rc.height-50) text1=_("Billing") text2=_("period") ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(10.0) ext0=ctx.font_extents() ext=ctx.text_extents(text1) ctx.move_to(barras.left-ext[2], barras.bottom+ext0[0]) # ascent ctx.set_source_rgb(0,0,0) ctx.show_text(text1) ctx.stroke() ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(10.0) ext0=ctx.font_extents() ext=ctx.text_extents(text2) ctx.move_to(barras.left-ext[2], barras.bottom+ext0[0]+ext0[1]+ext0[0]) # ascent descent ascent ctx.set_source_rgb(0,0,0) ctx.show_text(text2) ctx.stroke() text=_("Data used (MB)") ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(10.0) ext0=ctx.font_extents() ext=ctx.text_extents(text) ctx.move_to(barras.left-ext[2]/2, barras.top-ext0[1]) # descent ctx.set_source_rgb(0,0,0) ctx.show_text(text) ctx.stroke() # Clean cached column information if needed self.cached_columns_data = [] # Draw monthly expenses columns for b in xrange(self.vis_cols): if self.pos+b>=len(self.values): continue; if is_uk: b2=len(self.values)-1-b else: b2=b x1=barras.left+2+(barras.right-(barras.left+2))*b2/self.vis_cols x2=barras.left+2+(barras.right-(barras.left+2))*(b2+1)/self.vis_cols w=x2-x1 centerx=(x1+x2)/2 x1+=w*10/100 x2-=w*10/100 w=x2-x1 # Store some information needed for building the tooltip coords = (x1, x2, barras.top, barras.bottom) month_name = self.values[self.pos+b][1] expenses = self.values[self.pos+b][0] non_roaming = format_to_maximun_unit_one_decimal(expenses[0], "GB","MB") roaming = format_to_maximun_unit_one_decimal(expenses[1], "GB","MB") expenses_data = (non_roaming, roaming) self.cached_columns_data.append({ 'coords' : coords, 'expenses' : expenses_data, 'month_name' : month_name, }) # Expenses columns for roaming and non-roaming for d in xrange(2): l=x1+w*d/2; r=x1+w*(d+1)/2 -1; if r<l+5: r=l+5; data=self.values[self.pos+b][0][d] if max_data!=0: h=data*(barras.bottom-barras.top)/max_data; else: h=0 if self.pos+b==len(self.values)-1: col=1 else: col=0 color_border=colors[col][d][0] color_bar1=colors[col][d][1] color_bar2=colors[col][d][2] re=Rect(l,barras.bottom-h,r,barras.bottom) if re.bottom>=re.top+5: for x in xrange(int(l), int(r-2), 2): re2=Rect(x,re.top+2,x+3,re.bottom-2) rr=color_bar1[0]+(color_bar2[0]-color_bar1[0])*(x-l)/(r-l) gg=color_bar1[1]+(color_bar2[1]-color_bar1[1])*(x-l)/(r-l) bb=color_bar1[2]+(color_bar2[2]-color_bar1[2])*(x-l)/(r-l) ctx.set_source_rgb(rr,gg,bb) self.fill_rect(ctx, re2) ctx.set_source_rgb(color_border[0],color_border[1],color_border[2]) self.fill_rect(ctx, Rect(re.left,re.top,re.left+2,re.bottom)) if re.top+2<=re.bottom: self.fill_rect(ctx, Rect(re.left,re.top,re.right,re.top+2)) self.fill_rect(ctx, Rect(re.right-2,re.top,re.right,re.bottom)) if re.bottom-2>=re.top: self.fill_rect(ctx, Rect(re.left,re.bottom-2,re.right,re.bottom)) text="%i" % int(data) ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(0.75*10.0) extent=ctx.text_extents(text) fextent=ctx.font_extents() ctx.set_source_rgb(0,0,0) ctx.move_to((l+r)/2-extent[2]/2,re.bottom+1+fextent[0]) # ascent ctx.show_text(text) ctx.stroke() if is_uk and (b==len(self.values)-1 or b==len(self.values)-2): if b==len(self.values)-1: text1=_("This") elif b==len(self.values)-2: text1=_("Last") text2=_("month") text="0000" ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(0.75*10.0) fextent0=ctx.font_extents() text=text1 ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) ctx.set_font_size(10.0*1.25) extent=ctx.text_extents(text) fextent=ctx.font_extents() ctx.set_source_rgb(0,0,0) ctx.move_to((x1+x2)/2-extent[2]/2, barras.bottom+fextent0[2]+fextent[0]) # height + ascent ctx.show_text(text) ctx.stroke() text=text2 ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) ctx.set_font_size(10.0*1.25) extent=ctx.text_extents(text) fextent=ctx.font_extents() ctx.set_source_rgb(0,0,0) ctx.move_to((x1+x2)/2-extent[2]/2, barras.bottom+fextent0[2]+fextent[0]+fextent[2]*0.75) # height + ascent + height ctx.show_text(text) ctx.stroke() else: text="0000" ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(0.75*10.0) fextent0=ctx.font_extents() if is_uk: text=_("Month %d") % (b2+1) else: text=self.values[self.pos+b][1] ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) ctx.set_font_size(10.0*1.25) extent=ctx.text_extents(text) fextent=ctx.font_extents() ctx.set_source_rgb(0,0,0) ctx.move_to((x1+x2)/2-extent[2]/2, barras.bottom+fextent0[2]+fextent[0]) # height + ascent ctx.show_text(text) ctx.stroke() ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(0.75*10.0) for s in xrange(1,5): y=barras.bottom+(barras.top-barras.bottom)*s/4; text="%.2f" % (float(max_data) * s / 4) extent=ctx.text_extents(text) fextent=ctx.font_extents() ctx.move_to(barras.left-extent[2]-2,y-extent[3]/2+fextent[0]) ctx.show_text(text) ctx.stroke() # Graph data legend rc=Rect(0,0,rc.width,rc.height) ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) ctx.set_font_size(10.0) extent=ctx.font_extents() fascent=extent[0] fdescent=extent[1] fheight=extent[2] if is_uk: text=_("%s network") % self.conf.get_company_name() ext=ctx.text_extents(text) w1=ext[2] text=_("Roaming") ext=ctx.text_extents(text) w2=ext[2] x=rc.right-7-33-w1-10-33-w2 else: x=rc.left+7 ctx.set_source_rgb(0,0,0.2) self.fill_rect(ctx, Rect(x,rc.bottom-10-fdescent,x+30,rc.bottom-10+7-fdescent)) ctx.set_source_rgb(0.2,0.2,1.0) self.fill_rect(ctx, Rect(x+2,rc.bottom-10+2-fdescent,x+30-2,rc.bottom-10+7-2-fdescent)) x+=33 text=_("%s network") % self.conf.get_company_name() ext=ctx.text_extents(text) ctx.move_to(x,rc.bottom-3-fdescent) ctx.set_source_rgb(0,0,0) ctx.show_text(text) ctx.stroke() x+=ext[2]+10; ctx.set_source_rgb(0.2,0,0) self.fill_rect(ctx, Rect(x,rc.bottom-10-fdescent,x+30,rc.bottom-10+7-fdescent)) ctx.set_source_rgb(0.8,0,0) self.fill_rect(ctx, Rect(x+2,rc.bottom-10+2-fdescent,x+30-2,rc.bottom-10+7-2-fdescent)) x+=33 text=_("Roaming") ext=ctx.text_extents(text) ctx.move_to(x,rc.bottom-3-fdescent) ctx.set_source_rgb(0,0,0) ctx.show_text(text) ctx.stroke() ctx.set_source_rgb(0.4,0.4,0.4) self.fill_rect(ctx, Rect(barras.left,barras.top,barras.left+2,barras.bottom)) self.fill_rect(ctx, Rect(barras.left-9,barras.bottom-2,barras.right,barras.bottom)) return False