/[ascend]/trunk/pygtk/imagewindow.py
ViewVC logotype

Contents of /trunk/pygtk/imagewindow.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1686 - (show annotations) (download) (as text)
Fri Dec 21 05:37:45 2007 UTC (12 years, 6 months ago) by jpye
File MIME type: text/x-python
File size: 3043 byte(s)
Fixed scrollbar policy (almost)
1 # General-purpose popup window for reporting texty stuff
2
3 import gtk, gtk.glade, pango
4 import ascpy
5 from varentry import *
6
7 class ImageWindow:
8 def __init__(self,browser,parent,imagefilename,title):
9 self.browser = browser;
10 self.imagefilename = imagefilename
11
12 # GUI config
13 _xml = gtk.glade.XML(browser.glade_file,"imagewindow")
14 self.window = _xml.get_widget("imagewindow")
15 self.vbox = _xml.get_widget("vbox")
16 self.closebutton = _xml.get_widget("closebutton")
17 self.window.set_title(title)
18
19 if self.browser.icon:
20 self.window.set_icon(self.browser.icon)
21
22 self.parent = None
23 if parent:
24 self.parent = parent
25 self.window.set_transient_for(self.parent)
26
27 self.pixbuf = gtk.gdk.pixbuf_new_from_file(imagefilename)
28 self.w_orig = self.pixbuf.get_width()
29 self.h_orig = self.pixbuf.get_height()
30
31 self.scrollwin = gtk.ScrolledWindow()
32 self.scrollwin.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
33 self.imageview = gtk.Image()
34
35 self.scrollwin.add_with_viewport(self.imageview)
36 self.imageview.show()
37 self.scrollwin.show()
38 self.vbox.add(self.scrollwin)
39
40 _xml.signal_autoconnect(self)
41
42 # more than 100% is pointless
43 self.zoom_max = 1
44 self.zoom_step = 1.5;
45
46 self.zoom(fit=True)
47 self.zoom_fit = self.zoom_current
48
49 def on_save_clicked(self,*args):
50 self.browser.reporter.reportNote("SAVE %s" % self.imagefilename)
51 chooser = gtk.FileChooserDialog(title="Save Incidence Graph (PNG)",action=gtk.FILE_CHOOSER_ACTION_SAVE,
52 buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))
53 chooser.set_current_name("incidence.png")
54
55 response = chooser.run()
56 if response==gtk.RESPONSE_OK:
57 self.browser.reporter.reportWarning("NOT IMPLEMENTED: SAVE AS '%s'" % chooser.get_filename())
58 chooser.destroy()
59
60
61 def on_zoomfit_clicked(self,*args):
62 self.zoom(fit=1)
63
64 def on_zoomnormal_clicked(self,*args):
65 self.zoom()
66
67 def on_zoomin_clicked(self,*args):
68 newzoom = self.zoom_current * self.zoom_step
69 if newzoom > self.zoom_max:
70 newzoom = self.zoom_max
71 self.zoom(newzoom)
72
73 def on_zoomout_clicked(self,*args):
74 newzoom = float(self.zoom_current) / self.zoom_step
75 self.zoom(newzoom)
76
77 def zoom(self,ratio=1,fit=False):
78 self.browser.reporter.reportNote("ZOOM TO %d %%" % (ratio*100))
79 w_view,h_view = self.window.get_size()
80
81 r_w = float(w_view) / self.w_orig
82 r_h = float(h_view) / self.h_orig
83 if r_w < r_h:
84 ratio_fit = r_w
85 else:
86 ratio_fit = r_h
87
88 if fit:
89 ratio = ratio_fit
90 self.is_fit = True
91 else:
92 self.is_fit = False
93
94 if ratio < ratio_fit:
95 ratio = ratio_fit
96
97 w = int(self.w_orig * ratio)
98 h = int(self.h_orig * ratio)
99 if ratio==1:
100 self.imageview.set_from_pixbuf(self.pixbuf)
101 else:
102 pixbufnew = self.pixbuf.scale_simple(w,h,gtk.gdk.INTERP_BILINEAR)
103 self.imageview.set_from_pixbuf(pixbufnew)
104
105 self.zoom_current = ratio
106
107 def run(self):
108 self.window.show()
109
110 def on_imagewindow_destroy_event(self,*args):
111 pass
112
113 def on_imagewindow_size_request(self,*args):
114 if self.is_fit:
115 self.zoom(fit=1)
116
117

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22