Skip to content

Commit

Permalink
add copy function
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias47n9e committed Jun 30, 2015
1 parent 6951bb9 commit 842b6af
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
7 changes: 2 additions & 5 deletions innstereo/gui_layout.glade
Original file line number Diff line number Diff line change
Expand Up @@ -4037,9 +4037,8 @@ customizable grid.</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="toolbutton8">
<object class="GtkToolButton" id="toolbutton_cut">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Cut</property>
<property name="use_underline">True</property>
Expand All @@ -4053,7 +4052,6 @@ customizable grid.</property>
<child>
<object class="GtkToolButton" id="toolbutton_copy">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Copy</property>
<property name="use_underline">True</property>
Expand All @@ -4066,9 +4064,8 @@ customizable grid.</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="toolbutton10">
<object class="GtkToolButton" id="toolbutton_paste">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Paste</property>
<property name="use_underline">True</property>
Expand Down
57 changes: 43 additions & 14 deletions innstereo/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def __init__(self, builder):
context = self.tb1.get_style_context()
context.add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)

#Clipboard
self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)

#Set up default options class
self.settings = PlotSettings()

Expand Down Expand Up @@ -112,23 +115,14 @@ def __init__(self, builder):
self.redraw_plot()
self.main_window.show_all()

def drag_begin(self, treeview, context):
def copy_layer(self):
"""
Drag begin signal of the layer view. Currently does nothing.
Copies the contents of a layer and all its children.
This signal could be used to set up a e.g. drag icon.
This method is called by the drag-and-drop and copy-paste functions.
It returns the data as JSON.
"""
pass

def drag_data_get(self, treeview, context, selection, info, time):
"""
Gets the data from the drag source. Serializes the data to JSON.
Iterates over the draged layer and all its children. Serializes the
path, properties and data. Encodes into JSON and sens it to the
drag destinations.
"""
tree_selection = treeview.get_selection()
tree_selection = self.layer_view.get_selection()
store, itr = tree_selection.get_selected_rows()
model = self.layer_view.get_model()
path = itr[0]
Expand Down Expand Up @@ -175,6 +169,25 @@ def iterate_over_store(model, path, itr, start_path):

self.layer_store.foreach(iterate_over_store, path_str)
data = json.dumps(copy)
return data

def drag_begin(self, treeview, context):
"""
Drag begin signal of the layer view. Currently does nothing.
This signal could be used to set up a e.g. drag icon.
"""
pass

def drag_data_get(self, treeview, context, selection, info, time):
"""
Gets the data from the drag source. Serializes the data to JSON.
Iterates over the draged layer and all its children. Serializes the
path, properties and data. Encodes into JSON and sens it to the
drag destinations.
"""
data = self.copy_layer()
selection.set(selection.get_target(), 8, data.encode())

def drag_drop(self, treeview, context, selection, info, time):
Expand Down Expand Up @@ -309,6 +322,22 @@ def drag_data_delete(self, treeview, context):
"""
pass

def on_toolbutton_copy_clicked(self, toolbutton):
"""
Copies the selected layer data into the Gdk.Clipboard.
The data is returned by the copy_layer method. It is returned as
JSON data.
"""
selection = self.layer_view.get_selection()
model, row_list = selection.get_selected_rows()

if len(row_list) == 0:
return

data = self.copy_layer()
self.clipboard.set_text(data, -1)

def on_menuitem_stereo_activate(self, widget):
# pylint: disable=unused-argument
"""
Expand Down

0 comments on commit 842b6af

Please sign in to comment.