Implement graph_open when clicking on graph_view
This commit is contained in:
1 parent
d99afb5387
commit
4cf3cd5a47
5 files changed
+46
-2
No files matched your search
@@ -86,6 +86,13 @@ class Bar(Graph):
|
||||
self.queue_draw_area(minx - 1, miny - 1,
|
||||
maxx - minx + 2, maxy - miny + 2)
|
||||
|
||||
def action(self, window):
|
||||
super(Bar, self).action(window)
|
||||
for bar in self.bars:
|
||||
if bar.highlight:
|
||||
ids = self.ids[bar.xname]
|
||||
self.action_keyword(ids, window)
|
||||
|
||||
|
||||
class VerticalBar(Bar):
|
||||
'Vertical Bar Graph'
|
||||
|
||||
@@ -7,6 +7,7 @@ import mx.DateTime
|
||||
import time
|
||||
import tryton.rpc as rpc
|
||||
import cairo
|
||||
from tryton.action import Action
|
||||
|
||||
|
||||
class Popup(object):
|
||||
@@ -61,7 +62,7 @@ class Graph(gtk.DrawingArea):
|
||||
|
||||
__gsignals__ = { "expose-event": "override" }
|
||||
|
||||
def __init__(self, xfield, yfields, attrs):
|
||||
def __init__(self, xfield, yfields, attrs, model):
|
||||
super(Graph, self).__init__()
|
||||
self.xfield = xfield
|
||||
self.yfields = yfields
|
||||
@@ -75,6 +76,7 @@ class Graph(gtk.DrawingArea):
|
||||
self.connect('leave-notify-event', self.leave)
|
||||
self.popup = Popup(self)
|
||||
self.attrs = attrs
|
||||
self.model = model
|
||||
|
||||
def destroy(self):
|
||||
self.popup.destroy()
|
||||
@@ -118,6 +120,24 @@ class Graph(gtk.DrawingArea):
|
||||
|
||||
self.queue_draw()
|
||||
|
||||
def action(self, window):
|
||||
self.popup.hide()
|
||||
|
||||
def action_keyword(self, ids, window):
|
||||
if not ids:
|
||||
return
|
||||
ctx = self.models.context.copy()
|
||||
if 'active_ids' in ctx:
|
||||
del ctx['active_ids']
|
||||
if 'active_id' in ctx:
|
||||
del ctx['active_id']
|
||||
return Action.exec_keyword('graph_open', {
|
||||
'model': self.model,
|
||||
'id': ids[0],
|
||||
'ids': ids,
|
||||
'window': window,
|
||||
}, context=ctx, warning=False)
|
||||
|
||||
def drawBackground(self, cr, width, height):
|
||||
# Fill the background with gray
|
||||
cr.save()
|
||||
@@ -303,6 +323,7 @@ class Graph(gtk.DrawingArea):
|
||||
self.datas = {}
|
||||
self.labels = {}
|
||||
self.ids = {}
|
||||
self.models = models
|
||||
minx = None
|
||||
maxx = None
|
||||
for model in models:
|
||||
|
||||
@@ -163,6 +163,13 @@ class Line(Graph):
|
||||
super(Line, self).drawAxis(cr, width, height)
|
||||
self.drawLine(cr, 1.0, 0)
|
||||
|
||||
def action(self, window):
|
||||
super(Line, self).action(window)
|
||||
for point in self.points:
|
||||
if point.highlight:
|
||||
ids = self.ids[point.xname]
|
||||
self.action_keyword(ids, window)
|
||||
|
||||
|
||||
class Point(object):
|
||||
|
||||
|
||||
@@ -100,6 +100,8 @@ def button_press(widget, event, graph, window):
|
||||
menu.append(item)
|
||||
menu.popup(None, None, None, event.button, event.time)
|
||||
return True
|
||||
elif event.button == 1:
|
||||
graph.action(window)
|
||||
|
||||
|
||||
class ParserGraph(ParserInterface):
|
||||
@@ -131,7 +133,7 @@ class ParserGraph(ParserInterface):
|
||||
yattrs['string'] = fields[yattrs['name']]['string']
|
||||
yfields.append(yattrs)
|
||||
|
||||
widget = GRAPH_TYPE[attrs.get('type', 'vbar')](xfield, yfields, attrs)
|
||||
widget = GRAPH_TYPE[attrs.get('type', 'vbar')](xfield, yfields, attrs, model)
|
||||
event = gtk.EventBox()
|
||||
event.add(widget)
|
||||
event.connect('button-press-event', button_press, widget, self.window)
|
||||
|
||||
@@ -154,6 +154,13 @@ class Pie(Graph):
|
||||
slice.highlight = False
|
||||
self.queue_draw()
|
||||
|
||||
def action(self, window):
|
||||
super(Pie, self).action(window)
|
||||
for slice in self.slices:
|
||||
if slice.highlight:
|
||||
ids = self.ids[slice.xname]
|
||||
self.action_keyword(ids, window)
|
||||
|
||||
|
||||
class Slice(object):
|
||||
|
||||
|
||||
Reference in new issue
Block a user