ability to edit queries

This commit is contained in:
Romain Bignon 2012-02-18 12:56:11 +01:00
commit c8b6c7087b
4 changed files with 75 additions and 33 deletions

View file

@ -49,6 +49,7 @@ class MainWindow(QtMainWindow):
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
self.connect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
self.connect(self.ui.addQueryButton, SIGNAL('clicked()'), self.addQuery)
self.connect(self.ui.editQueryButton, SIGNAL('clicked()'), self.editQuery)
self.connect(self.ui.bookmarksButton, SIGNAL('clicked()'), self.displayBookmarks)
self.connect(self.ui.housingsList, SIGNAL('itemClicked(QListWidgetItem*)'), self.housingSelected)
self.connect(self.ui.previousButton, SIGNAL('clicked()'), self.previousClicked)
@ -61,6 +62,9 @@ class MainWindow(QtMainWindow):
if self.weboob.count_backends() == 0:
self.backendsConfig()
if len(self.config.get('queries')) == 0:
self.addQuery()
def backendsConfig(self):
bckndcfg = BackendCfg(self.weboob, (ICapHousing,), self)
if bckndcfg.run():
@ -69,14 +73,43 @@ class MainWindow(QtMainWindow):
def reloadQueriesList(self, select_name=None):
self.disconnect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
self.ui.queriesList.clear()
to_select = None
for name in self.config.get('queries', default={}).iterkeys():
self.ui.queriesList.addItem(name)
if name == select_name:
self.ui.queriesList.setCurrentIndex(len(self.ui.queriesList)-1)
to_select = len(self.ui.queriesList)-1
self.connect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
def addQuery(self):
if to_select is not None:
self.ui.queriesList.setCurrentIndex(to_select)
def editQuery(self):
name = unicode(self.ui.queriesList.itemText(self.ui.queriesList.currentIndex()))
self.addQuery(name)
self.queryChanged()
def addQuery(self, name=None):
querydlg = QueryDialog(self.weboob, self)
if name is not None:
query = self.config.get('queries', name)
querydlg.ui.nameEdit.setText(name)
querydlg.ui.nameEdit.setEnabled(False)
for c in query['cities']:
city = City(c['id'])
city.backend = c['backend']
city.name = c['name']
item = querydlg.buildCityItem(city)
querydlg.ui.citiesList.addItem(item)
querydlg.ui.areaMin.setValue(query['area_min'])
querydlg.ui.areaMax.setValue(query['area_max'])
querydlg.ui.costMin.setValue(query['cost_min'])
querydlg.ui.costMax.setValue(query['cost_max'])
for i in xrange(querydlg.ui.nbRooms.count()):
if querydlg.ui.nbRooms.itemText(i) == str(query['nb_rooms']):
querydlg.ui.nbRooms.setCurrentIndex(i)
break
if querydlg.exec_():
name = unicode(querydlg.ui.nameEdit.text())
query = {}
@ -98,7 +131,7 @@ class MainWindow(QtMainWindow):
self.reloadQueriesList(name)
def queryChanged(self, i):
def queryChanged(self, i=None):
self.refreshHousingsList()
def refreshHousingsList(self):
@ -198,6 +231,9 @@ class MainWindow(QtMainWindow):
except KeyError:
pass
if not housing.photos:
return False
img = None
for photo in housing.photos:
if photo.data:
@ -262,30 +298,30 @@ class MainWindow(QtMainWindow):
self.storage.save()
def previousClicked(self):
if len(self.housing.photos) == 0:
if not self.housing.photos or len(self.housing.photos) == 0:
return
self.displayed_photo_idx = (self.displayed_photo_idx - 1) % len(self.housing.photos)
self.display_photo()
def nextClicked(self):
if len(self.housing.photos) == 0:
if not self.housing.photos or len(self.housing.photos) == 0:
return
self.displayed_photo_idx = (self.displayed_photo_idx + 1) % len(self.housing.photos)
self.display_photo()
def display_photo(self):
if not self.housing.photos:
self.ui.photoUrlLabel.setText('')
self.ui.photoLabel.setText('')
self.ui.photosFrame.hide()
return
if self.displayed_photo_idx >= len(self.housing.photos):
self.displayed_photo_idx = len(self.housing.photos) - 1
if self.displayed_photo_idx < 0:
self.ui.photoLabel.setText('')
self.ui.photoUrlLabel.setText('')
self.ui.photosFrame.hide()
return
self.ui.photosFrame.show()
photo = self.housing.photos[self.displayed_photo_idx]
if photo.data:
data = photo.data

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from PyQt4.QtGui import QDialog, QListWidgetItem
from PyQt4.QtGui import QDialog, QListWidgetItem, QMessageBox
from PyQt4.QtCore import SIGNAL, Qt
from weboob.tools.application.qt import QtDo, HTMLDelegate
@ -39,6 +39,7 @@ class QueryDialog(QDialog):
self.connect(self.ui.cityEdit, SIGNAL('returnPressed()'), self.searchCity)
self.connect(self.ui.resultsList, SIGNAL('itemDoubleClicked(QListWidgetItem*)'), self.insertCity)
self.connect(self.ui.citiesList, SIGNAL('itemDoubleClicked(QListWidgetItem*)'), self.removeCity)
self.connect(self.ui.buttonBox, SIGNAL('accepted()'), self.okButton)
def keyPressEvent(self, event):
"""
@ -60,12 +61,16 @@ class QueryDialog(QDialog):
self.search_process = None
self.ui.cityEdit.setEnabled(True)
return
item = QListWidgetItem()
item.setText('<b>%s</b> (%s)' % (city.name, backend.name))
item.setData(Qt.UserRole, city)
item = self.buildCityItem(city)
self.ui.resultsList.addItem(item)
self.ui.resultsList.sortItems()
def buildCityItem(self, city):
item = QListWidgetItem()
item.setText('<b>%s</b> (%s)' % (city.name, city.backend))
item.setData(Qt.UserRole, city)
return item
def insertCity(self, i):
item = QListWidgetItem()
item.setText(i.text())
@ -73,5 +78,15 @@ class QueryDialog(QDialog):
self.ui.citiesList.addItem(item)
def removeCity(self, item):
print item
self.ui.citiesList.removeItemWidget(item)
def okButton(self):
if not self.ui.nameEdit.text():
QMessageBox.critical(self, self.tr('Error'), self.tr('Please enter a name to your query.'), QMessageBox.Ok)
return
if self.ui.citiesList.count() == 0:
QMessageBox.critical(self, self.tr('Error'), self.tr('Please add at least one city.'), QMessageBox.Ok)
return
self.accept()

View file

@ -36,9 +36,6 @@
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="queriesList"/>
</item>
<item>
<widget class="QToolButton" name="addQueryButton">
<property name="text">
@ -46,6 +43,16 @@
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="queriesList"/>
</item>
<item>
<widget class="QToolButton" name="editQueryButton">
<property name="text">
<string>edit</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -296,7 +303,7 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QFrame" name="frame_3">
<widget class="QFrame" name="photosFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>

View file

@ -263,22 +263,6 @@
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QueryDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>