def onStop(self): log.debug('############ onStop') self.lyricsPanel.pauseAnimation() self.playing = False #self.fadeOut() self.lastStop = gobject.get_current_time() gobject.timeout_add(5000, lambda: self.minimize("paused") if not self.playing and (gobject.get_current_time() - self.lastStop) > 4.8 else 1)
def sequencer_pitch_tap(self): '''Sequencer pitch tap button clicked.''' if self.tap_counter == 0: # first tap, grab time self.start_time = gobject.get_current_time() self.tap_counter = 1 else: if self.tap_counter == 1: # second tap, count up self.tap_counter = 2 else: if self.tap_counter == 2: # second tap, count up self.tap_counter = 3 else: if self.tap_counter == 3: # third tap, get time, set bpm self.end_time = gobject.get_current_time() self.time = (self.end_time - self.start_time) / 3 if self.time < 2: self.bpm = int(60.0 / self.time) self.loop_callback() self.tap_counter = 0 # return bpm to gui to update it return self.bpm
def pause(self): print "############## Pause Animation" self.timeline.pause() self.stop() if self.timer != None: self._step_elapsed += (gobject.get_current_time() - self._step_start) * 1000 print "pause, elapsed %f" % self._step_elapsed if self.startupDelayTimer != None: self._delay_elapsed += (gobject.get_current_time() - self._delay_start) * 1000
def changeLyrics(self, songFile): print "CHANGE LYRICS" self.fading = False if songFile != None: self.lyricsPanel.stopAnimation() #self.lyricsPanel.actualLine = 0 self.lyricsPanel.render_lyrics = False self.t1 = gobject.get_current_time() self.lyricsPanel.setLyrics(None) #print "new song -> set elapsed 0.2" # depends on fade duration self.lyricsPanel.setElapsed(0.2) songInfo = {} if not songFile.startswith("http"): songInfo = {'file': songFile} title = self.player.getTitle() if title != None and len(title) > 0: songInfo['title'] = self.player.getTitle() artist = self.player.getArtist() if artist != None and len(artist) > 0: songInfo['artist'] = artist album = self.player.getAlbum() if album != None and len(album) > 0: songInfo['album'] = album print "Song Info:" print songInfo if not songInfo.has_key('artist') and title: if title.find("-") != -1: info = title.split("-") songInfo['artist'] = info[0].strip() songInfo['title'] = info[1].strip() if songInfo['title'].find("(") != -1: songInfo['title'] = songInfo['title'][ : songInfo['title'].find("(")].strip() print songInfo self.songInfo = songInfo self.lyricsList = [] self.saveFirstLyrics = False lyrics = self.getLyricsFromDisk() if lyrics != None: self.addLyrics(lyrics) elif songInfo.has_key('file'): alsongEngine = ALSong.ALSongEngine() self.freezeXmmsPlayer() lyrics = alsongEngine.findByCheckSum(songInfo['file']) #print "skipping alsong" #lyrics = None self.defreezeXmmsPlayer() self.saveFirstLyrics = True if lyrics != None: self.addLyrics(lyrics) else: #print "GO AND FIND ON NET!" self.searchOnNet() else: self.saveFirstLyrics = True self.searchOnNet()
def new_game(tw): tw.deck.shuffle() tw.deck.deal(tw) tw.matches = 0 tw.total_time = 0 tw.start_time = gobject.get_current_time() tw.timeout_id = None _counter(tw)
def __init__(self, text_iter, text, length): self.time = gobject.get_current_time() self.offset = text_iter.get_offset() self.text = text self.length = length if self.length > 1 or self.text in ('\r', '\n', ' '): self.mergeable = False else: self.mergeable = True
def show(self, obj, event=None): self.gui.get_object('shutdown_check').set_sensitive(True) if self.timer: diff = (self.endtime - int(gobject.get_current_time())) / 60 self.gui.get_object('spinbutton4').set_value(int(diff)) self.gui.get_object('lblShutdownCancel').show() else: self.gui.get_object('spinbutton4').set_value(0) self.gui.get_object('sleepw').show()
def timer_callback(self, p): start = gobject.get_current_time() """one second timer callback""" if not self.timer_enable: return True self.meta_pos += 1 self.error_check() if self.meta_pos >= self.meta_total or self.error: self.play_next() return False self.progress.set_value(float(self.meta_pos) / self.meta_total * 100) self.meta_pos_view_update() self.proxy.lyric_view.scroll_lyric(self.meta_pos) end = gobject.get_current_time() losttime = int((end - start) * 1000) # We have lost some time self.timer = gobject.timeout_add(1000 - losttime, self.timer_callback, self) # Start a new one return False
def _scroll_out_init(self, part): draw_area = part.get_allocation() self._scroller = gobject.timeout_add( max(int(1000.0 / self.ANIMATE_FPS), 10), # interval self._scroll_out_cb, part.get_size_request()[0], self.ANIMATE_DURATION*0.001, # 1 over duration (converted to seconds) gobject.get_current_time(), (draw_area.x, draw_area.y, draw_area.width, draw_area.height)) return False
def __hscroll_out_init(self, distance, draw_area, duration, fps): self.__scroller = gobject.timeout_add( int(1000.0 / fps), # interval self.__hscroll_out_cb, distance, duration*0.001, # 1 over duration (converted to seconds) gobject.get_current_time(), draw_area.x, draw_area.y, draw_area.width, draw_area.height) return
def resume(self): self.timeline.resume() print "############## Resume Animation" print self.timer if self.timer != None: self._step_start = gobject.get_current_time() print "resume main animation" #print "elapsed %f" % self._step_elapsed #print "wait %d" % int(self.duration/self.steps_count - self._step_elapsed) print self.fraction self.timer = gobject.timeout_add(int(self.duration/self.steps_count), self.animation) remaining_time = self.duration/self.steps_count - self._step_elapsed #if remaining_time > 5: #self.timer = gobject.timeout_add(int(remaining_time), self.animation) #else: # self.animation() if self.startupDelayTimer != None: print "resume startup delay" self._delay_start = gobject.get_current_time() self.startupDelayTimer = gobject.timeout_add(int(self.startupDelay - self._delay_elapsed), self.__start)
def set_shutdown(self, value, halt=False): if self.timer: gobject.source_remove(self.timer) if self.warning_timer: gobject.source_remove(self.warning_timer) self.warning_timer = None self.timer = None timeout = value * 1000 * 60 if timeout == 0: self.cancel(None) else: if value > 1: self.warning_timer = gobject.timeout_add((value * 1000 * 60) - 60000, self.warning) self.timer = gobject.timeout_add(timeout, self.shutdown, halt) self.endtime = int(gobject.get_current_time()) + timeout / 1000
def __hscroll_out_cb(self, distance, duration, start_t, x, y, w, h): cur_t = gobject.get_current_time() xO = distance - distance*((cur_t - start_t) / duration) if xO > 0: self.__scroll_xO = xO self.queue_draw_area(x, y, w, h) else: # final frame self.__scroll_xO = 0 # redraw the entire widget # incase some timeouts are skipped due to high system load self.queue_draw() self.__scroller = None return False return True
def set_shutdown(self, value, halt=False): if self.timer: gobject.source_remove(self.timer) if self.warning_timer: gobject.source_remove(self.warning_timer) self.warning_timer = None self.timer = None timeout = value * 1000 * 60 if timeout == 0: self.cancel(None) else: if value > 1: self.warning_timer = gobject.timeout_add( (value * 1000 * 60) - 60000, self.warning) self.timer = gobject.timeout_add(timeout, self.shutdown, halt) self.endtime = int(gobject.get_current_time()) + timeout / 1000
def __init__(self, text_buffer, start_iter, end_iter): self.time = gobject.get_current_time() self.text = text_buffer.get_text(start_iter, end_iter) self.start = start_iter.get_offset() self.end = end_iter.get_offset() # need to find out if backspace or delete key has been used # so we don't mess up during redo insert_iter = text_buffer.get_iter_at_mark(text_buffer.get_insert()) if insert_iter.get_offset() <= self.start: self.delete_key_used = True else: self.delete_key_used = False if self.end - self.start > 1 or self.text in ('\r', '\n', ' '): self.mergeable = False else: self.mergeable = True
def remote(self): cycles = [0, 15, 30, 60, 120, 180] next = 0 if self.timer: diff = (self.endtime - int(gobject.get_current_time())) / 60 if self.remoteiter == -1: self.OSD("Sleep: " + str(diff) + ' min') if diff > cycles[len(cycles) - 1]: self.remoteiter = 0 else: for c, t in enumerate(cycles): if diff >= t: self.remoteiter = c else: if self.remoteiter > len(cycles) - 1: self.remoteiter = 0 next = cycles[self.remoteiter] if next > 0: self.OSD( "Sleep: " + str(next) + " min\nWarning: this will turn off your computer!") self.set_shutdown(next, True) else: self.cancel(None) self.OSD("Sleep: disabled") else: if self.remoteiter == -1: self.OSD("Sleep: disabled") self.cancel(None) self.remoteiter = 0 else: if self.remoteiter > len(cycles) - 1: self.remoteiter = 0 next = cycles[self.remoteiter] if next > 0: self.OSD( "Sleep: " + str(next) + " min\nWarning: this will turn off your computer!") self.set_shutdown(next, True) else: self.cancel(None) self.OSD("Sleep: disabled") self.remoteiter = self.remoteiter + 1 if self.remoteres: gobject.source_remove(self.remoteres) self.remoteres = gobject.timeout_add(3000, self.reset_remote)
def start(self, after_callback, reverse = False): #print "START ANIMATION" self.after_callback = after_callback self.stop() self.reverse = reverse if self.reverse: self.time = self.steps_count else: self.time = 0 if self.startupDelay > 0: #gobject.timeout_add(self.startupDelay, lambda: self.minimize("paused") if not self.playing and (gobject.get_current_time() - self.lastStop) > 4.8 else 1) #gobject.timeout_add(self.startupDelay, lambda: self.timer = gobject.timeout_add(self.duration/self.steps_count, self.animation, reverse)) self.startupDelayTimer = gobject.timeout_add(self.startupDelay, self.__start) self._delay_elapsed = 0 self._delay_start = gobject.get_current_time() else: self.__start()
def animation(self): self._step_elapsed = 0 self._step_start = gobject.get_current_time() if self.reverse: self.time -= 1 else: self.time += 1 if self.time < 0 or self.time > self.steps_count: if self.loop: self.start(self.after_callback, self.reverse) else: self.onFinish() return False self.fraction = self.time/float(self.steps_count) self.interpolateTransitions() self.after_callback() return True
def remote(self): cycles = [0, 15, 30, 60, 120, 180] next = 0 if self.timer: diff = (self.endtime - int(gobject.get_current_time())) / 60 if self.remoteiter == -1: self.OSD("Sleep: " + str(diff) + ' min') if diff > cycles[len(cycles)-1]: self.remoteiter = 0 else: for c, t in enumerate(cycles): if diff >= t: self.remoteiter = c else: if self.remoteiter > len(cycles)-1: self.remoteiter = 0 next = cycles[self.remoteiter] if next > 0: self.OSD("Sleep: " + str(next) + " min\nWarning: this will turn off your computer!") self.set_shutdown(next, True) else: self.cancel(None) self.OSD("Sleep: disabled") else: if self.remoteiter == -1: self.OSD("Sleep: disabled") self.cancel(None) self.remoteiter = 0 else: if self.remoteiter > len(cycles)-1: self.remoteiter = 0 next = cycles[self.remoteiter] if next > 0: self.OSD("Sleep: " + str(next) + " min\nWarning: this will turn off your computer!") self.set_shutdown(next, True) else: self.cancel(None) self.OSD("Sleep: disabled") self.remoteiter = self.remoteiter + 1 if self.remoteres: gobject.source_remove(self.remoteres) self.remoteres = gobject.timeout_add(3000, self.reset_remote)
def __init__(self): super(type(self), self).__init__() self._to_search_region = None self._search_text = None self._uri = None self._vfs_uri = None self._untitled_number = get_untitled_number() self._mime_type = "text/plain" self._readonly = False self._stop_cursor_moved_emission = False self._last_save_was_manually = True self._language_set_by_user = False self._dispose_has_run = False self._mtime = 0 self._time_of_last_save_or_load = gobject.get_current_time() self._encoding = encoding_get_utf8() self.set_max_undo_levels(prefs_manager_get_undo_actions_limit()) self.set_highlight_matching_brackets( prefs_manager_get_bracket_matching()) self.set_enable_search_highlighting( prefs_manager_get_enable_search_highlighting()) self.set_highlight_syntax(True) style_scheme = get_default_style_scheme() if style_scheme != None: self.set_style_scheme(style_scheme)
def __init__(self): super(type(self), self).__init__() self._to_search_region = None self._search_text = None self._uri = None self._vfs_uri = None self._untitled_number = get_untitled_number() self._mime_type = "text/plain" self._readonly = False self._stop_cursor_moved_emission = False self._last_save_was_manually = True self._language_set_by_user = False self._dispose_has_run = False self._mtime = 0 self._time_of_last_save_or_load = gobject.get_current_time() self._encoding = encoding_get_utf8() self.set_max_undo_levels(prefs_manager_get_undo_actions_limit()) self.set_highlight_matching_brackets(prefs_manager_get_bracket_matching()) self.set_enable_search_highlighting(prefs_manager_get_enable_search_highlighting()) self.set_highlight_syntax(True) style_scheme = get_default_style_scheme() if style_scheme != None: self.set_style_scheme(style_scheme)
def update_track(self): def worker(track): self.__update_track(track) self.fetcher.fetch_lyrics(track, self.__timestamp) self.cover_display.fetch_cover() return False gobject.source_remove(self.__tid) track = player.get_track() state = player.get_state() if track == self.track: return self.__clear() self.__timestamp = gobject.get_current_time() if state == blaconst.STATE_STOPPED or player.radio: BlaSidePane.track = None self.cover_display.reset() else: self.__tid = gobject.timeout_add(self.__DELAY, worker, track) BlaSidePane.track = track
def __update_timestamp(self): # Update and return the new timestamp. self.__timestamp = gobject.get_current_time() return self.__timestamp
def _counter(tw): tw.activity.clock_label.set_text(str(int(gobject.get_current_time()-\ tw.start_time))) tw.timeout_id = gobject.timeout_add(1000, _counter, tw)
def resume(self): if self.stopped: self.real = gobject.get_current_time() self.stopped = False
def getTime(self): if self.stopped: return self.elapsed return self.elapsed+(gobject.get_current_time() - self.real)*1000
def setTime(self, time): print "SET TIME %f" % time self.elapsed = time self.real = gobject.get_current_time()
def pause(self): if not self.stopped: self.elapsed += (gobject.get_current_time() - self.real)*1000 self.stopped = True
def drawComponent(self, ctx): #print "redraw Lyrics Panel" #print self.anim_fraction #print self.actualLine t_start = gobject.get_current_time() matrix = ctx.get_matrix() self.text_matrix = cairo.Matrix(1, matrix[1], matrix[2], 1, matrix[4], matrix[5]) lastScale = self.gscale self.gscale = matrix[0] if self.gscale != lastScale: self.resizeBuffers() ctx.set_matrix(self.text_matrix) #ctx.scale(1.0/scale_x, 1.0/scale_y) if self.layout == None: self.layout = ctx.create_layout() self.setAlignment() self.layout.set_font_description(self.font) self.clipBounds = Rectangle(*[int(ceil(v))for v in ctx.clip_extents()]) #print self.clipBounds #print 'draw: '+str(ctx.clip_extents()) #ctx.set_source_rgba(1, 0, 0, 1) #ctx.rectangle(0, 0, self.bounds.width, self.bounds.height) #ctx.fill() #ctx.set_operator(cairo.OPERATOR_SOURCE) ctx.set_operator(cairo.OPERATOR_OVER) if not self.text_scale or not self.font:# or not self.color_highlight or not self.color_normal: return ######################### ##### RENDER LYRICS ##### ######################### if self.lyrics_need_update: self.updateLyrics() """ if ([self.actualLine, self.animation.fraction] == self.lastState): #TODO add lyrics to state print "EQUAL" #return else: print "NOT EQUAL" self.lastState = [self.actualLine, self.animation.fraction] """ #options = ctx.get_font_options() #options.set_hint_metrics(cairo.HINT_METRICS_OFF) #options.set_hint_style(cairo.HINT_STYLE_FULL) #ctx.set_font_options(options) if self._buffer1 == None: self._buffer1 = PixmapBuffer(self.root.root.window, self.bounds.width*self.gscale*0.9, 20) if self._buffer2 == None: self._buffer2 = PixmapBuffer(self.root.root.window, self.bounds.width*self.gscale, 20) if self.anim_fraction == 1.0: self.anim_fraction = 0.0 self.textForAnimation = None self.actualLine += 1 if self.render_lyrics and self.lyrics and self.actualLine < len(self.lyrics.entities): #fraction = math.sin(self.animation.fraction*1.57) fraction = math.sin(self.anim_fraction*1.57) # non-linear interpolation of animation fraction #fraction = self.anim_fraction ############################### ##### Compute positioning ##### ############################### if ([self.actualLine, self.anim_fraction] != self.lastState): #TODO add lyrics to state actual_y = (self.bounds.height - self.lyrics.entities[self.actualLine].trimmed_height*self.text_scale)/2.0 if self.actualLine+1 < len(self.lyrics.entities): next_y = (self.bounds.height - self.lyrics.entities[self.actualLine+1].trimmed_height*self.text_scale)/2.0 # center y position, interpolation between actual and next texts y-center position (if their heights are diffrent) self.center_y = actual_y+(next_y-actual_y)*fraction else: self.center_y = actual_y self.center_y = int(self.center_y) # texts moving animation - actual text must translate about it's height by y-axle self.motion_y = -fraction*(self.lyrics.entities[self.actualLine].height) # decreasing scale text factor in animation self.dec_scale = self.text_scale-fraction*(self.text_scale-1.0) # increasing scale text factor in animation self.inc_scale = 1.0+fraction*(self.text_scale-1.0) # must be integer due to nice text rendering on raster if self.textAlign == ALIGN_CENTER: self.center_x = int(((self.bounds.width-self.bounds.width/self.text_scale)/2.0)*self.gscale) elif self.textAlign == ALIGN_LEFT: self.center_x = 0 else: self.center_x = int((self.bounds.width-self.bounds.width/self.text_scale)*self.gscale) #self.center_x = ((self.bounds.width-self.bounds.width/self.text_scale)/2.0)*self.gscale #print (self.center_y + self.motion_y)*self.gscale if self.textForAnimation != self.actualLine: #print "treba to %f" % self.anim_fraction self.textForAnimation = self.actualLine # resize text buffer if needed if self.lyrics.entities[self.actualLine].height*self.gscale > self._buffer1.height: self._buffer1.resize(self._buffer1.width, self.lyrics.entities[self.actualLine].height*self.gscale) self._buffer1.clear() #options = self._buffer1.ctx.get_font_options() #options.set_hint_metrics(cairo.HINT_METRICS_OFF) #self._buffer1.ctx.set_font_options(options) self.drawScaledLyric(self._buffer1.ctx, self.lyrics.entities[self.actualLine], 1) # create text path for next line for animation if self.actualLine + 1 < len(self.lyrics.entities): #self.next_text_i = self.getScaledText(ctx, self.lyrics.entities[self.actualLine+1], self.text_scale) ctx.set_source_rgba(1, 1, 1, 1) # resize text buffer if needed if self.lyrics.entities[self.actualLine+1].height*self.gscale*self.text_scale > self._buffer2.height: self._buffer2.resize(self._buffer2.width, self.lyrics.entities[self.actualLine+1].height*self.gscale*self.text_scale) self._buffer2.clear() self.drawScaledLyric(self._buffer2.ctx, self.lyrics.entities[self.actualLine+1], self.text_scale) options = ctx.get_font_options() #else: print "NETREBA" self.lastState = [self.actualLine, self.anim_fraction] self.dec_color = (self.color_highlight[0]+(self.color_normal[0]-self.color_highlight[0])*fraction, self.color_highlight[1]+(self.color_normal[1]-self.color_highlight[1])*fraction, self.color_highlight[2]+(self.color_normal[2]-self.color_highlight[2])*fraction, self.color_highlight[3]+(self.color_normal[3]-self.color_highlight[3])*fraction) self.inc_color = (self.color_normal[0]+(self.color_highlight[0]-self.color_normal[0])*fraction, self.color_normal[1]+(self.color_highlight[1]-self.color_normal[1])*fraction, self.color_normal[2]+(self.color_highlight[2]-self.color_normal[2])*fraction, self.color_normal[3]+(self.color_highlight[3]-self.color_normal[3])*fraction) ################################# ##### And finally Rendering ##### ################################# ctx.translate(0, (self.center_y + self.motion_y)*self.gscale) #ctx.translate(0, int((self.center_y + self.motion_y)*self.gscale)) self.dec_scale2 = 1.0-fraction*(1.0 - 1.0/self.text_scale) ############################## ##### render actual text ##### ############################## if self.anim_fraction == 0.0: # render actual line - scaled at maximum ctx.set_source_rgba(self.color_highlight[0], self.color_highlight[1], self.color_highlight[2], self.color_highlight[3]) self.drawScaledLyric(ctx, self.lyrics.entities[self.actualLine], self.text_scale) else: ctx.save() #ctx.translate(center_x, 0) ctx.translate(self.center_x*fraction, 0) ctx.scale(self.dec_scale, self.dec_scale) """ ctx.set_source_rgba (*self.dec_color) ctx.rectangle(0,0, self.bounds.width, 50) ctx.fill() ctx.set_operator(cairo.OPERATOR_DEST_IN) ctx.set_source_pixmap(self.__buffer, 0, 0) ctx.paint() """ ctx.rectangle(0,0, self._buffer1.width, self._buffer1.height) ctx.clip() ctx.set_source_pixmap(self._buffer1.pixmap, 0, 0) ctx.paint() ctx.set_operator(cairo.OPERATOR_IN) ctx.set_source_rgba (*self.dec_color) ctx.rectangle(0,0, self._buffer1.width, self._buffer1.height) ctx.fill() ctx.restore() ############################### ##### render texts before ##### ############################### #""" ctx.translate(self.center_x, 0) #CENTER # set graphics state for text before and after actual lyrics line ctx.set_source_rgba (self.color_normal[0], self.color_normal[1], self.color_normal[2], self.color_normal[3]) ctx.save() i = self.actualLine y = self.center_y + self.motion_y while i > 0 and y > 0: i -= 1 ctx.translate(0, -self.lyrics.entities[i].height*self.gscale) #matrix = ctx.get_matrix() #print matrix #self.drawScaledLyric(ctx, self.lyrics.entities[i], 1, cache = self.anim_fraction != 0.0) self.drawScaledLyric(ctx, self.lyrics.entities[i], 1, cache = True) #extents = self.last_text_extents[1] #ctx.rectangle(*extents) #ctx.stroke() #ctx.fill() y -= self.lyrics.entities[i].height ctx.restore() #""" ############################### ##### render texts behind ##### ############################### # height after text scale operation h = self.lyrics.entities[self.actualLine].trimmed_height*self.dec_scale+self.lyrics.entities[self.actualLine].height-self.lyrics.entities[self.actualLine].trimmed_height h = int(h) ctx.translate(0, h*self.gscale) i = self.actualLine y = self.center_y + self.motion_y + h while i+1 < len(self.lyrics.entities) and y < self.bounds.height: i += 1 if i == self.actualLine+1: # next text - need some animation ctx.save() #ctx.set_source_rgba (*self.inc_color) ctx.set_source_rgba (*self.inc_color) if fraction != 0: ctx.save() # align to center, correction after scale operation ctx.translate(-self.center_x*fraction, 0) self.inc_scalei = 1.0/self.text_scale + (1.0 - (1.0/self.text_scale))*fraction ctx.scale(self.inc_scalei, self.inc_scalei) #ctx.set_source_rgba (*self.inc_color) #ctx.mask(self.next_text_i) ctx.rectangle(0,0, self._buffer2.width, self._buffer2.height) ctx.clip() ctx.set_source_pixmap(self._buffer2.pixmap, 0, 0) ctx.paint() ctx.set_operator(cairo.OPERATOR_IN) ctx.set_source_rgba (*self.inc_color) ctx.rectangle(0,0, self._buffer2.width, self._buffer2.height) ctx.fill() ctx.restore() if fraction == 0: self.drawScaledLyric(ctx, self.lyrics.entities[i], 1) #text = self.getScaledText(ctx, self.lyrics.entities[i], 1);ctx.mask(text);ctx.fill() ctx.restore() # height after text scale operation h = self.lyrics.entities[i].trimmed_height*self.inc_scale+self.lyrics.entities[i].height-self.lyrics.entities[i].trimmed_height ctx.translate(0, h*self.gscale) y += h else: #self.drawScaledLyric(ctx, self.lyrics.entities[i], 1, cache = self.anim_fraction != 0) self.drawScaledLyric(ctx, self.lyrics.entities[i], 1, cache = True) ctx.translate(0, self.lyrics.entities[i].height*self.gscale) y += self.lyrics.entities[i].height # make soft edges ctx.save() ctx.set_operator(cairo.OPERATOR_DEST_OUT) ctx.set_source(self.gradient) ctx.rectangle(0, 0, self.bounds.width, 10) ctx.fill() ctx.scale(1, -1) ctx.translate(0, -self.bounds.height) ctx.set_source(self.gradient) ctx.rectangle(0, 0, self.bounds.width, 10) ctx.fill() ctx.set_source_rgba(1,0,1, 1.0-self.alpha) ctx.rectangle(0, 0, self.bounds.width, self.bounds.height) ctx.fill() ctx.restore() ctx.save() ctx.set_operator(cairo.OPERATOR_DEST_OVER) ctx.scale(self.bounds.width/300.0, self.bounds.height/130.0) self.theme.render(ctx,'background') ctx.restore() """ # render message instead of lyrics if not self.render_lyrics: ctx.translate(center_x, self.bounds.height/2) ctx.set_source_rgba (1, 1, 1, 1) self.layout.set_text(self.message) ctx.show_layout(self.layout) """ #while gtk.events_pending(): # gtk.main_iteration(False) t_end = gobject.get_current_time()
def start(self): self.elapsed = 0 self.real = gobject.get_current_time() self.stopped = False
def __init__(self, type, screen=None, time=None): gtk.MessageDialog.__init__(self, type=gtk.MESSAGE_WARNING) if not time: time = gobject.get_current_time() self.dialog_type = type self.set_skip_pager_hint(True) self.set_skip_taskbar_hint(True) self.set_keep_above(True) self.stick() self.timeout_id = 0 self.set_title("") self.connect("destroy", self._destroy) self.connect("response", self._response) if type is self.SHUTDOWN: icon_name = "gnome-shutdown" primary_text = _("Shut down this computer now?") try: if gpm_dbus.AllowedSuspend(): btn = self.add_button(_("_Sleep"), self.RESPONSE_SUSPEND_TO_RAM) btn.set_image( icon_factory.load_image("gnome-session-suspend.png", gtk.ICON_SIZE_BUTTON)) if gpm_dbus.AllowedHibernate(): btn = self.add_button(_("_Hibernate"), self.RESPONSE_SUSPEND_TO_DISK) btn.set_image( icon_factory.load_image("gnome-session-hibernate.png", gtk.ICON_SIZE_BUTTON)) except dbus.DBusException: pass btn = self.add_button(_("_Reboot"), self.RESPONSE_REBOOT) btn.set_image( icon_factory.load_image("gnome-session-reboot.png", gtk.ICON_SIZE_BUTTON)) self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) btn = self.add_button(_("Shut _Down"), self.RESPONSE_SHUTDOWN) btn.set_image( icon_factory.load_image("gnome-session-halt.png", gtk.ICON_SIZE_BUTTON)) self.timed_out_response = self.RESPONSE_SHUTDOWN elif type is self.LOGOUT: icon_name = "gnome-logout" primary_text = _("Log out of this computer now?") self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) btn = self.add_button(_("_Log Out"), self.RESPONSE_LOGOUT) btn.set_image( icon_factory.load_image("gnome-session-logout.png", gtk.ICON_SIZE_BUTTON)) self.timed_out_response = self.RESPONSE_LOGOUT else: assert False, "Not reached" # GTK before 2.10 crashes when setting a custom icon in message dialogs if gtk.gtk_version[2] >= 10: self.image.set_from_icon_name(icon_name, gtk.ICON_SIZE_DIALOG) self.set_markup("<span size=\"larger\" weight=\"bold\">%s</span>" % primary_text) self.set_default_response(gtk.RESPONSE_CANCEL) if screen: self.set_screen(screen) self.set_timeout()
def get_minutes_left(self): if self.timer: return (self.endtime - int(gobject.get_current_time())) / 60 else: return 0
def _button_release_cb(win, event, tw): win.grab_focus() x, y = map(int, event.get_coords()) spr = findsprite(tw, (x, y)) if spr is None: return True # check to make sure a card in the matched pile isn't selected if spr.x == 10: return True # check to make sure that the current card isn't already selected for a in tw.clicked: if a is spr: # on second click, unselect i = tw.clicked.index(a) tw.clicked[i] = None tw.selected[i].hide_card() return True # add the selected card to the list # and show the selection mask for a in tw.clicked: if a is None: i = tw.clicked.index(a) tw.clicked[i] = spr tw.selected[i].spr.x = spr.x tw.selected[i].spr.y = spr.y tw.selected[i].show_card() break # we only want to add the card to the list once # if we have three cards selected, test for a set #check to see if it's a set if None in tw.clicked: pass else: if match_check([ tw.deck.spr_to_card(tw.clicked[0]), tw.deck.spr_to_card(tw.clicked[1]), tw.deck.spr_to_card(tw.clicked[2]) ]): # stop the timer if tw.timeout_id is not None: gobject.source_remove(tw.timeout_id) tw.total_time += gobject.get_current_time() - tw.start_time # out with the old and in with the new tw.deck.remove_and_replace(tw.clicked, tw) tw.activity.deck_label.set_text(_("%d cards remaining") % \ (tw.deck.count-tw.deck.index)) # test to see if the game is over if tw.deck.count - tw.deck.index == 0: if find_a_match(tw) is False: tw.activity.deck_label.set_text("") tw.activity.clock_label.set_text("") tw.activity.status_label.set_text(_("Game over") +\ " (" +\ str(int(tw.total_time)) +\ " " + _("seconds") + ")") gobject.source_remove(tw.timeout_id) unselect(tw) return True tw.matches += 1 tw.activity.status_label.set_text(_("Match")) if tw.matches == 1: tw.activity.match_label.set_text(_("%d match") % (tw.matches)) else: tw.activity.match_label.set_text( _("%d matches") % (tw.matches)) # reset the timer tw.start_time = gobject.get_current_time() tw.timeout_id = None _counter(tw) else: tw.activity.status_label.set_text(_("No match")) unselect(tw) return True
def show_time(self): cur_time = gobject.get_current_time() print(cur_time)
def __init__(self, source = None): self.source = source self.time = int(gobject.get_current_time() * 1000)
def drawComponent(self, ctx): #print "redraw Lyrics Panel" #print self.anim_fraction #print self.actualLine t_start = gobject.get_current_time() ctx.save() matrix = ctx.get_matrix() self.text_matrix = cairo.Matrix(1, matrix[1], matrix[2], 1, matrix[4], matrix[5]) lastScale = self.gscale self.gscale = matrix[0] if self.gscale != lastScale: self.resizeBuffers() ctx.set_matrix(self.text_matrix) #ctx.scale(1.0/scale_x, 1.0/scale_y) if self.layout == None: self.layout = ctx.create_layout() self.setAlignment() self.layout.set_font_description(self.font) self.clipBounds = Rectangle( *[int(ceil(v)) for v in ctx.clip_extents()]) #print self.clipBounds #print 'draw: '+str(ctx.clip_extents()) #ctx.set_source_rgba(1, 0, 0, 1) #ctx.rectangle(0, 0, self.bounds.width, self.bounds.height) #ctx.fill() #ctx.set_operator(cairo.OPERATOR_SOURCE) ctx.set_operator(cairo.OPERATOR_OVER) if not self.text_scale or not self.font: # or not self.color_highlight or not self.color_normal: return ######################### ##### RENDER LYRICS ##### ######################### if self.lyrics_need_update: self.updateLyrics() """ if ([self.actualLine, self.animation.fraction] == self.lastState): #TODO add lyrics to state print "EQUAL" #return else: print "NOT EQUAL" self.lastState = [self.actualLine, self.animation.fraction] """ #options = ctx.get_font_options() #options.set_hint_metrics(cairo.HINT_METRICS_OFF) #options.set_hint_style(cairo.HINT_STYLE_FULL) #ctx.set_font_options(options) if self._buffer1 == None: self._buffer1 = PixmapBuffer(self.root.root.window, self.bounds.width * self.gscale * 0.9, 20) if self._buffer2 == None: self._buffer2 = PixmapBuffer(self.root.root.window, self.bounds.width * self.gscale, 20) if self.anim_fraction == 1.0: self.anim_fraction = 0.0 self.textForAnimation = None self.actualLine += 1 if self.render_lyrics and self.lyrics and self.actualLine < len( self.lyrics.entities): #fraction = math.sin(self.animation.fraction*1.57) fraction = math.sin( self.anim_fraction * 1.57) # non-linear interpolation of animation fraction #fraction = self.anim_fraction ############################### ##### Compute positioning ##### ############################### if ([self.actualLine, self.anim_fraction] != self.lastState): #TODO add lyrics to state actual_y = (self.bounds.height - self.lyrics.entities[ self.actualLine].trimmed_height * self.text_scale) / 2.0 if self.actualLine + 1 < len(self.lyrics.entities): next_y = (self.bounds.height - self.lyrics.entities[self.actualLine + 1]. trimmed_height * self.text_scale) / 2.0 # center y position, interpolation between actual and next texts y-center position (if their heights are diffrent) self.center_y = actual_y + (next_y - actual_y) * fraction else: self.center_y = actual_y self.center_y = int(self.center_y) # texts moving animation - actual text must translate about it's height by y-axle self.motion_y = -fraction * ( self.lyrics.entities[self.actualLine].height) # decreasing scale text factor in animation self.dec_scale = self.text_scale - fraction * ( self.text_scale - 1.0) # increasing scale text factor in animation self.inc_scale = 1.0 + fraction * (self.text_scale - 1.0) # must be integer due to nice text rendering on raster if self.textAlign == ALIGN_CENTER: self.center_x = int( ((self.bounds.width - self.bounds.width / self.text_scale) / 2.0) * self.gscale) elif self.textAlign == ALIGN_LEFT: self.center_x = 0 else: self.center_x = int( (self.bounds.width - self.bounds.width / self.text_scale) * self.gscale) #self.center_x = ((self.bounds.width-self.bounds.width/self.text_scale)/2.0)*self.gscale #print (self.center_y + self.motion_y)*self.gscale if self.textForAnimation != self.actualLine: #print "treba to %f" % self.anim_fraction self.textForAnimation = self.actualLine # resize text buffer if needed if self.lyrics.entities[ self. actualLine].height * self.gscale > self._buffer1.height: self._buffer1.resize( self._buffer1.width, self.lyrics.entities[self.actualLine].height * self.gscale) self._buffer1.clear() #options = self._buffer1.ctx.get_font_options() #options.set_hint_metrics(cairo.HINT_METRICS_OFF) #self._buffer1.ctx.set_font_options(options) self.drawScaledLyric(self._buffer1.ctx, self.lyrics.entities[self.actualLine], 1) # create text path for next line for animation if self.actualLine + 1 < len(self.lyrics.entities): #self.next_text_i = self.getScaledText(ctx, self.lyrics.entities[self.actualLine+1], self.text_scale) ctx.set_source_rgba(1, 1, 1, 1) # resize text buffer if needed if self.lyrics.entities[ self.actualLine + 1].height * self.gscale * self.text_scale > self._buffer2.height: self._buffer2.resize( self._buffer2.width, self.lyrics.entities[self.actualLine + 1].height * self.gscale * self.text_scale) self._buffer2.clear() self.drawScaledLyric( self._buffer2.ctx, self.lyrics.entities[self.actualLine + 1], self.text_scale) options = ctx.get_font_options() #else: print "NETREBA" self.lastState = [self.actualLine, self.anim_fraction] self.dec_color = ( self.color_highlight[0] + (self.color_normal[0] - self.color_highlight[0]) * fraction, self.color_highlight[1] + (self.color_normal[1] - self.color_highlight[1]) * fraction, self.color_highlight[2] + (self.color_normal[2] - self.color_highlight[2]) * fraction, self.color_highlight[3] + (self.color_normal[3] - self.color_highlight[3]) * fraction) self.inc_color = ( self.color_normal[0] + (self.color_highlight[0] - self.color_normal[0]) * fraction, self.color_normal[1] + (self.color_highlight[1] - self.color_normal[1]) * fraction, self.color_normal[2] + (self.color_highlight[2] - self.color_normal[2]) * fraction, self.color_normal[3] + (self.color_highlight[3] - self.color_normal[3]) * fraction) ################################# ##### And finally Rendering ##### ################################# ctx.translate(0, (self.center_y + self.motion_y) * self.gscale) #ctx.translate(0, int((self.center_y + self.motion_y)*self.gscale)) self.dec_scale2 = 1.0 - fraction * (1.0 - 1.0 / self.text_scale) ############################## ##### render actual text ##### ############################## if self.anim_fraction == 0.0: # render actual line - scaled at maximum ctx.set_source_rgba(self.color_highlight[0], self.color_highlight[1], self.color_highlight[2], self.color_highlight[3]) self.drawScaledLyric(ctx, self.lyrics.entities[self.actualLine], self.text_scale) else: ctx.save() #ctx.translate(center_x, 0) ctx.translate(self.center_x * fraction, 0) ctx.scale(self.dec_scale, self.dec_scale) """ ctx.set_source_rgba (*self.dec_color) ctx.rectangle(0,0, self.bounds.width, 50) ctx.fill() ctx.set_operator(cairo.OPERATOR_DEST_IN) ctx.set_source_pixmap(self.__buffer, 0, 0) ctx.paint() """ ctx.rectangle(0, 0, self._buffer1.width, self._buffer1.height) ctx.clip() ctx.set_source_pixmap(self._buffer1.pixmap, 0, 0) ctx.paint() ctx.set_operator(cairo.OPERATOR_IN) ctx.set_source_rgba(*self.dec_color) ctx.rectangle(0, 0, self._buffer1.width, self._buffer1.height) ctx.fill() ctx.restore() ############################### ##### render texts before ##### ############################### #""" ctx.translate(self.center_x, 0) #CENTER # set graphics state for text before and after actual lyrics line ctx.set_source_rgba(self.color_normal[0], self.color_normal[1], self.color_normal[2], self.color_normal[3]) ctx.save() i = self.actualLine y = self.center_y + self.motion_y while i > 0 and y > 0: i -= 1 ctx.translate(0, -self.lyrics.entities[i].height * self.gscale) #matrix = ctx.get_matrix() #print matrix #self.drawScaledLyric(ctx, self.lyrics.entities[i], 1, cache = self.anim_fraction != 0.0) self.drawScaledLyric(ctx, self.lyrics.entities[i], 1, cache=True) #extents = self.last_text_extents[1] #ctx.rectangle(*extents) #ctx.stroke() #ctx.fill() y -= self.lyrics.entities[i].height ctx.restore() #""" ############################### ##### render texts behind ##### ############################### # height after text scale operation h = self.lyrics.entities[ self. actualLine].trimmed_height * self.dec_scale + self.lyrics.entities[ self.actualLine].height - self.lyrics.entities[ self.actualLine].trimmed_height h = int(h) ctx.translate(0, h * self.gscale) i = self.actualLine y = self.center_y + self.motion_y + h while i + 1 < len(self.lyrics.entities) and y < self.bounds.height: i += 1 if i == self.actualLine + 1: # next text - need some animation ctx.save() #ctx.set_source_rgba (*self.inc_color) ctx.set_source_rgba(*self.inc_color) if fraction != 0: ctx.save() # align to center, correction after scale operation ctx.translate(-self.center_x * fraction, 0) self.inc_scalei = 1.0 / self.text_scale + ( 1.0 - (1.0 / self.text_scale)) * fraction ctx.scale(self.inc_scalei, self.inc_scalei) #ctx.set_source_rgba (*self.inc_color) #ctx.mask(self.next_text_i) ctx.rectangle(0, 0, self._buffer2.width, self._buffer2.height) ctx.clip() ctx.set_source_pixmap(self._buffer2.pixmap, 0, 0) ctx.paint() ctx.set_operator(cairo.OPERATOR_IN) ctx.set_source_rgba(*self.inc_color) ctx.rectangle(0, 0, self._buffer2.width, self._buffer2.height) ctx.fill() ctx.restore() if fraction == 0: self.drawScaledLyric(ctx, self.lyrics.entities[i], 1) #text = self.getScaledText(ctx, self.lyrics.entities[i], 1);ctx.mask(text);ctx.fill() ctx.restore() # height after text scale operation h = self.lyrics.entities[ i].trimmed_height * self.inc_scale + self.lyrics.entities[ i].height - self.lyrics.entities[i].trimmed_height ctx.translate(0, h * self.gscale) y += h else: #self.drawScaledLyric(ctx, self.lyrics.entities[i], 1, cache = self.anim_fraction != 0) self.drawScaledLyric(ctx, self.lyrics.entities[i], 1, cache=True) ctx.translate(0, self.lyrics.entities[i].height * self.gscale) y += self.lyrics.entities[i].height ctx.restore() # make soft edges ctx.save() ctx.set_operator(cairo.OPERATOR_DEST_OUT) ctx.set_source(self.gradient) ctx.rectangle(0, 0, self.bounds.width, 10) ctx.fill() ctx.scale(1, -1) ctx.translate(0, -self.bounds.height) ctx.set_source(self.gradient) ctx.rectangle(0, 0, self.bounds.width, 10) ctx.fill() ctx.set_source_rgba(1, 0, 1, 1.0 - self.alpha) ctx.rectangle(0, 0, self.bounds.width, self.bounds.height) ctx.fill() ctx.restore() ctx.save() ctx.set_operator(cairo.OPERATOR_DEST_OVER) ctx.scale(self.bounds.width / 300.0, self.bounds.height / 130.0) self.theme.render(ctx, 'background') ctx.restore() """ # render message instead of lyrics if not self.render_lyrics: ctx.translate(center_x, self.bounds.height/2) ctx.set_source_rgba (1, 1, 1, 1) self.layout.set_text(self.message) ctx.show_layout(self.layout) """ #while gtk.events_pending(): # gtk.main_iteration(False) t_end = gobject.get_current_time()
def test(self): if not self.playing: print gobject.get_current_time() - self.lastStop self.minimize()
def current_time(self): return gobject.get_current_time() * 1e6