本文整理汇总了Python中timer.Timer.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.connect方法的具体用法?Python Timer.connect怎么用?Python Timer.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类timer.Timer
的用法示例。
在下文中一共展示了Timer.connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TrayTime
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import connect [as 别名]
class TrayTime(gobject.GObject):
__gsignals__ = {
"send-time" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT, gobject.TYPE_INT)),
"hour-changed" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT, gobject.TYPE_INT)),
}
def __init__(self):
gobject.GObject.__init__(self)
self.__timer = Timer(5000)
self.__tray_time_hour_type = TRAY_TIME_12_HOUR
self.__timer.connect("Tick", self.__update_time)
# setting 12/24 hour.
if deepin_gsettings_bool:
self.set_date = deepin_gsettings.new("com.deepin.dde.datetime")
self.set_date.connect("changed", self.set_date_changed)
self.set_deepin_dde_datetime()
# start time.
self.__timer.Enabled = True
def set_date_changed(self, key):
self.set_deepin_dde_datetime()
def set_hour_type(self, hour_type):
self.__tray_time_hour_type = hour_type
self.emit("hour-changed", self.get_time(), self.__tray_time_hour_type)
def set_deepin_dde_datetime(self):
if self.set_date.get_boolean("is-24hour"):
self.set_hour_type(TRAY_TIME_24_HOUR)
else:
self.set_hour_type(TRAY_TIME_12_HOUR)
def get_time(self):
time_struct = time.localtime(time.time())
#
if self.__tray_time_hour_type == TRAY_TIME_12_HOUR:
time_show_text = time.strftime("%P %I %M", time.localtime()).split(" ")
if time_show_text[0].startswith(("a", "p")):
am = _("AM")
pm = _("PM")
if time_show_text[0].startswith("a"):
time_show_text[0] = am
elif time_show_text[0].startswith("p"):
time_show_text[0] = pm
elif self.__tray_time_hour_type == TRAY_TIME_24_HOUR:
time_show_text = time.strftime("%H %M", time.localtime()).split(" ")
#
return time_show_text
def __update_time(self, timer):
# modify interval.
if self.__timer.Interval == 1:
self.__timer.Interval = 1000
# emit event.
self.emit("send-time", self.get_time(), self.__tray_time_hour_type)
示例2: LDMP
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import connect [as 别名]
#.........这里部分代码省略.........
if self.player.tv_fps > 0:
self.command.append("-tv:fps")
self.command.append("%d" % (self.tv_fps))
self.command.append("-nocache")
self.command.append("%s" % (self.player.uri))
# print self.command
# 链接管道.
self.mp_id = subprocess.Popen(self.command,
stdin = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
shell = False)
self.mplayer_pid = self.mp_id.pid
(self.mplayer_in, self.mplayer_out, self.mplayer_err) = (self.mp_id.stdin, self.mp_id.stdout, self.mp_id.stderr)
fcntl.fcntl(self.mplayer_out,
fcntl.F_SETFL,
os.O_NONBLOCK)
# IO_HUP[Monitor the pipeline is disconnected].
self.watch_in_id = gobject.io_add_watch(self.mplayer_out,
gobject.gobject.IO_IN,
self.player_thread_reader)
self.watch_err_id = gobject.io_add_watch(self.mplayer_err,
gobject.IO_IN,
self.player_thread_reader_error)
self.watch_in_hup_id = gobject.io_add_watch(self.mplayer_out,
gobject.IO_HUP,
self.player_thread_complete)
#
self.timer = Timer(1000)
self.timer.connect("Tick", self.thread_query)
self.timer.Enabled = True
self.player.state = STARTING_STATE
#
# gobject.timeout_add_seconds(1, self.thread_query, 1)
#
def thread_query(self, tick):
self.get_time_pos()
'''获取Mplayer时间.''' # t12345
def get_percent_pos(self): # 获取当前位置为整数的百分比
self.cmd('get_percent_pos\n')
# return self.get_info("ANS_PERCENT_POSITION")
def get_sub_visibility(self):
self.cmd("get_sub_visibility\n")
def get_time_length(self):
self.cmd('get_time_length\n')
# return self.get_info("ANS_LENGTH")
def get_time_pos(self): # 当前位置用秒表示,采用浮点数.
self.cmd('get_time_pos\n')
# return self.get_info("ANS_TIME_POSITION").split("\n")[0]
def get_info(self, info_flags): # 获取返回信息.
while True:
try:
line = self.mplayer_out.readline()
except StandardError:
break
示例3: Element
# 需要导入模块: from timer import Timer [as 别名]
# 或者: from timer.Timer import connect [as 别名]
class Element(gtk.Button):
__gsignals__ = {
"popup-menu-event" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
(gobject.TYPE_PYOBJECT,)),
}
def __init__(self):
gtk.Button.__init__(self)
self.__init_element_values()
self.__init_element_events()
def __init_element_values(self):
self.tool_tip = ToolTip()
#self.__icon_theme = gtk.IconTheme()
#
self.__mode_type = TRAY_IMAGE_TEXT_TYPE
self.__blinking_check = False
self.__rotate_check = False
self.rotate_angle = 0
# init timer.
self.timer = Timer(200)
self.timer.Enabled = False
self.timer.connect("Tick", self.timer_tick)
# init event connect function.
self.popup_menu = None
self.expose_event = self.__expose_event_function
# add icon paths.
#path = get_run_app_path("image")
#self.append_search_path(path)
# init left line pixbuf.
self.left_line_pixbuf = self.load_icon("tray_left_line", size=22)
self.left_line_w = self.left_line_pixbuf.get_width()
self.left_line_h = self.left_line_pixbuf.get_height()
# init right line pixbuf.
self.right_lien_pixbuf = self.load_icon("tray_right_line", size=22)
self.right_line_w = self.left_line_pixbuf.get_width()
self.right_lien_h = self.right_lien_pixbuf.get_height()
def timer_tick(self, tick):
self.rotate_angle += 45
self.queue_draw()
def __init_element_events(self):
self.connect("clicked", self.__widget_clicked_event)
self.connect("button-press-event", self.__widget_button_press_event)
self.connect("expose-event", self.__widget_expose_event)
self.connect("enter-notify-event", self.__widget_enter_notify_event)
self.connect("leave-notify-event", self.__widget_leave_notify_event)
def append_search_path(self, file):
self.__icon_theme.append_search_path(file)
def get_pixbuf(self):
image = self.get_image()
if image:
return image.get_pixbuf()
else:
return image
def set_pixbuf(self, pixbuf):
image = gtk.Image()
image.set_from_pixbuf(pixbuf)
self.set_image(image)
def set_icon_theme(self, name):
try:
pixbuf = self.load_icon(name)
if pixbuf:
self.set_pixbuf(pixbuf)
except Exception, e:
print_msg("set_icon_theme[error]:%s"%(e))