Permalink
Browse files

ui: simplify the log display by removing the search functionality

This makes things the interface simpler by removing the rarely-used
search feature in the cola log gui.

Signed-off-by: David Aguilar <davvid@gmail.com>
  • Loading branch information...
davvid committed Mar 19, 2009
1 parent 7f714dc commit a3a86efe2db2ad029fdbfbacac24abde716f00fe
Showing with 10 additions and 163 deletions.
  1. +9 −101 cola/controllers/log.py
  2. +1 −62 ui/logger.ui
View
@@ -1,122 +1,30 @@
"""This module provides the controller for the log display
"""
+from PyQt4 import QtCore
from cola import qtutils
from cola.views import LogView
-from cola.qobserver import QObserver
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
def logger(model, parent):
- # TODO: subclass model
- model = model.clone()
- model.search_text = ''
- view = LogView(parent)
- ctl = LogController(model, view, parent)
- return ctl
+ """Returns an instance of a log controller"""
+ return LogController(model, parent)
-class LogController(QObserver):
+class LogController(object):
"""The output log controller"""
- def __init__(self, model, view, mainview):
- QObserver.__init__(self, model, view)
-
- self.add_observables('search_text')
- self.add_actions(search_text = self.insta_search)
- self.add_callbacks(clear_button = self.clear,
- next_button = self.next,
- prev_button = self.prev)
- self.connect(self.view.output_text,
- 'cursorPositionChanged()',
- self.cursor_position_changed)
-
- self._search_offset = 0
- self._main_view = mainview
-
- def insta_search(self, *rest):
- self._search_offset = 0
- txt = self.model.get_search_text().lower()
- if len(txt.strip()):
- self.next()
- else:
- cursor = self.view.output_text.textCursor()
- cursor.clearSelection()
- self.view.output_text.setTextCursor(cursor)
+ def __init__(self, model, parent):
+ self.model = model
+ self.view = LogView(parent)
+ self.parent = parent
def clear(self):
self.view.output_text.clear()
- self._search_offset = 0
-
- def next(self):
- text = self.model.get_search_text().lower().strip()
- if not text:
- return
- output = str(self.view.output_text.toPlainText())
- if self._search_offset + len(text) > len(output):
- title = unicode(self.tr('%s not found')) % text
- question = unicode(self.tr("Could not find '%s'.\n"
- 'Search from the beginning?')) % text
- if qtutils.question(self.view, title, question, default=False):
- self._search_offset = 0
- else:
- return
-
- find_in = output[self._search_offset:].lower()
- try:
- index = find_in.index(text)
- except:
- self._search_offset = 0
- title = unicode(self.tr("%s not found")) % text
- question = unicode(self.tr("Could not find '%s'.\n"
- 'Search from the beginning?')) % text
- if qtutils.question(self.view, title, question, default=False):
- self.next()
- return
- cursor = self.view.output_text.textCursor()
- offset = self._search_offset + index
- new_offset = offset + len(text)
-
- cursor.setPosition(offset)
- cursor.setPosition(new_offset, cursor.KeepAnchor)
-
- self.view.output_text.setTextCursor(cursor)
- self._search_offset = new_offset
-
- def prev(self):
- text = self.model.get_search_text().lower().strip()
- if not text:
- return
- output = str(self.view.output_text.toPlainText())
- if self._search_offset == 0:
- self._search_offset = len(output)
-
- find_in = output[:self._search_offset].lower()
- try:
- offset = find_in.rindex(text)
- except:
- self._search_offset = 0
- title = unicode(self.tr('%s not found')) % text
- question = unicode(self.tr("Could not find '%s'.\n"
- 'Search from the end?')) % text
- if qtutils.question(self.view, title, question):
- self.prev()
- return
- cursor = self.view.output_text.textCursor()
- new_offset = offset + len(text)
-
- cursor.setPosition(offset)
- cursor.setPosition(new_offset, cursor.KeepAnchor)
-
- self.view.output_text.setTextCursor(cursor)
- self._search_offset = offset
-
- def cursor_position_changed(self):
- cursor = self.view.output_text.textCursor()
- self._search_offset = cursor.selectionStart()
def log(self, status, output):
if not output:
return
self.view.log(output)
if self.model.should_display_log(status):
- self._main_view.display_log()
+ self.parent.display_log()
View
@@ -26,7 +26,7 @@
<number>6</number>
</property>
<property name="bottomMargin" >
- <number>2</number>
+ <number>0</number>
</property>
<item>
<widget class="QTextEdit" name="output_text" >
@@ -56,67 +56,6 @@
</property>
</widget>
</item>
- <item>
- <layout class="QHBoxLayout" name="search_layout" >
- <item>
- <widget class="QLabel" name="label" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text" >
- <string>Search</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="search_text" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
- <horstretch>1</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QPushButton" name="next_button" >
- <property name="text" >
- <string>Next</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="prev_button" >
- <property name="text" >
- <string>Previous</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="clear_button" >
- <property name="text" >
- <string>Clear</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
</layout>
</widget>
<tabstops>

0 comments on commit a3a86ef

Please sign in to comment.