|
36 | 36 | backend_version = "%s.%s.%s" % ( |
37 | 37 | Gtk.get_major_version(), Gtk.get_micro_version(), Gtk.get_minor_version()) |
38 | 38 |
|
39 | | -# the true dots per inch on the screen; should be display dependent |
40 | | -# see http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5 for some info about screen dpi |
41 | | -PIXELS_PER_INCH = 96 |
42 | | - |
43 | 39 | try: |
44 | 40 | cursord = { |
45 | | - cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR), |
46 | | - cursors.HAND : Gdk.Cursor.new(Gdk.CursorType.HAND2), |
47 | | - cursors.POINTER : Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR), |
48 | | - cursors.SELECT_REGION : Gdk.Cursor.new(Gdk.CursorType.TCROSS), |
49 | | - cursors.WAIT : Gdk.Cursor.new(Gdk.CursorType.WATCH), |
| 41 | + cursors.MOVE: Gdk.Cursor.new(Gdk.CursorType.FLEUR), |
| 42 | + cursors.HAND: Gdk.Cursor.new(Gdk.CursorType.HAND2), |
| 43 | + cursors.POINTER: Gdk.Cursor.new(Gdk.CursorType.LEFT_PTR), |
| 44 | + cursors.SELECT_REGION: Gdk.Cursor.new(Gdk.CursorType.TCROSS), |
| 45 | + cursors.WAIT: Gdk.Cursor.new(Gdk.CursorType.WATCH), |
50 | 46 | } |
51 | 47 | except TypeError as exc: |
52 | 48 | # Happens when running headless. Convert to ImportError to cooperate with |
@@ -154,23 +150,23 @@ class FigureCanvasGTK3(Gtk.DrawingArea, FigureCanvasBase): |
154 | 150 |
|
155 | 151 | # Setting this as a static constant prevents |
156 | 152 | # this resulting expression from leaking |
157 | | - event_mask = (Gdk.EventMask.BUTTON_PRESS_MASK | |
158 | | - Gdk.EventMask.BUTTON_RELEASE_MASK | |
159 | | - Gdk.EventMask.EXPOSURE_MASK | |
160 | | - Gdk.EventMask.KEY_PRESS_MASK | |
161 | | - Gdk.EventMask.KEY_RELEASE_MASK | |
162 | | - Gdk.EventMask.ENTER_NOTIFY_MASK | |
163 | | - Gdk.EventMask.LEAVE_NOTIFY_MASK | |
164 | | - Gdk.EventMask.POINTER_MOTION_MASK | |
165 | | - Gdk.EventMask.POINTER_MOTION_HINT_MASK| |
166 | | - Gdk.EventMask.SCROLL_MASK) |
| 153 | + event_mask = (Gdk.EventMask.BUTTON_PRESS_MASK |
| 154 | + | Gdk.EventMask.BUTTON_RELEASE_MASK |
| 155 | + | Gdk.EventMask.EXPOSURE_MASK |
| 156 | + | Gdk.EventMask.KEY_PRESS_MASK |
| 157 | + | Gdk.EventMask.KEY_RELEASE_MASK |
| 158 | + | Gdk.EventMask.ENTER_NOTIFY_MASK |
| 159 | + | Gdk.EventMask.LEAVE_NOTIFY_MASK |
| 160 | + | Gdk.EventMask.POINTER_MOTION_MASK |
| 161 | + | Gdk.EventMask.POINTER_MOTION_HINT_MASK |
| 162 | + | Gdk.EventMask.SCROLL_MASK) |
167 | 163 |
|
168 | 164 | def __init__(self, figure): |
169 | 165 | FigureCanvasBase.__init__(self, figure) |
170 | 166 | GObject.GObject.__init__(self) |
171 | 167 |
|
172 | | - self._idle_draw_id = 0 |
173 | | - self._lastCursor = None |
| 168 | + self._idle_draw_id = 0 |
| 169 | + self._lastCursor = None |
174 | 170 |
|
175 | 171 | self.connect('scroll_event', self.scroll_event) |
176 | 172 | self.connect('button_press_event', self.button_press_event) |
@@ -200,25 +196,24 @@ def scroll_event(self, widget, event): |
200 | 196 | x = event.x |
201 | 197 | # flipy so y=0 is bottom of canvas |
202 | 198 | y = self.get_allocation().height - event.y |
203 | | - if event.direction==Gdk.ScrollDirection.UP: |
204 | | - step = 1 |
205 | | - else: |
206 | | - step = -1 |
| 199 | + step = 1 if event.direction == Gdk.ScrollDirection.UP else -1 |
207 | 200 | FigureCanvasBase.scroll_event(self, x, y, step, guiEvent=event) |
208 | 201 | return False # finish event propagation? |
209 | 202 |
|
210 | 203 | def button_press_event(self, widget, event): |
211 | 204 | x = event.x |
212 | 205 | # flipy so y=0 is bottom of canvas |
213 | 206 | y = self.get_allocation().height - event.y |
214 | | - FigureCanvasBase.button_press_event(self, x, y, event.button, guiEvent=event) |
| 207 | + FigureCanvasBase.button_press_event( |
| 208 | + self, x, y, event.button, guiEvent=event) |
215 | 209 | return False # finish event propagation? |
216 | 210 |
|
217 | 211 | def button_release_event(self, widget, event): |
218 | 212 | x = event.x |
219 | 213 | # flipy so y=0 is bottom of canvas |
220 | 214 | y = self.get_allocation().height - event.y |
221 | | - FigureCanvasBase.button_release_event(self, x, y, event.button, guiEvent=event) |
| 215 | + FigureCanvasBase.button_release_event( |
| 216 | + self, x, y, event.button, guiEvent=event) |
222 | 217 | return False # finish event propagation? |
223 | 218 |
|
224 | 219 | def key_press_event(self, widget, event): |
@@ -472,7 +467,8 @@ def set_cursor(self, cursor): |
472 | 467 | Gtk.main_iteration() |
473 | 468 |
|
474 | 469 | def draw_rubberband(self, event, x0, y0, x1, y1): |
475 | | - 'adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744' |
| 470 | + # adapted from |
| 471 | + # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744 |
476 | 472 | self.ctx = self.canvas.get_property("window").cairo_create() |
477 | 473 |
|
478 | 474 | # todo: instead of redrawing the entire figure, copy the part of |
@@ -622,14 +618,14 @@ class FileChooserDialog(Gtk.FileChooserDialog): |
622 | 618 | selected and presents the user with a menu of supported image formats |
623 | 619 | """ |
624 | 620 | def __init__(self, |
625 | | - title = 'Save file', |
626 | | - parent = None, |
627 | | - action = Gtk.FileChooserAction.SAVE, |
628 | | - buttons = (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, |
629 | | - Gtk.STOCK_SAVE, Gtk.ResponseType.OK), |
630 | | - path = None, |
631 | | - filetypes = [], |
632 | | - default_filetype = None, |
| 621 | + title='Save file', |
| 622 | + parent=None, |
| 623 | + action=Gtk.FileChooserAction.SAVE, |
| 624 | + buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, |
| 625 | + Gtk.STOCK_SAVE, Gtk.ResponseType.OK), |
| 626 | + path=None, |
| 627 | + filetypes=[], |
| 628 | + default_filetype=None, |
633 | 629 | ): |
634 | 630 | super().__init__(title, parent, action, buttons) |
635 | 631 | self.set_default_response(Gtk.ResponseType.OK) |
@@ -961,15 +957,11 @@ def error_msg_gtk(msg, parent=None): |
961 | 957 | parent = parent.get_toplevel() |
962 | 958 | if not parent.is_toplevel(): |
963 | 959 | parent = None |
964 | | - |
965 | 960 | if not isinstance(msg, str): |
966 | 961 | msg = ','.join(map(str, msg)) |
967 | | - |
968 | 962 | dialog = Gtk.MessageDialog( |
969 | | - parent = parent, |
970 | | - type = Gtk.MessageType.ERROR, |
971 | | - buttons = Gtk.ButtonsType.OK, |
972 | | - message_format = msg) |
| 963 | + parent=parent, type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK, |
| 964 | + message_format=msg) |
973 | 965 | dialog.run() |
974 | 966 | dialog.destroy() |
975 | 967 |
|
|
0 commit comments