ability to edit queries
This commit is contained in:
parent
f340ac485e
commit
c8b6c7087b
4 changed files with 75 additions and 33 deletions
|
|
@ -49,6 +49,7 @@ class MainWindow(QtMainWindow):
|
||||||
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
|
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
|
||||||
self.connect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
|
self.connect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
|
||||||
self.connect(self.ui.addQueryButton, SIGNAL('clicked()'), self.addQuery)
|
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.bookmarksButton, SIGNAL('clicked()'), self.displayBookmarks)
|
||||||
self.connect(self.ui.housingsList, SIGNAL('itemClicked(QListWidgetItem*)'), self.housingSelected)
|
self.connect(self.ui.housingsList, SIGNAL('itemClicked(QListWidgetItem*)'), self.housingSelected)
|
||||||
self.connect(self.ui.previousButton, SIGNAL('clicked()'), self.previousClicked)
|
self.connect(self.ui.previousButton, SIGNAL('clicked()'), self.previousClicked)
|
||||||
|
|
@ -61,6 +62,9 @@ class MainWindow(QtMainWindow):
|
||||||
if self.weboob.count_backends() == 0:
|
if self.weboob.count_backends() == 0:
|
||||||
self.backendsConfig()
|
self.backendsConfig()
|
||||||
|
|
||||||
|
if len(self.config.get('queries')) == 0:
|
||||||
|
self.addQuery()
|
||||||
|
|
||||||
def backendsConfig(self):
|
def backendsConfig(self):
|
||||||
bckndcfg = BackendCfg(self.weboob, (ICapHousing,), self)
|
bckndcfg = BackendCfg(self.weboob, (ICapHousing,), self)
|
||||||
if bckndcfg.run():
|
if bckndcfg.run():
|
||||||
|
|
@ -69,14 +73,43 @@ class MainWindow(QtMainWindow):
|
||||||
def reloadQueriesList(self, select_name=None):
|
def reloadQueriesList(self, select_name=None):
|
||||||
self.disconnect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
|
self.disconnect(self.ui.queriesList, SIGNAL('currentIndexChanged(int)'), self.queryChanged)
|
||||||
self.ui.queriesList.clear()
|
self.ui.queriesList.clear()
|
||||||
|
to_select = None
|
||||||
for name in self.config.get('queries', default={}).iterkeys():
|
for name in self.config.get('queries', default={}).iterkeys():
|
||||||
self.ui.queriesList.addItem(name)
|
self.ui.queriesList.addItem(name)
|
||||||
if name == select_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)
|
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)
|
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_():
|
if querydlg.exec_():
|
||||||
name = unicode(querydlg.ui.nameEdit.text())
|
name = unicode(querydlg.ui.nameEdit.text())
|
||||||
query = {}
|
query = {}
|
||||||
|
|
@ -98,7 +131,7 @@ class MainWindow(QtMainWindow):
|
||||||
|
|
||||||
self.reloadQueriesList(name)
|
self.reloadQueriesList(name)
|
||||||
|
|
||||||
def queryChanged(self, i):
|
def queryChanged(self, i=None):
|
||||||
self.refreshHousingsList()
|
self.refreshHousingsList()
|
||||||
|
|
||||||
def refreshHousingsList(self):
|
def refreshHousingsList(self):
|
||||||
|
|
@ -198,6 +231,9 @@ class MainWindow(QtMainWindow):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if not housing.photos:
|
||||||
|
return False
|
||||||
|
|
||||||
img = None
|
img = None
|
||||||
for photo in housing.photos:
|
for photo in housing.photos:
|
||||||
if photo.data:
|
if photo.data:
|
||||||
|
|
@ -262,30 +298,30 @@ class MainWindow(QtMainWindow):
|
||||||
self.storage.save()
|
self.storage.save()
|
||||||
|
|
||||||
def previousClicked(self):
|
def previousClicked(self):
|
||||||
if len(self.housing.photos) == 0:
|
if not self.housing.photos or len(self.housing.photos) == 0:
|
||||||
return
|
return
|
||||||
self.displayed_photo_idx = (self.displayed_photo_idx - 1) % len(self.housing.photos)
|
self.displayed_photo_idx = (self.displayed_photo_idx - 1) % len(self.housing.photos)
|
||||||
self.display_photo()
|
self.display_photo()
|
||||||
|
|
||||||
def nextClicked(self):
|
def nextClicked(self):
|
||||||
if len(self.housing.photos) == 0:
|
if not self.housing.photos or len(self.housing.photos) == 0:
|
||||||
return
|
return
|
||||||
self.displayed_photo_idx = (self.displayed_photo_idx + 1) % len(self.housing.photos)
|
self.displayed_photo_idx = (self.displayed_photo_idx + 1) % len(self.housing.photos)
|
||||||
self.display_photo()
|
self.display_photo()
|
||||||
|
|
||||||
def display_photo(self):
|
def display_photo(self):
|
||||||
if not self.housing.photos:
|
if not self.housing.photos:
|
||||||
self.ui.photoUrlLabel.setText('')
|
self.ui.photosFrame.hide()
|
||||||
self.ui.photoLabel.setText('')
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.displayed_photo_idx >= len(self.housing.photos):
|
if self.displayed_photo_idx >= len(self.housing.photos):
|
||||||
self.displayed_photo_idx = len(self.housing.photos) - 1
|
self.displayed_photo_idx = len(self.housing.photos) - 1
|
||||||
if self.displayed_photo_idx < 0:
|
if self.displayed_photo_idx < 0:
|
||||||
self.ui.photoLabel.setText('')
|
self.ui.photosFrame.hide()
|
||||||
self.ui.photoUrlLabel.setText('')
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.ui.photosFrame.show()
|
||||||
|
|
||||||
photo = self.housing.photos[self.displayed_photo_idx]
|
photo = self.housing.photos[self.displayed_photo_idx]
|
||||||
if photo.data:
|
if photo.data:
|
||||||
data = photo.data
|
data = photo.data
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
# 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 PyQt4.QtCore import SIGNAL, Qt
|
||||||
|
|
||||||
from weboob.tools.application.qt import QtDo, HTMLDelegate
|
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.cityEdit, SIGNAL('returnPressed()'), self.searchCity)
|
||||||
self.connect(self.ui.resultsList, SIGNAL('itemDoubleClicked(QListWidgetItem*)'), self.insertCity)
|
self.connect(self.ui.resultsList, SIGNAL('itemDoubleClicked(QListWidgetItem*)'), self.insertCity)
|
||||||
self.connect(self.ui.citiesList, SIGNAL('itemDoubleClicked(QListWidgetItem*)'), self.removeCity)
|
self.connect(self.ui.citiesList, SIGNAL('itemDoubleClicked(QListWidgetItem*)'), self.removeCity)
|
||||||
|
self.connect(self.ui.buttonBox, SIGNAL('accepted()'), self.okButton)
|
||||||
|
|
||||||
def keyPressEvent(self, event):
|
def keyPressEvent(self, event):
|
||||||
"""
|
"""
|
||||||
|
|
@ -60,12 +61,16 @@ class QueryDialog(QDialog):
|
||||||
self.search_process = None
|
self.search_process = None
|
||||||
self.ui.cityEdit.setEnabled(True)
|
self.ui.cityEdit.setEnabled(True)
|
||||||
return
|
return
|
||||||
item = QListWidgetItem()
|
item = self.buildCityItem(city)
|
||||||
item.setText('<b>%s</b> (%s)' % (city.name, backend.name))
|
|
||||||
item.setData(Qt.UserRole, city)
|
|
||||||
self.ui.resultsList.addItem(item)
|
self.ui.resultsList.addItem(item)
|
||||||
self.ui.resultsList.sortItems()
|
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):
|
def insertCity(self, i):
|
||||||
item = QListWidgetItem()
|
item = QListWidgetItem()
|
||||||
item.setText(i.text())
|
item.setText(i.text())
|
||||||
|
|
@ -73,5 +78,15 @@ class QueryDialog(QDialog):
|
||||||
self.ui.citiesList.addItem(item)
|
self.ui.citiesList.addItem(item)
|
||||||
|
|
||||||
def removeCity(self, item):
|
def removeCity(self, item):
|
||||||
print item
|
|
||||||
self.ui.citiesList.removeItemWidget(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()
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,6 @@
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
|
||||||
<widget class="QComboBox" name="queriesList"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="addQueryButton">
|
<widget class="QToolButton" name="addQueryButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
@ -46,6 +43,16 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="queriesList"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="editQueryButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>edit</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
@ -296,7 +303,7 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QFrame" name="frame_3">
|
<widget class="QFrame" name="photosFrame">
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::StyledPanel</enum>
|
<enum>QFrame::StyledPanel</enum>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
|
|
@ -263,22 +263,6 @@
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<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>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>rejected()</signal>
|
<signal>rejected()</signal>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue