Adding an About dialog for copyright reasons, fixing quit issues with dialogs
authorEd Page <eopage@byu.net>
Wed, 8 Dec 2010 00:54:26 +0000 (18:54 -0600)
committerEd Page <eopage@byu.net>
Wed, 8 Dec 2010 00:54:26 +0000 (18:54 -0600)
src/dialcentral_qt.py
src/dialogs.py

index dcec292..fd5f0c5 100755 (executable)
@@ -338,6 +338,7 @@ class MainWindow(object):
                self._credentialsDialog = None
                self._smsEntryDialog = None
                self._accountDialog = None
+               self._aboutDialog = None
 
                self._errorLog = qui_utils.QErrorLog()
                self._errorDisplay = qui_utils.ErrorDisplay(self._errorLog)
@@ -402,6 +403,10 @@ class MainWindow(object):
                self._refreshTabAction.setShortcut(QtGui.QKeySequence("CTRL+r"))
                self._refreshTabAction.triggered.connect(self._on_refresh)
 
+               self._aboutAction = QtGui.QAction(None)
+               self._aboutAction.setText("About")
+               self._aboutAction.triggered.connect(self._on_about)
+
                self._closeWindowAction = QtGui.QAction(None)
                self._closeWindowAction.setText("Close")
                self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
@@ -415,6 +420,7 @@ class MainWindow(object):
                        toolsMenu = self._window.menuBar().addMenu("&Tools")
                        toolsMenu.addAction(self._accountTabAction)
                        toolsMenu.addAction(self._importTabAction)
+                       toolsMenu.addAction(self._aboutAction)
 
                        self._window.addAction(self._closeWindowAction)
                        self._window.addAction(self._app.quitAction)
@@ -432,6 +438,7 @@ class MainWindow(object):
                        toolsMenu = self._window.menuBar().addMenu("&Tools")
                        toolsMenu.addAction(self._accountTabAction)
                        toolsMenu.addAction(self._importTabAction)
+                       toolsMenu.addAction(self._aboutAction)
 
                self._window.addAction(self._app.logAction)
 
@@ -449,7 +456,14 @@ class MainWindow(object):
                return self._defaultCredentials
 
        def walk_children(self):
-               return ()
+               return (diag for diag in (
+                       self._credentialsDialog,
+                       self._smsEntryDialog,
+                       self._accountDialog,
+                       self._aboutDialog,
+                       )
+                       if diag is not None
+               )
 
        def start(self):
                assert self._session.state == self._session.LOGGEDOUT_STATE
@@ -462,7 +476,6 @@ class MainWindow(object):
 
        def close(self):
                for child in self.walk_children():
-                       child.window.destroyed.disconnect(self._on_child_close)
                        child.close()
                self._window.close()
 
@@ -638,6 +651,14 @@ class MainWindow(object):
 
        @QtCore.pyqtSlot()
        @QtCore.pyqtSlot(bool)
+       def _on_about(self, checked = True):
+               if self._aboutDialog is None:
+                       import dialogs
+                       self._aboutDialog = dialogs.AboutDialog(self._app)
+               response = self._aboutDialog.run()
+
+       @QtCore.pyqtSlot()
+       @QtCore.pyqtSlot(bool)
        @misc_utils.log_exception(_moduleLogger)
        def _on_close_window(self, checked = True):
                self.close()
index c0dd69e..67950aa 100644 (file)
@@ -10,6 +10,7 @@ import logging
 from PyQt4 import QtGui
 from PyQt4 import QtCore
 
+import constants
 from util import qui_utils
 from util import misc as misc_utils
 
@@ -71,6 +72,62 @@ class CredentialsDialog(object):
                finally:
                        self._dialog.setParent(None, QtCore.Qt.Dialog)
 
+       def close(self):
+               self._dialog.reject()
+
+       @QtCore.pyqtSlot()
+       @QtCore.pyqtSlot(bool)
+       @misc_utils.log_exception(_moduleLogger)
+       def _on_close_window(self, checked = True):
+               self._dialog.reject()
+
+
+class AboutDialog(object):
+
+       def __init__(self, app):
+               self._title = QtGui.QLabel(
+                       "<h1>%s</h1><h3>Version: %s</h3>" % (
+                               constants.__pretty_app_name__, constants.__version__
+                       )
+               )
+               self._title.setTextFormat(QtCore.Qt.RichText)
+               self._title.setAlignment(QtCore.Qt.AlignCenter)
+               self._copyright = QtGui.QLabel("<h6>Developed by Ed Page<h6><h6>Icons: See website</h6>")
+               self._copyright.setTextFormat(QtCore.Qt.RichText)
+               self._copyright.setAlignment(QtCore.Qt.AlignCenter)
+               self._link = QtGui.QLabel('<a href="http://gc-dialer.garage.maemo.org">DialCentral Website</a>')
+               self._link.setTextFormat(QtCore.Qt.RichText)
+               self._link.setAlignment(QtCore.Qt.AlignCenter)
+               self._link.setOpenExternalLinks(True)
+
+               self._layout = QtGui.QVBoxLayout()
+               self._layout.addWidget(self._title)
+               self._layout.addWidget(self._copyright)
+               self._layout.addWidget(self._link)
+
+               self._dialog = QtGui.QDialog()
+               self._dialog.setWindowTitle("About")
+               self._dialog.setLayout(self._layout)
+               qui_utils.set_autorient(self._dialog, True)
+
+               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)
+
+       def run(self, parent=None):
+               self._dialog.setParent(parent)
+
+               response = self._dialog.exec_()
+               return response
+
+       def close(self):
+               self._dialog.reject()
+
        @QtCore.pyqtSlot()
        @QtCore.pyqtSlot(bool)
        @misc_utils.log_exception(_moduleLogger)
@@ -163,6 +220,9 @@ class AccountDialog(object):
                response = self._dialog.exec_()
                return response
 
+       def close(self):
+               self._dialog.reject()
+
        @QtCore.pyqtSlot()
        @QtCore.pyqtSlot(bool)
        def _on_clear(self, checked = False):
@@ -270,6 +330,9 @@ class SMSEntryWindow(object):
                self._window.show()
                self._update_recipients()
 
+       def close(self):
+               self._dialog.reject()
+
        def _update_letter_count(self):
                count = self._smsEntry.toPlainText().size()
                numTexts, numCharInText = divmod(count, self.MAX_CHAR)