Polishing things up
[ejpi] / src / qhistory.py
index 62d53e7..c67e719 100644 (file)
@@ -40,6 +40,7 @@ class QCalcHistory(history.AbstractHistory):
                self._historyView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
                self._historyView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
                self._historyView.setHeaderHidden(True)
+               self._historyView.activated.connect(self._on_row_activated)
 
                viewHeader = self._historyView.header()
                viewHeader.setSortIndicatorShown(True)
@@ -64,12 +65,19 @@ class QCalcHistory(history.AbstractHistory):
        def push(self, node):
                simpleNode = node.simplify()
 
-               icon = QtGui.QStandardItem(QtGui.QIcon.fromTheme("gtk-close"), "")
+               closeIcon = QtGui.QIcon.fromTheme("general_close")
+               if closeIcon.isNull():
+                       closeIcon = QtGui.QIcon.fromTheme("gtk-close")
+               icon = QtGui.QStandardItem(closeIcon, "")
                icon.setEditable(False)
+               icon.setCheckable(False)
                equation = QtGui.QStandardItem(operation.render_operation(self._prettyRenderer, node))
                equation.setData(node)
+               equation.setCheckable(False)
                result = QtGui.QStandardItem(operation.render_operation(self._prettyRenderer, simpleNode))
                result.setData(simpleNode)
+               result.setEditable(False)
+               result.setCheckable(False)
 
                row = (icon, equation, result)
                self._historyStore.appendRow(row)
@@ -101,6 +109,18 @@ class QCalcHistory(history.AbstractHistory):
                self._rowCount = 0
 
        @misc_utils.log_exception(_moduleLogger)
+       def _on_row_activated(self, index):
+               if index.column() == self._CLOSE_COLUMN:
+                       self._historyStore.removeRow(index.row(), index.parent())
+                       self._rowCount -= 1
+               elif index.column() == self._EQ_COLUMN:
+                       self._duplicate_row(index)
+               elif index.column() == self._RESULT_COLUMN:
+                       self._duplicate_row(index)
+               else:
+                       raise NotImplementedError("Unsupported column to activate %s" % index.column())
+
+       @misc_utils.log_exception(_moduleLogger)
        def _on_item_changed(self, item):
                if self._programmaticUpdate:
                        _moduleLogger.info("Blocking updating %r recursively" % item)
@@ -116,6 +136,10 @@ class QCalcHistory(history.AbstractHistory):
                finally:
                        self._programmaticUpdate = False
 
+       def _duplicate_row(self, index):
+               item = self._historyStore.item(index.row(), self._EQ_COLUMN)
+               self.push(item.data().toPyObject())
+
        def _parse_value(self, value):
                raise NotImplementedError("What?")
 
@@ -144,4 +168,7 @@ class QCalcHistory(history.AbstractHistory):
 
        def __iter__(self):
                for i in xrange(self._rowCount):
-                       yield self._historyStore.item(i, 1).data().toPyObject()
+                       item = self._historyStore.item(i, self._EQ_COLUMN)
+                       if item is None:
+                               continue
+                       yield item.data().toPyObject()