/usr/lib/python2.7/dist-packages/tryton/gui/window/view_form/view/graph.py is in tryton-client 3.8.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | # This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import sys
import gtk
import gettext
from . import View
from tryton.common import node_attributes, get_toplevel_window, message
from tryton.config import TRYTON_ICON
from .graph_gtk.bar import VerticalBar, HorizontalBar
from .graph_gtk.line import Line
from .graph_gtk.pie import Pie
_ = gettext.gettext
class ViewGraph(View):
def __init__(self, screen, xml):
super(ViewGraph, self).__init__(screen, xml)
self.view_type = 'graph'
self.widgets = {}
self.widget = self.parse(xml)
def parse(self, node):
xfield = None
yfields = []
for node in node.childNodes:
if node.nodeType != node.ELEMENT_NODE:
continue
if node.tagName == 'x':
for child in node.childNodes:
if not child.nodeType == child.ELEMENT_NODE:
continue
xfield = node_attributes(child)
field = self.screen.group.fields[xfield['name']]
if not xfield.get('string'):
xfield['string'] = field.attrs['string']
elif node.tagName == 'y':
for child in node.childNodes:
if not child.nodeType == child.ELEMENT_NODE:
continue
yattrs = node_attributes(child)
if not yattrs.get('string') and yattrs['name'] != '#':
field = self.screen.group.fields[yattrs['name']]
yattrs['string'] = field.attrs['string']
yfields.append(yattrs)
Widget = self.get_widget(self.attributes.get('type', 'vbar'))
widget = Widget(self, xfield, yfields)
self.widgets['root'] = widget
event = gtk.EventBox()
event.add(widget)
event.connect('button-press-event', self.button_press)
return event
WIDGETS = {
'vbar': VerticalBar,
'hbar': HorizontalBar,
'line': Line,
'pie': Pie,
}
@classmethod
def get_widget(cls, name):
return cls.WIDGETS[name]
def __getitem__(self, name):
return None
def destroy(self):
self.widget.destroy()
self.widgets['root'].destroy()
self.widgets.clear()
def set_value(self):
pass
def reset(self):
pass
def display(self):
self.widgets['root'].display(self.screen.group)
return True
def set_cursor(self, new=False, reset_view=True):
pass
def get_fields(self):
return []
def get_buttons(self):
return []
def save(self, widget):
parent = get_toplevel_window()
dia = gtk.Dialog(_('Save As'), parent,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_OK, gtk.RESPONSE_OK))
dia.set_icon(TRYTON_ICON)
dia.set_has_separator(True)
dia.set_default_response(gtk.RESPONSE_OK)
dia.vbox.set_spacing(5)
dia.vbox.set_homogeneous(False)
title = gtk.Label('<b>' + _('Image Size') + '</b>')
title.set_alignment(0.0, 0.5)
title.set_use_markup(True)
dia.vbox.pack_start(title)
table = gtk.Table(2, 2)
table.set_col_spacings(3)
table.set_row_spacings(3)
table.set_border_width(1)
table.attach(gtk.Label(_('Width:')), 0, 1, 0, 1, yoptions=False,
xoptions=gtk.FILL)
spinwidth = gtk.SpinButton(gtk.Adjustment(400.0,
0.0, sys.maxint, 1.0, 10.0))
spinwidth.set_numeric(True)
spinwidth.set_activates_default(True)
table.attach(spinwidth, 1, 2, 0, 1, yoptions=False, xoptions=gtk.FILL)
table.attach(gtk.Label(_('Height:')), 0, 1, 1, 2, yoptions=False,
xoptions=gtk.FILL)
spinheight = gtk.SpinButton(gtk.Adjustment(200.0,
0.0, sys.maxint, 1.0, 10.0))
spinheight.set_numeric(True)
spinheight.set_activates_default(True)
table.attach(spinheight, 1, 2, 1, 2, yoptions=False, xoptions=gtk.FILL)
dia.vbox.pack_start(table)
filechooser = gtk.FileChooserWidget(gtk.FILE_CHOOSER_ACTION_SAVE, None)
filter = gtk.FileFilter()
filter.set_name(_('PNG image (*.png)'))
filter.add_mime_type('image/png')
filter.add_pattern('*.png')
filechooser.add_filter(filter)
dia.vbox.pack_start(filechooser)
dia.show_all()
while True:
response = dia.run()
width = spinwidth.get_value_as_int()
height = spinheight.get_value_as_int()
filename = filechooser.get_filename()
if response == gtk.RESPONSE_OK:
if width and height and filename:
if not filename.endswith('.png'):
filename = filename + '.png'
try:
self.widgets['root'].export_png(
filename, width, height)
break
except MemoryError:
message(_('Image size too large!'), dia,
gtk.MESSAGE_ERROR)
else:
break
parent.present()
dia.destroy()
def button_press(self, widget, event):
if event.button == 3:
menu = gtk.Menu()
item = gtk.ImageMenuItem(_('Save As...'))
img = gtk.Image()
img.set_from_stock('tryton-save-as', gtk.ICON_SIZE_MENU)
item.set_image(img)
item.connect('activate', self.save)
item.show()
menu.append(item)
menu.popup(None, None, None, event.button, event.time)
return True
elif event.button == 1:
self.widgets['root'].action()
|