def __init__(self, *args, **kwargs):
QDialog.__init__(self, *args, **kwargs)
+ self.editName=QLineEdit(self)
self.editCycle=QSpinBox(self)
self.editCurrent=QSpinBox(self)
self.editCycle.setRange(10,50)
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)
self.setWindowTitle("Configuration")
def slotButOk(self):
+ self.name=str(self.editName.text())
self.cycle=self.editCycle.value()
self.current=self.editCurrent.value()-1
self.editCurrent.setMaximum(value)
# current starts from 0
- def initValues(self, cycle, current):
- self.cycle=cycle
- self.current=current
- self.editCycle.setValue(cycle)
- self.editCurrent.setValue(current+1)
+ def initValues(self, dt):
+ self.dt=dt
+ self.editName.setText(dt['name'])
+ self.editCycle.setValue(dt['cycle'])
+ self.editCurrent.setValue(dt['day0']+1)
class MyMsgDialog(QDialog):
"""
self._mm_q.setWidget(self.w)
self._mm_l0.addWidget(self._mm_q)
-class AboutDialog2(QDialog):
- def __init__(self, *args, **kwargs):
- QDialog.__init__(self, *args, **kwargs)
-
- txt="""
-<p> A program to monitor the women's cycle. Good for planning (or acting ;-).
-Inspired by "MyDays" app which is (was?) available for Java ME capable phones.
-
-<p> 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 :-).
-
-<p> Copyright © 2010, Stefanos Harhalakis <v13@v13.gr>
-
-<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.
- """
-
- self.setWindowTitle("About MaeDays")
-
- # This freaking thing is hard
- # It needs two layouts, one extra widget, the fingerscrollable
- # property set to true *and* setWidgetResizable(True)
- self.l0=QVBoxLayout(self)
-
- self.q=QScrollArea(self)
- self.q.setWidgetResizable(True)
- self.q.setProperty('FingerScrollable', True)
- self.w1=QWidget(self.q)
-
- self.l=QVBoxLayout(self.w1)
-
- self.ltitle=QLabel("MaeDays", self.w1)
- self.ltitle.setObjectName("title")
- self.ltitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
- self.ltitle.setAlignment(Qt.AlignCenter)
- self.l.addWidget(self.ltitle)
-
- self.label=QLabel(txt, self.w1)
- self.label.setWordWrap(True)
- self.label.setTextFormat(Qt.RichText)
- self.label.setAlignment(Qt.AlignJustify)
-
- self.l.addWidget(self.label)
- self.q.setWidget(self.w1)
- self.l0.addWidget(self.q)
-
- self.ltitle.setStyleSheet("""
- QLabel {
- font-size: 25pt;
- color: rgb(192,192,192);
- margin-bottom: 0.5ex;
- }
- """)
-
class AboutDialog(MyMsgDialog):
def __init__(self, *args, **kwargs):
MyMsgDialog.__init__(self, *args, **kwargs)
txt="""
<p> A program to monitor the women's cycle. Good for planning (or acting ;-).
-Inspired by "MyDays" app which is (was?) available for Java ME capable phones.
+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
license, version 3 or any later.
"""
- self.setWindowTitle("About MaeDays")
+ self.setWindowTitle("About MaeGirls")
- self.ltitle=QLabel("MaeDays", self.w)
+ self.ltitle=QLabel("MaeGirls", self.w)
self.ltitle.setObjectName("title")
self.ltitle.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
self.ltitle.setAlignment(Qt.AlignCenter)
MyMsgDialog.__init__(self, *args, **kwargs)
txt="""
-<p> MaeDays shows information about women's cycle using some generic
+<p> MaeGirls shows information about women's cycle using some generic
guidelines. It assumes that the ovolution 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.
to the above rules!!!
<p> Assuming that you understand the risk of being wrong, you become
-entitle to read the graph as follows:
+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.
<p> <span style="color: blue">In blue:</span> The days of PMS
-(Premenstrual Syndrome)
+(Premenstrual Syndrome).
<p> Navigation is easy: Use left-right finger movement to move the calendar
view. Use up-down finger movement to zoom in/out.
self.label.setAlignment(Qt.AlignJustify)
self.l.addWidget(self.label)
-class MyDays(QMainWindow):
+class GirlsDialog(QDialog):
+ def __init__(self, *args, **kwargs):
+ QDialog.__init__(self, *args, **kwargs)
+
+ self.l0=QHBoxLayout(self)
+
+ self.lstm=QStringListModel()
+ self.lst=QListView(self)
+ self.lst.setModel(self.lstm)
+
+ self.l0.addWidget(self.lst)
+
+ self.buttonNew=QPushButton(self)
+ self.buttonNew.setText("New")
+
+ self.buttonSelect=QPushButton(self)
+ self.buttonSelect.setText("Select")
+
+ self.buttonDelete=QPushButton(self)
+ self.buttonDelete.setText("Delete")
+
+ spacer=QSpacerItem(20, 20, QSizePolicy.Minimum,QSizePolicy.Expanding)
+
+ self.l1=QVBoxLayout()
+ self.l0.addLayout(self.l1)
+ self.l1.addWidget(self.buttonNew)
+ self.l1.addWidget(self.buttonSelect)
+ self.l1.addWidget(self.buttonDelete)
+ self.l1.addItem(spacer)
+
+ self.buttonNew.clicked.connect(self.slotNew)
+ self.buttonDelete.clicked.connect(self.slotDelete)
+ self.buttonSelect.clicked.connect(self.slotSelect)
+
+ self.what=""
+ self.which=None
+
+ def _get_selection(self):
+ sel=self.lst.selectedIndexes()
+ if len(sel)==1:
+ d=sel[0]
+ ret=str(d.data().toString())
+ else:
+ ret=None
+
+ return(ret)
+
+ def exec_(self, current):
+ # Set data
+ girls=config.loadGirls()
+ dt=girls.keys()
+ dt.sort()
+ self.lstm.setStringList(dt)
+
+ # Set current selection
+ idx=dt.index(current)
+ self.lst.setCurrentIndex(self.lstm.index(idx))
+
+ # Run
+ QDialog.exec_(self)
+
+ def slotNew(self):
+ self.what="new"
+ self.which=None
+ self.accept()
+
+ def slotDelete(self):
+ self.what="delete"
+ self.which=self._get_selection()
+ self.accept()
+
+ def slotSelect(self):
+ self.what="select"
+ self.which=self._get_selection()
+ self.accept()
+
+class MaeGirls(QMainWindow):
def __init__(self, algo):
QMainWindow.__init__(self)
self.dlgConfig=ConfigDialog(self)
self.dlgAbout=AboutDialog(self)
self.dlgHelp=HelpDialog(self)
+ self.dlgGirls=None
self.algo=algo
self.menureset=QAction('Go to today', self)
self.menureset.triggered.connect(self.menuReset)
+ self.menugirls=QAction('Girls', self)
+ self.menugirls.triggered.connect(self.menuGirls)
+
self.menuabout=QAction('About', self)
self.menuabout.triggered.connect(self.menuAbout)
m=self.menuBar()
m.addAction(self.menuconfig)
m.addAction(self.menureset)
- m.addAction(self.menuabout)
+ m.addAction(self.menugirls)
m.addAction(self.menuhelp)
+ m.addAction(self.menuabout)
- self.setWindowTitle("MaeDays")
+ self.setWindowTitle("MaeGirls")
def setAlgo(self, algo):
self.dg.setAlgo(algo)
+ def setGirl(self, name):
+ cfg=config.loadGirl(name)
+ self.girl=name
+ self.algo.setReference(cfg['day0'], cfg['cycle'])
+ self.repaint()
+
def menuConfig(self):
if self.dlgConfig==None:
self.dlgConfig=ConfigDialog(self)
- self.dlgConfig.initValues(self.algo.cycleLength(),
- self.algo.currentDayInCycle())
+ dt={
+ 'name': self.girl,
+ 'cycle': self.algo.cycleLength(),
+ 'day0': self.algo.currentDayInCycle()
+ }
+
+ self.dlgConfig.initValues(dt)
ret=self.dlgConfig.exec_()
if ret==self.dlgConfig.Accepted:
today=algo.today()
+
+ name=self.dlgConfig.name
day0=today-self.dlgConfig.current
- self.algo.setReference(day0, self.dlgConfig.cycle)
- config.store("default", self.dlgConfig.cycle, day0)
+
+ dt={
+ 'cycle': self.dlgConfig.cycle,
+ 'day0': day0,
+ }
+
+ config.storeGirl(name, dt)
+ config.setCurrentGirl(name)
+
+ # If this is a rename, remove the old one
+ if self.girl!=name:
+ config.removeGirl(self.girl)
+
+ self.setGirl(name)
+
self.repaint()
+ def menuGirls(self):
+ if self.dlgGirls==None:
+ self.dlgGirls=GirlsDialog(self)
+
+ ret=self.dlgGirls.exec_(self.girl)
+
+ what=self.dlgGirls.what
+ which=self.dlgGirls.which
+ if what=='new':
+ # Determine a unique name
+ base="newgirl"
+ idx=0
+ name=base
+ while config.girlExists(name):
+ idx+=1
+ name="%s%d" % (base, idx)
+ # Store this
+ config.newGirl(name)
+ # Set it as current
+ config.setCurrentGirl(name)
+ self.setGirl(name)
+ # Edit it
+ self.menuConfig()
+ elif what=='delete' and which!=None:
+ if self.girl==which:
+ msg=QMessageBox(self)
+ msg.setText("You cannot delete the current girl")
+ msg.exec_()
+ else:
+ config.removeGirl(which)
+ elif what=='select' and which!=None:
+ config.setCurrentGirl(which)
+ self.setGirl(which)
+
def menuAbout(self):
if self.dlgAbout==None:
self.dlgAbout=AboutDialog(self)
app=QApplication(sys.argv)
#app.setAttribute(Qt.WA_Maemo5PortraitOrientation, True);
- win=MyDays(algo)
+ win=MaeGirls(algo)
win.show()
def setAlgo(algo):
global win
win.setAlgo(algo)
+def setGirl(name):
+ global win
+ win.setGirl(name)
+
def doit():
global app
app.exec_()