Ejemplo n.º 1
0
class YearMonthDayBox(gtk.HBox):
    def __init__(self):
        gtk.HBox.__init__(self, spacing=4)
        self.mode = core.primaryMode
        ####
        self.pack_start(gtk.Label(_('Year')), 0, 0)
        self.spinY = YearSpinButton()
        self.pack_start(self.spinY, 0, 0)
        ####
        self.pack_start(gtk.Label(_('Month')), 0, 0)
        comboMonth = gtk.combo_box_new_text()
        module = core.modules[self.mode]
        for i in xrange(12):
            comboMonth.append_text(_(module.getMonthName(i+1, None)))## year=None means all months
        comboMonth.set_active(0)
        self.pack_start(comboMonth, 0, 0)
        self.comboMonth = comboMonth
        ####
        self.pack_start(gtk.Label(_('Day')), 0, 0)
        self.spinD = DaySpinButton()
        self.pack_start(self.spinD, 0, 0)
        self.comboMonthConn = comboMonth.connect('changed', self.comboMonthChanged)
        self.spinY.connect('changed', self.comboMonthChanged) 
    def set_mode(self, mode):
        self.comboMonth.disconnect(self.comboMonthConn)
        self.mode = mode
        module = core.modules[mode]
        combo = self.comboMonth
        for i in xrange(len(combo.get_model())):
            combo.remove_text(0)
        for i in xrange(12):
            combo.append_text(_(module.getMonthName(i+1)))
        self.spinD.set_range(1, module.maxMonthLen)
        self.comboMonthConn = self.comboMonth.connect('changed', self.comboMonthChanged)
    def changeMode(self, mode, newMode):## FIXME naming standard?
        self.set_mode(newMode)
    def set_value(self, date):
        (y, m, d) = date
        self.spinY.set_value(y)
        self.comboMonth.set_active(m-1)
        self.spinD.set_value(d)
    def get_value(self):
        return (
            self.spinY.get_value(),
            self.comboMonth.get_active() + 1,
            self.spinD.get_value(),
        )
    def comboMonthChanged(self, widget=None):
        self.spinD.set_range(1, getMonthLen(
            self.spinY.get_value(),
            self.comboMonth.get_active() + 1,
            self.mode,
        ))
Ejemplo n.º 2
0
class EventWidget(common.EventWidget):
    def __init__(self, event):  ## FIXME
        common.EventWidget.__init__(self, event)
        ################
        hbox = gtk.HBox()
        hbox.pack_start(gtk.Label(_("Month")), 0, 0)
        self.monthCombo = gtk.combo_box_new_text()
        hbox.pack_start(self.monthCombo, 0, 0)
        hbox.pack_start(gtk.Label(""), 1, 1)
        # self.pack_start(hbox, 0, 0)
        ###
        # hbox = gtk.HBox()
        hbox.pack_start(gtk.Label(_("Day")), 0, 0)
        self.daySpin = DaySpinButton()
        hbox.pack_start(self.daySpin, 0, 0)
        hbox.pack_start(gtk.Label(""), 1, 1)
        self.pack_start(hbox, 0, 0)
        ###
        hbox = gtk.HBox()
        self.startYearCheck = gtk.CheckButton(_("Start Year"))
        hbox.pack_start(self.startYearCheck, 0, 0)
        self.startYearSpin = YearSpinButton()
        hbox.pack_start(self.startYearSpin, 0, 0)
        hbox.pack_start(gtk.Label(""), 1, 1)
        self.pack_start(hbox, 0, 0)
        self.startYearCheck.connect("clicked", self.startYearCheckClicked)
        ####
        self.notificationBox = common.NotificationBox(event)
        self.pack_start(self.notificationBox, 0, 0)
        ####
        # self.filesBox = common.FilesBox(self.event)
        # self.pack_start(self.filesBox, 0, 0)

    startYearCheckClicked = lambda self, obj=None: self.startYearSpin.set_sensitive(self.startYearCheck.get_active())

    def updateWidget(self):  ## FIXME
        common.EventWidget.updateWidget(self)
        self.monthCombo.set_active(self.event.getMonth() - 1)
        self.daySpin.set_value(self.event.getDay())
        try:
            startRule = self.event["start"]
        except:
            self.startYearCheck.set_active(False)
            self.startYearSpin.set_value(self.event.getSuggestedStartYear())
        else:
            self.startYearCheck.set_active(True)
            self.startYearSpin.set_value(startRule.date[0])
        self.startYearCheckClicked()

    def updateVars(self):  ## FIXME
        common.EventWidget.updateVars(self)
        self.event.setMonth(self.monthCombo.get_active() + 1)
        self.event.setDay(int(self.daySpin.get_value()))
        if self.startYearCheck.get_active():
            startRule = self.event.getAddRule("start")
            startRule.date = (self.startYearSpin.get_value(), 1, 1)
        else:
            try:
                del self.event["start"]
            except KeyError:
                pass

    def modeComboChanged(self, obj=None):  ## overwrite method from common.EventWidget
        newMode = self.modeCombo.get_active()
        module = core.modules[newMode]
        monthCombo = self.monthCombo
        active = monthCombo.get_active()
        for i in range(len(monthCombo.get_model())):
            monthCombo.remove_text(0)
        for i in range(12):
            monthCombo.append_text(_(module.getMonthName(i + 1)))
        # monthCombo.set_active(active)
        y2, m2, d2 = convert(
            int(self.startYearSpin.get_value()), active + 1, int(self.daySpin.get_value()), self.event.mode, newMode
        )
        self.startYearSpin.set_value(y2)
        monthCombo.set_active(m2 - 1)
        self.daySpin.set_value(d2)
        self.event.mode = newMode
Ejemplo n.º 3
0
class EventWidget(common.EventWidget):
    def __init__(self, event):## FIXME
        common.EventWidget.__init__(self, event)
        ################
        hbox = gtk.HBox()
        hbox.pack_start(gtk.Label(_('Month')), 0, 0)
        self.monthCombo = MonthComboBox()
        self.monthCombo.build(event.mode)
        hbox.pack_start(self.monthCombo, 0, 0)
        hbox.pack_start(gtk.Label(''), 1, 1)
        #self.pack_start(hbox, 0, 0)
        ###
        #hbox = gtk.HBox()
        hbox.pack_start(gtk.Label(_('Day')), 0, 0)
        self.daySpin = DaySpinButton()
        hbox.pack_start(self.daySpin, 0, 0)
        hbox.pack_start(gtk.Label(''), 1, 1)
        self.pack_start(hbox, 0, 0)
        ###
        hbox = gtk.HBox()
        self.startYearCheck = gtk.CheckButton(_('Start Year'))
        hbox.pack_start(self.startYearCheck, 0, 0)
        self.startYearSpin = YearSpinButton()
        hbox.pack_start(self.startYearSpin, 0, 0)
        hbox.pack_start(gtk.Label(''), 1, 1)
        self.pack_start(hbox, 0, 0)
        self.startYearCheck.connect('clicked', self.startYearCheckClicked)
        ####
        self.notificationBox = common.NotificationBox(event)
        self.pack_start(self.notificationBox, 0, 0)
        ####
        #self.filesBox = common.FilesBox(self.event)
        #self.pack_start(self.filesBox, 0, 0)
    startYearCheckClicked = lambda self, obj=None: self.startYearSpin.set_sensitive(self.startYearCheck.get_active())
    def updateWidget(self):## FIXME
        common.EventWidget.updateWidget(self)
        self.monthCombo.setValue(self.event.getMonth())
        self.daySpin.set_value(self.event.getDay())
        try:
            startRule = self.event['start']
        except:
            self.startYearCheck.set_active(False)
            self.startYearSpin.set_value(self.event.getSuggestedStartYear())
        else:
            self.startYearCheck.set_active(True)
            self.startYearSpin.set_value(startRule.date[0])
        self.startYearCheckClicked()
    def updateVars(self):## FIXME
        common.EventWidget.updateVars(self)
        self.event.setMonth(self.monthCombo.getValue())
        self.event.setDay(int(self.daySpin.get_value()))
        if self.startYearCheck.get_active():
            startRule = self.event.getAddRule('start')
            startRule.date = (self.startYearSpin.get_value(), 1, 1)
        else:
            try:
                del self.event['start']
            except KeyError:
                pass
    def modeComboChanged(self, obj=None):## overwrite method from common.EventWidget
        newMode = self.modeCombo.get_active()
        module = calTypes[newMode]
        monthCombo = self.monthCombo
        month = monthCombo.getValue()
        monthCombo.build(newMode)
        y2, m2, d2 = convert(
            int(self.startYearSpin.get_value()),
            month,
            int(self.daySpin.get_value()),
            self.event.mode,
            newMode,
        )
        self.startYearSpin.set_value(y2)
        monthCombo.setValue(m2)
        self.daySpin.set_value(d2)
        self.event.mode = newMode