def on_right_click_item(self, pos): item_clicked = self.window().downloads_list.itemAt(pos) if not item_clicked or self.selected_items is None: return if item_clicked not in self.selected_items: self.selected_items.append(item_clicked) menu = TriblerActionMenu(self) start_action = QAction('Start', self) stop_action = QAction('Stop', self) remove_download_action = QAction('Remove download', self) force_recheck_action = QAction('Force recheck', self) export_download_action = QAction('Export .torrent file', self) explore_files_action = QAction('Explore files', self) no_anon_action = QAction('No anonymity', self) one_hop_anon_action = QAction('One hop', self) two_hop_anon_action = QAction('Two hops', self) three_hop_anon_action = QAction('Three hops', self) start_action.triggered.connect(self.on_start_download_clicked) start_action.setEnabled(DownloadsPage.start_download_enabled(self.selected_items)) stop_action.triggered.connect(self.on_stop_download_clicked) stop_action.setEnabled(DownloadsPage.stop_download_enabled(self.selected_items)) remove_download_action.triggered.connect(self.on_remove_download_clicked) force_recheck_action.triggered.connect(self.on_force_recheck_download) force_recheck_action.setEnabled(DownloadsPage.force_recheck_download_enabled(self.selected_items)) export_download_action.triggered.connect(self.on_export_download) explore_files_action.triggered.connect(self.on_explore_files) no_anon_action.triggered.connect(lambda: self.change_anonymity(0)) one_hop_anon_action.triggered.connect(lambda: self.change_anonymity(1)) two_hop_anon_action.triggered.connect(lambda: self.change_anonymity(2)) three_hop_anon_action.triggered.connect(lambda: self.change_anonymity(3)) menu.addAction(start_action) menu.addAction(stop_action) if self.window().vlc_available and len(self.selected_items) == 1: play_action = QAction('Play', self) play_action.triggered.connect(self.on_play_download_clicked) menu.addAction(play_action) menu.addSeparator() menu.addAction(remove_download_action) menu.addSeparator() menu.addAction(force_recheck_action) menu.addSeparator() menu.addAction(export_download_action) menu.addSeparator() menu_anon_level = menu.addMenu("Change anonymity") menu_anon_level.addAction(no_anon_action) menu_anon_level.addAction(one_hop_anon_action) menu_anon_level.addAction(two_hop_anon_action) menu_anon_level.addAction(three_hop_anon_action) menu.addAction(explore_files_action) menu.exec_(self.window().downloads_list.mapToGlobal(pos))
def on_right_click_file_item(self, pos): num_selected = len(self.window().download_files_list.selectedItems()) if num_selected == 0: return item_infos = [] # Array of (item, included, is_selected) selected_files_info = [] for i in range(self.window().download_files_list.topLevelItemCount()): item = self.window().download_files_list.topLevelItem(i) is_selected = item in self.window( ).download_files_list.selectedItems() item_infos.append((item, item.file_info["included"], is_selected)) if is_selected: selected_files_info.append(item.file_info) item_clicked = self.window().download_files_list.itemAt(pos) if not item_clicked or not item_clicked in self.window( ).download_files_list.selectedItems(): return # Check whether we should enable the 'exclude' button num_excludes = 0 num_includes_selected = 0 for item_info in item_infos: if item_info[1] and item_info[0] in self.window( ).download_files_list.selectedItems(): num_includes_selected += 1 if not item_info[1]: num_excludes += 1 menu = TriblerActionMenu(self) include_action = QAction( 'Include file' + ('(s)' if num_selected > 1 else ''), self) exclude_action = QAction( 'Exclude file' + ('(s)' if num_selected > 1 else ''), self) include_action.triggered.connect( lambda: self.on_files_included(selected_files_info)) include_action.setEnabled(True) exclude_action.triggered.connect( lambda: self.on_files_excluded(selected_files_info)) exclude_action.setEnabled(not ( num_excludes + num_includes_selected == len(item_infos))) menu.addAction(include_action) menu.addAction(exclude_action) if len(selected_files_info) == 1 and is_video_file(selected_files_info[0]['name'])\ and self.window().vlc_available: play_action = QAction('Play', self) play_action.triggered.connect( lambda: self.on_play_file(selected_files_info[0])) menu.addAction(play_action) menu.exec_(self.window().download_files_list.mapToGlobal(pos))
def on_add_wallet_clicked(self): menu = TriblerActionMenu(self) for wallet_id in self.wallets_to_create: wallet_action = QAction(self.wallets[wallet_id]['name'], self) wallet_action.triggered.connect( lambda _, wid=wallet_id: self.should_create_wallet(wid)) menu.addAction(wallet_action) menu.exec_(QCursor.pos())
def on_asset_type_clicked(self): menu = TriblerActionMenu(self) for first_wallet_id in self.wallets.keys(): for second_wallet_id in self.wallets.keys(): if first_wallet_id >= second_wallet_id: continue wallet_action = QAction('%s / %s' % (first_wallet_id, second_wallet_id), self) wallet_action.triggered.connect( lambda _, id1=first_wallet_id, id2=second_wallet_id: self.on_asset_type_changed(id1, id2)) menu.addAction(wallet_action) menu.exec_(QCursor.pos())
def on_right_click_file_item(self, pos): item_clicked = self.window().create_torrent_files_list.itemAt(pos) if not item_clicked: return self.selected_item_index = self.window().create_torrent_files_list.row(item_clicked) menu = TriblerActionMenu(self) remove_action = QAction('Remove file', self) remove_action.triggered.connect(self.on_remove_entry) menu.addAction(remove_action) menu.exec_(self.window().create_torrent_files_list.mapToGlobal(pos))
def on_right_click_order(self, pos): item_clicked = self.window().market_orders_list.itemAt(pos) if not item_clicked: return self.selected_item = item_clicked if self.selected_item.order['status'] == 'open': # We can only cancel an open order menu = TriblerActionMenu(self) cancel_action = QAction('Cancel order', self) cancel_action.triggered.connect(self.on_cancel_order_clicked) menu.addAction(cancel_action) menu.exec_(self.window().market_orders_list.mapToGlobal(pos))
def on_right_click_file_item(self, pos): item_clicked = self.window().create_torrent_files_list.itemAt(pos) if not item_clicked: return self.selected_item_index = self.window().create_torrent_files_list.row(item_clicked) menu = TriblerActionMenu(self) remove_action = QAction('Remove file', self) remove_action.triggered.connect(self.on_remove_entry) menu.addAction(remove_action) menu.exec_(self.window().create_torrent_files_list.mapToGlobal(pos))
def on_right_click_item(self, pos): item_clicked = self.env_variables_list.itemAt(pos) if not item_clicked: return self.selected_item_index = self.env_variables_list.indexOfTopLevelItem(item_clicked) menu = TriblerActionMenu(self) remove_action = QAction('Remove entry', self) remove_action.triggered.connect(self.on_remove_entry) menu.addAction(remove_action) menu.exec_(self.env_variables_list.mapToGlobal(pos))
def on_right_click_file_item(self, pos): num_selected = len(self.window().download_files_list.selectedItems()) if num_selected == 0: return item_infos = [] # Array of (item, included, is_selected) selected_files_info = [] for i in range(self.window().download_files_list.topLevelItemCount()): item = self.window().download_files_list.topLevelItem(i) is_selected = item in self.window().download_files_list.selectedItems() item_infos.append((item, item.file_info["included"], is_selected)) if is_selected: selected_files_info.append(item.file_info) item_clicked = self.window().download_files_list.itemAt(pos) if not item_clicked or not item_clicked in self.window().download_files_list.selectedItems(): return # Check whether we should enable the 'exclude' button num_excludes = 0 num_includes_selected = 0 for item_info in item_infos: if item_info[1] and item_info[0] in self.window().download_files_list.selectedItems(): num_includes_selected += 1 if not item_info[1]: num_excludes += 1 menu = TriblerActionMenu(self) include_action = QAction('Include file' + ('(s)' if num_selected > 1 else ''), self) exclude_action = QAction('Exclude file' + ('(s)' if num_selected > 1 else ''), self) include_action.triggered.connect(lambda: self.on_files_included(selected_files_info)) include_action.setEnabled(True) exclude_action.triggered.connect(lambda: self.on_files_excluded(selected_files_info)) exclude_action.setEnabled(not (num_excludes + num_includes_selected == len(item_infos))) menu.addAction(include_action) menu.addAction(exclude_action) if len(selected_files_info) == 1 and is_video_file(selected_files_info[0]['name'])\ and self.window().vlc_available: play_action = QAction('Play', self) play_action.triggered.connect(lambda: self.on_play_file(selected_files_info[0])) menu.addAction(play_action) menu.exec_(self.window().download_files_list.mapToGlobal(pos))
def on_torrents_add_clicked(self): menu = TriblerActionMenu(self) browse_files_action = QAction('Import torrent from file', self) add_url_action = QAction('Add URL', self) create_torrent_action = QAction('Create torrent from file(s)', self) browse_files_action.triggered.connect(self.on_add_torrent_browse_file) add_url_action.triggered.connect(self.on_add_torrent_from_url) create_torrent_action.triggered.connect(self.on_create_torrent_from_files) menu.addAction(browse_files_action) menu.addAction(add_url_action) menu.addAction(create_torrent_action) menu.exec_(QCursor.pos())
def on_asset_type_clicked(self): menu = TriblerActionMenu(self) asset_pairs = [] for first_wallet_id in self.wallets.keys(): for second_wallet_id in self.wallets.keys(): if first_wallet_id >= second_wallet_id: continue asset_pairs.append((first_wallet_id, second_wallet_id)) for asset_pair in sorted(asset_pairs): wallet_action = QAction('%s / %s' % asset_pair, self) wallet_action.triggered.connect(lambda _, id1=asset_pair[ 0], id2=asset_pair[1]: self.on_asset_type_changed(id1, id2)) menu.addAction(wallet_action) menu.exec_(QCursor.pos())
def on_asset_type_clicked(self): menu = TriblerActionMenu(self) asset_pairs = [] for first_wallet_id in self.wallets.keys(): for second_wallet_id in self.wallets.keys(): if first_wallet_id >= second_wallet_id: continue asset_pairs.append((first_wallet_id, second_wallet_id)) for asset_pair in sorted(asset_pairs): wallet_action = QAction('%s / %s' % asset_pair, self) wallet_action.triggered.connect( lambda _, id1=asset_pair[0], id2=asset_pair[1]: self.on_asset_type_changed(id1, id2)) menu.addAction(wallet_action) menu.exec_(QCursor.pos())
def on_add_torrent_button_click(self, pos): menu = TriblerActionMenu(self) browse_files_action = QAction('Import torrent from file', self) browse_directory_action = QAction('Import torrents from directory', self) add_url_action = QAction('Import torrent from magnet/URL', self) browse_files_action.triggered.connect(self.on_add_torrent_browse_file) browse_directory_action.triggered.connect(self.on_add_torrent_browse_dir) add_url_action.triggered.connect(self.on_add_torrent_from_url) menu.addAction(browse_files_action) menu.addAction(browse_directory_action) menu.addAction(add_url_action) menu.exec_(self.mapToGlobal(self.add_torrent_button.pos()))
def on_right_click_item(self, pos): item_clicked = self.window().downloads_list.itemAt(pos) if not item_clicked: return self.selected_item = item_clicked menu = TriblerActionMenu(self) start_action = QAction('Start', self) stop_action = QAction('Stop', self) play_action = QAction('Play', self) remove_download_action = QAction('Remove download', self) force_recheck_action = QAction('Force recheck', self) export_download_action = QAction('Export .torrent file', self) explore_files_action = QAction('Explore files', self) start_action.triggered.connect(self.on_start_download_clicked) start_action.setEnabled( DownloadsPage.start_download_enabled(self.selected_item)) stop_action.triggered.connect(self.on_stop_download_clicked) stop_action.setEnabled( DownloadsPage.stop_download_enabled(self.selected_item)) play_action.triggered.connect(self.on_play_download_clicked) remove_download_action.triggered.connect( self.on_remove_download_clicked) force_recheck_action.triggered.connect(self.on_force_recheck_download) force_recheck_action.setEnabled( DownloadsPage.force_recheck_download_enabled(self.selected_item)) export_download_action.triggered.connect(self.on_export_download) explore_files_action.triggered.connect(self.on_explore_files) menu.addAction(start_action) menu.addAction(stop_action) menu.addAction(play_action) menu.addSeparator() menu.addAction(remove_download_action) menu.addSeparator() menu.addAction(force_recheck_action) menu.addSeparator() menu.addAction(export_download_action) menu.addSeparator() menu.addAction(explore_files_action) menu.exec_(self.window().downloads_list.mapToGlobal(pos))
def on_torrents_add_clicked(self): menu = TriblerActionMenu(self) browse_files_action = QAction('Import torrent from file', self) browse_dir_action = QAction('Import torrent(s) from dir', self) add_url_action = QAction('Add URL', self) create_torrent_action = QAction('Create torrent from file(s)', self) browse_files_action.triggered.connect(self.on_add_torrent_browse_file) browse_dir_action.triggered.connect(self.on_add_torrents_browse_dir) add_url_action.triggered.connect(self.on_add_torrent_from_url) create_torrent_action.triggered.connect(self.on_create_torrent_from_files) menu.addAction(browse_files_action) menu.addAction(browse_dir_action) menu.addAction(add_url_action) menu.addAction(create_torrent_action) menu.exec_(QCursor.pos())
def on_right_click_file_item(self, pos): item_clicked = self.window().download_files_list.itemAt(pos) if not item_clicked: return self.selected_item = item_clicked file_data = self.selected_item.data(0, Qt.UserRole) menu = TriblerActionMenu(self) include_action = QAction('Include', self) exclude_action = QAction('Exclude', self) include_action.triggered.connect( lambda: self.on_file_included(file_data)) include_action.setEnabled(not file_data["included"]) exclude_action.triggered.connect( lambda: self.on_file_excluded(file_data)) exclude_action.setEnabled(file_data["included"]) menu.addAction(include_action) menu.addAction(exclude_action) menu.exec_(self.window().download_files_list.mapToGlobal(pos))
def on_right_click_item(self, pos): item_clicked = self.window().downloads_list.itemAt(pos) if not item_clicked or self.selected_items is None: return if item_clicked not in self.selected_items: self.selected_items.append(item_clicked) menu = TriblerActionMenu(self) start_action = QAction('Start', self) stop_action = QAction('Stop', self) remove_download_action = QAction('Remove download', self) force_recheck_action = QAction('Force recheck', self) export_download_action = QAction('Export .torrent file', self) explore_files_action = QAction('Explore files', self) no_anon_action = QAction('No anonymity', self) one_hop_anon_action = QAction('One hop', self) two_hop_anon_action = QAction('Two hops', self) three_hop_anon_action = QAction('Three hops', self) start_action.triggered.connect(self.on_start_download_clicked) start_action.setEnabled(DownloadsPage.start_download_enabled(self.selected_items)) stop_action.triggered.connect(self.on_stop_download_clicked) stop_action.setEnabled(DownloadsPage.stop_download_enabled(self.selected_items)) remove_download_action.triggered.connect(self.on_remove_download_clicked) force_recheck_action.triggered.connect(self.on_force_recheck_download) force_recheck_action.setEnabled(DownloadsPage.force_recheck_download_enabled(self.selected_items)) export_download_action.triggered.connect(self.on_export_download) explore_files_action.triggered.connect(self.on_explore_files) no_anon_action.triggered.connect(lambda: self.change_anonymity(0)) one_hop_anon_action.triggered.connect(lambda: self.change_anonymity(1)) two_hop_anon_action.triggered.connect(lambda: self.change_anonymity(2)) three_hop_anon_action.triggered.connect(lambda: self.change_anonymity(3)) menu.addAction(start_action) menu.addAction(stop_action) if self.window().vlc_available and len(self.selected_items) == 1: play_action = QAction('Play', self) play_action.triggered.connect(self.on_play_download_clicked) menu.addAction(play_action) menu.addSeparator() menu.addAction(remove_download_action) menu.addSeparator() menu.addAction(force_recheck_action) menu.addSeparator() exclude_states = [DLSTATUS_METADATA, DLSTATUS_CIRCUITS, DLSTATUS_HASHCHECKING, DLSTATUS_WAITING4HASHCHECK] if len(self.selected_items) == 1 and self.selected_items[0].get_raw_download_status() not in exclude_states: menu.addAction(export_download_action) menu.addSeparator() menu_anon_level = menu.addMenu("Change anonymity") menu_anon_level.addAction(no_anon_action) menu_anon_level.addAction(one_hop_anon_action) menu_anon_level.addAction(two_hop_anon_action) menu_anon_level.addAction(three_hop_anon_action) menu.addAction(explore_files_action) menu.exec_(self.window().downloads_list.mapToGlobal(pos))