A4

Merge lp:~gaspa/a4/rotate-canvas into lp:a4

Proposed by Andrea Gasparini
Status: Merged
Merged at revision: 55
Proposed branch: lp:~gaspa/a4/rotate-canvas
Merge into: lp:a4
Diff against target: 164 lines (+74/-4)
3 files modified
a4lib/app.py (+21/-3)
a4lib/player.py (+27/-1)
ui/window_main.glade (+26/-0)
To merge this branch: bzr merge lp:~gaspa/a4/rotate-canvas
Reviewer Review Type Date Requested Status
Andrea Colangelo Approve
Review via email: mp+31350@code.launchpad.net

Description of the change

This merge adds a spinbutton that shows and set the rotation of the whole image.

Changing the spinbutton value trigger a transition towards the angle specified.
Viceversa, when you move around in the regions list, you'll see the angle that will be updated on the spinbutton as well.

To post a comment you must log in.
Revision history for this message
Andrea Gasparini (gaspa) wrote :

Just a note: it rotate around a corner, not the center. It'd behave correctly when we'll merge the merge lp:~andrea-gualano/a4/animations

lp:~gaspa/a4/rotate-canvas updated
57. By Andrea Gasparini

pep8 clean, reset spinbutton in open/close, adjustment with -180/180 range

58. By Andrea Gasparini

disabled spin with no opened file

Revision history for this message
Andrea Colangelo (warp10) wrote :

We need to work on the rotation range to make it continuous, but apart from that, it looks good. Nice work! :)

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-07-24 22:28:56 +0000
3+++ a4lib/app.py 2010-07-30 07:10:58 +0000
4@@ -8,6 +8,7 @@
5 import sys
6 import glib
7 import gtk
8+import math
9 from a4lib.presentation import PresentationError
10 from a4lib.player import GtkCairoPlayer
11
12@@ -50,6 +51,7 @@
13 self.player = None
14 self.last_path = None
15 self.is_fullscreen = False
16+ self.callback_called = False
17
18 def set_status(self, status):
19 """Put the given string in the status bar."""
20@@ -77,9 +79,17 @@
21 # Make the buttons sensitive.
22 for button in ('imagemenuitem_close', 'toolbutton_close',
23 'toolbutton_next', 'toolbutton_zoom_in',
24- 'toolbutton_zoom_out', 'toolbutton_editor'):
25+ 'toolbutton_zoom_out', 'toolbutton_editor',
26+ 'spin_rotation'):
27 self.builder.get_object(button).set_sensitive(True)
28- self.builder.get_object('toolbutton_previous').set_sensitive(False)
29+ spin_button = self.builder.get_object('spin_rotation')
30+ spin_button.set_value(0)
31+
32+ def change_rotation(region):
33+ degrees = int(math.degrees(region.rotate))
34+ self.callback_called = True
35+ spin_button.set_value(math.degrees(region.rotate))
36+ self.player.set_region_changed_callback(change_rotation)
37 finally:
38 # Restore the status string.
39 self.set_status('')
40@@ -98,8 +108,9 @@
41 for button in ('imagemenuitem_close', 'toolbutton_close',
42 'toolbutton_previous', 'toolbutton_next',
43 'toolbutton_zoom_in', 'toolbutton_zoom_out',
44- 'toolbutton_editor'):
45+ 'toolbutton_editor','spin_rotation'):
46 self.builder.get_object(button).set_sensitive(False)
47+ self.builder.get_object('spin_rotation').set_value(0)
48
49 def on_open_clicked(self, widget):
50 """Event called when the 'Open' button is clicked."""
51@@ -216,6 +227,13 @@
52 dialog.run()
53 dialog.destroy()
54
55+ def on_spin_rotation_value_changed(self, widget):
56+ if self.callback_called:
57+ self.callback_called = False
58+ return
59+ radians = math.radians(widget.get_value())
60+ self.player.rotate(radians)
61+
62 def quit(self, widget=None):
63 """Close the window and quit the application."""
64 gtk.main_quit()
65
66=== modified file 'a4lib/player.py'
67--- a4lib/player.py 2010-07-24 18:17:17 +0000
68+++ a4lib/player.py 2010-07-30 07:10:58 +0000
69@@ -13,12 +13,27 @@
70 def __init__(self, file_name):
71 image = Presentation(file_name)
72 self.presentation = image
73- self.current_region = Region.whole_image(image)
74+ self._current_region = Region.whole_image(image)
75 self.current_animation = None
76 # Each zoom call Region.scale_of with this factor.
77 self.zoom_factor = 1.4
78 self.view_status = -1
79
80+ self.region_changed_callback = None
81+
82+ def get_current_region(self):
83+ return self._current_region
84+
85+ def set_current_region(self, region):
86+ self._current_region = region
87+ if self.region_changed_callback:
88+ self.region_changed_callback(region)
89+
90+ current_region = property(get_current_region, set_current_region)
91+
92+ def set_region_changed_callback(self, callback):
93+ self.region_changed_callback = callback
94+
95 def _set_animation_to(self, target):
96 """Calculate `Animation` given the id of two point of a presentation.
97 """
98@@ -70,6 +85,13 @@
99 self.current_animation = None
100 self.current_region = self.current_region.move(step_x, step_y)
101
102+ def rotate(self, rotate):
103+ region = Region(self.current_region.x, self.current_region.y,
104+ self.current_region.width, self.current_region.height,
105+ rotate)
106+ self.current_animation = Animation(
107+ self.current_region, region, 0.2, linear_interpolation)
108+
109 @property
110 def last_region(self):
111 return self.view_status == len(self.presentation.get_path()) - 1
112@@ -118,6 +140,10 @@
113 Player.zoom_out(self, translation)
114 self._set_timer()
115
116+ def rotate(self, radians):
117+ Player.rotate(self, radians)
118+ self._set_timer()
119+
120 def move(self, stepx, stepy):
121 stepx = self.current_region.width * (
122 stepx / self.area.window.get_size()[0])
123
124=== modified file 'ui/window_main.glade'
125--- ui/window_main.glade 2010-07-24 22:28:56 +0000
126+++ ui/window_main.glade 2010-07-30 07:10:58 +0000
127@@ -218,6 +218,25 @@
128 </packing>
129 </child>
130 <child>
131+ <object class="GtkToolItem" id="spin_rotation_item">
132+ <property name="visible">True</property>
133+ <child>
134+ <object class="GtkSpinButton" id="spin_rotation">
135+ <property name="visible">True</property>
136+ <property name="can_focus">True</property>
137+ <property name="invisible_char">&#x25CF;</property>
138+ <property name="adjustment">adjustment1</property>
139+ <property name="climb_rate">5</property>
140+ <property name="digits">2</property>
141+ <signal name="value_changed" handler="on_spin_rotation_value_changed"/>
142+ </object>
143+ </child>
144+ </object>
145+ <packing>
146+ <property name="expand">False</property>
147+ </packing>
148+ </child>
149+ <child>
150 <object class="GtkSeparatorToolItem" id="separator3">
151 <property name="visible">True</property>
152 </object>
153@@ -277,4 +296,11 @@
154 </object>
155 </child>
156 </object>
157+ <object class="GtkAdjustment" id="adjustment1">
158+ <property name="lower">-180</property>
159+ <property name="upper">180</property>
160+ <property name="step_increment">5</property>
161+ <property name="page_increment">10</property>
162+ <property name="page_size">10</property>
163+ </object>
164 </interface>

Subscribers

People subscribed via source and target branches