Changeset 834:5651e303daa9 for src/mlx/gui/common.py
- Timestamp:
- 04/17/17 06:47:25 (7 years ago)
- Branch:
- default
- hg-Phase:
- (<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/gui/common.py
r833 r834 8 8 9 9 import os 10 import time11 10 12 11 #----------------------------------------------------------------------------- … … 284 283 else str(self._currentInteger)) 285 284 self._selfSetting = False 286 287 #------------------------------------------------------------------------------288 289 class TimeEntry(gtk.Entry):290 """Widget to display and edit a time value in HH:MM format."""291 def __init__(self):292 """Construct the entry"""293 super(TimeEntry, self).__init__(max = 5)294 295 self.connect("insert-text", self._insertText)296 self.connect("delete-text", self._deleteText)297 self.connect("focus-out-event", self._focusOutEvent)298 299 @property300 def hour(self):301 """Get the hour from the current text"""302 text = self.get_text()303 if not text or text==":":304 return 0305 306 words = text.split(":")307 if len(words)==1:308 return 0309 elif len(words)>=2:310 return 0 if len(words[0])==0 else int(words[0])311 else:312 return 0313 314 @property315 def minute(self):316 """Get the hour from the current text"""317 text = self.get_text()318 if not text or text==":":319 return 0320 321 words = text.split(":")322 if len(words)==1:323 return 0 if len(words[0])==0 else int(words[0])324 elif len(words)>=2:325 return 0 if len(words[1])==0 else int(words[1])326 else:327 return 0328 329 def setTimestamp(self, timestamp):330 """Set the hour and minute from the given timestamp in UTC."""331 tm = time.gmtime(timestamp)332 self.set_text("%02d:%02d" % (tm.tm_hour, tm.tm_min))333 334 def _focusOutEvent(self, widget, event):335 """Reformat the text to match pattern HH:MM"""336 text = "%02d:%02d" % (self.hour, self.minute)337 if text!=self.get_text():338 self.set_text(text)339 340 def _insertText(self, entry, text, length, position):341 """Called when some text is inserted into the entry."""342 text=text[:length]343 currentText = self.get_text()344 position = self.get_position()345 newText = currentText[:position] + text + currentText[position:]346 self._checkText(newText, "insert-text")347 348 def _deleteText(self, entry, start, end):349 """Called when some text is erased from the entry."""350 currentText = self.get_text()351 newText = currentText[:start] + currentText[end:]352 self._checkText(newText, "delete-text")353 354 def _checkText(self, newText, signal):355 """Check the given text.356 357 If it is not suitable, stop the emission of the signal to prevent the358 change from appearing."""359 if not newText or newText==":":360 return361 362 words = newText.split(":")363 if (len(words)==1 and364 len(words[0])<=2 and (len(words[0])==0 or365 (words[0].isdigit() and int(words[0])<60))) or \366 (len(words)==2 and367 len(words[0])<=2 and (len(words[0])==0 or368 (words[0].isdigit() and int(words[0])<24)) and369 len(words[1])<=2 and (len(words[1])==0 or370 (words[1].isdigit() and int(words[1])<60))):371 pass372 else:373 gtk.gdk.display_get_default().beep()374 self.stop_emission(signal)375 285 376 286 #------------------------------------------------------------------------------ … … 609 519 610 520 #------------------------------------------------------------------------------ 611 612 def createFlightTypeComboBox():613 flightTypeModel = gtk.ListStore(str, int)614 for type in _const.flightTypes:615 name = "flighttype_" + _const.flightType2string(type)616 flightTypeModel.append([xstr(name), type])617 618 flightType = gtk.ComboBox(model = flightTypeModel)619 renderer = gtk.CellRendererText()620 flightType.pack_start(renderer, True)621 flightType.add_attribute(renderer, "text", 0)622 623 return flightType624 625 #------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.