def switch_to_detail_page(page_switcher, detail_page, pkg_name): log("start switch to detail_page") page_switcher.slide_to_page(detail_page, "right") # ThreadMethod(detail_page.update_pkg_info, (pkg_name,)).start() detail_page.update_pkg_info(pkg_name) log("end switch to detail_page") global_event.emit("update-current-status-pkg-page", detail_page)
def button_press(self, column, offset_x, offset_y): # init Loading widget loading_box = LoadingBox() global_event.emit("show-pkg-view", loading_box) self.page_box = gtk.VBox() self.all_pkg_names = self.data_manager.get_second_category_packages(self.second_category_name) self.message_bar = MessageBar(18) self.message_bar.set_message(_("%s > %s : %s applications") % ( get_category_name(self.first_category_name), get_category_name(self.second_category_name), len(self.all_pkg_names), )) self.pkg_icon_view = IconView() self.pkg_icon_view.connect("motion-notify-item", tooltip_aciton) if len(self.all_pkg_names) > LOAD_ITEMS_NUMBER: self.load_new_items(self.all_pkg_names[:LOAD_ITEMS_NUMBER]) else: self.load_new_items(self.all_pkg_names) self.pkg_icon_scrolled_window = ScrolledWindow() self.pkg_icon_scrolled_window.connect("vscrollbar-state-changed", self.scrolled_window_vscrollbar_handler) self.pkg_icon_scrolled_window.add_child(self.pkg_icon_view) self.pkg_icon_view.draw_mask = self.draw_mask self.pkg_icon_view.draw_row_mask = self.draw_row_mask self.page_box.pack_start(self.message_bar, False, False) self.page_box.pack_start(self.pkg_icon_scrolled_window, True, True) global_event.emit("update-current-status-pkg-page", self.pkg_icon_view)
def fetch_screenshot(self): screenshot_dir = os.path.join(SCREENSHOT_DOWNLOAD_DIR, self.pkg_name) screenshot_md5_path = os.path.join(screenshot_dir, "screenshot_md5.txt") remote_screenshot_md5_url = "%s/zh_CN/%s/screenshot_md5.txt" % (SCREENSHOT_HOST, self.pkg_name) remote_screenshot_zip_url = "%s/zh_CN/%s/screenshot.zip" % (SCREENSHOT_HOST, self.pkg_name) try: remote_md5 = urllib2.urlopen(remote_screenshot_md5_url).read() need_download = False if os.path.exists(screenshot_dir): if os.path.exists(screenshot_md5_path): local_md5 = read_file(screenshot_md5_path) if remote_md5 != local_md5: need_download = True else: need_download = True else: need_download = True if need_download: write_file(screenshot_md5_path, remote_md5, True) try: urllib.urlretrieve(remote_screenshot_zip_url, os.path.join(SCREENSHOT_DOWNLOAD_DIR, self.pkg_name, "screenshot.zip") ) global_event.emit("download-screenshot-finish", self.pkg_name) except Exception, e: global_logger.logerror("Download screenshot error: %s" % e) except Exception, e: global_logger.logerror("fetch_screenshot got error: %s" % e)
def icon_item_button_press(self, x, y): ''' Handle button-press event. This is IconView interface, you should implement it. ''' global_event.emit("switch-to-album-detail-view", self.album_info)
def click_rank_tab(self, tab_index): if self.tab_index != tab_index: self.active_flag = False elif not self.active_flag: self.active_flag = True global_event.emit("update-rank-page", self.tab_index)
def tooltip_aciton(view, item, x, y): if item.is_in_name_area(x, y): new_cursor_postion = "name" else: new_cursor_postion = "other" global_event.emit("cursor-position-changed", item, new_cursor_postion)
def status_change(self, pkg, percent, status): """Called when the status changed. Emits: action-update(status, percent) """ self.time_last_update = time.time() global_event.emit("action-update", (self.upgrade_id, self.action_type, int(percent), status))
def handle_pkg_status(self, *reply): container_remove_all(self.left_action_box) install_status = reply if install_status[0][0]: if not self.data_manager.get_pkg_desktop_info(self.pkg_name): status_label = Label(_("Successfully installed")) self.left_action_box.pack_start(status_label) else: action_button = ImageButton( app_theme.get_pixbuf("button/start_normal.png"), app_theme.get_pixbuf("button/start_hover.png"), app_theme.get_pixbuf("button/start_press.png"), ) action_button.connect("button-press-event", self.button_press_start_button) self.left_action_box.pack_start(action_button) else: action_button = ImageButton( app_theme.get_pixbuf("button/install_normal.png"), app_theme.get_pixbuf("button/install_hover.png"), app_theme.get_pixbuf("button/install_press.png"), ) action_button.connect("clicked", lambda w: global_event.emit("install-pkg", [self.pkg_name])) self.left_action_box.pack_start(action_button) self.left_action_box.show_all() global_event.emit('update-current-status-pkg-page', self)
def handle_pkg_status(self, reply, success): container_remove_all(self.left_action_box) if success: install_status = str(reply) print install_status if install_status == "installed": if not self.data_manager.get_pkg_desktop_info(self.pkg_name): status_label = Label(_("Successfully installed")) self.left_action_box.pack_start(status_label) else: action_button = ImageButton( app_theme.get_pixbuf("button/start_normal.png"), app_theme.get_pixbuf("button/start_hover.png"), app_theme.get_pixbuf("button/start_press.png"), ) action_button.connect("button-press-event", self.button_press_start_button) self.left_action_box.pack_start(action_button) elif install_status == "unknown": status_label = Label(_("Not found")) self.left_action_box.pack_start(status_label) else: action_button = ImageButton( app_theme.get_pixbuf("button/install_normal.png"), app_theme.get_pixbuf("button/install_hover.png"), app_theme.get_pixbuf("button/install_press.png"), ) action_button.connect("clicked", lambda w: global_event.emit("install-pkg", [self.pkg_name])) self.left_action_box.pack_start(action_button) self.left_action_box.show_all() global_event.emit('update-current-status-pkg-page', self) else: global_logger.logerror("get_pkg_installed handle_dbus_error") global_logger.logerror(reply)
def button_press_start_button(self, widget, event, desktops): pixbuf = app_theme.get_pixbuf("button/start_normal.png").get_pixbuf() desktop_infos = self.data_manager.get_pkg_desktop_info(desktops) global_event.emit("start-pkg", self.alias_name, desktop_infos, (int(event.x), int(event.y), pixbuf.get_width() / 2, 0))
def icon_item_double_click(self, x, y): ''' Handle double click event. This is IconView interface, you should implement it. ''' global_event.emit("switch-to-detail-page", self.info[0])
def load_new_items(self, pkg_names): items = [] for pkg_name in pkg_names: info = self.data_manager.get_item_pkg_info(pkg_name) items.append(PkgIconItem(info[0], info[1], info[2], self.data_manager)) self.pkg_icon_view.add_items(items) global_event.emit("show-pkg-view", self.page_box)
def icon_item_button_press(self, x, y): ''' Handle button-press event. This is IconView interface, you should implement it. ''' global_event.emit("start-desktop", self.pkg_name, self.desktop_path)
def update_home_page(self, data): if not data: self.check_network_connection() return slide_infos = sort_for_home_page_data(data['slide']) self.slider_switcher = IndexSlideSwitcher(slide_infos) self.slider_switcher.connect( "motion-notify-index", lambda w, i: global_event.emit("set-cursor", gtk.gdk.HAND2)) self.slider_switcher.connect( "button-press-index", lambda w, i: global_event.emit( "switch-to-detail-page", slide_infos[i][0])) self.slider_switcher.connect( "leave-notify-index", lambda w, i: global_event.emit("set-cursor", None)) self.recommend_infos = sort_for_home_page_data(data['recommend']) self.tab_switcher = TabSwitcher( [_("Recommendations"), _("HotApps"), _("Download rank")], CATEGORY_ITEM_NAME_SIZE) self.tab_switcher_align = gtk.Alignment() self.tab_switcher_align.set(0.5, 0.5, 1, 1) self.tab_switcher_align.set_padding(10, 0, 0, 9) self.tab_switcher_align.add(self.tab_switcher) self.tab_switcher_pages_callback = [ "get_pkg_icon_view_page", "get_album_page", "get_download_rank_page", ] self.page_box = gtk.VBox() self.box.pack_start(self.slider_switcher, False, False) self.box.pack_start(self.tab_switcher_align, False, False) self.box_align = gtk.Alignment() self.box_align.set(0.5, 0.5, 1, 1) self.box_align.set_padding(5, 0, 10, 11) self.box_align.add(self.box) self.page_box_align = gtk.Alignment() self.page_box_align.set(0.5, 0, 1, 1) self.page_box_align.add(self.page_box) self.background_box.pack_start(self.box_align, False, False) self.background_box.pack_start(self.page_box_align) self.recommend_scrolled_window.add_child(self.background_box) self.switch_page(0) self.tab_switcher.connect( "tab-switch-start", lambda switcher, page_index: self.switch_page(page_index)) self.tab_switcher.connect( "click-current-tab", lambda switcher, page_index: self.click_page()) self.switch_page_view(self.recommend_scrolled_window) self.recommend_scrolled_window_initial = True
def clean_download_cache_reply(obj, result): num, size = result if num != 0: message = _("You have cleared up %s packages and saved %s of space.") % (num, bit_to_human_str(size)) else: message = _("Your system cache is empty.") global_event.emit("show-message", message, 5000)
def get_pkgs_status(self): if self.show_flag: infos = self.data_manager.get_download_rank_info(self.pkg_names) if len(infos) > 25: infos = infos[:25] valid_pkg_names = [] for info in infos: valid_pkg_names.append(info[0]) view = self.view_list[self.current_page_index][1] view.clear() container_remove_all(self.page_align) items = [] for i in range(len(infos)): items.append(PkgIconItem(self.data_manager, *infos[i])) view.add_items(items) self.page_align.add(self.view_list[self.current_page_index][2]) global_event.emit("update-current-status-pkg-page", view) self.show_all() self.show_flag = None return True
def filter_uninstall_pkg_infos(self, uninstall_pkg_infos): pkg_infos = [] for pkg_info in uninstall_pkg_infos: pkg_name, pkg_version = pkg_info if self.is_uninstallable_kernel(pkg_name) or \ self.data_manager.is_pkg_display_in_uninstall_page(pkg_name): pkg_infos.append((pkg_name, pkg_version)) global_event.emit("uninstall-items-filtered", pkg_infos)
def error(self, pkg, errormsg): """Called when an error happens. Emits: action-error() """ global_event.emit("action-error", (pkg, errormsg)) global_event.emit("action-failed", (pkg, ACTION_UPGRADE, [], str(errormsg))) log("error: %s" % errormsg)
def expand(self): self.is_expand = True self.add_child_item() if self.redraw_request_callback: self.redraw_request_callback(self) global_event.emit("category-expand", self)
def download_parse_failed(self): self.status = self.STATUS_PARSE_DOWNLOAD_FAILED self.status_text = _("Dependencies analysis failed") if self.redraw_request_callback: self.redraw_request_callback(self) global_event.emit("request-clear-failed-action", self.pkg_name, ACTION_INSTALL)
def load_items_reply_handler(self, status, pkg_infos): items = [] for (index, (pkg_name, short_desc, star, alias_name)) in enumerate(pkg_infos): if short_desc != None: items.append(PkgIconItem(status[index], alias_name, pkg_name, short_desc, star, self.all_desktop_infos[pkg_name])) self.pkg_icon_view.add_items(items) global_event.emit("show-pkg-view", self.page_box)
def load_new_items(self, pkg_names): items = [] for pkg_name in pkg_names: info = self.data_manager.get_item_pkg_info(pkg_name) items.append( PkgIconItem(info[0], info[1], info[2], self.data_manager)) self.pkg_icon_view.add_items(items) global_event.emit("show-pkg-view", self.page_box)
def uninstall_pkg_from_desktop_thread(self, path, purge): pkg_name = self.get_pkg_name_from_path(path) if pkg_name: self.uninstall_pkg(pkg_name, purge) else: global_event.emit("action-failed", (path, ACTION_UNINSTALL, [], "no package found for path: %s" % path))
def __init__(self, data_manager): # Init. gtk.VBox.__init__(self) self.data_manager = data_manager self.tab_box = gtk.HBox() self.tab_box.set_size_request(-1, RANK_TAB_HEIGHT) self.tab_box.set_spacing(1) self.tab_box_align = gtk.Alignment() self.tab_box_align.set(1, 0, 0, 0) self.tab_box_align.set_padding(3, 9, 25, 48) for (tab_index, tab_name) in enumerate([_("Top 25 weekly"), _("Top 25 monthly"), _("Top 25 totally")]): self.tab_box.pack_start(RankTab(tab_index, tab_name, tab_index == 0), False, False) self.page_box = gtk.VBox() self.page_align = gtk.Alignment() self.page_align.set(0.5, 0.5, 1, 1) self.page_align.set_padding(0, 0, 15, 15) self.week_rank_icon_view = IconView() self.week_rank_icon_view_scrlledwindow = ScrolledWindow() self.week_rank_icon_view.draw_mask = self.draw_mask self.month_rank_icon_view = IconView() self.month_rank_icon_view_scrlledwindow = ScrolledWindow() self.month_rank_icon_view.draw_mask = self.draw_mask self.all_rank_icon_view = IconView() self.all_rank_icon_view_scrlledwindow = ScrolledWindow() self.all_rank_icon_view.draw_mask = self.draw_mask self.week_rank_icon_view_scrlledwindow.add_child(self.week_rank_icon_view) self.month_rank_icon_view_scrlledwindow.add_child(self.month_rank_icon_view) self.all_rank_icon_view_scrlledwindow.add_child(self.all_rank_icon_view) self.tab_box_align.add(self.tab_box) self.page_box.pack_start(self.page_align) self.pack_start(self.tab_box_align, False, False) self.pack_start(self.page_box, True, True) self.loading = LoadingBox() self.view_list = [ ('week', self.week_rank_icon_view, self.week_rank_icon_view_scrlledwindow), ('month', self.month_rank_icon_view, self.month_rank_icon_view_scrlledwindow), ('all', self.all_rank_icon_view, self.all_rank_icon_view_scrlledwindow)] self.pkg_names = [] self.show_flag = None self.all_show_flag = ['week', 'month', 'all'] global_event.register_event("update-rank-page", self.update_rank_page) gtk.timeout_add(300, self.get_pkgs_status) global_event.emit("update-rank-page", 0)
def update_message_bar(self, treeview): if len(treeview.visible_items) > 0: self.message_bar.set_message(_("%s: %s matched applications") % (' '.join(self.keywords), len(self.all_pkg_names))) container_remove_all(self) self.pack_start(self.content_box) global_event.emit("update-current-status-pkg-page", treeview) else: container_remove_all(self) self.pack_start(self.cute_message_image)
def update_interface(self): """Called periodically to update the interface. Emits: action-timeout() [When a timeout happens] """ #print "update_interface >>", self.time_last_update apb.InstallProgress.update_interface(self) if self.time_last_update + self.INSTALL_TIMEOUT < time.time(): global_event.emit("action-timeout")
def change_to_nearest_mirror_thread(self, widget): from mirror_speed.ip_detect import get_nearest_mirrors hostnames = get_nearest_mirrors() self.mirror_test_obj = MirrorTest(hostnames) hostname = self.mirror_test_obj.run() for mirror in self.mirrors_list: if mirror.hostname == hostname: global_event.emit("mirror-test-finished", mirror) break
def change_download_save_dir(self, widget): local_dir = FolderChooseDialog(False).run() if local_dir: local_dir = os.path.expanduser(local_dir) if local_dir != get_software_download_dir(): self.dir_entry.set_editable(True) self.dir_entry.set_text(local_dir) self.dir_entry.set_editable(False) set_software_download_dir(local_dir) global_event.emit('download-directory-changed')
def dist_upgrade(self): action_type = ACTION_UPGRADE action_id = '%s_%s' % (self.get_unique_id(), action_type) self.update_signal([( "ready-download-start", (action_id, action_type))]) dist_upgrade_changes = self.pkg_cache.get_dist_upgrade_changes() # detect and prevent the system components from being uninstalled pkg_in_white_list = [] download_pkgs = [] self.all_upgrade_pkg_names = [] for pkg in dist_upgrade_changes["delete"]: name = pkg.name if name in SYS_PKG_WHITE_LIST: pkg_in_white_list.append(name) if len(pkg_in_white_list) > 0: self.update_signal([( "remove-pkgs-in-white-list", (json.dumps(pkg_in_white_list), action_type))]) logger.error("found remove system packages: %s" % json.dumps(pkg_in_white_list)) else: for status in dist_upgrade_changes: for pkg in dist_upgrade_changes[status]: self.all_upgrade_pkg_names.append(pkg.name) if status == "delete" or status == "keep": continue if not parse_pkg.pkg_file_has_exist(pkg): download_pkgs.append(pkg) self.update_signal([("ready-download-finish", (action_id, action_type))]) if len(download_pkgs) == 0: global_event.emit("download-finish", action_id, action_type, self.all_upgrade_pkg_names) else: names = [] download_urls = [] download_hash_infos = [] pkg_sizes = [] for pkg in download_pkgs: names.append(pkg.name) download_urls.append(pkg.candidate.uri) download_hash_infos.append(pkg.candidate.md5) pkg_sizes.append(pkg.candidate.size) self.download_manager.add_download( action_id, action_type, download_urls, download_sizes=pkg_sizes, download_md5s=download_hash_infos, all_task_names=names, all_change_pkgs=self.all_upgrade_pkg_names, file_save_dir=self.download_dir )
def update_message_bar(self, treeview): if len(treeview.visible_items) > 0: self.message_bar.set_message( " ".join(self.keywords) + ": " + _("%s applications searched") % len(self.all_pkg_names)) container_remove_all(self) self.pack_start(self.content_box) global_event.emit("update-current-status-pkg-page", treeview) else: container_remove_all(self) self.pack_start(self.cute_message_image)
def icon_item_button_press(self, x, y): ''' Handle button-press event. This is IconView interface, you should implement it. ''' try: self.desktop_info.launch() global_event.emit("show-message", _("%s: request for starting applications sent") % self.desktop_display_name, 5000) except: logging.error("Launch error: %s" % self.desktop_info)
def update_item(self, data): items = [] if data: for album_info in data: items.append(AlbumSummaryItem(album_info)) items.sort(key=attrgetter('album_order'), reverse=True) self.iconview.add_items(items) global_event.emit('switch-to-album-summary-view') else: global_event.emit('switch-to-network-problem-view')
def dist_upgrade(self): action_type = ACTION_UPGRADE action_id = '%s_%s' % (self.get_unique_id(), action_type) self.update_signal([("ready-download-start", (action_id, action_type)) ]) dist_upgrade_changes = self.pkg_cache.get_dist_upgrade_changes() # detect and prevent the system components from being uninstalled pkg_in_white_list = [] download_pkgs = [] self.all_upgrade_pkg_names = [] for pkg in dist_upgrade_changes["delete"]: name = pkg.name if name in SYS_PKG_WHITE_LIST: pkg_in_white_list.append(name) if len(pkg_in_white_list) > 0: self.update_signal([("remove-pkgs-in-white-list", (json.dumps(pkg_in_white_list), action_type)) ]) logger.error("found remove system packages: %s" % json.dumps(pkg_in_white_list)) else: for status in dist_upgrade_changes: for pkg in dist_upgrade_changes[status]: self.all_upgrade_pkg_names.append(pkg.name) if status == "delete" or status == "keep": continue if not parse_pkg.pkg_file_has_exist(pkg): download_pkgs.append(pkg) self.update_signal([("ready-download-finish", (action_id, action_type))]) if len(download_pkgs) == 0: global_event.emit("download-finish", action_id, action_type, self.all_upgrade_pkg_names) else: names = [] download_urls = [] download_hash_infos = [] pkg_sizes = [] for pkg in download_pkgs: names.append(pkg.name) download_urls.append(pkg.candidate.uri) download_hash_infos.append(pkg.candidate.md5) pkg_sizes.append(pkg.candidate.size) self.download_manager.add_download( action_id, action_type, download_urls, download_sizes=pkg_sizes, download_md5s=download_hash_infos, all_task_names=names, all_change_pkgs=self.all_upgrade_pkg_names, file_save_dir=self.download_dir)
def switch_to_album_detail_view(self, album_info): self.in_detail_view = True container_remove_all(self) container_remove_all(self.album_detail_align) album_detail_page = AlbumDetailPage(self.data_manager, album_info) self.album_detail_align.add(album_detail_page) self.pack_start(self.album_detail_align, True, True) self.show_all() global_event.emit("update-current-status-pkg-page", album_detail_page.treeview)
def run(self): url = "%sgame/analytics/?type=star&appid=%s&mark=%s" % (GAME_CENTER_SERVER_ADDRESS, self.appid, self.star) try: js = urllib2.urlopen(url).read() if js: js = json.loads(js) if js['status'] == 'OK': global_event.emit('set-star-score-success', js) else: print "Star error" print js except Exception, e: print 'SetStarScore Error:', e
def icon_item_button_press(self, x, y): ''' Handle button-press event. This is IconView interface, you should implement it. ''' try: self.desktop_info.launch() global_event.emit( "show-message", _("%s: request for starting applications sent") % self.desktop_display_name, 5000) except: logging.error("Launch error: %s" % self.desktop_info)
def run(self): '''Run''' try: args = {'n' : self.name, 'm' : self.vote} js = urllib2.urlopen( "%s/softcenter/v1/mark?%s" % (SERVER_ADDRESS, urllib.urlencode(args)), timeout=POST_TIMEOUT ).read() js = json.loads(js) global_event.emit('vote-send-success', (self.name, self.obj, js)) except Exception, e: global_event.emit('vote-send-failed', self.name) traceback.print_exc(file=sys.stdout) print "SendVote Error: ", e
def download_json_info(self, appid): info_json_url = "%sgame/info/%s" % (GAME_CENTER_SERVER_ADDRESS, appid) try: js = urllib2.urlopen(info_json_url).read() if js: info = json.loads(js) json.dump(info, open(self.desc_info_path, 'wb')) self.finish_fetch_info(info['index_pic_url']) global_event.emit('download-app-info-finish', json.dumps(info)) except Exception, e: traceback.print_exc(sys.stdout) print "Error msg:", e if os.path.exists(self.desc_info_path): info = json.load(open(self.desc_info_path)) global_event.emit('download-app-info-finish', json.dumps(info))
def handle_pkg_status(self, status, success): if success: self.install_status= str(status) if self.install_status == "unknown": global_event.emit("delete-search-page-items", [self]) else: try: self.desktops = json.loads(self.install_status) self.desktops = self.data_manager.get_pkg_desktop_info(self.desktops) except: pass self.emit_redraw_request() else: utils.global_logger.error("%s: get_pkg_installed handle_dbus_error" % self.pkg_name) utils.global_logger.error(status)
class FetchAlbumData(td.Thread): def __init__(self, language, status="publish"): td.Thread.__init__(self) self.language = language self.album_data_url = BAIDU_SERVER_ADDRESS + "album/" self.data = { 'hl': language if language != 'zh_HK' else 'zh_TW', 'status': status_modes.get(status), } self.setDaemon(True) def run(self): json_data = None try: query = urllib.urlencode(self.data) request_url = ("%s?%s") % (self.album_data_url, query) connection = urllib2.urlopen( request_url, timeout=POST_TIMEOUT, ) json_data = json.loads(connection.read()) except Exception, e: traceback.print_exc(file=sys.stdout) print "Fetch album data failed: %s." % (e) global_event.emit("download-album-infos-finish", json_data)
def run(self): try: filename = utils.generate_log_tar() o_name, ext = os.path.splitext(filename) dt_now = datetime.now() folder = dt_now.strftime("/files/%Y/%m/%d/") name = "%s_%s%s" % (dt_now.strftime("%Y%m%d%H%M%S"), uuid.uuid4().hex, ext) up_path = os.path.join(folder, name) bcs_obj = bucket.object(up_path) with open(filename) as fp: bcs_obj.put(fp.read()) global_event.emit('upload-error-log-success') print "Upload Error Log Success" except Exception, e: print "Upload Error Log Failed: %s" % e global_event.emit("upload-error-log-failed", e)
class FetchHomeData(td.Thread): def __init__(self, language, status="publish"): td.Thread.__init__(self) self.language = language self.home_data_url = BAIDU_SERVER_ADDRESS + "home/" self.data = { 'hl': language if language != 'zh_HK' else 'zh_TW', 'status': status_modes.get(status), } self.setDaemon(True) def run(self): json_data = {} query = urllib.urlencode(self.data) request_url = ("%s?%s") % (self.home_data_url, query) try: connection = urllib2.urlopen( request_url, timeout=POST_TIMEOUT, ) json_data = json.loads(connection.read()) touch_file(HOME_CACHE_DATA_PATH) with open(HOME_CACHE_DATA_PATH, "wb") as fp: json.dump(json_data, fp) except Exception, e: traceback.print_exc(file=sys.stdout) print "Fetch home data failed: %s." % (e) print "url:", request_url if os.path.exists(HOME_CACHE_DATA_PATH): with open(HOME_CACHE_DATA_PATH) as fp: json_data = json.load(fp) global_event.emit("download-home-infos-finish", json_data)
def __init__(self, bus_interface, data_manager): ''' init docs ''' # Init. gtk.VBox.__init__(self) self.bus_interface = bus_interface self.data_manager = data_manager self.message_bar = MessageBar(32) self.message_box = gtk.HBox() self.treeview = TreeView(enable_drag_drop=False) self.treeview.set_expand_column(0) self.cute_message_image = gtk.VBox() self.content_box = gtk.VBox() self.pack_start(self.message_box, False, False) self.pack_start(self.content_box, True, True) self.cute_message_pixbuf = utils.get_common_locale_image_pixbuf( "info", "no_download.png") self.content_box.pack_start(self.cute_message_image, True, True) self.treeview.draw_mask = self.draw_mask self.cute_message_image.connect("expose-event", self.expose_cute_message_image) self.treeview.connect("items-change", self.update_message_bar) self.treeview.connect( "items-change", lambda treeview: global_event.emit( "update-install-notify-number", self.get_installing_pkgs_number()))
def cursor_postion_changed(item, new_cursor_postion): global cursor_postion global timeout_tooltip_action_id if new_cursor_postion != cursor_postion and new_cursor_postion == "name": if timeout_tooltip_action_id: gobject.source_remove(timeout_tooltip_action_id) timeout_tooltip_action_id = None timeout_tooltip_action_id = gobject.timeout_add( 1000, timeout_tooltip_action, item) elif new_cursor_postion != cursor_postion and new_cursor_postion == 'other': if timeout_tooltip_action_id: gobject.source_remove(timeout_tooltip_action_id) timeout_tooltip_action_id = None global_event.emit('hide-pkg-name-tooltip') cursor_postion = new_cursor_postion
def get_upgrade_download_info_with_new_policy(cache, pkg_names): cache._depcache.init() failed_analyze_pkgs = [] dependence = [] try: for name in pkg_names: new_name, pkg = get_cache_pkg(cache, name) if not pkg: failed_analyze_pkgs.append(name) global_event.emit('parse-download-error', name, ACTION_UPGRADE) else: if cache.is_pkg_upgradable(new_name): pkg.mark_upgrade() elif not cache.is_pkg_installed(new_name): pkg.mark_install() except Exception, e: global_event.emit('parse-packages-failed', e)
def handle_pkg_status(self, reply, success): container_remove_all(self.left_action_box) if success: install_status = str(reply) if install_status == "uninstalled": action_button = ImageButton( app_theme.get_pixbuf("button/install_normal.png"), app_theme.get_pixbuf("button/install_hover.png"), app_theme.get_pixbuf("button/install_press.png"), ) action_button.connect( "clicked", lambda w: global_event.emit( "install-pkg", [self.pkg_name])) self.left_action_box.pack_start(action_button) elif install_status == "unknown": status_label = Label(_("Not found")) self.left_action_box.pack_start(status_label) else: try: desktops = json.loads(install_status) if not desktops: status_label = Label(_("Successfully installed")) self.left_action_box.pack_start(status_label) else: action_button = ImageButton( app_theme.get_pixbuf("button/start_normal.png"), app_theme.get_pixbuf("button/start_hover.png"), app_theme.get_pixbuf("button/start_press.png"), ) action_button.connect( "button-press-event", lambda w, e: self.button_press_start_button( w, e, desktops)) self.left_action_box.pack_start(action_button) except: logging.error("detail install status: %s = %s" % (self.pkg_name, install_status)) self.left_action_box.show_all() global_event.emit('update-current-status-pkg-page', self) else: global_logger.error("get_pkg_installed handle_dbus_error") global_logger.error(reply)
def get_pkgs_status(self): if self.show_flag: view = self.view_list[self.current_page_index][1] view.clear() container_remove_all(self.page_align) items = [] pkg_names = self.pkg_names[:25] for pkg_name in pkg_names: info = self.data_manager.get_item_pkg_info(pkg_name) items.append(PkgIconItem(pkg_name, info[1], self.data_manager)) view.add_items(items) self.page_align.add(self.view_list[self.current_page_index][2]) global_event.emit("update-current-status-pkg-page", view) self.show_flag = None self.show_all() return True
def pulse(self, owner): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" apt.progress.base.AcquireProgress.pulse(self, owner) self.percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) end = "" if self.current_cps: eta = long( float(self.total_bytes - self.current_bytes) / self.current_cps) end = " %sB/s %s" % (apt_pkg.size_to_str( self.current_cps), apt_pkg.time_to_str(eta)) global_event.emit("update-list-update", self.percent, self.status_message, end) return True
def motion_notify(self, column, offset_x, offset_y): if column == 0: if self.is_in_icon_area(column, offset_x, offset_y): global_event.emit("set-cursor", gtk.gdk.HAND2) elif self.is_in_name_area(column, offset_x, offset_y): global_event.emit("set-cursor", gtk.gdk.HAND2) else: global_event.emit("set-cursor", None) else: if self.status == self.STATUS_NORMAL: if self.is_in_button_area(column, offset_x, offset_y): self.button_status = BUTTON_HOVER if self.redraw_request_callback: self.redraw_request_callback(self) elif self.button_status != BUTTON_NORMAL: self.button_status = BUTTON_NORMAL if self.redraw_request_callback: self.redraw_request_callback(self) if self.is_in_star_area(column, offset_x, offset_y): global_event.emit("set-cursor", gtk.gdk.HAND2) times = offset_x / STAR_SIZE self.grade_star = times * 2 + 2 self.grade_star = min(self.grade_star, 10) self.star_buffer.star_level = self.grade_star if self.redraw_request_callback: self.redraw_request_callback(self) else: global_event.emit("set-cursor", None) if self.star_buffer.star_level != self.star_level: self.star_buffer.star_level = self.star_level if self.redraw_request_callback: self.redraw_request_callback(self)