def _update_total_size(self): """Update progress bar and labels for total size""" # update label formated_size = self._size_format.format( common.format_size(self._current_size, self._size_format_type), common.format_size(self._total_size, self._size_format_type)) self._value_total_size.set_label(formated_size) if self._total_size > 0: self.set_total_size_fraction( float(self._current_size) / self._total_size) else: self.set_total_size_fraction(1)
def _update_total_size(self): """Update progress bar and labels for total size""" # update label formated_size = self._size_format.format( common.format_size(self._current_size, self._size_format_type), common.format_size(self._total_size, self._size_format_type) ) self._value_total_size.set_label(formated_size) if self._total_size > 0: self.set_total_size_fraction(float(self._current_size) / self._total_size) else: self.set_total_size_fraction(1)
def _update_speed(self): """Aggregate speed and update ETA label This method is automatically called by the gobject timeout. Don't call this method automatically! """ if self._paused: return True # don't update speed when paused speed = self._current_size - self._total_checkpoint # get current speed self._total_checkpoint = self._current_size # update aggregates speeds list if len(self._speeds) > self.MAX_SPEED_POINTS: self._speeds.pop(0) self._speeds.append(speed) # calculate average speed average = sum(self._speeds) / len(self._speeds) # update labels if average > 0: # calculate time based on average speed remainder = (self._total_size - self._current_size) / average hours, remainder = divmod(remainder, 3600) minutes, seconds = divmod(remainder, 60) time_text = '{0} {1}'.format( seconds, ngettext('second', 'seconds', seconds) ) if minutes > 0: time_text = '{0} {1}, {2}'.format( minutes, ngettext('minute', 'minutes', minutes), time_text ) if hours > 0: time_text = '{0} {1}, {2}'.format( hours, ngettext('hour', 'hours', hours), time_text ) else: # we don't have average speed yet time_text = _('unknown') average_text = common.format_size(average, self._size_format_type) speed_text = '{0}/s'.format(average_text) self._value_eta.set_text(time_text) self._value_speed.set_text(speed_text) # make sure we keep updating return True
def cb_dl(self, _target, _transferred, _total): if _target.endswith('.db'): action = _('Refreshing {repo}').format(repo = _target.replace('.db', ''))+'...' action_long = '' icon = 'cinnamon-installer-refresh' else: action = _('Downloading {pkgname}').format(pkgname = _target.replace('.pkg.tar.xz', ''))+'...' action_long = action+'\n' icon = 'cinnamon-installer-download' if self.total_size > 0: percent = round((_transferred+self.already_transferred)/self.total_size, 2) if _transferred+self.already_transferred <= self.total_size: target = '{transferred}/{size}'.format(transferred = common.format_size(_transferred+self.already_transferred), size = common.format_size(self.total_size)) else: target = '' else: percent = round(_transferred/_total, 2) target = '' if action != self.previous_action: self.previous_action = action self.EmitAction(action) if action_long != self.previous_action_long: self.previous_action_long = action_long self.EmitActionLong(action_long) if icon != self.previous_icon: self.previous_icon = icon self.EmitIcon(icon) if target != self.previous_target: self.previous_target = target self.EmitTarget(target) if percent != self.previous_percent: self.previous_percent = percent self.EmitPercent(percent) elif _transferred == _total: self.already_transferred += _total
def _update_data(self): """Update widgets to represent item state""" associations_manager = self._application.associations_manager # get the rest of the infromation description = associations_manager.get_mime_description( self._mime_type) time_format = self._application.options.section('item_list').get( 'time_format') size_format = self._application.options.get('size_format') item_stat = self._provider.get_stat(self._path, extended=True) # get item size if self._is_file: # file size item_size = common.format_size(item_stat.size, size_format) else: # directory size dir_size = len(self._provider.list_dir(self._path)) item_size = '{0} {1}'.format(locale.format('%d', dir_size, True), ngettext('item', 'items', dir_size)) # set mode self._mode = item_stat.mode # time_format item time item_a_date = time.strftime(time_format, time.localtime(item_stat.time_access)) item_m_date = time.strftime(time_format, time.localtime(item_stat.time_modify)) # get volume try: mount = gio.File(self._path).find_enclosing_mount() volume_name = mount.get_name() except gio.Error: # item is not on any known volume volume_name = _('unknown') # update widgets self._entry_name.set_text(os.path.basename(self._path)) self._label_type.set_text('{0}\n{1}'.format(description, self._mime_type)) self._label_size.set_text(item_size) self._label_location.set_text( os.path.dirname(os.path.abspath(self._path))) self._label_volume.set_text(volume_name) self._label_accessed.set_text(item_a_date) self._label_modified.set_text(item_m_date) # update permissions list self._permission_update_mode(initial_update=True) # update ownership self._ownership_update() # update "open with" list self._load_associated_applications()
def _update_data(self): """Update widgets to represent item state""" associations_manager = self._application.associations_manager # get the rest of the infromation description = associations_manager.get_mime_description(self._mime_type) time_format = self._application.options.section('item_list').get('time_format') size_format = self._application.options.get('size_format') item_stat = self._provider.get_stat(self._path, extended=True) # get item size if self._is_file: # file size item_size = common.format_size(item_stat.size, size_format) else: # directory size dir_size = len(self._provider.list_dir(self._path)) item_size = '{0} {1}'.format( locale.format('%d', dir_size, True), ngettext('item', 'items', dir_size) ) # set mode self._mode = item_stat.mode # time_format item time item_a_date = time.strftime(time_format, time.localtime(item_stat.time_access)) item_m_date = time.strftime(time_format, time.localtime(item_stat.time_modify)) # get volume try: mount = gio.File(self._path).find_enclosing_mount() volume_name = mount.get_name() except gio.Error: # item is not on any known volume volume_name = _('unknown') # update widgets self._entry_name.set_text(os.path.basename(self._path)) self._label_type.set_text('{0}\n{1}'.format(description, self._mime_type)) self._label_size.set_text(item_size) self._label_location.set_text(os.path.dirname(os.path.abspath(self._path))) self._label_volume.set_text(volume_name) self._label_accessed.set_text(item_a_date) self._label_modified.set_text(item_m_date) # update permissions list self._permission_update_mode(initial_update=True) # update ownership self._ownership_update() # update "open with" list self._load_associated_applications()
def _update_total_size(self): """Update progress bar and labels for total size""" if self._human_readable: formated_size = self._size_format.format( common.format_size(self._current_size), common.format_size(self._total_size) ) else: formated_size = self._size_format.format( locale.format('%d', self._current_size, True), locale.format('%d', self._total_size, True) ) # update lable self._value_total_size.set_label(formated_size) if self._total_size > 0: self.set_total_size_fraction(float(self._current_size) / self._total_size) else: self.set_total_size_fraction(1)
def _update_speed(self): """Aggregate speed and update ETA label This method is automatically called by the gobject timeout. Don't call this method automatically! """ if self._paused: return True # don't update speed when paused speed = self._current_size - self._total_checkpoint # get current speed self._total_checkpoint = self._current_size # update aggregates speeds list if len(self._speeds) > self.MAX_SPEED_POINTS: self._speeds.pop(0) self._speeds.append(speed) # calculate average speed average = sum(self._speeds) / len(self._speeds) # update labels if average > 0: # calculate time based on average speed remainder = (self._total_size - self._current_size) / average hours, remainder = divmod(remainder, 3600) minutes, seconds = divmod(remainder, 60) time_text = '{0} {1}'.format( seconds, ngettext('second', 'seconds', seconds)) if minutes > 0: time_text = '{0} {1}, {2}'.format( minutes, ngettext('minute', 'minutes', minutes), time_text) if hours > 0: time_text = '{0} {1}, {2}'.format( hours, ngettext('hour', 'hours', hours), time_text) else: # we don't have average speed yet time_text = _('unknown') average_text = common.format_size(average, self._size_format_type) speed_text = '{0}/s'.format(average_text) self._value_eta.set_text(time_text) self._value_speed.set_text(speed_text) # make sure we keep updating return True
def _get_free_space_input(self, needed, available): """Get user input when there is not enough space""" size_format = self._application.options.get('size_format') space_needed = format_size(needed, size_format) space_available = format_size(available, size_format) if self._options is not None and self._options[Option.SILENT]: # silent option is enabled, we skip operation by default self._error_list.append(_( 'Aborted. Not enough free space on target file system.\n' 'Needed: {0}\n' 'Available: {1}' ).format(space_needed, space_available)) should_continue = False else: # ask user what to do with gtk.gdk.lock: dialog = gtk.MessageDialog( self._dialog.get_window(), gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO, _( 'Target file system does not have enough ' 'free space for this operation to continue.\n\n' 'Needed: {0}\n' 'Available: {1}\n\n' 'Do you wish to continue?' ).format(space_needed, space_available) ) dialog.set_default_response(gtk.RESPONSE_YES) result = dialog.run() dialog.destroy() should_continue = result == gtk.RESPONSE_YES return should_continue
def write_file(chunk): nonlocal transferred nonlocal f if self.cancel_download: if ftp: ftp.quit() raise Exception('Download cancelled') return f.write(chunk) transferred += len(chunk) if total_size > 0: percent = round(transferred/total_size, 2) self.percent_handler(None, percent) if transferred <= total_size: target = '{transferred}/{size}'.format(transferred = common.format_size(transferred), size = common.format_size(total_size)) else: target = '' self.target_handler(None, target) self.updateGtk()
def set_transaction_sum(self, show_updates = True): dsize = 0 self.mainApp._transactionSum.clear() transaction_dict = self.get_transaction_sum() self.mainApp._sumTopLabel.set_markup('<big><b>{}</b></big>'.format(_('Transaction Summary'))) if transaction_dict['to_remove']: self.mainApp._transactionSum.append([_('To remove')+':', transaction_dict['to_remove'][0]]) i = 1 while i < len(transaction_dict['to_remove']): self.mainApp._transactionSum.append(['', transaction_dict['to_remove'][i]]) i += 1 if transaction_dict['to_downgrade']: self.mainApp._transactionSum.append([_('To downgrade')+':', transaction_dict['to_downgrade'][0][0]]) dsize += transaction_dict['to_downgrade'][0][1] i = 1 while i < len(transaction_dict['to_downgrade']): self.mainApp._transactionSum.append(['', transaction_dict['to_downgrade'][i][0]]) dsize += transaction_dict['to_downgrade'][i][1] i += 1 if transaction_dict['to_build']: self.mainApp._transactionSum.append([_('To build')+':', transaction_dict['to_build'][0]]) i = 1 while i < len(transaction_dict['to_build']): self.mainApp._transactionSum.append(['', transaction_dict['to_build'][i]]) i += 1 if transaction_dict['to_install']: self.mainApp._transactionSum.append([_('To install')+':', transaction_dict['to_install'][0][0]]) dsize += transaction_dict['to_install'][0][1] i = 1 while i < len(transaction_dict['to_install']): self.mainApp._transactionSum.append(['', transaction_dict['to_install'][i][0]]) dsize += transaction_dict['to_install'][i][1] i += 1 if transaction_dict['to_reinstall']: self.mainApp._transactionSum.append([_('To reinstall')+':', transaction_dict['to_reinstall'][0][0]]) dsize += transaction_dict['to_reinstall'][0][1] i = 1 while i < len(transaction_dict['to_reinstall']): self.mainApp._transactionSum.append(['', transaction_dict['to_reinstall'][i][0]]) dsize += transaction_dict['to_reinstall'][i][1] i += 1 if show_updates: if transaction_dict['to_update']: self.mainApp._transactionSum.append([_('To update')+':', transaction_dict['to_update'][0][0]]) dsize += transaction_dict['to_update'][0][1] i = 1 while i < len(transaction_dict['to_update']): self.mainApp._transactionSum.append(['', transaction_dict['to_update'][i][0]]) dsize += transaction_dict['to_update'][i][1] i += 1 else: for name, size in transaction_dict['to_update']: dsize += size if dsize == 0: self.mainApp._sumBottomLabel.set_markup('') else: self.mainApp._sumBottomLabel.set_markup('<b>{} {}</b>'.format(_('Total download size:'), common.format_size(dsize)))