import datetime
import logging
-from PyQt4 import QtCore
-from PyQt4 import QtGui
+import qt_compat
+QtCore = qt_compat.QtCore
+QtGui = qt_compat.import_module("QtGui")
import misc
class QErrorLog(QtCore.QObject):
- messagePushed = QtCore.pyqtSignal()
- messagePopped = QtCore.pyqtSignal()
+ messagePushed = qt_compat.Signal()
+ messagePopped = qt_compat.Signal()
def __init__(self):
QtCore.QObject.__init__(self)
self._severityLabel.setPixmap(self._icons[error.level])
self._widget.show()
- @QtCore.pyqtSlot()
- @QtCore.pyqtSlot(bool)
+ @qt_compat.Slot()
+ @qt_compat.Slot(bool)
@misc.log_exception(_moduleLogger)
def _on_close(self, checked = False):
self._errorLog.pop()
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc.log_exception(_moduleLogger)
def _on_message_pushed(self):
self._show_error()
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc.log_exception(_moduleLogger)
def _on_message_popped(self):
if len(self._errorLog) == 0:
class QSignalingMainWindow(QtGui.QMainWindow):
- closed = QtCore.pyqtSignal()
- hidden = QtCore.pyqtSignal()
- shown = QtCore.pyqtSignal()
+ closed = qt_compat.Signal()
+ hidden = qt_compat.Signal()
+ shown = qt_compat.Signal()
+ resized = qt_compat.Signal()
def __init__(self, *args, **kwd):
QtGui.QMainWindow.__init__(*((self, )+args), **kwd)
def closeEvent(self, event):
- QtGui.QMainWindow.closeEvent(self, event)
+ val = QtGui.QMainWindow.closeEvent(self, event)
self.closed.emit()
+ return val
def hideEvent(self, event):
- QtGui.QMainWindow.hideEvent(self, event)
+ val = QtGui.QMainWindow.hideEvent(self, event)
self.hidden.emit()
+ return val
def showEvent(self, event):
- QtGui.QMainWindow.showEvent(self, event)
+ val = QtGui.QMainWindow.showEvent(self, event)
self.shown.emit()
+ return val
+
+ def resizeEvent(self, event):
+ val = QtGui.QMainWindow.resizeEvent(self, event)
+ self.resized.emit()
+ return val
+
+def set_current_index(selector, itemText, default = 0):
+ for i in xrange(selector.count()):
+ if selector.itemText(i) == itemText:
+ selector.setCurrentIndex(i)
+ break
+ else:
+ itemText.setCurrentIndex(default)
def _null_set_stackable(window, isStackable):
set_stackable = _null_set_stackable
-def _null_set_autorient(window, isStackable):
+def _null_set_autorient(window, doAutoOrient):
pass
-def _maemo_set_autorient(window, isStackable):
- window.setAttribute(QtCore.Qt.WA_Maemo5AutoOrientation, isStackable)
+def _maemo_set_autorient(window, doAutoOrient):
+ window.setAttribute(QtCore.Qt.WA_Maemo5AutoOrientation, doAutoOrient)
try:
def _maemo_set_window_orientation(window, orientation):
if orientation == QtCore.Qt.Vertical:
- oldHint = QtCore.Qt.WA_Maemo5LandscapeOrientation
- newHint = QtCore.Qt.WA_Maemo5PortraitOrientation
+ window.setAttribute(QtCore.Qt.WA_Maemo5LandscapeOrientation, False)
+ window.setAttribute(QtCore.Qt.WA_Maemo5PortraitOrientation, True)
elif orientation == QtCore.Qt.Horizontal:
- oldHint = QtCore.Qt.WA_Maemo5PortraitOrientation
- newHint = QtCore.Qt.WA_Maemo5LandscapeOrientation
- window.setAttribute(oldHint, False)
- window.setAttribute(newHint, True)
+ window.setAttribute(QtCore.Qt.WA_Maemo5LandscapeOrientation, True)
+ window.setAttribute(QtCore.Qt.WA_Maemo5PortraitOrientation, False)
+ elif orientation is None:
+ window.setAttribute(QtCore.Qt.WA_Maemo5LandscapeOrientation, False)
+ window.setAttribute(QtCore.Qt.WA_Maemo5PortraitOrientation, False)
+ else:
+ raise RuntimeError("Unknown orientation: %r" % orientation)
try: