Skip to content
This repository
Browse code

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...
commit a3a86efe2db2ad029fdbfbacac24abde716f00fe 1 parent 7f714dc
David Aguilar authored
110  cola/controllers/log.py
... ...
@@ -1,122 +1,30 @@
1 1
 """This module provides the controller for the log display
2 2
 
3 3
 """
  4
+from PyQt4 import QtCore
4 5
 
5 6
 from cola import qtutils
6 7
 from cola.views import LogView
7  
-from cola.qobserver import QObserver
8 8
 
9 9
 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 10
 def logger(model, parent):
11  
-    # TODO: subclass model
12  
-    model = model.clone()
13  
-    model.search_text = ''
14  
-    view = LogView(parent)
15  
-    ctl = LogController(model, view, parent)
16  
-    return ctl
  11
+    """Returns an instance of a log controller"""
  12
+    return LogController(model, parent)
17 13
 
18  
-class LogController(QObserver):
  14
+class LogController(object):
19 15
     """The output log controller"""
20 16
 
21  
-    def __init__(self, model, view, mainview):
22  
-        QObserver.__init__(self, model, view)
23  
-
24  
-        self.add_observables('search_text')
25  
-        self.add_actions(search_text = self.insta_search)
26  
-        self.add_callbacks(clear_button = self.clear,
27  
-                           next_button = self.next,
28  
-                           prev_button = self.prev)
29  
-        self.connect(self.view.output_text,
30  
-                     'cursorPositionChanged()',
31  
-                     self.cursor_position_changed)
32  
-
33  
-        self._search_offset = 0
34  
-        self._main_view = mainview
35  
-
36  
-    def insta_search(self, *rest):
37  
-        self._search_offset = 0
38  
-        txt = self.model.get_search_text().lower()
39  
-        if len(txt.strip()):
40  
-            self.next()
41  
-        else:
42  
-            cursor = self.view.output_text.textCursor()
43  
-            cursor.clearSelection()
44  
-            self.view.output_text.setTextCursor(cursor)
  17
+    def __init__(self, model, parent):
  18
+        self.model = model
  19
+        self.view = LogView(parent)
  20
+        self.parent = parent
45 21
 
46 22
     def clear(self):
47 23
         self.view.output_text.clear()
48  
-        self._search_offset = 0
49  
-
50  
-    def next(self):
51  
-        text = self.model.get_search_text().lower().strip()
52  
-        if not text:
53  
-            return
54  
-        output = str(self.view.output_text.toPlainText())
55  
-        if self._search_offset + len(text) > len(output):
56  
-            title = unicode(self.tr('%s not found')) % text
57  
-            question = unicode(self.tr("Could not find '%s'.\n"
58  
-                                       'Search from the beginning?')) % text
59  
-            if qtutils.question(self.view, title, question, default=False):
60  
-                self._search_offset = 0
61  
-            else:
62  
-                return
63  
-
64  
-        find_in = output[self._search_offset:].lower()
65  
-        try:
66  
-            index = find_in.index(text)
67  
-        except:
68  
-            self._search_offset = 0
69  
-            title = unicode(self.tr("%s not found")) % text
70  
-            question = unicode(self.tr("Could not find '%s'.\n"
71  
-                                       'Search from the beginning?')) % text
72  
-            if qtutils.question(self.view, title, question, default=False):
73  
-                self.next()
74  
-            return
75  
-        cursor = self.view.output_text.textCursor()
76  
-        offset = self._search_offset + index
77  
-        new_offset = offset + len(text)
78  
-
79  
-        cursor.setPosition(offset)
80  
-        cursor.setPosition(new_offset, cursor.KeepAnchor)
81  
-
82  
-        self.view.output_text.setTextCursor(cursor)
83  
-        self._search_offset = new_offset
84  
-
85  
-    def prev(self):
86  
-        text = self.model.get_search_text().lower().strip()
87  
-        if not text:
88  
-            return
89  
-        output = str(self.view.output_text.toPlainText())
90  
-        if self._search_offset == 0:
91  
-            self._search_offset = len(output)
92  
-
93  
-        find_in = output[:self._search_offset].lower()
94  
-        try:
95  
-            offset = find_in.rindex(text)
96  
-        except:
97  
-            self._search_offset = 0
98  
-            title = unicode(self.tr('%s not found')) % text
99  
-            question = unicode(self.tr("Could not find '%s'.\n"
100  
-                                       'Search from the end?')) % text
101  
-            if qtutils.question(self.view, title, question):
102  
-                self.prev()
103  
-            return
104  
-        cursor = self.view.output_text.textCursor()
105  
-        new_offset = offset + len(text)
106  
-
107  
-        cursor.setPosition(offset)
108  
-        cursor.setPosition(new_offset, cursor.KeepAnchor)
109  
-
110  
-        self.view.output_text.setTextCursor(cursor)
111  
-        self._search_offset = offset
112  
-
113  
-    def cursor_position_changed(self):
114  
-        cursor = self.view.output_text.textCursor()
115  
-        self._search_offset = cursor.selectionStart()
116 24
 
117 25
     def log(self, status, output):
118 26
         if not output:
119 27
             return
120 28
         self.view.log(output)
121 29
         if self.model.should_display_log(status):
122  
-            self._main_view.display_log()
  30
+            self.parent.display_log()
63  ui/logger.ui
@@ -26,7 +26,7 @@
26 26
     <number>6</number>
27 27
    </property>
28 28
    <property name="bottomMargin" >
29  
-    <number>2</number>
  29
+    <number>0</number>
30 30
    </property>
31 31
    <item>
32 32
     <widget class="QTextEdit" name="output_text" >
@@ -56,67 +56,6 @@
56 56
      </property>
57 57
     </widget>
58 58
    </item>
59  
-   <item>
60  
-    <layout class="QHBoxLayout" name="search_layout" >
61  
-     <item>
62  
-      <widget class="QLabel" name="label" >
63  
-       <property name="sizePolicy" >
64  
-        <sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
65  
-         <horstretch>0</horstretch>
66  
-         <verstretch>0</verstretch>
67  
-        </sizepolicy>
68  
-       </property>
69  
-       <property name="text" >
70  
-        <string>Search</string>
71  
-       </property>
72  
-      </widget>
73  
-     </item>
74  
-     <item>
75  
-      <widget class="QLineEdit" name="search_text" >
76  
-       <property name="sizePolicy" >
77  
-        <sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
78  
-         <horstretch>1</horstretch>
79  
-         <verstretch>0</verstretch>
80  
-        </sizepolicy>
81  
-       </property>
82  
-      </widget>
83  
-     </item>
84  
-     <item>
85  
-      <spacer name="horizontalSpacer" >
86  
-       <property name="orientation" >
87  
-        <enum>Qt::Horizontal</enum>
88  
-       </property>
89  
-       <property name="sizeHint" stdset="0" >
90  
-        <size>
91  
-         <width>40</width>
92  
-         <height>20</height>
93  
-        </size>
94  
-       </property>
95  
-      </spacer>
96  
-     </item>
97  
-     <item>
98  
-      <widget class="QPushButton" name="next_button" >
99  
-       <property name="text" >
100  
-        <string>Next</string>
101  
-       </property>
102  
-      </widget>
103  
-     </item>
104  
-     <item>
105  
-      <widget class="QPushButton" name="prev_button" >
106  
-       <property name="text" >
107  
-        <string>Previous</string>
108  
-       </property>
109  
-      </widget>
110  
-     </item>
111  
-     <item>
112  
-      <widget class="QPushButton" name="clear_button" >
113  
-       <property name="text" >
114  
-        <string>Clear</string>
115  
-       </property>
116  
-      </widget>
117  
-     </item>
118  
-    </layout>
119  
-   </item>
120 59
   </layout>
121 60
  </widget>
122 61
  <tabstops>

0 notes on commit a3a86ef

Please sign in to comment.
Something went wrong with that request. Please try again.