Fixed link in about box.
[maegirls] / trunk / src / win.py
index 9097a9e..2085258 100755 (executable)
@@ -3,20 +3,20 @@
 # 
 # Copyright (C) 2010 Stefanos Harhalakis
 #
-# This file is part of mydays.
+# This file is part of maegirls.
 #
-# mydays is free software: you can redistribute it and/or modify
+# maegirls is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
-# mydays is distributed in the hope that it will be useful,
+# maegirls is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with mydays.  If not, see <http://www.gnu.org/licenses/>.
+# along with maegirls.  If not, see <http://www.gnu.org/licenses/>.
 #
 # $Id: 0.py 2265 2010-02-21 19:16:26Z v13 $
 
@@ -27,6 +27,7 @@ from PyQt4.QtCore import *
 
 import sys
 import time
+import locale
 
 from graph import DaysGraph
 import config
@@ -45,16 +46,16 @@ class ConfigDialog(QDialog):
        self.editCycle.setRange(10,50)
        self.editCurrent.setRange(1,50)
        self.editCurrent.setWrapping(True)
-       self.editCycle.setSuffix(" days")
+       self.editCycle.setSuffix(self.tr(" days"))
 
        self.editCycle.valueChanged.connect(self.slotEditCycleChanged)
 
        self.l0=QHBoxLayout(self)
 
        l1=QFormLayout()
-       l1.addRow("Name:", self.editName)
-       l1.addRow("Cycle length:", self.editCycle)
-       l1.addRow("Current day in cycle:", self.editCurrent)
+       l1.addRow(self.tr("Name:"), self.editName)
+       l1.addRow(self.tr("Cycle length:"), self.editCycle)
+       l1.addRow(self.tr("Current day in cycle:"), self.editCurrent)
 
        self.l0.addLayout(l1)
 
@@ -65,14 +66,14 @@ class ConfigDialog(QDialog):
        self.l0.addLayout(l2)
 
        self.buttonOk=QPushButton(self)
-       self.buttonOk.setText("OK")
+       self.buttonOk.setText(self.tr("OK"))
        self.buttonOk.clicked.connect(self.slotButOk)
        l2.addWidget(self.buttonOk)
 
        spacer=QSpacerItem(20, 20, QSizePolicy.Minimum,QSizePolicy.Expanding)
        l2.addItem(spacer)
 
-       self.setWindowTitle("Configuration")
+       self.setWindowTitle(self.tr("Configuration"))
 
     def slotButOk(self):
        self.name=str(self.editName.text())
@@ -134,26 +135,46 @@ class AboutDialog(MyMsgDialog):
     def __init__(self, *args, **kwargs):
        MyMsgDialog.__init__(self, *args, **kwargs)
 
-       txt="""
+       txt=self.tr("""
+<html><style>
+div.title {
+    text-decoration:   underline;
+}
+</style>
+<body>
 <p> A program to monitor the women's cycle.  Good for planning (or acting ;-).
 Inspired by "MyGirls" app which is (was?) available for Java ME capable phones.
 
 <p style="color: orange;">
-WARNING!!! This is not accurate nor correct! You cannot trust
-this program (or any other program) for accurate predictions!
-(after all, this is about women... how can one be sure :-).
-
+WARNING!!! This app is not guaranteed to be accurate or correct!  You cannot 
+trust this program, or any program, to give accurate predictions!
+The whole women-cycle-thing highly depends on a number of factors that
+only a doctor can tell.
+<p>
+<div class="title">Copyright</div>
 <p> Copyright &copy; 2010, Stefanos Harhalakis &lt;v13@v13.gr&gt;
 
 <p> Send comments and bug reports to the above address.
 
-<p> This program can be distributed under the terms of the GNU public
-license, version 3 or any later.
-       """
+<div class="title">License</div>
+<p> This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+<p> This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+<p> You should have received a copy of the GNU General Public License
+along with this program.  If not, see
+<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>.
+</body>
+</html>
+       """)
 
-       self.setWindowTitle("About MaeGirls")
+       self.setWindowTitle(self.tr("About MaeGirls"))
 
-       self.ltitle=QLabel("MaeGirls", self.w)
+       self.ltitle=QLabel("MaeGirls v" + config.version, self.w)
        self.ltitle.setObjectName("title")
        self.ltitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        self.ltitle.setAlignment(Qt.AlignCenter)
@@ -177,29 +198,32 @@ class HelpDialog(MyMsgDialog):
     def __init__(self, *args, **kwargs):
        MyMsgDialog.__init__(self, *args, **kwargs)
 
-       txt="""
+       txt=self.tr("""
 <p> MaeGirls shows information about women's cycle using some generic
-guidelines.  It assumes that the ovolution happens 14 days before the start
+guidelines:  It assumes that the ovulation happens 14 days before the start
 of the next period and that the period cycle is constant. Also, it assumes
 that sperm can live for 4 days, while an egg can live for 2 days.
 
 <p style="color: orange;">
 WARNING!!! This is not always correct. There are FAR TOO MANY exceptions
-to the above rules!!!
+to the above rules!!! You MUST consult a doctor in order to get accurate
+predictions!!!
 
-<p> Assuming that you understand the risk of being wrong, you become
-entitled to read the graph as follows:
+<p> Assuming that you understand the risks of blindly trusting this program,
+you become entitled to read the graph as follows:
 <p> <span style="color: red">In red:</span> The days that menstruation
-happens.
-<p> <span style="color: green">In green:</span> The fertile days.
+happens, assumed to last 5 days.
+<p> <span style="color: green">In green:</span> The fertile days as described above.
 <p> <span style="color: blue">In blue:</span> The days of PMS
-(Premenstrual Syndrome).
+(Premenstrual Syndrome), assumed to last 7 days.
 
 <p> Navigation is easy: Use left-right finger movement to move the calendar
 view. Use up-down finger movement to zoom in/out.
-       """
 
-       self.setWindowTitle("Help")
+<p> This program allows for "monitoring" the cycle of multiple girls.
+       """)
+
+       self.setWindowTitle(self.tr("Help"))
 
        self.label=QLabel(txt, self.w)
        self.label.setWordWrap(True)
@@ -222,13 +246,13 @@ class GirlsDialog(QDialog):
        self.l0.addWidget(self.lst)
 
        self.buttonNew=QPushButton(self)
-       self.buttonNew.setText("New")
+       self.buttonNew.setText(self.tr("New"))
 
        self.buttonSelect=QPushButton(self)
-       self.buttonSelect.setText("Select")
+       self.buttonSelect.setText(self.tr("Select"))
 
        self.buttonDelete=QPushButton(self)
-       self.buttonDelete.setText("Delete")
+       self.buttonDelete.setText(self.tr("Delete"))
 
        spacer=QSpacerItem(20, 20, QSizePolicy.Minimum,QSizePolicy.Expanding)
 
@@ -270,6 +294,8 @@ class GirlsDialog(QDialog):
        # The selection works but isn't shown
        idx2=self.lstm.index(idx, 0)
        self.lst.setCurrentIndex(idx2)
+       # Give if focus to show the current selection - is this normal?
+       self.lst.setFocus(Qt.OtherFocusReason)
 
        # Run
        QDialog.exec_(self)
@@ -295,9 +321,12 @@ class MaeGirls(QMainWindow):
 
        self.setupUi(algo)
 
-       self.dlgConfig=ConfigDialog(self)
-       self.dlgAbout=AboutDialog(self)
-       self.dlgHelp=HelpDialog(self)
+#      self.dlgConfig=ConfigDialog(self)
+#      self.dlgAbout=AboutDialog(self)
+#      self.dlgHelp=HelpDialog(self)
+       self.dlgConfig=None
+       self.dlgAbout=None
+       self.dlgHelp=None
        self.dlgGirls=None
 
        self.algo=algo
@@ -312,29 +341,31 @@ class MaeGirls(QMainWindow):
        self.l0.addWidget(self.dg)
 
        # Menu
-       self.menuconfig=QAction('Configure', self)
+       self.menuconfig=QAction(self.tr('Configure'), self)
        self.menuconfig.triggered.connect(self.menuConfig)
 
-       self.menureset=QAction('Go to today', self)
+       self.menureset=QAction(self.tr('Go to today'), self)
        self.menureset.triggered.connect(self.menuReset)
 
-       self.menugirls=QAction('Girls', self)
+       self.menugirls=QAction(self.tr('Girls'), self)
        self.menugirls.triggered.connect(self.menuGirls)
 
-       self.menuabout=QAction('About', self)
+       self.menuabout=QAction(self.tr('About'), self)
        self.menuabout.triggered.connect(self.menuAbout)
 
-       self.menuhelp=QAction('Help', self)
+       self.menuhelp=QAction(self.tr('Help'), self)
        self.menuhelp.triggered.connect(self.menuHelp)
 
        m=self.menuBar()
-       m.addAction(self.menuconfig)
        m.addAction(self.menureset)
+       m.addAction(self.menuconfig)
        m.addAction(self.menugirls)
        m.addAction(self.menuhelp)
        m.addAction(self.menuabout)
 
-       self.setWindowTitle("MaeGirls")
+    def updateTitle(self):
+       txt="MaeGirls - %s" % (self.girl, )
+       self.setWindowTitle(txt)
 
     def setAlgo(self, algo):
        self.dg.setAlgo(algo)
@@ -343,7 +374,8 @@ class MaeGirls(QMainWindow):
        cfg=config.loadGirl(name)
        self.girl=name
        self.algo.setReference(cfg['day0'], cfg['cycle'])
-       self.repaint()
+       self.update()
+       self.updateTitle()
 
     def menuConfig(self):
        if self.dlgConfig==None:
@@ -379,7 +411,7 @@ class MaeGirls(QMainWindow):
 
            self.setGirl(name)
 
-           self.repaint()
+           self.update()
 
     def menuGirls(self):
        if self.dlgGirls==None:
@@ -407,7 +439,7 @@ class MaeGirls(QMainWindow):
        elif what=='delete' and which!=None:
            if self.girl==which:
                msg=QMessageBox(self)
-               msg.setText("You cannot delete the current girl")
+               msg.setText(self.tr('You cannot delete the current girl'))
                msg.exec_()
            else:
                config.removeGirl(which)
@@ -433,9 +465,36 @@ class MaeGirls(QMainWindow):
 def init(algo):
     global app
     global win
+    global qttr, maetr
 
+    # Create the application
     app=QApplication(sys.argv)
+
+    # This returns the country and *NOT* the required locale
+    # This means that if you have'set language==en_GB and countr==Greece
+    # it will return el_GR.
+    # IOW: If you want english messages this will not work
+    #loc=QLocale.system().name()
+
+    loc=locale.setlocale(locale.LC_MESSAGES, '')
+
+    # Load translations
+    qttr=QTranslator()
+    qttr.load("qt_" + loc,
+       QLibraryInfo.location(QLibraryInfo.TranslationsPath))
+    app.installTranslator(qttr)
+
+    maetr=QTranslator()
+    maetr.load("maegirls_" + loc,
+       "/usr/share/maegirls/translations")
+
+    # Install the translation
+    app.installTranslator(maetr)
+
+    # One day support portrait mode
     #app.setAttribute(Qt.WA_Maemo5PortraitOrientation, True);
+
+    # Create the main window
     win=MaeGirls(algo)
     win.show()