Stefan Schuermans commited on 2020-07-28 19:32:14
Showing 1 changed files, with 20 additions and 3 deletions.
... | ... |
@@ -14,9 +13,10 @@ import uproctrace.processes |
14 | 13 |
|
15 | 14 |
# pylint: disable=C0411 |
16 | 15 |
import gi |
16 |
+gi.require_version('Gdk', '3.0') |
|
17 | 17 |
gi.require_version('Gtk', '3.0') |
18 | 18 |
# pylint: disable=C0413 |
19 |
-from gi.repository import Gtk |
|
19 |
+from gi.repository import Gdk, Gtk |
|
20 | 20 |
|
21 | 21 |
|
22 | 22 |
def cmdline2str(cmdline: list) -> str: |
... | ... |
@@ -126,6 +126,7 @@ class UptGui: |
126 | 126 |
""" |
127 | 127 |
self.builder = Gtk.Builder() |
128 | 128 |
self.builder.add_from_string(uproctrace.gui_glade.DATA) |
129 |
+ self.clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) |
|
129 | 130 |
self.wid_details_tree = self.builder.get_object('DetailsTree') |
130 | 131 |
self.wid_details_view = self.builder.get_object('DetailsView') |
131 | 132 |
self.wid_processes_tree = self.builder.get_object('ProcessesTree') |
... | ... |
@@ -149,16 +150,31 @@ class UptGui: |
149 | 150 |
""" |
150 | 151 |
Row in details view has been activated. |
151 | 152 |
""" |
152 |
- # get proc_id of selected row (if any) |
|
153 |
+ # get selected row (if any) |
|
153 | 154 |
detail_sel = self.wid_details_view.get_selection() |
154 | 155 |
if detail_sel is None: |
155 | 156 |
return |
156 | 157 |
detail_iter = detail_sel.get_selected()[1] |
157 | 158 |
if detail_iter is None: |
158 | 159 |
return |
160 |
+ # copy string of selected item or subtree to clipboard |
|
161 |
+ string = self.wid_details_tree.get_value(detail_iter, |
|
162 |
+ self.DETAIL_VALUE) |
|
163 |
+ child_iter = self.wid_details_tree.iter_children(detail_iter) |
|
164 |
+ if child_iter is not None: |
|
165 |
+ # selected row has children, assemble command line from children |
|
166 |
+ strings = [] |
|
167 |
+ while child_iter is not None: |
|
168 |
+ strings.append( |
|
169 |
+ self.wid_details_tree.get_value(child_iter, |
|
170 |
+ self.DETAIL_VALUE)) |
|
171 |
+ child_iter = self.wid_details_tree.iter_next(child_iter) |
|
172 |
+ string = cmdline2str(strings) |
|
173 |
+ self.clipboard.set_text(string, -1) |
|
174 |
+ self.clipboard.store() |
|
175 |
+ # get proc_id of selected row, nothing else to do if none |
|
159 | 176 |
proc_id = self.wid_details_tree.get_value(detail_iter, |
160 | 177 |
self.DETAIL_PROC_ID) |
161 |
- # do nothing for rows without valid proc_id |
|
162 | 178 |
if proc_id < 0: |
163 | 179 |
return |
164 | 180 |
# select process |
165 | 181 |