def motion(self, widget, event): super(Pie, self).motion(widget, event) if not getattr(self, 'area', None): return d = (event.x - self.centerx)**2 + (event.y - self.centery)**2 if d > self.radius**2: self.popup.hide() for slice in self.slices: if slice.highlight: self.queue_draw() slice.highlight = False return self.popup.show() if event.y == self.centery: angle = math.pi / 2 else: angle = math.atan( (event.x - self.centerx) / (self.centery - event.y)) if event.x >= self.centerx: if event.y <= self.centery: pass else: angle += math.pi else: if event.y < self.centery: angle += 2 * math.pi else: angle += math.pi for slice in self.slices: if slice.startAngle <= angle <= slice.endAngle: if not slice.highlight: slice.highlight = True if self.yfields[0].get('widget') == 'float_time': conv = None if self.yfields[0].get('float_time'): conv = rpc.CONTEXT.get( self.yfields[0]['float_time']) value = float_time_to_text(slice.fraction * self.sum, conv) sum = float_time_to_text(self.sum, conv) else: value = locale.format('%.2f', slice.fraction * self.sum) sum = locale.format('%.2f', self.sum) label = '%s (%s%%)\n%s/%s' % (self.labels[slice.xname], locale.format( '%.2f', slice.fraction * 100), value, sum) self.popup.set_text(label) self.queue_draw() else: if slice.highlight: slice.highlight = False self.queue_draw()
def motion(self, widget, event): super(Pie, self).motion(widget, event) d = (event.x - self.centerx) ** 2 + (event.y - self.centery) ** 2 if d > self.radius ** 2: self.popup.hide() for slice in self.slices: if slice.highlight: self.queue_draw() slice.highlight = False return self.popup.show() if event.y == self.centery: angle = math.pi / 2 else: angle = math.atan((event.x - self.centerx) / (self.centery - event.y)) if event.x >= self.centerx: if event.y <= self.centery: pass else: angle += math.pi else: if event.y < self.centery: angle += 2 * math.pi else: angle += math.pi for slice in self.slices: if slice.startAngle <= angle <= slice.endAngle: if not slice.highlight: slice.highlight = True if self.yfields[0].get('widget') == 'float_time': conv = None if self.yfields[0].get('float_time'): conv = rpc.CONTEXT.get( self.yfields[0]['float_time']) value = float_time_to_text(slice.fraction * self.sum, conv) sum = float_time_to_text(self.sum, conv) else: value = locale.format('%.2f', slice.fraction * self.sum) sum = locale.format('%.2f', self.sum) label = '%s (%s%%)\n%s/%s' % (self.labels[slice.xname], locale.format('%.2f', slice.fraction * 100), value, sum) self.popup.set_text(label) self.queue_draw() else: if slice.highlight: slice.highlight = False self.queue_draw()
def motion(self, widget, event): super(Bar, self).motion(widget, event) def intersect(bar, event): x = self.area.w * bar.x + self.area.x y = self.area.h * bar.y + self.area.y w = self.area.w * bar.w h = self.area.h * bar.h if x <= event.x <= x + w and y <= event.y <= y + h: return True return False highlight = False draw_bars = [] yfields_float_time = dict( (x.get('key', x['name']), x.get('float_time')) for x in self.yfields if x.get('widget')) for bar in self.bars: if intersect(bar, event): if not bar.highlight: bar.highlight = True if bar.yname in yfields_float_time: conv = None if yfields_float_time[bar.yname]: conv = rpc.CONTEXT.get( yfields_float_time[bar.yname]) label = float_time_to_text(bar.yval, conv) else: label = locale.format('%.2f', bar.yval, True) label += '\n' label += str(self.labels[bar.xname]) self.popup.set_text(label) draw_bars.append(bar) else: if bar.highlight: bar.highlight = False draw_bars.append(bar) if bar.highlight: highlight = True if highlight: self.popup.show() else: self.popup.hide() if draw_bars: minx = self.area.w + self.area.x miny = self.area.h + self.area.y maxx = maxy = 0.0 for bar in draw_bars: x = self.area.w * bar.x + self.area.x y = self.area.h * bar.y + self.area.y minx = int(min(x, minx)) miny = int(min(y, miny)) maxx = int(max(x + self.area.w * bar.w, maxx)) maxy = int(max(y + self.area.h * bar.h, maxy)) self.queue_draw_area(minx - 1, miny - 1, maxx - minx + 2, maxy - miny + 2)
def display(self, record, field): super(FloatTime, self).display(record, field) if not field: self.entry.set_text('') return False val = field.get(record) self.entry.set_text(common.float_time_to_text(val, self.conv))
def XLabels(self): ylabels = super(HorizontalBar, self).YLabels() if len([x.get('key', x['name']) for x in self.yfields if x.get('widget')]) == len(self.yfields): conv = None float_time = reduce(lambda x, y: x == y and x or False, [x.get('float_time') for x in self.yfields]) if float_time: conv = rpc.CONTEXT.get(float_time) return [(x[0], float_time_to_text(locale.atof(x[1]), conv)) for x in ylabels] return [(x[0], x[1]) for x in ylabels]
def modified(self): if self.record and self.field: value = self.entry.get_text() return common.float_time_to_text(self.field.get(self.record), self.conv) != value return False
def get_textual_value(self, record): val = record[self.field_name].get(record) return common.float_time_to_text(val, self.conv)
def motion(self, widget, event): super(Bar, self).motion(widget, event) if not getattr(self, 'area', None): return def intersect(bar, event): x = self.area.w * bar.x + self.area.x y = self.area.h * bar.y + self.area.y w = self.area.w * bar.w h = self.area.h * bar.h if x <= event.x <= x + w and y <= event.y <= y + h: return True return False highlight = False draw_bars = [] yfields_float_time = dict( (x.get('key', x['name']), x.get('float_time')) for x in self.yfields if x.get('widget')) for bar in self.bars: if intersect(bar, event): if not bar.highlight: bar.highlight = True if bar.yname in yfields_float_time: conv = None if yfields_float_time[bar.yname]: conv = rpc.CONTEXT.get( yfields_float_time[bar.yname]) label = float_time_to_text(bar.yval, conv) else: label = locale.format('%.2f', bar.yval, True) label += '\n' label += str(self.labels[bar.xname]) self.popup.set_text(label) draw_bars.append(bar) else: if bar.highlight: bar.highlight = False draw_bars.append(bar) if bar.highlight: highlight = True if highlight: self.popup.show() else: self.popup.hide() if draw_bars: minx = self.area.w + self.area.x miny = self.area.h + self.area.y maxx = maxy = 0.0 for bar in draw_bars: x = self.area.w * bar.x + self.area.x y = self.area.h * bar.y + self.area.y minx = int(min(x, minx)) miny = int(min(y, miny)) maxx = int(max(x + self.area.w * bar.w, maxx)) maxy = int(max(y + self.area.h * bar.h, maxy)) self.queue_draw_area(minx - 1, miny - 1, maxx - minx + 2, maxy - miny + 2)
def motion(self, widget, event): nearest = None for point in self.points: x = point.x * self.area.w + self.area.x y = point.y * self.area.h + self.area.y l = (event.x - x) ** 2 + (event.y - y) ** 2 if not nearest or l < nearest[1]: nearest = (point, l) dia = self.area.w ** 2 + self.area.h ** 2 keys2txt = {} for yfield in self.yfields: keys2txt[yfield.get('key', yfield['name'])] = yfield['string'] highlight = False draw_points = [] yfields_float_time = dict( (x.get('key', x['name']), x.get('float_time')) for x in self.yfields if x.get('widget')) for point in self.points: if point == nearest[0] and nearest[1] < dia / 100: if not point.highlight: point.highlight = True label = keys2txt[point.yname] label += '\n' if point.yname in yfields_float_time: conv = None if yfields_float_time[point.yname]: conv = rpc.CONTEXT.get( yfields_float_time[point.yname]) label += float_time_to_text(point.yval, conv) else: label += locale.format('%.2f', point.yval, True) label += '\n' label += str(self.labels[point.xname]) self.popup.set_text(label) draw_points.append(point) else: if point.highlight: point.highlight = False draw_points.append(point) if point.highlight: self.popup.set_position(self, point.x * self.area.w + self.area.x, point.y * self.area.h + self.area.y) highlight = True if highlight: self.popup.show() else: self.popup.hide() if draw_points: minx = self.area.w + self.area.x miny = self.area.h + self.area.y maxx = maxy = 0.0 for point in draw_points: x = self.area.w * point.x + self.area.x y = self.area.h * point.y + self.area.y minx = min(x - 5, minx) miny = min(y - 5, miny) maxx = max(x + 5, maxx) maxy = max(y + 5, maxy) self.queue_draw_area(int(minx - 1), int(miny - 1), int(maxx - minx + 1), int(maxy - miny + 1))
def motion(self, widget, event): if not getattr(self, 'area', None): return nearest = None for point in self.points: x = point.x * self.area.w + self.area.x y = point.y * self.area.h + self.area.y l = (event.x - x)**2 + (event.y - y)**2 if not nearest or l < nearest[1]: nearest = (point, l) dia = self.area.w**2 + self.area.h**2 keys2txt = {} for yfield in self.yfields: keys2txt[yfield.get('key', yfield['name'])] = yfield['string'] highlight = False draw_points = [] yfields_float_time = dict( (x.get('key', x['name']), x.get('float_time')) for x in self.yfields if x.get('widget')) for point in self.points: if point == nearest[0] and nearest[1] < dia / 100: if not point.highlight: point.highlight = True label = keys2txt[point.yname] label += '\n' if point.yname in yfields_float_time: conv = None if yfields_float_time[point.yname]: conv = rpc.CONTEXT.get( yfields_float_time[point.yname]) label += float_time_to_text(point.yval, conv) else: label += locale.format('%.2f', point.yval, True) label += '\n' label += str(self.labels[point.xname]) self.popup.set_text(label) draw_points.append(point) else: if point.highlight: point.highlight = False draw_points.append(point) if point.highlight: self.popup.set_position(self, point.x * self.area.w + self.area.x, point.y * self.area.h + self.area.y) highlight = True if highlight: self.popup.show() else: self.popup.hide() if draw_points: minx = self.area.w + self.area.x miny = self.area.h + self.area.y maxx = maxy = 0.0 for point in draw_points: x = self.area.w * point.x + self.area.x y = self.area.h * point.y + self.area.y minx = min(x - 5, minx) miny = min(y - 5, miny) maxx = max(x + 5, maxx) maxy = max(y + 5, maxy) self.queue_draw_area(int(minx - 1), int(miny - 1), int(maxx - minx + 1), int(maxy - miny + 1))