Commit b127973b authored by sumpfralle's avatar sumpfralle

added a "copy-to-clipboard" button to the memory analyzer plugin


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1245 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent b4262197
......@@ -115,6 +115,20 @@
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="MemoryAnalyzerCopyButton">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="MemoryAnalyzerRefreshButton">
<property name="label">gtk-refresh</property>
......@@ -126,7 +140,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
......@@ -140,7 +154,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
......@@ -153,6 +167,7 @@
</object>
</child>
<action-widgets>
<action-widget response="0">MemoryAnalyzerCopyButton</action-widget>
<action-widget response="0">MemoryAnalyzerRefreshButton</action-widget>
<action-widget response="0">MemoryAnalyzerCloseButton</action-widget>
</action-widgets>
......
......@@ -21,6 +21,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import StringIO
import csv
import gobject
import guppy
......@@ -30,7 +32,7 @@ import pycam.Plugins
class MemoryAnalyzer(pycam.Plugins.PluginBase):
UI_FILE = "memory_analyzer.ui"
DEPENDS = []
DEPENDS = ["Clipboard"]
CATEGORIES = ["System"]
def setup(self):
......@@ -55,6 +57,8 @@ class MemoryAnalyzer(pycam.Plugins.PluginBase):
(self.window, "destroy", hide_window),
(self.gui.get_object("MemoryAnalyzerCloseButton"),
"clicked", hide_window),
(self.gui.get_object("MemoryAnalyzerCopyButton"),
"clicked", self.copy_to_clipboard),
(self.gui.get_object("MemoryAnalyzerRefreshButton"),
"clicked", self.refresh_memory_analyzer)])
self.model = self.gui.get_object("MemoryAnalyzerModel")
......@@ -95,7 +99,9 @@ class MemoryAnalyzer(pycam.Plugins.PluginBase):
def refresh_memory_analyzer(self, widget=None):
self.model.clear()
self.gui.get_object("MemoryAnalyzerLoadingLabel").show()
self.gui.get_object("MemoryAnalyzerRefreshButton").set_sensitive(False)
for objname in ("MemoryAnalyzerRefreshButton",
"MemoryAnalyzerCopyButton"):
self.gui.get_object(objname).set_sensitive(False)
gobject.idle_add(self._refresh_data_in_background)
def _refresh_data_in_background(self):
......@@ -103,6 +109,18 @@ class MemoryAnalyzer(pycam.Plugins.PluginBase):
for row in memory_state.stat.get_rows():
item = (row.name, row.count, row.size / 1024, row.size / row.count)
self.model.append(item)
for objname in ("MemoryAnalyzerRefreshButton",
"MemoryAnalyzerCopyButton"):
self.gui.get_object(objname).set_sensitive(True)
self.gui.get_object("MemoryAnalyzerRefreshButton").set_sensitive(True)
self.gui.get_object("MemoryAnalyzerLoadingLabel").hide()
def copy_to_clipboard(self, widget=None):
text_buffer = StringIO.StringIO()
writer = csv.writer(text_buffer)
writer.writerow(("Type", "Count", "Size (all) [kB]", "Average size [B]"))
for row in self.model:
writer.writerow(row)
self.core.get("clipboard-set")(text_buffer.getvalue())
text_buffer.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment