import copy
import logging
-from PyQt4 import QtGui
-from PyQt4 import QtCore
+import util.qt_compat as qt_compat
+QtCore = qt_compat.QtCore
+QtGui = qt_compat.import_module("QtGui")
import constants
from util import qwrappers
except RuntimeError:
_moduleLogger.exception("Oh well")
- @QtCore.pyqtSlot()
- @QtCore.pyqtSlot(bool)
+ @qt_compat.Slot()
+ @qt_compat.Slot(bool)
@misc_utils.log_exception(_moduleLogger)
def _on_close_window(self, checked = True):
with qui_utils.notify_error(self._app.errorLog):
except RuntimeError:
_moduleLogger.exception("Oh well")
- @QtCore.pyqtSlot()
- @QtCore.pyqtSlot(bool)
+ @qt_compat.Slot()
+ @qt_compat.Slot(bool)
@misc_utils.log_exception(_moduleLogger)
def _on_close_window(self, checked = True):
with qui_utils.notify_error(self._app.errorLog):
self._dialog.reject()
-class AccountDialog(object):
+class AccountDialog(QtCore.QObject, qwrappers.WindowWrapper):
# @bug Can't enter custom callback numbers
VOICEMAIL_CHECK_DISABLED = "Disabled"
VOICEMAIL_CHECK_ENABLED = "Enabled"
- def __init__(self, app):
+ settingsApproved = qt_compat.Signal()
+
+ def __init__(self, parent, app, errorLog):
+ QtCore.QObject.__init__(self)
+ qwrappers.WindowWrapper.__init__(self, parent, app)
self._app = app
self._doClear = False
self._callbackSelector = QtGui.QComboBox()
#self._callbackSelector.setEditable(True)
self._callbackSelector.setInsertPolicy(QtGui.QComboBox.InsertAtTop)
+ self._orientationSelector = QtGui.QComboBox()
+ for orientationMode in [
+ self._app.DEFAULT_ORIENTATION,
+ self._app.AUTO_ORIENTATION,
+ self._app.LANDSCAPE_ORIENTATION,
+ self._app.PORTRAIT_ORIENTATION,
+ ]:
+ self._orientationSelector.addItem(orientationMode)
self._update_notification_state()
self._credLayout.addWidget(self._voicemailNotificationButton, 4, 1)
self._credLayout.addWidget(QtGui.QLabel(""), 5, 0)
self._credLayout.addWidget(self._smsNotificationButton, 5, 1)
- self._credLayout.addWidget(QtGui.QLabel(""), 6, 0)
+ self._credLayout.addWidget(QtGui.QLabel("Other"), 6, 0)
self._credLayout.addWidget(self._voicemailOnMissedButton, 6, 1)
-
- self._credLayout.addWidget(QtGui.QLabel(""), 7, 0)
- self._credLayout.addWidget(self._clearButton, 7, 1)
-
- self._loginButton = QtGui.QPushButton("&Apply")
- self._buttonLayout = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Cancel)
- self._buttonLayout.addButton(self._loginButton, QtGui.QDialogButtonBox.AcceptRole)
-
- self._layout = QtGui.QVBoxLayout()
- self._layout.addLayout(self._credLayout)
+ self._credLayout.addWidget(QtGui.QLabel("Orientation"), 7, 0)
+ self._credLayout.addWidget(self._orientationSelector, 7, 1)
+ self._credLayout.addWidget(QtGui.QLabel(""), 8, 0)
+ self._credLayout.addWidget(QtGui.QLabel(""), 9, 0)
+ self._credLayout.addWidget(self._clearButton, 9, 1)
+
+ self._credWidget = QtGui.QWidget()
+ self._credWidget.setLayout(self._credLayout)
+ self._credWidget.setContentsMargins(0, 0, 0, 0)
+ self._scrollSettings = QtGui.QScrollArea()
+ self._scrollSettings.setWidget(self._credWidget)
+ self._scrollSettings.setWidgetResizable(True)
+ self._scrollSettings.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
+ self._scrollSettings.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
+
+ self._applyButton = QtGui.QPushButton("&Apply")
+ self._applyButton.clicked.connect(self._on_settings_apply)
+ self._cancelButton = QtGui.QPushButton("&Cancel")
+ self._cancelButton.clicked.connect(self._on_settings_cancel)
+ self._buttonLayout = QtGui.QDialogButtonBox()
+ self._buttonLayout.addButton(self._applyButton, QtGui.QDialogButtonBox.AcceptRole)
+ self._buttonLayout.addButton(self._cancelButton, QtGui.QDialogButtonBox.RejectRole)
+
+ self._layout.addWidget(self._scrollSettings)
self._layout.addWidget(self._buttonLayout)
+ self._layout.setDirection(QtGui.QBoxLayout.TopToBottom)
- self._dialog = QtGui.QDialog()
- self._dialog.setWindowTitle("Account")
- self._dialog.setLayout(self._layout)
- self._buttonLayout.accepted.connect(self._dialog.accept)
- self._buttonLayout.rejected.connect(self._dialog.reject)
-
- self._closeWindowAction = QtGui.QAction(None)
- self._closeWindowAction.setText("Close")
- self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
- self._closeWindowAction.triggered.connect(self._on_close_window)
-
- self._dialog.addAction(self._closeWindowAction)
- self._dialog.addAction(app.quitAction)
- self._dialog.addAction(app.fullscreenAction)
+ self._window.setWindowTitle("Account")
+ self._window.setAttribute(QtCore.Qt.WA_DeleteOnClose, False)
@property
def doClear(self):
def set_account_number(self, num):
self._accountNumberLabel.setText(num)
+ orientation = property(
+ lambda self: str(self._orientationSelector.currentText()),
+ lambda self, mode: qui_utils.set_current_index(self._orientationSelector, mode),
+ )
+
def _set_voicemail_on_missed(self, status):
if status == self.VOICEMAIL_CHECK_NOT_SUPPORTED:
self._voicemailOnMissedButton.setChecked(False)
updateVMOnMissedCall = property(_get_voicemail_on_missed, _set_voicemail_on_missed)
- def _set_notifications(self, enabled):
- for i in xrange(self._notificationSelecter.count()):
- if self._notificationSelecter.itemText(i) == enabled:
- self._notificationSelecter.setCurrentIndex(i)
- break
- else:
- self._notificationSelecter.setCurrentIndex(0)
-
notifications = property(
lambda self: str(self._notificationSelecter.currentText()),
- _set_notifications,
+ lambda self, enabled: qui_utils.set_current_index(self._notificationSelecter, enabled),
)
notifyOnMissed = property(
@property
def selectedCallback(self):
index = self._callbackSelector.currentIndex()
- data = str(self._callbackSelector.itemData(index).toPyObject())
+ data = str(self._callbackSelector.itemData(index))
return data
def set_callbacks(self, choices, default):
if uglyNumber == uglyDefault:
self._callbackSelector.setCurrentIndex(self._callbackSelector.count() - 1)
- def run(self, parent=None):
+ def run(self):
self._doClear = False
- self._dialog.setParent(parent, QtCore.Qt.Dialog)
-
- response = self._dialog.exec_()
- return response
+ self._window.show()
def close(self):
try:
- self._dialog.reject()
+ self._window.hide()
except RuntimeError:
_moduleLogger.exception("Oh well")
self._voicemailNotificationButton.setChecked(False)
self._smsNotificationButton.setChecked(False)
- @QtCore.pyqtSlot(int)
+ @qt_compat.Slot(int)
@misc_utils.log_exception(_moduleLogger)
def _on_notification_change(self, index):
with qui_utils.notify_error(self._app.errorLog):
self._update_notification_state()
- @QtCore.pyqtSlot()
- @QtCore.pyqtSlot(bool)
+ @qt_compat.Slot()
+ @qt_compat.Slot(bool)
@misc_utils.log_exception(_moduleLogger)
- def _on_clear(self, checked = False):
+ def _on_settings_cancel(self, checked = False):
with qui_utils.notify_error(self._app.errorLog):
- self._doClear = True
- self._dialog.accept()
+ self.hide()
- @QtCore.pyqtSlot()
- @QtCore.pyqtSlot(bool)
+ @qt_compat.Slot()
+ @qt_compat.Slot(bool)
@misc_utils.log_exception(_moduleLogger)
- def _on_close_window(self, checked = True):
+ def _on_settings_apply(self, checked = False):
with qui_utils.notify_error(self._app.errorLog):
- self._dialog.reject()
+ self.settingsApproved.emit()
+ self.hide()
+
+ @qt_compat.Slot()
+ @qt_compat.Slot(bool)
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_clear(self, checked = False):
+ with qui_utils.notify_error(self._app.errorLog):
+ self._doClear = True
+ self.settingsApproved.emit()
+ self.hide()
class ContactList(object):
)
callback.__name__ = "thanks partials for not having names and pyqt for requiring them"
numberSelector.activated.connect(
- QtCore.pyqtSlot(int)(callback)
+ qt_compat.Slot(int)(callback)
)
if self._closeIcon is self._SENTINEL_ICON:
self._session.download_voicemail(messageId)
self._hide()
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_recipients_changed(self):
with qui_utils.notify_error(self._app.errorLog):
self._update_state()
- @QtCore.pyqtSlot(str, str)
+ @qt_compat.Slot(str, str)
@misc_utils.log_exception(_moduleLogger)
def _on_voicemail_downloaded(self, messageId, filepath):
with qui_utils.notify_error(self._app.errorLog):
self._session.draft.called.connect(self._on_op_finished)
self._session.draft.cancelled.connect(self._on_op_finished)
self._session.draft.error.connect(self._on_op_error)
- self._errorLog = errorLog
- self._errorDisplay = qui_utils.ErrorDisplay(self._errorLog)
+ self._errorLog = errorLog
self._targetList = ContactList(self._app, self._session)
self._history = QtGui.QLabel()
self._window.setWindowTitle("Contact")
self._window.closed.connect(self._on_close_window)
self._window.hidden.connect(self._on_close_window)
+ self._window.resized.connect(self._on_window_resized)
self._scrollTimer = QtCore.QTimer()
self._scrollTimer.setInterval(100)
self._update_letter_count()
self._update_target_fields()
self.set_fullscreen(self._app.fullscreenAction.isChecked())
- self.set_orientation(self._app.orientationAction.isChecked())
+ self.update_orientation(self._app.orientation)
def close(self):
if self._window is None:
except RuntimeError:
_moduleLogger.exception("Oh well")
- def set_orientation(self, isPortrait):
- qwrappers.WindowWrapper.set_orientation(self, isPortrait)
+ def update_orientation(self, orientation):
+ qwrappers.WindowWrapper.update_orientation(self, orientation)
self._scroll_to_bottom()
def _update_letter_count(self):
- count = self._smsEntry.toPlainText().size()
+ count = len(self._smsEntry.toPlainText())
numTexts, numCharInText = divmod(count, self.MAX_CHAR)
numTexts += 1
numCharsLeftInText = self.MAX_CHAR - numCharInText
self._dialButton.setEnabled(False)
self._smsButton.setEnabled(False)
elif self._session.draft.get_num_contacts() == 1:
- count = self._smsEntry.toPlainText().size()
+ count = len(self._smsEntry.toPlainText())
if count == 0:
self._dialButton.setEnabled(True)
self._smsButton.setEnabled(False)
self._smsButton.setEnabled(True)
else:
self._dialButton.setEnabled(False)
- count = self._smsEntry.toPlainText().size()
+ count = len(self._smsEntry.toPlainText())
if count == 0:
self._smsButton.setEnabled(False)
else:
self._session.draft.message = message
self._session.draft.call()
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_cancel_clicked(self, message):
with qui_utils.notify_error(self._app.errorLog):
number = numbers[index][0]
self._session.draft.set_selected_number(cid, number)
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_refresh_history(self):
with qui_utils.notify_error(self._app.errorLog):
(cid, ) = self._session.draft.get_contacts()
self._update_history(cid)
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_recipients_changed(self):
with qui_utils.notify_error(self._app.errorLog):
self._update_target_fields()
self._update_button_state()
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_op_started(self):
with qui_utils.notify_error(self._app.errorLog):
self._dialButton.setVisible(False)
self.show()
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_calling_started(self):
with qui_utils.notify_error(self._app.errorLog):
self._cancelButton.setVisible(True)
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_op_finished(self):
with qui_utils.notify_error(self._app.errorLog):
self.close()
self.destroy()
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_op_error(self, message):
with qui_utils.notify_error(self._app.errorLog):
self._errorLog.push_error(message)
- @QtCore.pyqtSlot()
+ @qt_compat.Slot()
@misc_utils.log_exception(_moduleLogger)
def _on_letter_count_changed(self):
with qui_utils.notify_error(self._app.errorLog):
self._update_letter_count()
self._update_button_state()
- @QtCore.pyqtSlot()
- @QtCore.pyqtSlot(bool)
+ @qt_compat.Slot()
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_window_resized(self):
+ with qui_utils.notify_error(self._app.errorLog):
+ self._scroll_to_bottom()
+
+ @qt_compat.Slot()
+ @qt_compat.Slot(bool)
@misc_utils.log_exception(_moduleLogger)
def _on_close_window(self, checked = True):
with qui_utils.notify_error(self._app.errorLog):