Пример #1
0
	def timeEdited(self, cell, path, newText):
		index = int(path)
		parts = newText.split(":")
		h = numDecode(parts[0])
		m = numDecode(parts[1])
		hm = hmEncode((h, m))
		self.trees[index][0] = hm
Пример #2
0
	def timeEdited(self, cell, path, newText):
		index = int(path)
		parts = newText.split(':')
		h = numDecode(parts[0])
		m = numDecode(parts[1])
		hm = hmEncode((h, m))
		self.trees[index][0] = hm
Пример #3
0
def parseDroppedDate(text):
	part = text.split("/")
	if len(part) == 3:
		try:
			part[0] = numDecode(part[0])
			part[1] = numDecode(part[1])
			part[2] = numDecode(part[2])
		except:
			myRaise(__file__)
			return None
		maxPart = max(part)
		if maxPart > 999:
			minMax = (
				(1000, 2100),
				(1, 12),
				(1, 31),
			)
			formats = (
				[0, 1, 2],
				[1, 2, 0],
				[2, 1, 0],
			)
			for format in formats:
				for i in range(3):
					valid = True
					f = format[i]
					if not (minMax[f][0] <= part[i] <= minMax[f][1]):
						valid = False
						break
				if valid:
					# "format" must be list because we use method "index"
					year = part[format.index(0)]
					month = part[format.index(1)]
					day = part[format.index(2)]
					break
		else:
			valid = 0 <= part[0] <= 99 and \
				1 <= part[1] <= 12 and \
				1 <= part[2] <= 31
			###
			year = 2000 + part[0]  # FIXME
			month = part[1]
			day = part[2]
		if not valid:
			return None
	else:
		return None
	# FIXME: when drag from a persian GtkCalendar with format %y/%m/%d
	#if year < 100:
	#	year += 2000
	return (year, month, day)
Пример #4
0
def parseDroppedDate(text):
	part = text.split("/")
	if len(part) == 3:
		try:
			part[0] = numDecode(part[0])
			part[1] = numDecode(part[1])
			part[2] = numDecode(part[2])
		except:
			myRaise(__file__)
			return None
		maxPart = max(part)
		if maxPart > 999:
			minMax = (
				(1000, 2100),
				(1, 12),
				(1, 31),
			)
			formats = (
				[0, 1, 2],
				[1, 2, 0],
				[2, 1, 0],
			)
			for format in formats:
				for i in range(3):
					valid = True
					f = format[i]
					if not (minMax[f][0] <= part[i] <= minMax[f][1]):
						valid = False
						break
				if valid:
					# "format" must be list because we use method "index"
					year = part[format.index(0)]
					month = part[format.index(1)]
					day = part[format.index(2)]
					break
		else:
			valid = 0 <= part[0] <= 99 and \
				1 <= part[1] <= 12 and \
				1 <= part[2] <= 31
			###
			year = 2000 + part[0]  # FIXME
			month = part[1]
			day = part[2]
		if not valid:
			return None
	else:
		return None
	# FIXME: when drag from a persian GtkCalendar with format %y/%m/%d
	#if year < 100:
	#	year += 2000
	return (year, month, day)
Пример #5
0
 def keyPress(self, obj, gevent):
     kval = gevent.keyval
     kname = gdk.keyval_name(gevent.keyval).lower()
     #print(kval, kname)
     if kname in (
         'tab', 'escape', 'backspace', 'delete', 'insert',
         'home', 'end',
         'control_l', 'control_r',
         'iso_next_group',
     ):
         return False
     elif kname == 'return':
         self.validate()
         return False
     elif kname=='up':
         self.numPlus(1)
     elif kname=='down':
         self.numPlus(-1)
     elif kname=='page_up':
         self.numPlus(self.page_inc)
     elif kname=='page_down':
         self.numPlus(-self.page_inc)
     elif kname=='left':
         return False## FIXME
     elif kname=='right':
         return False## FIXME
     #elif kname in ('braceleft', 'bracketleft'):
     #    self.insertText(u'[')
     #elif kname in ('braceright', 'bracketright'):
     #    self.insertText(u']')
     elif kname in ('comma', 'arabic_comma'):
         self.insertText(', ', False)
     elif kname=='minus':
         pos = self.get_position()
         text = toStr(self.get_text())
         n = len(text)
         if pos==n:
             start = numDecode(text.split(',')[-1].strip())
             self.insertText('-' + _(start + 2), False)
         else:
             self.insertText('-', False)
     elif ord('0') <= kval <= ord('9'):
         self.insertText(self.digs[kval-ord('0')])
     else:
         uniVal = gdk.keyval_to_unicode(kval)
         #print('uniVal=%r'%uniVal)
         if uniVal!=0:
             ch = chr(uniVal)
             #print('ch=%r'%ch)
             if ch in self.digs:
                 self.insertText(ch)
             if gevent.get_state() & gdk.ModifierType.CONTROL_MASK:## Shortcuts like Ctrl + [A, C, X, V]
                 return False
         else:
             print(kval, kname)
     return True
Пример #6
0
	def keyPress(self, obj, gevent):
		kval = gevent.keyval
		kname = gdk.keyval_name(gevent.keyval).lower()
		#print(kval, kname)
		if kname in (
			'tab', 'escape', 'backspace', 'delete', 'insert',
			'home', 'end',
			'control_l', 'control_r',
			'iso_next_group',
		):
			return False
		elif kname == 'return':
			self.validate()
			return False
		elif kname=='up':
			self.numPlus(1)
		elif kname=='down':
			self.numPlus(-1)
		elif kname=='page_up':
			self.numPlus(self.page_inc)
		elif kname=='page_down':
			self.numPlus(-self.page_inc)
		elif kname=='left':
			return False## FIXME
		elif kname=='right':
			return False## FIXME
		#elif kname in ('braceleft', 'bracketleft'):
		#	self.insertText(u'[')
		#elif kname in ('braceright', 'bracketright'):
		#	self.insertText(u']')
		elif kname in ('comma', 'arabic_comma'):
			self.insertText(', ', False)
		elif kname=='minus':
			pos = self.get_position()
			text = toStr(self.get_text())
			n = len(text)
			if pos==n:
				start = numDecode(text.split(',')[-1].strip())
				self.insertText('-' + _(start + 2), False)
			else:
				self.insertText('-', False)
		elif ord('0') <= kval <= ord('9'):
			self.insertText(self.digs[kval-ord('0')])
		else:
			uniVal = gdk.keyval_to_unicode(kval)
			#print('uniVal=%r'%uniVal)
			if uniVal!=0:
				ch = chr(uniVal)
				#print('ch=%r'%ch)
				if ch in self.digs:
					self.insertText(ch)
				if gevent.get_state() & gdk.ModifierType.CONTROL_MASK:## Shortcuts like Ctrl + [A, C, X, V]
					return False
			else:
				print(kval, kname)
		return True
Пример #7
0
 def numPlus(self, plus):
     pos = self.get_position()
     text = toStr(self.get_text())
     n = len(text)
     commaI = text.rfind(',', 0, pos)
     if commaI == -1:
         startI = 0
     else:
         if text[commaI + 1] == ' ':
             startI = commaI + 2
         else:
             startI = commaI + 1
     nextCommaI = text.find(',', pos)
     if nextCommaI == -1:
         endI = n
     else:
         endI = nextCommaI
     dashI = text.find('-', startI, endI)
     if dashI != -1:
         #print('dashI=%r'%dashI)
         if pos < dashI:
             endI = dashI
         else:
             startI = dashI + 1
     thisNumStr = text[startI:endI]
     #print(startI, endI, thisNumStr)
     if thisNumStr:
         thisNum = numDecode(thisNumStr)
         newNum = thisNum + plus
         if not self._min <= newNum <= self._max:
             return
     else:
         if plus > 0:
             newNum = self._max
         else:
             newNum = self._min
     newNumStr = _(newNum)
     newText = text[:startI] + newNumStr + text[endI:]
     self.set_text(newText)
     #print('new end index', endI - len(thisNumStr) + len(newNumStr))
     self.set_position(pos)
     self.select_region(
         startI,
         endI - len(thisNumStr) + len(newNumStr),
     )
Пример #8
0
 def numPlus(self, plus):
     pos = self.get_position()
     text = toStr(self.get_text())
     n = len(text)
     commaI = text.rfind(',', 0, pos)
     if commaI == -1:
         startI = 0
     else:
         if text[commaI+1]==' ':
             startI = commaI + 2
         else:
             startI = commaI + 1
     nextCommaI = text.find(',', pos)
     if nextCommaI == -1:
         endI = n
     else:
         endI = nextCommaI
     dashI = text.find('-', startI, endI)
     if dashI != -1:
         #print('dashI=%r'%dashI)
         if pos < dashI:
             endI = dashI
         else:
             startI = dashI + 1
     thisNumStr = text[startI:endI]
     #print(startI, endI, thisNumStr)
     if thisNumStr:
         thisNum = numDecode(thisNumStr)
         newNum = thisNum + plus
         if not self._min <= newNum <= self._max:
             return
     else:
         if plus > 0:
             newNum = self._max
         else:
             newNum = self._min
     newNumStr = _(newNum)
     newText = text[:startI] + newNumStr + text[endI:]
     self.set_text(newText)
     #print('new end index', endI - len(thisNumStr) + len(newNumStr))
     self.set_position(pos)
     self.select_region(
         startI,
         endI - len(thisNumStr) + len(newNumStr),
     )
Пример #9
0
	def courseUnitsEdited(self, cell, path, newText):
		index = int(path)
		units = numDecode(newText)
		self.trees[index][2] = units
Пример #10
0
	def courseUnitsEdited(self, cell, path, newText):
		index = int(path)
		units = numDecode(newText)
		self.trees[index][2] = units
Пример #11
0
	def keyPress(self, obj, gevent):
		kval = gevent.keyval
		kname = gdk.keyval_name(gevent.keyval).lower()
		#print(kval, kname)
		if kname in (
			"tab",
			"escape",
			"backspace",
			"delete",
			"insert",
			"home",
			"end",
			"control_l",
			"control_r",
			"iso_next_group",
		):
			return False
		elif kname == "return":
			self.validate()
			return False
		elif kname == "up":
			self.numPlus(1)
		elif kname == "down":
			self.numPlus(-1)
		elif kname == "page_up":
			self.numPlus(self.page_inc)
		elif kname == "page_down":
			self.numPlus(-self.page_inc)
		elif kname == "left":
			return False  # FIXME
		elif kname == "right":
			return False  # FIXME
		#elif kname in ("braceleft", "bracketleft"):
		#	self.insertText(u"[")
		#elif kname in ("braceright", "bracketright"):
		#	self.insertText(u"]")
		elif kname in ("comma", "arabic_comma"):
			self.insertText(", ", False)
		elif kname == "minus":
			pos = self.get_position()
			text = toStr(self.get_text())
			n = len(text)
			if pos == n:
				start = numDecode(text.split(",")[-1].strip())
				self.insertText("-" + _(start + 2), False)
			else:
				self.insertText("-", False)
		elif ord("0") <= kval <= ord("9"):
			self.insertText(self.digs[kval - ord("0")])
		else:
			uniVal = gdk.keyval_to_unicode(kval)
			#print("uniVal=%r"%uniVal)
			if uniVal != 0:
				ch = chr(uniVal)
				#print("ch=%r"%ch)
				if ch in self.digs:
					self.insertText(ch)
				if gevent.get_state() & gdk.ModifierType.CONTROL_MASK:
					# Shortcuts like Ctrl + [A, C, X, V]
					return False
			else:
				print(kval, kname)
		return True