Added version information in about.
[maegirls] / trunk / src / win.py
index 9097a9e..56a45be 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 $
 
@@ -45,16 +45,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 +65,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,7 +134,7 @@ class AboutDialog(MyMsgDialog):
     def __init__(self, *args, **kwargs):
        MyMsgDialog.__init__(self, *args, **kwargs)
 
-       txt="""
+       txt=self.tr("""
 <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.
 
@@ -149,11 +149,11 @@ this program (or any other program) for accurate predictions!
 
 <p> This program can be distributed under the terms of the GNU public
 license, version 3 or any later.
-       """
+       """)
 
-       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,9 +177,9 @@ 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.
 
@@ -197,9 +197,9 @@ happens.
 
 <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")
+       self.setWindowTitle(self.tr("Help"))
 
        self.label=QLabel(txt, self.w)
        self.label.setWordWrap(True)
@@ -222,13 +222,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 +270,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 +297,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,24 +317,24 @@ 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)
@@ -407,7 +412,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 +438,28 @@ class MaeGirls(QMainWindow):
 def init(algo):
     global app
     global win
+    global qttr, maetr
 
+    # Create the application
     app=QApplication(sys.argv)
+
+    # Load translations
+    qttr=QTranslator()
+    qttr.load("qt_" + QLocale.system().name(),
+       QLibraryInfo.location(QLibraryInfo.TranslationsPath))
+    app.installTranslator(qttr)
+
+    maetr=QTranslator()
+    maetr.load("maegirls_" + QLocale.system().name(),
+       "/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()