Esempio n. 1
0
    def __init__(self, init_date=None):
        """
        date is a tuple containing the default DateEntry value. date is in the form of (YYYY, MM, DD) as three integers. 
        """
        gtk.Entry.__init__(self)
        self.set_alignment(0.5)
        self.connect("focus-out-event", self.correctDate)
#        self.connect("hide", self.correctDate)
        
        self.cal = calverter()

        if init_date != None:
            (self.year, self.month, self.day) = init_date
        else:
            today = date.today()
            if share.config.datetypes[share.config.datetype] == "jalali":
                jd = self.cal.gregorian_to_jd (today.year, today.month, today.day)
                jalali = self.cal.jd_to_jalali(jd)
                (self.year, self.month, self.day) = jalali
            else:
                self.year = today.year
                self.month = today.month
                self.day = today.day
                
        self.showDate(self.year, self.month, self.day)
Esempio n. 2
0
    def __init__(self, init_date=None):
        """
        date is a tuple containing the default DateEntry value. date is in the form of (YYYY, MM, DD) as three integers. 
        """
        GObject.GObject.__init__(self)
        self.set_alignment(0.5)
        self.connect("focus-out-event", self.correctDate)
        #        self.connect("hide", self.correctDate)

        self.cal = calverter()

        if init_date != None:
            (self.year, self.month, self.day) = init_date
        else:
            today = date.today()
            if share.config.datetypes[share.config.datetype] == "jalali":
                jd = self.cal.gregorian_to_jd(today.year, today.month,
                                              today.day)
                jalali = self.cal.jd_to_jalali(jd)
                (self.year, self.month, self.day) = jalali
            else:
                self.year = today.year
                self.month = today.month
                self.day = today.day

        self.showDate(self.year, self.month, self.day)
Esempio n. 3
0
    def menu_setup(self):
        self.menu = Gtk.Menu()
        cal = calverter()
        jd = cal.gregorian_to_jd(self.today.year, self.today.month, self.today.day)
        self.date = add2menu(self.menu,text =(self.today.strftime("%A, ") + str(cal.string_jd_to_islamic(jd))))
        self.date.show()

        add2menu(self.menu)

        self.Fajr = Gtk.MenuItem("Fajr\t\t\t" + self.times['fajr'])
        self.Fajr.set_sensitive(False) #use this to enable only one prayer
        self.Fajr.show()
        self.menu.append(self.Fajr)

        self.Sunrise = Gtk.MenuItem("Sunrise\t\t" + self.times['sunrise'])
        self.Sunrise.set_sensitive(False)
        self.Sunrise.show()
        self.menu.append(self.Sunrise)

        self.Dhuhr = Gtk.MenuItem("Dhuhr\t\t\t" + self.times['dhuhr'])
        self.Dhuhr.set_sensitive(False)
        self.Dhuhr.show()
        self.menu.append(self.Dhuhr)

        self.Asr = Gtk.MenuItem("Asr\t\t\t" + self.times['asr'])
        self.Asr.set_sensitive(False)
        self.Asr.show()
        self.menu.append(self.Asr)

        self.Maghrib = Gtk.MenuItem("Maghrib\t\t" + self.times['maghrib'])
        self.Maghrib.set_sensitive(False)
        self.Maghrib.show()
        self.menu.append(self.Maghrib)

        self.Isha = Gtk.MenuItem("Isha\t\t\t" + self.times['isha'])
        self.Isha.set_sensitive(False)
        self.Isha.show()
        self.menu.append(self.Isha)

        add2menu(self.menu)

        self.preferences = add2menu(self.menu,text=('Preferences'))
        self.preferences.connect("activate", self.show_preferences) # write a uclean def
        self.preferences.show()

        self.help_menu = add2menu(self.menu,text =('Help'))
        self.help_menu.set_submenu(self.get_help_menu())
        self.help_menu.show()
	
        self.quit_item = Gtk.MenuItem("Quit Salatuk")
        self.quit_item.connect("activate", self.quit)
        self.quit_item.show()
        self.menu.append(self.quit_item)
Esempio n. 4
0
class DateEntry(Gtk.Entry):

    cal = calverter()

    def __init__(self, init_date=None):
        """
        date is a tuple containing the default DateEntry value. date is in the form of (YYYY, MM, DD) as three integers. 
        """
        GObject.GObject.__init__(self)
        self.set_alignment(0.5)
        self.connect("focus-out-event", self.correctDate)
        #        self.connect("hide", self.correctDate)

        self.cal = calverter()

        if init_date != None:
            (self.year, self.month, self.day) = init_date
        else:
            today = date.today()
            if share.config.datetypes[share.config.datetype] == "jalali":
                jd = self.cal.gregorian_to_jd(today.year, today.month,
                                              today.day)
                jalali = self.cal.jd_to_jalali(jd)
                (self.year, self.month, self.day) = jalali
            else:
                self.year = today.year
                self.month = today.month
                self.day = today.day

        self.showDate(self.year, self.month, self.day)

    def showDate(self, year, month, day):
        datelist = ["", "", ""]
        datelist[share.config.datefields["year"]] = year
        datelist[share.config.datefields["month"]] = month
        datelist[share.config.datefields["day"]] = day

        delim = share.config.datedelims[share.config.datedelim]
        datestring = str(datelist[0]) + delim + str(datelist[1]) + delim + str(
            datelist[2])
        datestring = LN(datestring, False)
        self.set_text(datestring)
        self.year = year
        self.month = month
        self.day = day

    #Assuming that date objects show gregorian date.
    def showDateObject(self, date):
        if share.config.datetypes[share.config.datetype] == "jalali":
            jd = self.cal.gregorian_to_jd(date.year, date.month, date.day)
            (jyear, jmonth, jday) = self.cal.jd_to_jalali(jd)
            self.showDate(jyear, jmonth, jday)
        else:
            self.showDate(date.year, date.month, date.day)

    def getDateObject(self, d=None):
        if share.config.datetypes[share.config.datetype] == "jalali":

            dat = [self.year, self.month, self.day]
            jd = self.cal.jalali_to_jd(dat[0], dat[1], dat[2])
            (gyear, gmonth, gday) = self.cal.jd_to_gregorian(jd)
            return date(gyear, gmonth, gday)
        else:
            return date(self.year, self.month, self.day)

    def correctDate(self, sender, event):
        text = self.get_text()
        datelist = string.split(
            text, share.config.datedelims[share.config.datedelim])
        try:
            tyear = datelist[share.config.datefields["year"]]
            tyear = convertToLatin(tyear)
        except IndexError:
            tyear = ""
        try:
            tmonth = datelist[share.config.datefields["month"]]
            tmonth = convertToLatin(tmonth)
        except IndexError:
            tmonth = ""
        try:
            tday = datelist[share.config.datefields["day"]]
            tday = convertToLatin(tday)
        except IndexError:
            tday = ""

        if share.config.datetypes[share.config.datetype] == "jalali":
            minyear = 1349
            baseyear = "1300"
        else:
            minyear = 1970
            baseyear = "2000"

        try:
            if len(tyear) > 4:
                year = self.year
            else:
                year = int(baseyear[:4 - len(tyear)] + tyear)

            if year < minyear:
                year = minyear
        except ValueError:
            year = minyear

        try:
            month = int(tmonth)
            if month > 12:
                month = 12
            else:
                if month < 1:
                    month = 1
        except ValueError:
            month = 1

        try:
            day = int(tday)
            if day > 31:
                day = 31
            else:
                if day < 1:
                    day = 1
        except ValueError:
            day = 1

        if share.config.datetypes[share.config.datetype] == "jalali":
            jd = self.cal.jalali_to_jd(year, month, day)
            (gyear, gmonth, gday) = self.cal.jd_to_gregorian(jd)
        else:
            (gyear, gmonth, gday) = (year, month, day)

        correct = 0
        while correct == 0:
            try:
                testdate = date(gyear, gmonth, gday)
                correct = 1
            except ValueError:
                gday -= 1
                day -= 1

        self.showDate(year, month, day)
        self.year = year
        self.month = month
        self.day = day
Esempio n. 5
0
 def update_hijri_date(self):
     cal = calverter()
     jd = cal.gregorian_to_jd(self.today.year, self.today.month, self.today.day)
     self.date.set_label(self.today.strftime("%A, ") + str(cal.string_jd_to_islamic(jd)))
Esempio n. 6
0
def update(inputfile, outputfile):

    engine = create_engine('sqlite:///%s' % inputfile, echo=True)
    metadata = MetaData(bind=engine)

    outdb = Database(outputfile)
    outsession = outdb.session

    ledger = Table(
        'ledger',
        metadata,
        Column('id', Integer, primary_key=True),
        Column('name', String),
        Column('type', Integer),
    )

    subledger = Table(
        'sub_ledger',
        metadata,
        Column('ledger', Integer),
        Column('name', String),
        Column('id', Integer, primary_key=True),
        Column('bed', Integer),
        Column('bes', Integer),
    )

    moin = Table(
        'moin',
        metadata,
        Column('sub_name', String),
        Column('ledger', Integer),
        Column('name', String),
        Column('sub', Integer),
        Column('number', Integer),
        Column('date', String),
        Column('des', String),
        Column('bed', Integer),
        Column('bes', Integer),
        Column('mondeh', Integer),
        Column('tashkhis', String),
    )
    metadata.create_all()

    query = outsession.query(Subject.code).select_from(Subject).order_by(
        Subject.id.desc())
    code = query.filter(Subject.parent_id == 0).first()
    if code == None:
        lastcode = 0
    else:
        lastcode = int(code[0][-2:])

    s = outerjoin(ledger, subledger,
                  ledger.c.id == subledger.c.ledger).select().order_by(
                      ledger.c.id)
    result = s.execute()

    parent_id = 0
    pid = 0
    sid = 0
    pcode = ""
    mainids = {
    }  #stores tuples like (oldid:newid) pairs to have old subject ids for later use
    subids = {
    }  #stores tuples like (oldid:newid) pairs to have old subject ids for later use

    for row in result:
        if row[0] != parent_id:
            lastcode += 1
            if lastcode > 99:
                logging.error("Ledgers with numbers greater than %d are not imported to the new database" \
                      "Because you can have just 99 Ledgers (level one subject)" % row[0])
                break
            pcode = "%02d" % lastcode
            parentsub = Subject(pcode, row[1], 0, 2)
            childcode = 0
            outsession.add(parentsub)
            if pid == 0:
                outsession.commit()
                sid = parentsub.id
            else:
                sid += 1
            pid = sid
            parent_id = row[0]
            mainids[row[0]] = pid

        if row[3] != None:
            childcode += 1
            if childcode > 99:
                logging.error("SubLedgers with number %d is not imported to the new database" \
                      "Because you can have just 99 subjects per level" % row[5])
                continue
            childsub = Subject(pcode + "%02d" % childcode, row[4], pid, 2)
            outsession.add(childsub)
            sid += 1
            subids[row[5]] = sid

    outsession.commit()

    s = moin.select().order_by(moin.c.number)
    result = s.execute()

    bnumber = 0
    bid = 0
    value = 0
    cal = calverter.calverter()

    for row in result:
        if row.number != bnumber:

            fields = re.split(r"[:-]+", row.date)
            jd = cal.jalali_to_jd(int(fields[0]), int(fields[1]),
                                  int(fields[2]))
            (gyear, gmonth, gday) = cal.jd_to_gregorian(jd)
            ndate = date(gyear, gmonth, gday)

            bill = Bill(row.number, ndate, ndate, ndate)
            outsession.add(bill)
            if bid == 0:
                outsession.commit()
                bid = bill.id
            else:
                bid += 1
            bnumber = row.number

        if row.sub == 0:
            subid = mainids[row.ledger]
        else:
            subid = subids[row.sub]
        if row.bed == 0:
            value = row.bes
        else:
            value = -(row.bed)
        n = Notebook(subid, bid, value, row.des)
        outsession.add(n)
    outsession.commit()
Esempio n. 7
0
def update(inputfile, outputfile):
        
    engine = create_engine('sqlite:///%s' % inputfile, echo=True)
    metadata = MetaData(bind=engine)
    
    outdb =  Database(outputfile)
    outsession = outdb.session
    
    ledger = Table('ledger', metadata,
        Column('id', Integer, primary_key = True),
        Column('name', String),
        Column('type', Integer),
    )
    
    subledger = Table('sub_ledger', metadata,
        Column('ledger', Integer),
        Column('name', String),
        Column('id', Integer, primary_key = True),
        Column('bed', Integer),
        Column('bes', Integer),
    )
    
    moin = Table('moin', metadata,
        Column('sub_name', String),
        Column('ledger', Integer),
        Column('name', String),
        Column('sub', Integer),
        Column('number', Integer),
        Column('date', String),
        Column('des', String),
        Column('bed', Integer),
        Column('bes', Integer),
        Column('mondeh', Integer),
        Column('tashkhis', String),
    )
    metadata.create_all()
    
    
    query = outsession.query(Subject.code).select_from(Subject).order_by(Subject.id.desc())
    code = query.filter(Subject.parent_id == 0).first()
    if code == None :
        lastcode = 0
    else :
        lastcode = int(code[0][-2:])
    
    s = outerjoin(ledger, subledger, ledger.c.id == subledger.c.ledger).select().order_by(ledger.c.id)
    result = s.execute()
    
    parent_id = 0
    pid = 0
    sid = 0
    pcode = ""
    mainids = {}   #stores tuples like (oldid:newid) pairs to have old subject ids for later use
    subids = {}    #stores tuples like (oldid:newid) pairs to have old subject ids for later use
    
    for row in result:
        if row[0] != parent_id:
            lastcode += 1
            if lastcode > 99:
                logging.error("Ledgers with numbers greater than %d are not imported to the new database" \
                      "Because you can have just 99 Ledgers (level one subject)" % row[0])
                break
            pcode = "%02d" % lastcode
            parentsub = Subject(pcode, row[1], 0, 2)
            childcode = 0
            outsession.add(parentsub)
            if pid == 0:
                outsession.commit()
                sid = parentsub.id
            else:
                sid += 1
            pid = sid
            parent_id = row[0]
            mainids[row[0]] = pid
            
        if row[3] != None:
            childcode += 1
            if childcode > 99:
                logging.error("SubLedgers with number %d is not imported to the new database" \
                      "Because you can have just 99 subjects per level" % row[5])
                continue 
            childsub = Subject(pcode + "%02d" % childcode, row[4], pid, 2)
            outsession.add(childsub)
            sid += 1
            subids[row[5]] = sid
     
    outsession.commit()      
        
    s = moin.select().order_by(moin.c.number)
    result = s.execute()
    
    bnumber = 0
    bid = 0
    value = 0
    cal = calverter.calverter()
    
    for row in result:
        if row.number != bnumber:
            
            fields = re.split(r"[:-]+",row.date)
            jd = cal.jalali_to_jd(int(fields[0]), int(fields[1]), int(fields[2]))
            (gyear, gmonth, gday) = cal.jd_to_gregorian(jd)
            ndate = date(gyear, gmonth, gday)
            
            bill = Bill(row.number, ndate, ndate, ndate)
            outsession.add(bill)
            if bid == 0:
                outsession.commit()
                bid = bill.id
            else:
                bid += 1
            bnumber = row.number
        
        if row.sub == 0:
            subid = mainids[row.ledger]
        else:
            subid = subids[row.sub]
        if row.bed == 0:
            value = row.bes
        else:
            value = -(row.bed) 
        n = Notebook(subid, bid, value, row.des)
        outsession.add(n)
    outsession.commit()