From 8fd4337915f21fc3216e9b84a744543e4524224a Mon Sep 17 00:00:00 2001
From: Aneesh Dogra <lionaneesh@gmail.com>
Date: Thu, 6 Dec 2012 01:21:14 +0530
Subject: [PATCH] Add functionality to export plots to clipboard.
Fix #2701
---
calculate.py | 15 ++++++++------
layout.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 65 insertions(+), 15 deletions(-)
diff --git a/calculate.py b/calculate.py
index 79f362f..7ee58a4 100644
a
|
b
|
class Calculate(ShareableActivity): |
416 | 416 | tree: the parsed tree, this will be used to set the label variable |
417 | 417 | so that the equation can be used symbolicaly. |
418 | 418 | """ |
419 | | |
420 | 419 | if eq.equation is not None and len(eq.equation) > 0: |
421 | 420 | if prepend: |
422 | 421 | self.old_eqs.insert(0, eq) |
… |
… |
class Calculate(ShareableActivity): |
733 | 732 | self.select_reason = self.SELECT_SELECT |
734 | 733 | |
735 | 734 | def text_copy(self): |
736 | | str = self.text_entry.get_text() |
737 | | sel = self.text_entry.get_selection_bounds() |
| 735 | if self.layout.graph_selected is not None: |
| 736 | self.clipboard.set_image(self.layout.graph_selected.child.get_pixbuf()) |
| 737 | self.layout.toggle_select_graph(self.layout.graph_selected) |
| 738 | else: |
| 739 | str = self.text_entry.get_text() |
| 740 | sel = self.text_entry.get_selection_bounds() |
738 | 741 | # _logger.info('text_copy, sel: %r, str: %s', sel, str) |
739 | | if len(sel) == 2: |
740 | | (start, end) = sel |
741 | | self.clipboard.set_text(str[start:end]) |
| 742 | if len(sel) == 2: |
| 743 | (start, end) = sel |
| 744 | self.clipboard.set_text(str[start:end]) |
742 | 745 | |
743 | 746 | def get_clipboard_text(self): |
744 | 747 | text = self.clipboard.wait_for_text() |
diff --git a/layout.py b/layout.py
index 5a77357..50981ef 100644
a
|
b
|
|
1 | 1 | # layout.py, see calculate.py for info |
| 2 | # Copyright (C) 2012 Aneesh Dogra <lionaneesh@gmail.com> |
2 | 3 | |
3 | 4 | from gettext import gettext as _ |
4 | 5 | import pygtk |
… |
… |
class CalcLayout: |
37 | 38 | self._showing_history = True |
38 | 39 | self._showing_all_history = True |
39 | 40 | self._var_textviews = {} |
| 41 | self.graph_selected = None |
40 | 42 | |
41 | 43 | self.create_dialog() |
42 | 44 | |
… |
… |
class CalcLayout: |
295 | 297 | self.variable_vbox.hide() |
296 | 298 | self.history_vbox.show() |
297 | 299 | |
| 300 | def toggle_select_graph(self, widget, host=None): |
| 301 | # if we have a graph already selected, we must deselect it first |
| 302 | if self.graph_selected and self.graph_selected != widget: |
| 303 | self.toggle_select_graph(self.graph_selected) |
| 304 | |
| 305 | if not self.graph_selected: |
| 306 | widget.set_visible_window(True) |
| 307 | widget.set_above_child(True) |
| 308 | self.graph_selected = widget |
| 309 | white = gtk.gdk.color_parse('white') |
| 310 | widget.modify_bg(gtk.STATE_NORMAL, white) |
| 311 | else: |
| 312 | widget.set_visible_window(False) |
| 313 | self.graph_selected = False |
| 314 | |
298 | 315 | def add_equation(self, textview, own, prepend=False): |
299 | 316 | """Add a gtk.TextView of an equation to the history_vbox.""" |
300 | 317 | |
| 318 | GraphEventBox = None |
| 319 | if isinstance(textview, gtk.Image): |
| 320 | # Add the image inside the eventBox |
| 321 | GraphEventBox = gtk.EventBox() |
| 322 | GraphEventBox.add(textview) |
| 323 | GraphEventBox.set_visible_window(False) |
| 324 | GraphEventBox.connect('button_press_event', self.toggle_select_graph) |
| 325 | GraphEventBox.show() |
| 326 | |
301 | 327 | if prepend: |
302 | | self.history_vbox.pack_start(textview, False, True) |
303 | | self.history_vbox.reorder_child(textview, 0) |
| 328 | if GraphEventBox: |
| 329 | self.history_vbox.pack_start(GraphEventBox, False, True) |
| 330 | self.history_vbox.reorder_child(GraphEventBox, 0) |
| 331 | else: |
| 332 | self.history_vbox.pack_start(textview, False, True) |
| 333 | self.history_vbox.reorder_child(textview, 0) |
304 | 334 | else: |
305 | | self.history_vbox.pack_end(textview, False, True) |
| 335 | if GraphEventBox: |
| 336 | self.history_vbox.pack_end(GraphEventBox, False, True) |
| 337 | else: |
| 338 | self.history_vbox.pack_end(textview, False, True) |
306 | 339 | |
307 | 340 | if own: |
308 | | self._own_equations.append(textview) |
309 | | textview.show() |
| 341 | if GraphEventBox: |
| 342 | self._own_equations.append(GraphEventBox) |
| 343 | GraphEventBox.child.show() |
| 344 | else: |
| 345 | self._own_equations.append(textview) |
| 346 | textview.show() |
310 | 347 | else: |
311 | | self._other_equations.append(textview) |
312 | 348 | if self._showing_all_history: |
313 | | textview.show() |
| 349 | if GraphEventBox: |
| 350 | self._other_equations.append(GraphEventBox) |
| 351 | GraphEventBox.child.show() |
| 352 | else: |
| 353 | self._other_equations.append(textview) |
| 354 | textview.show() |
314 | 355 | |
315 | 356 | def show_all_history(self): |
316 | 357 | """Show both owned and other equations.""" |
317 | 358 | self._showing_all_history = True |
318 | 359 | for key in self._other_equations: |
319 | | key.show() |
| 360 | if isinstance(key, gtk.EventBox): |
| 361 | key.child.show() |
| 362 | else: |
| 363 | key.show() |
320 | 364 | |
321 | 365 | def show_own_history(self): |
322 | 366 | """Show only owned equations.""" |
323 | 367 | self._showing_all_history = False |
324 | 368 | for key in self._other_equations: |
325 | | key.hide() |
| 369 | if isinstance(key, gtk.EventBox): |
| 370 | key.child.hide() |
| 371 | else: |
| 372 | key.hide() |
326 | 373 | |
327 | 374 | def add_variable(self, varname, textview): |
328 | 375 | """Add a gtk.TextView of a variable to the variable_vbox.""" |