Skip to content

Commit

Permalink
new sexy lineedit widget with builtin clear button
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Dec 3, 2012
1 parent 4215ea7 commit 8cd52d0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 23 deletions.
60 changes: 60 additions & 0 deletions python/plugins/sextante/gui/FilterLineEdit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
FilterEdit.py
---------------------
Date : October 2012
Copyright : (C) 2012 by Alexander Bruy
Email : alexander dot bruy at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Alexander Bruy'
__date__ = 'October 2012'
__copyright__ = '(C) 2012, Alexander Bruy'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

from PyQt4.QtCore import *
from PyQt4.QtGui import *

import sextante.resources_rc

class FilterLineEdit(QLineEdit):
def __init__(self, parent=None, placeholder="Filter"):
QLineEdit.__init__(self, parent)

if hasattr(self, "setPlaceholderText"):
self.setPlaceholderText(placeholder)

self.btnClear = QToolButton(self)
self.btnClear.setIcon(QIcon(":/sextante/images/clear.png"))
self.btnClear.setCursor(Qt.ArrowCursor)
self.btnClear.setStyleSheet("QToolButton { border: none; padding: 0px; }")
self.btnClear.hide()

self.btnClear.clicked.connect(self.clear)
self.textChanged.connect(self.updateClearButton)

frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
self.setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(self.btnClear.sizeHint().width() + frameWidth + 1))
msz = self.minimumSizeHint()
self.setMinimumSize(max(msz.width(), self.btnClear.sizeHint().height() + frameWidth * 2 + 2),
max(msz.height(), self.btnClear.sizeHint().height() + frameWidth * 2 + 2))

def resizeEvent(self, event):
sz = self.btnClear.sizeHint()
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
self.btnClear.move(self.rect().right() - frameWidth - sz.width(),
(self.rect().bottom() + 1 - sz.height())/2)

def updateClearButton(self, text):
self.btnClear.setVisible(not text.isEmpty())
8 changes: 0 additions & 8 deletions python/plugins/sextante/gui/SextanteToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

from sextante.ui.ui_SextanteToolbox import Ui_SextanteToolbox

import sextante.resources_rc

try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
Expand All @@ -57,13 +55,10 @@ def __init__(self, iface):

self.iface=iface

self.btnClear.setIcon(QIcon(":/sextante/images/clear.png"))

self.externalAppsButton.clicked.connect(self.configureProviders)
self.searchBox.textChanged.connect(self.fillTree)
self.algorithmTree.customContextMenuRequested.connect(self.showPopupMenu)
self.algorithmTree.doubleClicked.connect(self.executeAlgorithm)
self.btnClear.clicked.connect(self.clearFilter)

self.fillTree()

Expand All @@ -73,9 +68,6 @@ def algsListHasChanged(self):
def updateTree(self):
Sextante.updateAlgsList()

def clearFilter(self):
self.searchBox.clear()

def configureProviders(self):
webbrowser.open("http://docs.qgis.org/html/en/user_manual/sextante/3rdParty.html")
#=======================================================================
Expand Down
23 changes: 8 additions & 15 deletions python/plugins/sextante/ui/SextanteToolbox.ui
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,7 @@ additional algorithm providers</string>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<item>
<widget class="QLineEdit" name="searchBox"/>
</item>
<item>
<widget class="QToolButton" name="btnClear">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
<widget class="FilterLineEdit" name="searchBox"/>
</item>
<item>
<widget class="QTreeWidget" name="algorithmTree">
Expand All @@ -64,6 +50,13 @@ additional algorithm providers</string>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>FilterLineEdit</class>
<extends>QLineEdit</extends>
<header>sextante.gui.FilterLineEdit</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

0 comments on commit 8cd52d0

Please sign in to comment.