本文整理汇总了Python中sugar3.util.timestamp_to_elapsed_string函数的典型用法代码示例。如果您正苦于以下问题:Python timestamp_to_elapsed_string函数的具体用法?Python timestamp_to_elapsed_string怎么用?Python timestamp_to_elapsed_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了timestamp_to_elapsed_string函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_activity
def _add_activity(self, activity_info):
if activity_info.get_bundle_id() == 'org.laptop.JournalActivity':
return
timestamp = activity_info.get_installation_time()
version = activity_info.get_activity_version()
registry = bundleregistry.get_registry()
favorite = registry.is_bundle_favorite(activity_info.get_bundle_id(),
version)
tag_list = activity_info.get_tags()
if tag_list is None or not tag_list:
title = '<b>%s</b>' % activity_info.get_name()
else:
tags = ', '.join(tag_list)
title = '<b>%s</b>\n' \
'<span style="italic" weight="light">%s</span>' % \
(activity_info.get_name(), tags)
self._model.append([activity_info.get_bundle_id(),
favorite,
activity_info.get_icon(),
title,
version,
_('Version %s') % version,
int(timestamp),
util.timestamp_to_elapsed_string(timestamp)])
示例2: add_separator
def add_separator(self, timestamp):
'''Add whitespace and timestamp between chat sessions.'''
time_with_current_year = \
(time.localtime(time.time())[0], ) + \
time.strptime(timestamp, '%b %d %H:%M:%S')[1:]
timestamp_seconds = time.mktime(time_with_current_year)
if timestamp_seconds > time.time():
time_with_previous_year = \
(time.localtime(time.time())[0] - 1, ) + \
time.strptime(timestamp, '%b %d %H:%M:%S')[1:]
timestamp_seconds = time.mktime(time_with_previous_year)
message = TextBox(self,
style.COLOR_BUTTON_GREY, style.COLOR_BUTTON_GREY,
style.COLOR_WHITE, style.COLOR_BUTTON_GREY, False,
None, timestamp_to_elapsed_string(timestamp_seconds))
self._message_list.append(message)
box = Gtk.HBox()
align = Gtk.Alignment.new(
xalign=0.5, yalign=0.0, xscale=0.0, yscale=0.0)
box.pack_start(align, True, True, 0)
align.show()
align.add(message)
message.show()
self._conversation.attach(box, 0, self._row_counter, 1, 1)
box.show()
self._row_counter += 1
self.add_log_timestamp(timestamp)
self._last_msg_sender = None
示例3: _add_activity
def _add_activity(self, activity_info):
if activity_info.get_bundle_id() == "org.laptop.JournalActivity":
return
timestamp = activity_info.get_installation_time()
version = activity_info.get_activity_version()
registry = bundleregistry.get_registry()
favorites = []
for i in range(desktop.get_number_of_views()):
favorites.append(registry.is_bundle_favorite(activity_info.get_bundle_id(), version, i))
tag_list = activity_info.get_tags()
if tag_list is None or not tag_list:
title = "<b>%s</b>" % activity_info.get_name()
else:
tags = ", ".join(tag_list)
title = "<b>%s</b>\n" '<span style="italic" weight="light">%s</span>' % (activity_info.get_name(), tags)
model_list = [activity_info.get_bundle_id()]
for i in range(desktop.get_number_of_views()):
model_list.append(favorites[i])
model_list.append(activity_info.get_icon())
model_list.append(title)
model_list.append(version)
model_list.append(_("Version %s") % version)
model_list.append(int(timestamp))
model_list.append(util.timestamp_to_elapsed_string(timestamp))
self._model.append(model_list)
示例4: get_date
def get_date(metadata):
""" Convert from a string in iso format to a more human-like format. """
if 'timestamp' in metadata:
try:
timestamp = float(metadata['timestamp'])
except (TypeError, ValueError):
logging.warning('Invalid timestamp: %r', metadata['timestamp'])
else:
return util.timestamp_to_elapsed_string(timestamp)
if 'mtime' in metadata:
try:
ti = time.strptime(metadata['mtime'], '%Y-%m-%dT%H:%M:%S')
except (TypeError, ValueError):
logging.warning('Invalid mtime: %r', metadata['mtime'])
else:
return util.timestamp_to_elapsed_string(time.mktime(ti))
return _('No date')
示例5: _add_columns
def _add_columns(self):
self.cell_icon = CellRendererActivityIcon(self.tree_view)
column = Gtk.TreeViewColumn()
column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
column.props.fixed_width = self.cell_icon.props.width
column.pack_start(self.cell_icon, True)
column.add_attribute(self.cell_icon, 'file-name',
COLUMN_MIME)
#column.add_attribute(self.cell_icon, 'xo-color',
# COLUMN_MIME)
self.tree_view.append_column(column)
self.cell_title = Gtk.CellRendererText()
self.cell_title.props.ellipsize = Pango.EllipsizeMode.MIDDLE
self.cell_title.props.ellipsize_set = True
self._title_column = Gtk.TreeViewColumn()
self._title_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self._title_column.props.expand = True
self._title_column.props.clickable = True
self._title_column.pack_start(self.cell_title, True)
self._title_column.add_attribute(self.cell_title, 'markup',
COLUMN_TITLE)
self.tree_view.append_column(self._title_column)
cell_text = Gtk.CellRendererText()
cell_text.props.xalign = 1
# Measure the required width for a date in the form of "10 hours, 10
# minutes ago"
timestamp = time.time() - 10 * 60 - 10 * 60 * 60
date = util.timestamp_to_elapsed_string(timestamp)
date_width = self._get_width_for_string(date)
self.sort_column = Gtk.TreeViewColumn()
self.sort_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self.sort_column.props.fixed_width = date_width
self.sort_column.set_alignment(1)
self.sort_column.props.resizable = True
self.sort_column.props.clickable = True
self.sort_column.pack_start(cell_text, True)
self.sort_column.add_attribute(cell_text, 'text',
COLUMN_TIMESTAMP)
self.tree_view.append_column(self.sort_column)
示例6: __bookmark_icon_query_tooltip_cb
def __bookmark_icon_query_tooltip_cb(self, widget, x, y, keyboard_mode,
tip, bookmark):
tooltip_header = bookmark.get_note_title()
tooltip_body = bookmark.get_note_body()
time = timestamp_to_elapsed_string(bookmark.timestamp)
#TRANS: This goes like Bookmark added by User 5 days ago
#TRANS: (the elapsed string gets translated automatically)
tooltip_footer = (
_('Bookmark added by %(user)s %(time)s')
% {'user': bookmark.nick.decode('utf-8'),
'time': time.decode('utf-8')})
vbox = Gtk.VBox()
l = Gtk.Label('<big>%s</big>' % tooltip_header)
l.set_use_markup(True)
l.set_width_chars(40)
l.set_line_wrap(True)
vbox.pack_start(l, False, False, 0)
l.show()
l = Gtk.Label('%s' % tooltip_body)
l.set_use_markup(True)
l.set_alignment(0, 0)
l.set_padding(2, 6)
l.set_width_chars(40)
l.set_line_wrap(True)
l.set_justify(Gtk.Justification.FILL)
vbox.pack_start(l, True, True, 0)
l.show()
l = Gtk.Label('<small><i>%s</i></small>' % tooltip_footer)
l.set_use_markup(True)
l.set_width_chars(40)
l.set_line_wrap(True)
vbox.pack_start(l, False, False, 0)
l.show()
tip.set_custom(vbox)
return True
示例7: _add_columns
def _add_columns(self):
cell_favorite = CellRendererFavorite(self.tree_view)
cell_favorite.connect('clicked', self.__favorite_clicked_cb)
column = Gtk.TreeViewColumn()
column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
column.props.fixed_width = cell_favorite.props.width
column.pack_start(cell_favorite, True)
column.set_cell_data_func(cell_favorite, self.__favorite_set_data_cb)
self.tree_view.append_column(column)
self.cell_icon = CellRendererActivityIcon(self.tree_view)
column = Gtk.TreeViewColumn()
column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
column.props.fixed_width = self.cell_icon.props.width
column.pack_start(self.cell_icon, True)
column.add_attribute(self.cell_icon, 'file-name',
ListModel.COLUMN_ICON)
column.add_attribute(self.cell_icon, 'xo-color',
ListModel.COLUMN_ICON_COLOR)
self.tree_view.append_column(column)
self.cell_title = Gtk.CellRendererText()
self.cell_title.props.ellipsize = Pango.EllipsizeMode.MIDDLE
self.cell_title.props.ellipsize_set = True
self._title_column = Gtk.TreeViewColumn()
self._title_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self._title_column.props.expand = True
self._title_column.props.clickable = True
self._title_column.pack_start(self.cell_title, True)
self._title_column.add_attribute(self.cell_title, 'markup',
ListModel.COLUMN_TITLE)
self.tree_view.append_column(self._title_column)
buddies_column = Gtk.TreeViewColumn()
buddies_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self.tree_view.append_column(buddies_column)
for column_index in [ListModel.COLUMN_BUDDY_1,
ListModel.COLUMN_BUDDY_2,
ListModel.COLUMN_BUDDY_3]:
cell_icon = CellRendererBuddy(self.tree_view,
column_index=column_index)
buddies_column.pack_start(cell_icon, True)
buddies_column.props.fixed_width += cell_icon.props.width
buddies_column.add_attribute(cell_icon, 'buddy', column_index)
buddies_column.set_cell_data_func(cell_icon,
self.__buddies_set_data_cb)
cell_progress = Gtk.CellRendererProgress()
cell_progress.props.ypad = style.GRID_CELL_SIZE / 4
buddies_column.pack_start(cell_progress, True)
buddies_column.add_attribute(cell_progress, 'value',
ListModel.COLUMN_PROGRESS)
buddies_column.set_cell_data_func(cell_progress,
self.__progress_data_cb)
cell_text = Gtk.CellRendererText()
cell_text.props.xalign = 1
# Measure the required width for a date in the form of "10 hours, 10
# minutes ago"
timestamp = time.time() - 10 * 60 - 10 * 60 * 60
date = util.timestamp_to_elapsed_string(timestamp)
date_width = self._get_width_for_string(date)
self.sort_column = Gtk.TreeViewColumn()
self.sort_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self.sort_column.props.fixed_width = date_width
self.sort_column.set_alignment(1)
self.sort_column.props.resizable = True
self.sort_column.props.clickable = True
self.sort_column.pack_start(cell_text, True)
self.sort_column.add_attribute(cell_text, 'text',
ListModel.COLUMN_TIMESTAMP)
self.tree_view.append_column(self.sort_column)
示例8: do_get_value
def do_get_value(self, iterator, column):
if self.view_is_resizing:
return None
index = iterator.user_data
if index == self._last_requested_index:
return self._cached_row[column]
if index >= self._result_set.length:
return None
self._result_set.seek(index)
metadata = self._result_set.read()
metadata.update(self._updated_entries.get(metadata['uid'], {}))
self._last_requested_index = index
self._cached_row = []
self._cached_row.append(metadata['uid'])
self._cached_row.append(metadata.get('keep', '0') == '1')
self._cached_row.append(misc.get_icon_name(metadata))
if misc.is_activity_bundle(metadata):
xo_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
style.COLOR_TRANSPARENT.get_svg()))
else:
xo_color = misc.get_icon_color(metadata)
self._cached_row.append(xo_color)
title = GObject.markup_escape_text(metadata.get('title',
_('Untitled')))
self._cached_row.append('<b>%s</b>' % (title, ))
try:
timestamp = float(metadata.get('timestamp', 0))
except (TypeError, ValueError):
timestamp_content = _('Unknown')
else:
timestamp_content = util.timestamp_to_elapsed_string(timestamp)
self._cached_row.append(timestamp_content)
try:
creation_time = float(metadata.get('creation_time'))
except (TypeError, ValueError):
self._cached_row.append(_('Unknown'))
else:
self._cached_row.append(
util.timestamp_to_elapsed_string(float(creation_time)))
try:
size = int(metadata.get('filesize'))
except (TypeError, ValueError):
size = None
self._cached_row.append(util.format_size(size))
try:
progress = int(float(metadata.get('progress', 100)))
except (TypeError, ValueError):
progress = 100
self._cached_row.append(progress)
buddies = []
if metadata.get('buddies'):
try:
buddies = json.loads(metadata['buddies']).values()
except json.decoder.JSONDecodeError as exception:
logging.warning('Cannot decode buddies for %r: %s',
metadata['uid'], exception)
if not isinstance(buddies, list):
logging.warning('Content of buddies for %r is not a list: %r',
metadata['uid'], buddies)
buddies = []
for n_ in xrange(0, 3):
if buddies:
try:
nick, color = buddies.pop(0)
except (AttributeError, ValueError) as exception:
logging.warning('Malformed buddies for %r: %s',
metadata['uid'], exception)
else:
self._cached_row.append([nick, XoColor(color)])
continue
self._cached_row.append(None)
return self._cached_row[column]
示例9: _add_columns
def _add_columns(self):
if self._enable_multi_operations:
cell_select = Gtk.CellRendererToggle()
cell_select.connect('toggled', self.__cell_select_toggled_cb)
cell_select.props.activatable = True
cell_select.props.xpad = style.DEFAULT_PADDING
cell_select.props.indicator_size = style.zoom(26)
column = Gtk.TreeViewColumn()
column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
column.props.fixed_width = style.GRID_CELL_SIZE
column.pack_start(cell_select, True)
column.set_cell_data_func(cell_select, self.__select_set_data_cb)
self.tree_view.append_column(column)
cell_favorite = CellRendererFavorite()
cell_favorite.connect('clicked', self._favorite_clicked_cb)
cell_favorite.connect_to_scroller(self._scrolling_detector)
self._fav_column = Gtk.TreeViewColumn()
self._fav_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self._fav_column.props.fixed_width = cell_favorite.props.width
self._fav_column.pack_start(cell_favorite, True)
self._fav_column.set_cell_data_func(
cell_favorite, self.__favorite_set_data_cb)
self.tree_view.append_column(self._fav_column)
self.cell_icon = CellRendererActivityIcon()
self.cell_icon.connect_to_scroller(self._scrolling_detector)
column = Gtk.TreeViewColumn()
self.tree_view.icon_activity_column = column
column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
column.props.fixed_width = self.cell_icon.props.width
column.pack_start(self.cell_icon, True)
column.add_attribute(self.cell_icon, 'file-name',
ListModel.COLUMN_ICON)
column.add_attribute(self.cell_icon, 'xo-color',
ListModel.COLUMN_ICON_COLOR)
self.tree_view.append_column(column)
self.icon_activity_column = column
self.cell_title = Gtk.CellRendererText()
self.cell_title.props.ellipsize = style.ELLIPSIZE_MODE_DEFAULT
self.cell_title.props.ellipsize_set = True
self._title_column = Gtk.TreeViewColumn()
self._title_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self._title_column.props.expand = True
self._title_column.props.clickable = True
self._title_column.pack_start(self.cell_title, True)
self._title_column.add_attribute(self.cell_title, 'markup',
ListModel.COLUMN_TITLE)
self.tree_view.append_column(self._title_column)
for column_index in [ListModel.COLUMN_BUDDY_1,
ListModel.COLUMN_BUDDY_2,
ListModel.COLUMN_BUDDY_3]:
buddies_column = Gtk.TreeViewColumn()
buddies_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self.tree_view.append_column(buddies_column)
cell_icon = CellRendererBuddy(column_index=column_index)
buddies_column.pack_start(cell_icon, True)
buddies_column.props.fixed_width += cell_icon.props.width
buddies_column.add_attribute(cell_icon, 'buddy', column_index)
buddies_column.set_cell_data_func(cell_icon,
self.__buddies_set_data_cb)
self.tree_view.buddies_columns.append(buddies_column)
cell_progress = Gtk.CellRendererProgress()
cell_progress.props.ypad = style.GRID_CELL_SIZE / 4
buddies_column.pack_start(cell_progress, True)
buddies_column.add_attribute(cell_progress, 'value',
ListModel.COLUMN_PROGRESS)
buddies_column.set_cell_data_func(cell_progress,
self.__progress_data_cb)
cell_text = Gtk.CellRendererText()
cell_text.props.xalign = 1
# Measure the required width for a date in the form of "10 hours, 10
# minutes ago"
timestamp = time.time() - 10 * 60 - 10 * 60 * 60
date = util.timestamp_to_elapsed_string(timestamp)
date_width = self._get_width_for_string(date)
self.sort_column = Gtk.TreeViewColumn()
self.sort_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED
self.sort_column.props.fixed_width = date_width
self.sort_column.set_alignment(1)
self.sort_column.props.resizable = True
self.sort_column.props.clickable = True
self.sort_column.pack_start(cell_text, True)
self.sort_column.add_attribute(cell_text, 'text',
ListModel.COLUMN_TIMESTAMP)
self.tree_view.append_column(self.sort_column)
示例10: __init__
def __init__(self, parent):
Gtk.EventBox.__init__(self)
self._reflection = parent
self._collapse = True
self._collapse_id = None
self.modify_bg(
Gtk.StateType.NORMAL, style.COLOR_WHITE.get_gdk_color())
self._title_color = self._reflection.activity.fg_color.get_html()
self._grid = Gtk.Grid()
self.add(self._grid)
self._grid.show()
self._grid.set_row_spacing(style.DEFAULT_PADDING)
self._grid.set_column_spacing(style.DEFAULT_SPACING)
self._grid.set_column_homogeneous(True)
self._grid.set_border_width(style.DEFAULT_PADDING)
row = 0
self._expand_button = EventIcon(icon_name='expand',
pixel_size=BUTTON_SIZE)
self._collapse_id = self._expand_button.connect('button-press-event',
self._expand_cb)
self._expand_button.set_tooltip(_('Expand'))
self._grid.attach(self._expand_button, 0, row, 1, 1)
self._expand_button.show()
self._title_align = Gtk.Alignment.new(
xalign=0, yalign=0.5, xscale=0, yscale=0)
self._title = Gtk.TextView()
self._title.set_size_request(ENTRY_WIDTH, -1)
self._title.set_wrap_mode(Gtk.WrapMode.WORD)
self._title_tag = self._title.get_buffer().create_tag(
'title', foreground=self._title_color, weight=Pango.Weight.BOLD,
size=12288)
iter_text = self._title.get_buffer().get_iter_at_offset(0)
self._title.get_buffer().insert_with_tags(
iter_text, self._reflection.data['title'], self._title_tag)
if self._reflection.activity.initiating:
self._title.connect('focus-out-event', self._title_focus_out_cb)
else:
self._title.set_editable(False)
self._title_align.add(self._title)
self._title.show()
self._grid.attach(self._title_align, 1, row, 5, 1)
self._title_align.show()
delete_button = EventIcon(icon_name='delete', pixel_size=BUTTON_SIZE)
delete_button.set_tooltip(_('Delete'))
delete_button.connect('button-press-event', self.__delete_cb)
self._grid.attach(delete_button, 6, row, 1, 1)
delete_button.show()
''' Notification that a new comment has been shared. '''
self.notify_button = EventIcon(icon_name='chat',
pixel_size=BUTTON_SIZE)
self._grid.attach(self.notify_button, 6, row, 1, 1)
row += 1
self._time_align = Gtk.Alignment.new(
xalign=0, yalign=0.5, xscale=0, yscale=0)
self._time = Gtk.Label()
self._time.set_size_request(ENTRY_WIDTH, -1)
self._time.set_justify(Gtk.Justification.LEFT)
self._time.set_use_markup(True)
try:
time_string = util.timestamp_to_elapsed_string(
int(self._reflection.data['modification_time']))
except Exception as e:
logging.error('Could not convert modification time %s: %s' %
(self._reflection.data['modification_time'], e))
self._reflection.data['modification_time'] = \
self._reflection.data['creation_time']
time_string = util.timestamp_to_elapsed_string(
int(self._reflection.data['modification_time']))
self._time.set_markup(
'<span foreground="#808080"><small><b>%s</b></small></span>' %
time_string)
self._time_align.add(self._time)
self._time.show()
self._grid.attach(self._time_align, 1, row, 5, 1)
self._time_align.show()
row += 1
label = ''
if 'tags' in self._reflection.data:
for tag in self._reflection.data['tags']:
if len(label) > 0:
label += ', '
label += tag
if self._reflection.activity.initiating and label == '':
label = _('Add a #tag')
self._tag_align = Gtk.Alignment.new(
xalign=0, yalign=0.5, xscale=0, yscale=0)
self._tag_view = Gtk.TextView()
self._tag_view.set_size_request(ENTRY_WIDTH, -1)
self._tag_view.set_wrap_mode(Gtk.WrapMode.WORD)
#.........这里部分代码省略.........