Ticket #2701: 0001-Add-functionality-to-export-plots-to-clipboard.patch

File 0001-Add-functionality-to-export-plots-to-clipboard.patch, 5.7 KB (added by lionaneesh, 11 years ago)
  • calculate.py

    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): 
    416416            tree: the parsed tree, this will be used to set the label variable
    417417            so that the equation can be used symbolicaly.
    418418            """
    419 
    420419        if eq.equation is not None and len(eq.equation) > 0:
    421420            if prepend:
    422421                self.old_eqs.insert(0, eq)
    class Calculate(ShareableActivity): 
    733732        self.select_reason = self.SELECT_SELECT
    734733
    735734    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()
    738741 #       _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])
    742745
    743746    def get_clipboard_text(self):
    744747        text = self.clipboard.wait_for_text()
  • layout.py

    diff --git a/layout.py b/layout.py
    index 5a77357..50981ef 100644
    a b  
    11# layout.py, see calculate.py for info
     2# Copyright (C) 2012 Aneesh Dogra <lionaneesh@gmail.com>
    23
    34from gettext import gettext as _
    45import pygtk
    class CalcLayout: 
    3738        self._showing_history = True
    3839        self._showing_all_history = True
    3940        self._var_textviews = {}
     41        self.graph_selected = None
    4042
    4143        self.create_dialog()
    4244
    class CalcLayout: 
    295297        self.variable_vbox.hide()
    296298        self.history_vbox.show()
    297299
     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
    298315    def add_equation(self, textview, own, prepend=False):
    299316        """Add a gtk.TextView of an equation to the history_vbox."""
    300317
     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
    301327        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)
    304334        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)
    306339
    307340        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()
    310347        else:
    311             self._other_equations.append(textview)
    312348            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()
    314355
    315356    def show_all_history(self):
    316357        """Show both owned and other equations."""
    317358        self._showing_all_history = True
    318359        for key in self._other_equations:
    319             key.show()
     360            if isinstance(key, gtk.EventBox):
     361                key.child.show()
     362            else:
     363                key.show()
    320364
    321365    def show_own_history(self):
    322366        """Show only owned equations."""
    323367        self._showing_all_history = False
    324368        for key in self._other_equations:
    325             key.hide()
     369            if isinstance(key, gtk.EventBox):
     370                key.child.hide()
     371            else:
     372                key.hide()
    326373
    327374    def add_variable(self, varname, textview):
    328375        """Add a gtk.TextView of a variable to the variable_vbox."""