A4

Merge lp:~andrea.corbellini/a4/close-file into lp:a4

Proposed by Andrea Corbellini
Status: Merged
Merged at revision: 3
Proposed branch: lp:~andrea.corbellini/a4/close-file
Merge into: lp:a4
Diff against target: 83 lines (+32/-4)
2 files modified
a4lib/app.py (+24/-4)
ui/window_main.glade (+8/-0)
To merge this branch: bzr merge lp:~andrea.corbellini/a4/close-file
Reviewer Review Type Date Requested Status
Andrea Colangelo Approve
Review via email: mp+26299@code.launchpad.net

Commit message

Add a 'Close' button to the main window.

Description of the change

This is just a trivial change. I've added a 'Close' button to the main window.

To post a comment you must log in.
Revision history for this message
Andrea Colangelo (warp10) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'a4lib/app.py'
2--- a4lib/app.py 2010-05-27 14:23:58 +0000
3+++ a4lib/app.py 2010-05-28 13:09:30 +0000
4@@ -12,15 +12,14 @@
5 """The main window of the application."""
6
7 def __init__(self):
8- self.svg_image = None
9 self.builder = gtk.Builder()
10 # TODO Look into '/usr/share' too.
11 self.builder.add_from_file('ui/window_main.glade')
12 self.builder.connect_signals(self)
13-
14 self.gtk_window = self.builder.get_object('window_main')
15 self.gtk_window.show_all()
16 self.drawing_area = self.builder.get_object('drawing_area').window
17+ self.reset()
18
19 def set_status(self, status):
20 """Put the given string in the status bar."""
21@@ -44,13 +43,30 @@
22 dialog.destroy()
23 else:
24 # The file was OK. Set up the environment.
25- widget = self.builder.get_object('drawing_area')
26- widget.set_size_request(image.width + 20, image.height + 20)
27 self.svg_image = image
28+ area = self.builder.get_object('drawing_area')
29+ area.set_size_request(image.width + 20, image.height + 20)
30+ # Make the 'Close' button sensitive.
31+ menu_item = self.builder.get_object('imagemenuitem_close')
32+ menu_item.props.sensitive = True
33 finally:
34 # Restore the status string.
35 self.set_status('')
36
37+ def reset(self):
38+ """Reset the environment and put the window into its original state.
39+
40+ This function closes the file (if opened) and resets all the buttons
41+ and the menus.
42+ """
43+ # Destroy the image object and reset the drawing area's size.
44+ self.svg_image = None
45+ area = self.builder.get_object('drawing_area')
46+ area.set_size_request(0, 0)
47+ # Make the 'Close' button insensitive.
48+ menu_item = self.builder.get_object('imagemenuitem_close')
49+ menu_item.props.sensitive = False
50+
51 def on_open_clicked(self, widget):
52 """Even called when the 'Open' button is clicked."""
53 # Set up the file chooser dialog.
54@@ -74,6 +90,10 @@
55 if response == gtk.RESPONSE_OK:
56 self.open_file(file_name)
57
58+ def on_close_clicked(self, widget):
59+ """The 'Close' button has been clicked."""
60+ self.reset()
61+
62 def on_drawing_area_expose(self, widget, event):
63 """This method is called everytime the drawing area should be redrawn.
64 """
65
66=== modified file 'ui/window_main.glade'
67--- ui/window_main.glade 2010-05-27 14:23:58 +0000
68+++ ui/window_main.glade 2010-05-28 13:09:30 +0000
69@@ -35,6 +35,14 @@
70 </object>
71 </child>
72 <child>
73+ <object class="GtkImageMenuItem" id="imagemenuitem_close">
74+ <property name="label">gtk-close</property>
75+ <property name="visible">True</property>
76+ <property name="use_stock">True</property>
77+ <signal name="activate" handler="on_close_clicked"/>
78+ </object>
79+ </child>
80+ <child>
81 <object class="GtkImageMenuItem" id="imagemenuitem_quit">
82 <property name="label">gtk-quit</property>
83 <property name="visible">True</property>

Subscribers

People subscribed via source and target branches