示例#1
0
文件: timer.py 项目: ilius/starcal
	def __init__(self, **kwargs):
		TimeButton.__init__(self, **kwargs)
		#self.timer = False
		#self.clock = False
		self.delay = 1.0 # timer delay
		self.tPlus = -1 # timer plus (step)
		self.elapse = 0
示例#2
0
文件: dateTime.py 项目: ilius/starcal
class WidgetClass(gtk.HBox):
    def __init__(self, rule):
        self.rule = rule
        ###
        gtk.ComboBox.__init__(self)
        ###
        self.dateInput = DateButton()
        pack(self, self.dateInput)
        ###
        pack(self, gtk.Label("   " + _("Time")))
        self.timeInput = TimeButton()
        pack(self, self.timeInput)

    def updateWidget(self):
        self.dateInput.set_value(self.rule.date)
        self.timeInput.set_value(self.rule.time)

    def updateVars(self):
        self.rule.date = self.dateInput.get_value()
        self.rule.time = self.timeInput.get_value()

    def changeMode(self, mode):
        if mode == self.rule.getMode():
            return
        self.updateVars()
        self.rule.changeMode(mode)
        self.updateWidget()
示例#3
0
class WidgetClass(gtk.HBox):
    def __init__(self, rule):
        self.rule = rule
        ###
        gtk.ComboBox.__init__(self)
        ###
        self.dateInput = DateButton()
        pack(self, self.dateInput)
        ###
        pack(self, gtk.Label("   " + _("Time")))
        self.timeInput = TimeButton()
        pack(self, self.timeInput)

    def updateWidget(self):
        self.dateInput.set_value(self.rule.date)
        self.timeInput.set_value(self.rule.time)

    def updateVars(self):
        self.rule.date = self.dateInput.get_value()
        self.rule.time = self.timeInput.get_value()

    def changeMode(self, mode):
        curMode = self.rule.getMode()
        if mode != curMode:
            y, m, d = self.dateInput.get_value()
            self.dateInput.set_value(core.convert(y, m, d, curMode, mode))
示例#4
0
class WidgetClass(gtk.HBox):
    def __init__(self, rule):
        self.rule = rule
        ###
        gtk.ComboBox.__init__(self)
        ###
        self.dateInput = DateButton()
        pack(self, self.dateInput)
        ###
        pack(self, gtk.Label('   ' + _('Time')))
        self.timeInput = TimeButton()
        pack(self, self.timeInput)

    def updateWidget(self):
        self.dateInput.set_value(self.rule.date)
        self.timeInput.set_value(self.rule.time)

    def updateVars(self):
        self.rule.date = self.dateInput.get_value()
        self.rule.time = self.timeInput.get_value()

    def changeMode(self, mode):
        curMode = self.rule.getMode()
        if mode != curMode:
            y, m, d = self.dateInput.get_value()
            self.dateInput.set_value(core.convert(y, m, d, curMode, mode))
示例#5
0
文件: timer.py 项目: ilius/starcal
 def __init__(self, **kwargs):
     TimeButton.__init__(self, **kwargs)
     #self.timer = False
     #self.clock = False
     self.delay = 1.0  # timer delay
     self.tPlus = -1  # timer plus (step)
     self.elapse = 0
示例#6
0
	def __init__(self, rule):
		self.rule = rule
		###
		gtk.HBox.__init__(self)
		###
		self.startTbox = TimeButton()
		self.endTbox = TimeButton()
		pack(self, self.startTbox)
		pack(self, gtk.Label(' ' + _('to') + ' '))
		pack(self, self.endTbox)
示例#7
0
	def __init__(self, rule):
		self.rule = rule
		###
		gtk.HBox.__init__(self)
		###
		self.startTbox = TimeButton()
		self.endTbox = TimeButton()
		pack(self, self.startTbox)
		pack(self, gtk.Label(" " + _("to") + " "))
		pack(self, self.endTbox)
示例#8
0
 def __init__(self, rule):
     self.rule = rule
     ###
     gtk.HBox.__init__(self)
     ###
     self.startTbox = TimeButton()
     self.endTbox = TimeButton()
     pack(self, self.startTbox)
     pack(self, gtk.Label(' ' + _('to') + ' '))
     pack(self, self.endTbox)
示例#9
0
文件: dateTime.py 项目: ilius/starcal
 def __init__(self, rule):
     self.rule = rule
     ###
     gtk.ComboBox.__init__(self)
     ###
     self.dateInput = DateButton()
     pack(self, self.dateInput)
     ###
     pack(self, gtk.Label("   " + _("Time")))
     self.timeInput = TimeButton()
     pack(self, self.timeInput)
示例#10
0
 def __init__(self, event):  ## FIXME
     common.WidgetClass.__init__(self, event)
     ######
     sizeGroup = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
     ######
     hbox = gtk.HBox()
     label = gtk.Label(_('Start'))
     label.set_alignment(0, 0.5)
     sizeGroup.add_widget(label)
     pack(hbox, label)
     self.startDateInput = DateButton()
     pack(hbox, self.startDateInput)
     ##
     pack(hbox, gtk.Label(' ' + _('Time')))
     self.startTimeInput = TimeButton()
     pack(hbox, self.startTimeInput)
     ##
     pack(self, hbox)
     ######
     hbox = gtk.HBox()
     self.endTypeCombo = gtk.ComboBoxText()
     for item in ('Duration', 'End'):
         self.endTypeCombo.append_text(_(item))
     self.endTypeCombo.connect('changed', self.endTypeComboChanged)
     sizeGroup.add_widget(self.endTypeCombo)
     pack(hbox, self.endTypeCombo)
     ####
     self.durationBox = common.DurationInputBox()
     pack(hbox, self.durationBox, 1, 1)
     ####
     self.endDateHbox = gtk.HBox()
     self.endDateInput = DateButton()
     pack(self.endDateHbox, self.endDateInput)
     ##
     pack(self.endDateHbox, gtk.Label(' ' + _('Time')))
     self.endTimeInput = TimeButton()
     pack(self.endDateHbox, self.endTimeInput)
     ##
     pack(hbox, self.endDateHbox, 1, 1)
     ####
     pack(hbox, gtk.Label(''), 1, 1)
     pack(self, hbox)
     #############
     self.notificationBox = common.NotificationBox(event)
     pack(self, self.notificationBox)
示例#11
0
文件: task.py 项目: ilius/starcal
	def __init__(self, event):  # FIXME
		common.WidgetClass.__init__(self, event)
		######
		sizeGroup = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
		######
		hbox = gtk.HBox()
		label = gtk.Label(_("Start"))
		label.set_alignment(0, 0.5)
		sizeGroup.add_widget(label)
		pack(hbox, label)
		self.startDateInput = DateButton()
		pack(hbox, self.startDateInput)
		##
		pack(hbox, gtk.Label(" " + _("Time")))
		self.startTimeInput = TimeButton()
		pack(hbox, self.startTimeInput)
		##
		pack(self, hbox)
		######
		hbox = gtk.HBox()
		self.endTypeCombo = gtk.ComboBoxText()
		for item in ("Duration", "End"):
			self.endTypeCombo.append_text(_(item))
		self.endTypeCombo.connect("changed", self.endTypeComboChanged)
		sizeGroup.add_widget(self.endTypeCombo)
		pack(hbox, self.endTypeCombo)
		####
		self.durationBox = common.DurationInputBox()
		pack(hbox, self.durationBox, 1, 1)
		####
		self.endDateHbox = gtk.HBox()
		self.endDateInput = DateButton()
		pack(self.endDateHbox, self.endDateInput)
		##
		pack(self.endDateHbox, gtk.Label(" " + _("Time")))
		self.endTimeInput = TimeButton()
		pack(self.endDateHbox, self.endTimeInput)
		##
		pack(hbox, self.endDateHbox, 1, 1)
		####
		pack(hbox, gtk.Label(""), 1, 1)
		pack(self, hbox)
		#############
		self.notificationBox = common.NotificationBox(event)
		pack(self, self.notificationBox)
示例#12
0
	def __init__(self, rule):
		self.rule = rule
		###
		gtk.ComboBox.__init__(self)
		###
		self.dateInput = DateButton()
		pack(self, self.dateInput)
		###
		pack(self, gtk.Label('   '+_('Time')))
		self.timeInput = TimeButton()
		pack(self, self.timeInput)
示例#13
0
 def __init__(self, rule):
     self.rule = rule
     ###
     gtk.HBox.__init__(self)
     spin = IntSpinButton(0, 9999)
     pack(self, spin)
     self.spin = spin
     ##
     pack(self, gtk.Label(" " + _("days and") + " "))
     tbox = TimeButton()
     pack(self, tbox)
     self.tbox = tbox
示例#14
0
class WidgetClass(gtk.HBox):
	def __init__(self, rule):
		self.rule = rule
		###
		gtk.HBox.__init__(self)
		###
		self.startTbox = TimeButton()
		self.endTbox = TimeButton()
		pack(self, self.startTbox)
		pack(self, gtk.Label(' ' + _('to') + ' '))
		pack(self, self.endTbox)
	def updateWidget(self):
		self.startTbox.set_value(self.rule.dayTimeStart)
		self.endTbox.set_value(self.rule.dayTimeEnd)
	def updateVars(self):
		self.rule.dayTimeStart = self.startTbox.get_value()
		self.rule.dayTimeEnd = self.endTbox.get_value()
示例#15
0
文件: task.py 项目: ilius/starcal
class WidgetClass(common.WidgetClass):
	def __init__(self, event):  # FIXME
		common.WidgetClass.__init__(self, event)
		######
		sizeGroup = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
		######
		hbox = gtk.HBox()
		label = gtk.Label(_("Start"))
		label.set_alignment(0, 0.5)
		sizeGroup.add_widget(label)
		pack(hbox, label)
		self.startDateInput = DateButton()
		pack(hbox, self.startDateInput)
		##
		pack(hbox, gtk.Label(" " + _("Time")))
		self.startTimeInput = TimeButton()
		pack(hbox, self.startTimeInput)
		##
		pack(self, hbox)
		######
		hbox = gtk.HBox()
		self.endTypeCombo = gtk.ComboBoxText()
		for item in ("Duration", "End"):
			self.endTypeCombo.append_text(_(item))
		self.endTypeCombo.connect("changed", self.endTypeComboChanged)
		sizeGroup.add_widget(self.endTypeCombo)
		pack(hbox, self.endTypeCombo)
		####
		self.durationBox = common.DurationInputBox()
		pack(hbox, self.durationBox, 1, 1)
		####
		self.endDateHbox = gtk.HBox()
		self.endDateInput = DateButton()
		pack(self.endDateHbox, self.endDateInput)
		##
		pack(self.endDateHbox, gtk.Label(" " + _("Time")))
		self.endTimeInput = TimeButton()
		pack(self.endDateHbox, self.endTimeInput)
		##
		pack(hbox, self.endDateHbox, 1, 1)
		####
		pack(hbox, gtk.Label(""), 1, 1)
		pack(self, hbox)
		#############
		self.notificationBox = common.NotificationBox(event)
		pack(self, self.notificationBox)
		#############
		#self.filesBox = common.FilesBox(self.event)
		#pack(self, self.filesBox)

	def endTypeComboChanged(self, combo=None):
		active = self.endTypeCombo.get_active()
		if active == 0:  # duration
			self.durationBox.show()
			self.endDateHbox.hide()
		elif active == 1:  # end date
			self.durationBox.hide()
			self.endDateHbox.show()
		else:
			raise RuntimeError

	def updateWidget(self):## FIXME
		common.WidgetClass.updateWidget(self)
		###
		startDate, startTime = self.event.getStart()
		self.startDateInput.set_value(startDate)
		self.startTimeInput.set_value(startTime)
		###
		endType, values = self.event.getEnd()
		if endType == "duration":
			self.endTypeCombo.set_active(0)
			self.durationBox.setDuration(*values)
			self.endDateInput.set_value(startDate)## FIXME
			self.endTimeInput.set_value(startTime)## FIXME
		elif endType == "date":
			self.endTypeCombo.set_active(1)
			self.endDateInput.set_value(values[0])
			self.endTimeInput.set_value(values[1])
		else:
			raise RuntimeError
		self.endTypeComboChanged()

	def updateVars(self):  # FIXME
		common.WidgetClass.updateVars(self)
		self.event.setStart(
			self.startDateInput.get_value(),
			self.startTimeInput.get_value(),
		)
		###
		active = self.endTypeCombo.get_active()
		if active == 0:
			self.event.setEnd("duration", *self.durationBox.getDuration())
		elif active == 1:
			self.event.setEnd(
				"date",
				self.endDateInput.get_value(),
				self.endTimeInput.get_value(),
			)

	def modeComboChanged(self, obj=None):
		# overwrite method from common.WidgetClass
		newMode = self.modeCombo.get_active()
		self.startDateInput.changeMode(self.event.mode, newMode)
		self.endDateInput.changeMode(self.event.mode, newMode)
		self.event.mode = newMode
示例#16
0
	def __init__(self, **kwargs):
		gtk.Dialog.__init__(self, **kwargs)
		self.set_title(_("Adjust System Date & Time"))  # FIXME
		self.set_keep_above(True)
		try:
			self.set_icon(IconTheme.get_default().load_icon(
				icon_name = "preferences-system-time",
				size = 32,
				flags = 0,
			))
		except Exception:
			pass
		# render_icon: Deprecated since version 3.0: Use Gtk.Widget.render_icon_pixbuf() instead.
		# render_icon_pixbuf: Deprecated since version 3.10: Use Gtk.IconTheme.load_icon() instead.
		#########
		self.buttonCancel = self.add_button(gtk.STOCK_CANCEL, 0)
		#self.buttonCancel.connect("clicked", lambda w: sys.exit(0))
		self.buttonSet = self.add_button(_("Set System Time"), 1)
		#self.buttonSet.connect("clicked", self.setSysTimeClicked)
		#########
		hbox = gtk.HBox()
		self.label_cur = gtk.Label(label=_("Current:"))
		pack(hbox, self.label_cur)
		pack(self.vbox, hbox)
		#########
		hbox = gtk.HBox()
		self.radioMan = gtk.RadioButton.new_with_mnemonic(
			group=None,
			label=_("Set _Manully:"),
		)
		self.radioMan.connect("clicked", self.radioManClicked)
		pack(hbox, self.radioMan)
		pack(self.vbox, hbox)
		######
		vb = gtk.VBox()
		sg = gtk.SizeGroup(mode=gtk.SizeGroupMode.HORIZONTAL)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		self.ckeckbEditTime = gtk.CheckButton.new_with_mnemonic(_("Edit _Time"))
		self.editTime = False
		self.ckeckbEditTime.connect("clicked", self.ckeckbEditTimeClicked)
		pack(hbox, self.ckeckbEditTime)
		sg.add_widget(self.ckeckbEditTime)
		self.timeInput = TimeButton() ## ??????? options
		pack(hbox, self.timeInput)
		pack(vb, hbox)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		self.ckeckbEditDate = gtk.CheckButton.new_with_mnemonic(_("Edit _Date"))
		self.editDate = False
		self.ckeckbEditDate.connect("clicked", self.ckeckbEditDateClicked)
		pack(hbox, self.ckeckbEditDate)
		sg.add_widget(self.ckeckbEditDate)
		self.dateInput = DateButton() ## ??????? options
		pack(hbox, self.dateInput)
		pack(vb, hbox)
		###
		pack(self.vbox, vb, 0, 0, 10)#?????
		self.vboxMan = vb
		######
		hbox = gtk.HBox()
		self.radioNtp = gtk.RadioButton.new_with_mnemonic_from_widget(
			radio_group_member=self.radioMan,
			label=_("Set from _NTP:"),
		)
		self.radioNtp.connect("clicked", self.radioNtpClicked)
		pack(hbox, self.radioNtp)
		pack(self.vbox, hbox)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		pack(hbox, gtk.Label(label=_("Server:") + " "))
		combo = gtk.ComboBoxText.new_with_entry()
		combo.get_child().connect("changed", self.updateSetButtonSensitive)
		pack(hbox, combo, 1, 1)
		self.ntpServerEntry = combo.get_child()
		for s in ui.ntpServers:
			combo.append_text(s)
		combo.set_active(0)
		self.hboxNtp = hbox
		pack(self.vbox, hbox)
		######
		self.radioManClicked()
		#self.radioNtpClicked()
		self.ckeckbEditTimeClicked()
		self.ckeckbEditDateClicked()
		######
		self.updateTimes()
		self.vbox.show_all()
示例#17
0
class AdjusterDialog(gtk.Dialog):
	xpad = 15

	def __init__(self, **kwargs):
		gtk.Dialog.__init__(self, **kwargs)
		self.set_title(_("Adjust System Date & Time"))  # FIXME
		self.set_keep_above(True)
		try:
			self.set_icon(IconTheme.get_default().load_icon(
				icon_name = "preferences-system-time",
				size = 32,
				flags = 0,
			))
		except Exception:
			pass
		# render_icon: Deprecated since version 3.0: Use Gtk.Widget.render_icon_pixbuf() instead.
		# render_icon_pixbuf: Deprecated since version 3.10: Use Gtk.IconTheme.load_icon() instead.
		#########
		self.buttonCancel = self.add_button(gtk.STOCK_CANCEL, 0)
		#self.buttonCancel.connect("clicked", lambda w: sys.exit(0))
		self.buttonSet = self.add_button(_("Set System Time"), 1)
		#self.buttonSet.connect("clicked", self.setSysTimeClicked)
		#########
		hbox = gtk.HBox()
		self.label_cur = gtk.Label(label=_("Current:"))
		pack(hbox, self.label_cur)
		pack(self.vbox, hbox)
		#########
		hbox = gtk.HBox()
		self.radioMan = gtk.RadioButton.new_with_mnemonic(
			group=None,
			label=_("Set _Manully:"),
		)
		self.radioMan.connect("clicked", self.radioManClicked)
		pack(hbox, self.radioMan)
		pack(self.vbox, hbox)
		######
		vb = gtk.VBox()
		sg = gtk.SizeGroup(mode=gtk.SizeGroupMode.HORIZONTAL)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		self.ckeckbEditTime = gtk.CheckButton.new_with_mnemonic(_("Edit _Time"))
		self.editTime = False
		self.ckeckbEditTime.connect("clicked", self.ckeckbEditTimeClicked)
		pack(hbox, self.ckeckbEditTime)
		sg.add_widget(self.ckeckbEditTime)
		self.timeInput = TimeButton() ## ??????? options
		pack(hbox, self.timeInput)
		pack(vb, hbox)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		self.ckeckbEditDate = gtk.CheckButton.new_with_mnemonic(_("Edit _Date"))
		self.editDate = False
		self.ckeckbEditDate.connect("clicked", self.ckeckbEditDateClicked)
		pack(hbox, self.ckeckbEditDate)
		sg.add_widget(self.ckeckbEditDate)
		self.dateInput = DateButton() ## ??????? options
		pack(hbox, self.dateInput)
		pack(vb, hbox)
		###
		pack(self.vbox, vb, 0, 0, 10)#?????
		self.vboxMan = vb
		######
		hbox = gtk.HBox()
		self.radioNtp = gtk.RadioButton.new_with_mnemonic_from_widget(
			radio_group_member=self.radioMan,
			label=_("Set from _NTP:"),
		)
		self.radioNtp.connect("clicked", self.radioNtpClicked)
		pack(hbox, self.radioNtp)
		pack(self.vbox, hbox)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		pack(hbox, gtk.Label(label=_("Server:") + " "))
		combo = gtk.ComboBoxText.new_with_entry()
		combo.get_child().connect("changed", self.updateSetButtonSensitive)
		pack(hbox, combo, 1, 1)
		self.ntpServerEntry = combo.get_child()
		for s in ui.ntpServers:
			combo.append_text(s)
		combo.set_active(0)
		self.hboxNtp = hbox
		pack(self.vbox, hbox)
		######
		self.radioManClicked()
		#self.radioNtpClicked()
		self.ckeckbEditTimeClicked()
		self.ckeckbEditDateClicked()
		######
		self.updateTimes()
		self.vbox.show_all()

	def radioManClicked(self, radio=None):
		if self.radioMan.get_active():
			self.vboxMan.set_sensitive(True)
			self.hboxNtp.set_sensitive(False)
		else:
			self.vboxMan.set_sensitive(False)
			self.hboxNtp.set_sensitive(True)
		self.updateSetButtonSensitive()

	def radioNtpClicked(self, radio=None):
		if self.radioNtp.get_active():
			self.vboxMan.set_sensitive(False)
			self.hboxNtp.set_sensitive(True)
		else:
			self.vboxMan.set_sensitive(True)
			self.hboxNtp.set_sensitive(False)
		self.updateSetButtonSensitive()

	def ckeckbEditTimeClicked(self, checkb=None):
		self.editTime = self.ckeckbEditTime.get_active()
		self.timeInput.set_sensitive(self.editTime)
		self.updateSetButtonSensitive()

	def ckeckbEditDateClicked(self, checkb=None):
		self.editDate = self.ckeckbEditDate.get_active()
		self.dateInput.set_sensitive(self.editDate)
		self.updateSetButtonSensitive()

	#def set_sys_time(self):
	#	if os.path.isfile("/bin/date"):
	#		pass  # FIXME
	#	elif sys.platform == "win32":
	#		import win32api
	#		win32api.SetSystemTime()##????????
	#	else:
	#		pass

	def updateTimes(self):
		dt = now() % 1
		timeout_add(clockWaitMilliseconds(), self.updateTimes)
		#print("updateTimes", dt)
		lt = localtime()
		self.label_cur.set_label(
			_("Current:") +
			" %.4d/%.2d/%.2d - %.2d:%.2d:%.2d" % lt[:6]
		)
		if not self.editTime:
			self.timeInput.set_value(lt[3:6])
		if not self.editDate:
			self.dateInput.set_value(lt[:3])
		return False

	def updateSetButtonSensitive(self, widget=None):
		if self.radioMan.get_active():
			self.buttonSet.set_sensitive(self.editTime or self.editDate)
		elif self.radioNtp.get_active():
			self.buttonSet.set_sensitive(
				self.ntpServerEntry.get_text() != ""
			)

	def setSysTimeClicked(self, widget=None):
		if self.radioMan.get_active():
			if self.editTime:
				h, m, s = self.timeInput.get_value()
				if self.editDate:
					Y, M, D = self.dateInput.get_value()
					cmd = [
						"/bin/date",
						"-s",
						"%.4d/%.2d/%.2d %.2d:%.2d:%.2d" % (
							Y, M, D,
							h, m, s,
						),
					]
				else:
					cmd = [
						"/bin/date",
						"-s",
						"%.2d:%.2d:%.2d" % (h, m, s),
					]
			else:
				if self.editDate:
					Y, M, D = self.dateInput.get_value()
					##h, m, s = self.timeInput.get_value()
					h, m, s = localtime()[3:6]
					cmd = [
						"/bin/date",
						"-s",
						"%.4d/%.2d/%.2d %.2d:%.2d:%.2d" % (
							Y, M, D,
							h, m, s,
						),
					]
				else:
					error_exit("No change!", self)  # FIXME
		elif self.radioNtp.get_active():
			cmd = ["ntpdate", self.ntpServerEntry.get_text()]
			#if os.path.isfile("/usr/sbin/ntpdate"):
			#	cmd = ["/usr/sbin/ntpdate", self.ntpServerEntry.get_text()]
			#else:
			#	error_exit(
			#	"Could not find command /usr/sbin/ntpdate: no such file!",
			#	self,
			#)  # FIXME
		else:
			error_exit("Not valid option!", self)
		proc = subprocess.Popen(
			cmd,
			stderr=subprocess.PIPE,
			stdout=subprocess.PIPE,
		)
		resCode = proc.wait()
		error = proc.stderr.read().strip()
		output = proc.stdout.read().strip()
		if output:
			print(output)
		#print("resCode=%r, error=%r, output=%r" % (resCode, error, output))
		if error:
			print(error)
		if resCode != 0:
			error_exit(
				resCode,
				error,
				parent=self,
			)
示例#18
0
class WidgetClass(common.WidgetClass):
    def __init__(self, event):  ## FIXME
        common.WidgetClass.__init__(self, event)
        ######
        sizeGroup = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
        ######
        hbox = gtk.HBox()
        label = gtk.Label(_('Start'))
        label.set_alignment(0, 0.5)
        sizeGroup.add_widget(label)
        pack(hbox, label)
        self.startDateInput = DateButton()
        pack(hbox, self.startDateInput)
        ##
        pack(hbox, gtk.Label(' ' + _('Time')))
        self.startTimeInput = TimeButton()
        pack(hbox, self.startTimeInput)
        ##
        pack(self, hbox)
        ######
        hbox = gtk.HBox()
        self.endTypeCombo = gtk.ComboBoxText()
        for item in ('Duration', 'End'):
            self.endTypeCombo.append_text(_(item))
        self.endTypeCombo.connect('changed', self.endTypeComboChanged)
        sizeGroup.add_widget(self.endTypeCombo)
        pack(hbox, self.endTypeCombo)
        ####
        self.durationBox = common.DurationInputBox()
        pack(hbox, self.durationBox, 1, 1)
        ####
        self.endDateHbox = gtk.HBox()
        self.endDateInput = DateButton()
        pack(self.endDateHbox, self.endDateInput)
        ##
        pack(self.endDateHbox, gtk.Label(' ' + _('Time')))
        self.endTimeInput = TimeButton()
        pack(self.endDateHbox, self.endTimeInput)
        ##
        pack(hbox, self.endDateHbox, 1, 1)
        ####
        pack(hbox, gtk.Label(''), 1, 1)
        pack(self, hbox)
        #############
        self.notificationBox = common.NotificationBox(event)
        pack(self, self.notificationBox)
        #############
        #self.filesBox = common.FilesBox(self.event)
        #pack(self, self.filesBox)
    def endTypeComboChanged(self, combo=None):
        active = self.endTypeCombo.get_active()
        if active == 0:  ## duration
            self.durationBox.show()
            self.endDateHbox.hide()
        elif active == 1:  ## end date
            self.durationBox.hide()
            self.endDateHbox.show()
        else:
            raise RuntimeError

    def updateWidget(self):  ## FIXME
        common.WidgetClass.updateWidget(self)
        ###
        startDate, startTime = self.event.getStart()
        self.startDateInput.set_value(startDate)
        self.startTimeInput.set_value(startTime)
        ###
        endType, values = self.event.getEnd()
        if endType == 'duration':
            self.endTypeCombo.set_active(0)
            self.durationBox.setDuration(*values)
            self.endDateInput.set_value(startDate)  ## FIXME
            self.endTimeInput.set_value(startTime)  ## FIXME
        elif endType == 'date':
            self.endTypeCombo.set_active(1)
            self.endDateInput.set_value(values[0])
            self.endTimeInput.set_value(values[1])
        else:
            raise RuntimeError
        self.endTypeComboChanged()

    def updateVars(self):  ## FIXME
        common.WidgetClass.updateVars(self)
        self.event.setStart(self.startDateInput.get_value(),
                            self.startTimeInput.get_value())
        ###
        active = self.endTypeCombo.get_active()
        if active == 0:
            self.event.setEnd('duration', *self.durationBox.getDuration())
        elif active == 1:
            self.event.setEnd(
                'date',
                self.endDateInput.get_value(),
                self.endTimeInput.get_value(),
            )

    def modeComboChanged(self,
                         obj=None
                         ):  ## overwrite method from common.WidgetClass
        newMode = self.modeCombo.get_active()
        self.startDateInput.changeMode(self.event.mode, newMode)
        self.endDateInput.changeMode(self.event.mode, newMode)
        self.event.mode = newMode
示例#19
0
 def __init__(self, rule):
     self.rule = rule
     TimeButton.__init__(self)
示例#20
0
class AdjusterDialog(gtk.Dialog):
    xpad = 15

    def __init__(self, **kwargs):
        gtk.Dialog.__init__(self, **kwargs)
        self.set_title(_("Adjust System Date & Time"))  ##????????
        self.set_icon(self.render_icon(gtk.STOCK_PREFERENCES, gtk.IconSize.BUTTON))
        #########
        self.buttonCancel = self.add_button(gtk.STOCK_CANCEL, 0)
        # self.buttonCancel.connect('clicked', lambda w: sys.exit(0))
        self.buttonSet = self.add_button(_("Set System Time"), 1)
        # self.buttonSet.connect('clicked', self.setSysTimeClicked)
        #########
        hbox = gtk.HBox()
        self.label_cur = gtk.Label(_("Current:"))
        pack(hbox, self.label_cur)
        pack(self.vbox, hbox)
        #########
        hbox = gtk.HBox()
        self.radioMan = gtk.RadioButton(None, _("Set _Manully:"), True)
        self.radioMan.connect("clicked", self.radioManClicked)
        pack(hbox, self.radioMan)
        pack(self.vbox, hbox)
        ######
        vb = gtk.VBox()
        sg = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
        ###
        hbox = gtk.HBox()
        ##
        l = gtk.Label("")
        l.set_property("width-request", self.xpad)
        pack(hbox, l)
        ##
        self.ckeckbEditTime = gtk.CheckButton(_("Edit Time"))
        self.editTime = False
        self.ckeckbEditTime.connect("clicked", self.ckeckbEditTimeClicked)
        pack(hbox, self.ckeckbEditTime)
        sg.add_widget(self.ckeckbEditTime)
        self.timeInput = TimeButton()  ## ??????? options
        pack(hbox, self.timeInput)
        pack(vb, hbox)
        ###
        hbox = gtk.HBox()
        ##
        l = gtk.Label("")
        l.set_property("width-request", self.xpad)
        pack(hbox, l)
        ##
        self.ckeckbEditDate = gtk.CheckButton(_("Edit Date"))
        self.editDate = False
        self.ckeckbEditDate.connect("clicked", self.ckeckbEditDateClicked)
        pack(hbox, self.ckeckbEditDate)
        sg.add_widget(self.ckeckbEditDate)
        self.dateInput = DateButton()  ## ??????? options
        pack(hbox, self.dateInput)
        pack(vb, hbox)
        ###
        pack(self.vbox, vb, 0, 0, 10)  # ?????
        self.vboxMan = vb
        ######
        hbox = gtk.HBox()
        self.radioNtp = gtk.RadioButton(group=self.radioMan, label=_("Set from NTP:"))
        self.radioNtp.connect("clicked", self.radioNtpClicked)
        pack(hbox, self.radioNtp)
        pack(self.vbox, hbox)
        ###
        hbox = gtk.HBox()
        ##
        l = gtk.Label("")
        l.set_property("width-request", self.xpad)
        pack(hbox, l)
        ##
        pack(hbox, gtk.Label(_("Server:") + " "))
        combo = gtk.ComboBoxText.new_with_entry()
        combo.get_child().connect("changed", self.updateSetButtonSensitive)
        pack(hbox, combo, 1, 1)
        self.ntpServerEntry = combo.get_child()
        for s in ui.ntpServers:
            combo.append_text(s)
        combo.set_active(0)
        self.hboxNtp = hbox
        pack(self.vbox, hbox)
        ######
        self.radioManClicked()
        # self.radioNtpClicked()
        self.ckeckbEditTimeClicked()
        self.ckeckbEditDateClicked()
        ######
        self.updateTimes()
        self.vbox.show_all()

    def radioManClicked(self, radio=None):
        if self.radioMan.get_active():
            self.vboxMan.set_sensitive(True)
            self.hboxNtp.set_sensitive(False)
        else:
            self.vboxMan.set_sensitive(False)
            self.hboxNtp.set_sensitive(True)
        self.updateSetButtonSensitive()

    def radioNtpClicked(self, radio=None):
        if self.radioNtp.get_active():
            self.vboxMan.set_sensitive(False)
            self.hboxNtp.set_sensitive(True)
        else:
            self.vboxMan.set_sensitive(True)
            self.hboxNtp.set_sensitive(False)
        self.updateSetButtonSensitive()

    def ckeckbEditTimeClicked(self, checkb=None):
        self.editTime = self.ckeckbEditTime.get_active()
        self.timeInput.set_sensitive(self.editTime)
        self.updateSetButtonSensitive()

    def ckeckbEditDateClicked(self, checkb=None):
        self.editDate = self.ckeckbEditDate.get_active()
        self.dateInput.set_sensitive(self.editDate)
        self.updateSetButtonSensitive()

    """def set_sys_time(self):
        if os.path.isfile('/bin/date'):
            pass##????????
        elif sys.platform == 'win32':
            import win32api
            win32api.SetSystemTime()##????????
        else:
            pass"""

    def updateTimes(self):
        dt = now() % 1
        timeout_add(iceil(1000 * (1 - dt)), self.updateTimes)
        # print('updateTimes', dt)
        lt = localtime()
        self.label_cur.set_label(_("Current:") + " %.4d/%.2d/%.2d - %.2d:%.2d:%.2d" % lt[:6])
        if not self.editTime:
            self.timeInput.set_value(lt[3:6])
        if not self.editDate:
            self.dateInput.set_value(lt[:3])
        return False

    def updateSetButtonSensitive(self, widget=None):
        if self.radioMan.get_active():
            self.buttonSet.set_sensitive(self.editTime or self.editDate)
        elif self.radioNtp.get_active():
            self.buttonSet.set_sensitive(self.ntpServerEntry.get_text() != "")

    def setSysTimeClicked(self, widget=None):
        if self.radioMan.get_active():
            if self.editTime:
                h, m, s = self.timeInput.get_value()
                if self.editDate:
                    Y, M, D = self.dateInput.get_value()
                    cmd = ["/bin/date", "-s", "%.4d/%.2d/%.2d %.2d:%.2d:%.2d" % (Y, M, D, h, m, s)]
                else:
                    cmd = ["/bin/date", "-s", "%.2d:%.2d:%.2d" % (h, m, s)]
            else:
                if self.editDate:
                    Y, M, D = self.dateInput.get_value()
                    ##h, m, s = self.timeInput.get_value()
                    h, m, s = localtime()[3:6]
                    cmd = ["/bin/date", "-s", "%.4d/%.2d/%.2d %.2d:%.2d:%.2d" % (Y, M, D, h, m, s)]
                else:
                    error_exit("No change!", self)  # ??????????
        elif self.radioNtp.get_active():
            cmd = ["ntpdate", self.ntpServerEntry.get_text()]
            # if os.path.isfile('/usr/sbin/ntpdate'):
            #    cmd = ['/usr/sbin/ntpdate', self.ntpServerEntry.get_text()]
            # else:
            #    error_exit('Could not find command /usr/sbin/ntpdate: no such file!', self)#??????????
        else:
            error_exit("Not valid option!", self)
        proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        resCode = proc.wait()
        error = proc.stderr.read().strip()
        output = proc.stdout.read().strip()
        if output:
            print(output)
        # print('resCode=%r, error=%r, output=%r' % (resCode, error, output))
        if error:
            print(error)
        if resCode != 0:
            error_exit(resCode, error, parent=self)
示例#21
0
	def __init__(self, **kwargs):
		gtk.Dialog.__init__(self, **kwargs)
		self.set_title(_("Adjust System Date & Time"))  # FIXME
		self.set_keep_above(True)
		self.set_icon(IconTheme.get_default().load_icon(
			icon_name = "preferences-system-time",
			size = 32,
			flags = 0,
		))
		# render_icon: Deprecated since version 3.0: Use Gtk.Widget.render_icon_pixbuf() instead.
		# render_icon_pixbuf: Deprecated since version 3.10: Use Gtk.IconTheme.load_icon() instead.
		#########
		self.buttonCancel = self.add_button(gtk.STOCK_CANCEL, 0)
		#self.buttonCancel.connect("clicked", lambda w: sys.exit(0))
		self.buttonSet = self.add_button(_("Set System Time"), 1)
		#self.buttonSet.connect("clicked", self.setSysTimeClicked)
		#########
		hbox = gtk.HBox()
		self.label_cur = gtk.Label(label=_("Current:"))
		pack(hbox, self.label_cur)
		pack(self.vbox, hbox)
		#########
		hbox = gtk.HBox()
		self.radioMan = gtk.RadioButton.new_with_mnemonic(
			group=None,
			label=_("Set _Manully:"),
		)
		self.radioMan.connect("clicked", self.radioManClicked)
		pack(hbox, self.radioMan)
		pack(self.vbox, hbox)
		######
		vb = gtk.VBox()
		sg = gtk.SizeGroup(mode=gtk.SizeGroupMode.HORIZONTAL)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		self.ckeckbEditTime = gtk.CheckButton.new_with_mnemonic(_("Edit _Time"))
		self.editTime = False
		self.ckeckbEditTime.connect("clicked", self.ckeckbEditTimeClicked)
		pack(hbox, self.ckeckbEditTime)
		sg.add_widget(self.ckeckbEditTime)
		self.timeInput = TimeButton() ## ??????? options
		pack(hbox, self.timeInput)
		pack(vb, hbox)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		self.ckeckbEditDate = gtk.CheckButton.new_with_mnemonic(_("Edit _Date"))
		self.editDate = False
		self.ckeckbEditDate.connect("clicked", self.ckeckbEditDateClicked)
		pack(hbox, self.ckeckbEditDate)
		sg.add_widget(self.ckeckbEditDate)
		self.dateInput = DateButton() ## ??????? options
		pack(hbox, self.dateInput)
		pack(vb, hbox)
		###
		pack(self.vbox, vb, 0, 0, 10)#?????
		self.vboxMan = vb
		######
		hbox = gtk.HBox()
		self.radioNtp = gtk.RadioButton.new_with_mnemonic_from_widget(
			radio_group_member=self.radioMan,
			label=_("Set from _NTP:"),
		)
		self.radioNtp.connect("clicked", self.radioNtpClicked)
		pack(hbox, self.radioNtp)
		pack(self.vbox, hbox)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		pack(hbox, gtk.Label(label=_("Server:") + " "))
		combo = gtk.ComboBoxText.new_with_entry()
		combo.get_child().connect("changed", self.updateSetButtonSensitive)
		pack(hbox, combo, 1, 1)
		self.ntpServerEntry = combo.get_child()
		for s in ui.ntpServers:
			combo.append_text(s)
		combo.set_active(0)
		self.hboxNtp = hbox
		pack(self.vbox, hbox)
		######
		self.radioManClicked()
		#self.radioNtpClicked()
		self.ckeckbEditTimeClicked()
		self.ckeckbEditDateClicked()
		######
		self.updateTimes()
		self.vbox.show_all()
示例#22
0
class AdjusterDialog(gtk.Dialog):
    xpad = 15

    def __init__(self, **kwargs):
        gtk.Dialog.__init__(self, **kwargs)
        self.set_title(_('Adjust System Date & Time'))  ##????????
        self.set_icon(
            self.render_icon(gtk.STOCK_PREFERENCES, gtk.IconSize.BUTTON))
        #########
        self.buttonCancel = self.add_button(gtk.STOCK_CANCEL, 0)
        #self.buttonCancel.connect('clicked', lambda w: sys.exit(0))
        self.buttonSet = self.add_button(_('Set System Time'), 1)
        #self.buttonSet.connect('clicked', self.setSysTimeClicked)
        #########
        hbox = gtk.HBox()
        self.label_cur = gtk.Label(_('Current:'))
        pack(hbox, self.label_cur)
        pack(self.vbox, hbox)
        #########
        hbox = gtk.HBox()
        self.radioMan = gtk.RadioButton(None, _('Set _Manully:'), True)
        self.radioMan.connect('clicked', self.radioManClicked)
        pack(hbox, self.radioMan)
        pack(self.vbox, hbox)
        ######
        vb = gtk.VBox()
        sg = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
        ###
        hbox = gtk.HBox()
        ##
        l = gtk.Label('')
        l.set_property('width-request', self.xpad)
        pack(hbox, l)
        ##
        self.ckeckbEditTime = gtk.CheckButton(_('Edit Time'))
        self.editTime = False
        self.ckeckbEditTime.connect('clicked', self.ckeckbEditTimeClicked)
        pack(hbox, self.ckeckbEditTime)
        sg.add_widget(self.ckeckbEditTime)
        self.timeInput = TimeButton()  ## ??????? options
        pack(hbox, self.timeInput)
        pack(vb, hbox)
        ###
        hbox = gtk.HBox()
        ##
        l = gtk.Label('')
        l.set_property('width-request', self.xpad)
        pack(hbox, l)
        ##
        self.ckeckbEditDate = gtk.CheckButton(_('Edit Date'))
        self.editDate = False
        self.ckeckbEditDate.connect('clicked', self.ckeckbEditDateClicked)
        pack(hbox, self.ckeckbEditDate)
        sg.add_widget(self.ckeckbEditDate)
        self.dateInput = DateButton()  ## ??????? options
        pack(hbox, self.dateInput)
        pack(vb, hbox)
        ###
        pack(self.vbox, vb, 0, 0, 10)  #?????
        self.vboxMan = vb
        ######
        hbox = gtk.HBox()
        self.radioNtp = gtk.RadioButton(group=self.radioMan,
                                        label=_('Set from NTP:'))
        self.radioNtp.connect('clicked', self.radioNtpClicked)
        pack(hbox, self.radioNtp)
        pack(self.vbox, hbox)
        ###
        hbox = gtk.HBox()
        ##
        l = gtk.Label('')
        l.set_property('width-request', self.xpad)
        pack(hbox, l)
        ##
        pack(hbox, gtk.Label(_('Server:') + ' '))
        combo = gtk.ComboBoxText.new_with_entry()
        combo.get_child().connect('changed', self.updateSetButtonSensitive)
        pack(hbox, combo, 1, 1)
        self.ntpServerEntry = combo.get_child()
        for s in ui.ntpServers:
            combo.append_text(s)
        combo.set_active(0)
        self.hboxNtp = hbox
        pack(self.vbox, hbox)
        ######
        self.radioManClicked()
        #self.radioNtpClicked()
        self.ckeckbEditTimeClicked()
        self.ckeckbEditDateClicked()
        ######
        self.updateTimes()
        self.vbox.show_all()

    def radioManClicked(self, radio=None):
        if self.radioMan.get_active():
            self.vboxMan.set_sensitive(True)
            self.hboxNtp.set_sensitive(False)
        else:
            self.vboxMan.set_sensitive(False)
            self.hboxNtp.set_sensitive(True)
        self.updateSetButtonSensitive()

    def radioNtpClicked(self, radio=None):
        if self.radioNtp.get_active():
            self.vboxMan.set_sensitive(False)
            self.hboxNtp.set_sensitive(True)
        else:
            self.vboxMan.set_sensitive(True)
            self.hboxNtp.set_sensitive(False)
        self.updateSetButtonSensitive()

    def ckeckbEditTimeClicked(self, checkb=None):
        self.editTime = self.ckeckbEditTime.get_active()
        self.timeInput.set_sensitive(self.editTime)
        self.updateSetButtonSensitive()

    def ckeckbEditDateClicked(self, checkb=None):
        self.editDate = self.ckeckbEditDate.get_active()
        self.dateInput.set_sensitive(self.editDate)
        self.updateSetButtonSensitive()

    """def set_sys_time(self):
		if os.path.isfile('/bin/date'):
			pass##????????
		elif sys.platform == 'win32':
			import win32api
			win32api.SetSystemTime()##????????
		else:
			pass"""

    def updateTimes(self):
        dt = now() % 1
        timeout_add(iceil(1000 * (1 - dt)), self.updateTimes)
        #print('updateTimes', dt)
        lt = localtime()
        self.label_cur.set_label(
            _('Current:') + ' %.4d/%.2d/%.2d - %.2d:%.2d:%.2d' % lt[:6])
        if not self.editTime:
            self.timeInput.set_value(lt[3:6])
        if not self.editDate:
            self.dateInput.set_value(lt[:3])
        return False

    def updateSetButtonSensitive(self, widget=None):
        if self.radioMan.get_active():
            self.buttonSet.set_sensitive(self.editTime or self.editDate)
        elif self.radioNtp.get_active():
            self.buttonSet.set_sensitive(self.ntpServerEntry.get_text() != '')

    def setSysTimeClicked(self, widget=None):
        if self.radioMan.get_active():
            if self.editTime:
                h, m, s = self.timeInput.get_value()
                if self.editDate:
                    Y, M, D = self.dateInput.get_value()
                    cmd = [
                        '/bin/date', '-s',
                        '%.4d/%.2d/%.2d %.2d:%.2d:%.2d' % (Y, M, D, h, m, s)
                    ]
                else:
                    cmd = ['/bin/date', '-s', '%.2d:%.2d:%.2d' % (h, m, s)]
            else:
                if self.editDate:
                    Y, M, D = self.dateInput.get_value()
                    ##h, m, s = self.timeInput.get_value()
                    h, m, s = localtime()[3:6]
                    cmd = [
                        '/bin/date', '-s',
                        '%.4d/%.2d/%.2d %.2d:%.2d:%.2d' % (Y, M, D, h, m, s)
                    ]
                else:
                    error_exit('No change!', self)  #??????????
        elif self.radioNtp.get_active():
            cmd = ['ntpdate', self.ntpServerEntry.get_text()]
            #if os.path.isfile('/usr/sbin/ntpdate'):
            #	cmd = ['/usr/sbin/ntpdate', self.ntpServerEntry.get_text()]
            #else:
            #	error_exit('Could not find command /usr/sbin/ntpdate: no such file!', self)#??????????
        else:
            error_exit('Not valid option!', self)
        proc = subprocess.Popen(
            cmd,
            stderr=subprocess.PIPE,
            stdout=subprocess.PIPE,
        )
        resCode = proc.wait()
        error = proc.stderr.read().strip()
        output = proc.stdout.read().strip()
        if output:
            print(output)
        #print('resCode=%r, error=%r, output=%r' % (resCode, error, output))
        if error:
            print(error)
        if resCode != 0:
            error_exit(
                resCode,
                error,
                parent=self,
            )
示例#23
0
 def __init__(self, rule):
     self.rule = rule
     TimeButton.__init__(self)
示例#24
0
 def __init__(self, **kwargs):
     gtk.Dialog.__init__(self, **kwargs)
     self.set_title(_("Adjust System Date & Time"))  ##????????
     self.set_icon(self.render_icon(gtk.STOCK_PREFERENCES, gtk.IconSize.BUTTON))
     #########
     self.buttonCancel = self.add_button(gtk.STOCK_CANCEL, 0)
     # self.buttonCancel.connect('clicked', lambda w: sys.exit(0))
     self.buttonSet = self.add_button(_("Set System Time"), 1)
     # self.buttonSet.connect('clicked', self.setSysTimeClicked)
     #########
     hbox = gtk.HBox()
     self.label_cur = gtk.Label(_("Current:"))
     pack(hbox, self.label_cur)
     pack(self.vbox, hbox)
     #########
     hbox = gtk.HBox()
     self.radioMan = gtk.RadioButton(None, _("Set _Manully:"), True)
     self.radioMan.connect("clicked", self.radioManClicked)
     pack(hbox, self.radioMan)
     pack(self.vbox, hbox)
     ######
     vb = gtk.VBox()
     sg = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
     ###
     hbox = gtk.HBox()
     ##
     l = gtk.Label("")
     l.set_property("width-request", self.xpad)
     pack(hbox, l)
     ##
     self.ckeckbEditTime = gtk.CheckButton(_("Edit Time"))
     self.editTime = False
     self.ckeckbEditTime.connect("clicked", self.ckeckbEditTimeClicked)
     pack(hbox, self.ckeckbEditTime)
     sg.add_widget(self.ckeckbEditTime)
     self.timeInput = TimeButton()  ## ??????? options
     pack(hbox, self.timeInput)
     pack(vb, hbox)
     ###
     hbox = gtk.HBox()
     ##
     l = gtk.Label("")
     l.set_property("width-request", self.xpad)
     pack(hbox, l)
     ##
     self.ckeckbEditDate = gtk.CheckButton(_("Edit Date"))
     self.editDate = False
     self.ckeckbEditDate.connect("clicked", self.ckeckbEditDateClicked)
     pack(hbox, self.ckeckbEditDate)
     sg.add_widget(self.ckeckbEditDate)
     self.dateInput = DateButton()  ## ??????? options
     pack(hbox, self.dateInput)
     pack(vb, hbox)
     ###
     pack(self.vbox, vb, 0, 0, 10)  # ?????
     self.vboxMan = vb
     ######
     hbox = gtk.HBox()
     self.radioNtp = gtk.RadioButton(group=self.radioMan, label=_("Set from NTP:"))
     self.radioNtp.connect("clicked", self.radioNtpClicked)
     pack(hbox, self.radioNtp)
     pack(self.vbox, hbox)
     ###
     hbox = gtk.HBox()
     ##
     l = gtk.Label("")
     l.set_property("width-request", self.xpad)
     pack(hbox, l)
     ##
     pack(hbox, gtk.Label(_("Server:") + " "))
     combo = gtk.ComboBoxText.new_with_entry()
     combo.get_child().connect("changed", self.updateSetButtonSensitive)
     pack(hbox, combo, 1, 1)
     self.ntpServerEntry = combo.get_child()
     for s in ui.ntpServers:
         combo.append_text(s)
     combo.set_active(0)
     self.hboxNtp = hbox
     pack(self.vbox, hbox)
     ######
     self.radioManClicked()
     # self.radioNtpClicked()
     self.ckeckbEditTimeClicked()
     self.ckeckbEditDateClicked()
     ######
     self.updateTimes()
     self.vbox.show_all()
示例#25
0
 def __init__(self, **kwargs):
     gtk.Dialog.__init__(self, **kwargs)
     self.set_title(_('Adjust System Date & Time'))  ##????????
     self.set_icon(
         self.render_icon(gtk.STOCK_PREFERENCES, gtk.IconSize.BUTTON))
     #########
     self.buttonCancel = self.add_button(gtk.STOCK_CANCEL, 0)
     #self.buttonCancel.connect('clicked', lambda w: sys.exit(0))
     self.buttonSet = self.add_button(_('Set System Time'), 1)
     #self.buttonSet.connect('clicked', self.setSysTimeClicked)
     #########
     hbox = gtk.HBox()
     self.label_cur = gtk.Label(_('Current:'))
     pack(hbox, self.label_cur)
     pack(self.vbox, hbox)
     #########
     hbox = gtk.HBox()
     self.radioMan = gtk.RadioButton(None, _('Set _Manully:'), True)
     self.radioMan.connect('clicked', self.radioManClicked)
     pack(hbox, self.radioMan)
     pack(self.vbox, hbox)
     ######
     vb = gtk.VBox()
     sg = gtk.SizeGroup(gtk.SizeGroupMode.HORIZONTAL)
     ###
     hbox = gtk.HBox()
     ##
     l = gtk.Label('')
     l.set_property('width-request', self.xpad)
     pack(hbox, l)
     ##
     self.ckeckbEditTime = gtk.CheckButton(_('Edit Time'))
     self.editTime = False
     self.ckeckbEditTime.connect('clicked', self.ckeckbEditTimeClicked)
     pack(hbox, self.ckeckbEditTime)
     sg.add_widget(self.ckeckbEditTime)
     self.timeInput = TimeButton()  ## ??????? options
     pack(hbox, self.timeInput)
     pack(vb, hbox)
     ###
     hbox = gtk.HBox()
     ##
     l = gtk.Label('')
     l.set_property('width-request', self.xpad)
     pack(hbox, l)
     ##
     self.ckeckbEditDate = gtk.CheckButton(_('Edit Date'))
     self.editDate = False
     self.ckeckbEditDate.connect('clicked', self.ckeckbEditDateClicked)
     pack(hbox, self.ckeckbEditDate)
     sg.add_widget(self.ckeckbEditDate)
     self.dateInput = DateButton()  ## ??????? options
     pack(hbox, self.dateInput)
     pack(vb, hbox)
     ###
     pack(self.vbox, vb, 0, 0, 10)  #?????
     self.vboxMan = vb
     ######
     hbox = gtk.HBox()
     self.radioNtp = gtk.RadioButton(group=self.radioMan,
                                     label=_('Set from NTP:'))
     self.radioNtp.connect('clicked', self.radioNtpClicked)
     pack(hbox, self.radioNtp)
     pack(self.vbox, hbox)
     ###
     hbox = gtk.HBox()
     ##
     l = gtk.Label('')
     l.set_property('width-request', self.xpad)
     pack(hbox, l)
     ##
     pack(hbox, gtk.Label(_('Server:') + ' '))
     combo = gtk.ComboBoxText.new_with_entry()
     combo.get_child().connect('changed', self.updateSetButtonSensitive)
     pack(hbox, combo, 1, 1)
     self.ntpServerEntry = combo.get_child()
     for s in ui.ntpServers:
         combo.append_text(s)
     combo.set_active(0)
     self.hboxNtp = hbox
     pack(self.vbox, hbox)
     ######
     self.radioManClicked()
     #self.radioNtpClicked()
     self.ckeckbEditTimeClicked()
     self.ckeckbEditDateClicked()
     ######
     self.updateTimes()
     self.vbox.show_all()
示例#26
0
class AdjusterDialog(gtk.Dialog):
	xpad = 15

	def __init__(self, **kwargs):
		gtk.Dialog.__init__(self, **kwargs)
		self.set_title(_("Adjust System Date & Time"))  # FIXME
		self.set_keep_above(True)
		self.set_icon(IconTheme.get_default().load_icon(
			icon_name = "preferences-system-time",
			size = 32,
			flags = 0,
		))
		# render_icon: Deprecated since version 3.0: Use Gtk.Widget.render_icon_pixbuf() instead.
		# render_icon_pixbuf: Deprecated since version 3.10: Use Gtk.IconTheme.load_icon() instead.
		#########
		self.buttonCancel = self.add_button(gtk.STOCK_CANCEL, 0)
		#self.buttonCancel.connect("clicked", lambda w: sys.exit(0))
		self.buttonSet = self.add_button(_("Set System Time"), 1)
		#self.buttonSet.connect("clicked", self.setSysTimeClicked)
		#########
		hbox = gtk.HBox()
		self.label_cur = gtk.Label(label=_("Current:"))
		pack(hbox, self.label_cur)
		pack(self.vbox, hbox)
		#########
		hbox = gtk.HBox()
		self.radioMan = gtk.RadioButton.new_with_mnemonic(
			group=None,
			label=_("Set _Manully:"),
		)
		self.radioMan.connect("clicked", self.radioManClicked)
		pack(hbox, self.radioMan)
		pack(self.vbox, hbox)
		######
		vb = gtk.VBox()
		sg = gtk.SizeGroup(mode=gtk.SizeGroupMode.HORIZONTAL)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		self.ckeckbEditTime = gtk.CheckButton.new_with_mnemonic(_("Edit _Time"))
		self.editTime = False
		self.ckeckbEditTime.connect("clicked", self.ckeckbEditTimeClicked)
		pack(hbox, self.ckeckbEditTime)
		sg.add_widget(self.ckeckbEditTime)
		self.timeInput = TimeButton() ## ??????? options
		pack(hbox, self.timeInput)
		pack(vb, hbox)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		self.ckeckbEditDate = gtk.CheckButton.new_with_mnemonic(_("Edit _Date"))
		self.editDate = False
		self.ckeckbEditDate.connect("clicked", self.ckeckbEditDateClicked)
		pack(hbox, self.ckeckbEditDate)
		sg.add_widget(self.ckeckbEditDate)
		self.dateInput = DateButton() ## ??????? options
		pack(hbox, self.dateInput)
		pack(vb, hbox)
		###
		pack(self.vbox, vb, 0, 0, 10)#?????
		self.vboxMan = vb
		######
		hbox = gtk.HBox()
		self.radioNtp = gtk.RadioButton.new_with_mnemonic_from_widget(
			radio_group_member=self.radioMan,
			label=_("Set from _NTP:"),
		)
		self.radioNtp.connect("clicked", self.radioNtpClicked)
		pack(hbox, self.radioNtp)
		pack(self.vbox, hbox)
		###
		hbox = gtk.HBox()
		##
		l = gtk.Label()
		l.set_property("width-request", self.xpad)
		pack(hbox, l)
		##
		pack(hbox, gtk.Label(label=_("Server:") + " "))
		combo = gtk.ComboBoxText.new_with_entry()
		combo.get_child().connect("changed", self.updateSetButtonSensitive)
		pack(hbox, combo, 1, 1)
		self.ntpServerEntry = combo.get_child()
		for s in ui.ntpServers:
			combo.append_text(s)
		combo.set_active(0)
		self.hboxNtp = hbox
		pack(self.vbox, hbox)
		######
		self.radioManClicked()
		#self.radioNtpClicked()
		self.ckeckbEditTimeClicked()
		self.ckeckbEditDateClicked()
		######
		self.updateTimes()
		self.vbox.show_all()

	def radioManClicked(self, radio=None):
		if self.radioMan.get_active():
			self.vboxMan.set_sensitive(True)
			self.hboxNtp.set_sensitive(False)
		else:
			self.vboxMan.set_sensitive(False)
			self.hboxNtp.set_sensitive(True)
		self.updateSetButtonSensitive()

	def radioNtpClicked(self, radio=None):
		if self.radioNtp.get_active():
			self.vboxMan.set_sensitive(False)
			self.hboxNtp.set_sensitive(True)
		else:
			self.vboxMan.set_sensitive(True)
			self.hboxNtp.set_sensitive(False)
		self.updateSetButtonSensitive()

	def ckeckbEditTimeClicked(self, checkb=None):
		self.editTime = self.ckeckbEditTime.get_active()
		self.timeInput.set_sensitive(self.editTime)
		self.updateSetButtonSensitive()

	def ckeckbEditDateClicked(self, checkb=None):
		self.editDate = self.ckeckbEditDate.get_active()
		self.dateInput.set_sensitive(self.editDate)
		self.updateSetButtonSensitive()

	#def set_sys_time(self):
	#	if os.path.isfile("/bin/date"):
	#		pass  # FIXME
	#	elif sys.platform == "win32":
	#		import win32api
	#		win32api.SetSystemTime()##????????
	#	else:
	#		pass

	def updateTimes(self):
		dt = now() % 1
		timeout_add(clockWaitMilliseconds(), self.updateTimes)
		#print("updateTimes", dt)
		lt = localtime()
		self.label_cur.set_label(
			_("Current:") +
			" %.4d/%.2d/%.2d - %.2d:%.2d:%.2d" % lt[:6]
		)
		if not self.editTime:
			self.timeInput.set_value(lt[3:6])
		if not self.editDate:
			self.dateInput.set_value(lt[:3])
		return False

	def updateSetButtonSensitive(self, widget=None):
		if self.radioMan.get_active():
			self.buttonSet.set_sensitive(self.editTime or self.editDate)
		elif self.radioNtp.get_active():
			self.buttonSet.set_sensitive(
				self.ntpServerEntry.get_text() != ""
			)

	def setSysTimeClicked(self, widget=None):
		if self.radioMan.get_active():
			if self.editTime:
				h, m, s = self.timeInput.get_value()
				if self.editDate:
					Y, M, D = self.dateInput.get_value()
					cmd = [
						"/bin/date",
						"-s",
						"%.4d/%.2d/%.2d %.2d:%.2d:%.2d" % (
							Y, M, D,
							h, m, s,
						),
					]
				else:
					cmd = [
						"/bin/date",
						"-s",
						"%.2d:%.2d:%.2d" % (h, m, s),
					]
			else:
				if self.editDate:
					Y, M, D = self.dateInput.get_value()
					##h, m, s = self.timeInput.get_value()
					h, m, s = localtime()[3:6]
					cmd = [
						"/bin/date",
						"-s",
						"%.4d/%.2d/%.2d %.2d:%.2d:%.2d" % (
							Y, M, D,
							h, m, s,
						),
					]
				else:
					error_exit("No change!", self)  # FIXME
		elif self.radioNtp.get_active():
			cmd = ["ntpdate", self.ntpServerEntry.get_text()]
			#if os.path.isfile("/usr/sbin/ntpdate"):
			#	cmd = ["/usr/sbin/ntpdate", self.ntpServerEntry.get_text()]
			#else:
			#	error_exit(
			#	"Could not find command /usr/sbin/ntpdate: no such file!",
			#	self,
			#)  # FIXME
		else:
			error_exit("Not valid option!", self)
		proc = subprocess.Popen(
			cmd,
			stderr=subprocess.PIPE,
			stdout=subprocess.PIPE,
		)
		resCode = proc.wait()
		error = proc.stderr.read().strip()
		output = proc.stdout.read().strip()
		if output:
			print(output)
		#print("resCode=%r, error=%r, output=%r" % (resCode, error, output))
		if error:
			print(error)
		if resCode != 0:
			error_exit(
				resCode,
				error,
				parent=self,
			)