def search(self, widget, data=None): win = self.gld.get_widget("main_win") wait_cursor = Cursor(WATCH) dlg = search_dialog(self.gld.get_widget("main_win"), self.icon) def _fork(): repos_tree = self.gld.get_widget("repos_tree") repos_model = repos_tree.get_model() pacs = self.database.get_by_keywords(keywords) if self.search_iter: repos_model.remove(self.search_iter) self.search_iter = repos_model.append(None, [_("Search results for '%s'") %keywords]) self.models["search"] = search_list(pacs) repos_tree.set_cursor_on_cell((1)) dlg.destroy() win.window.set_cursor(None) if dlg.run() == RESPONSE_ACCEPT: keywords = dlg.entry.get_text() if keywords: dlg.vbox.set_sensitive(False) self._statusbar(_("Searching for %s..." %keywords)) win.window.set_cursor(wait_cursor) dlg.window.set_cursor(wait_cursor) gobject.idle_add(_fork) else: dlg.destroy() error_dlg = error_dialog(None, _("You should insert at least one keyword to search for"), self.icon) error_dlg.run() error_dlg.destroy() else: dlg.destroy()
def _req_pac_check(to_check, flag): to_do = [] try: pac = self.database.get_by_name(to_check) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%(dep)s is not in the database. %(dep)s is required by %(pkg)s.\nThis maybe either an error in %(pkg)s packaging or a gtkpacman's bug.\nIf you think it's the first, contact the %(pkg)s maintainer, else fill a bug report for gtkpacman, please.") %{'dep': dep, "pkg": name}, self.icon) dlg.run() dlg.destroy() pacs_queues["add"].remove(pac) self.queues["add"].remove(name) return try: if not pac.prop_setted: self.database.set_pac_properties(pac) except: return pac, to_do if flag == "req": for req in pac.req_by.split(", "): if len(req) >= 1: to_do.append(req) else: if not pac.installed: for dep in pac.dependencies.split(", "): if len(dep) >= 1: to_do.append(dep) else: pac = None return pac, to_do pac = None return pac, to_do
def _execute_dep_check(self, to_check, flag): to_do = [] pac = self.database.get_by_name(to_check) if not pac: dlg = error_dialog(self.gld.get_widget("main_win"), _("%(pkg)s is not in the database.\n%(pkg)s is required by one of your package(s).")%{"pkg": to_check}, self.icon) #This maybe either an error in %(pkg)s packaging or a gtkpacman's bug.")%{"pkg": to_check}, self.icon)#\n \ #If you think it's the first, contact the %(pkg)s maintainer, else fill a bug report for gtkpacman, please.") %{"pkg": to_check}, self.icon) dlg.run() dlg.destroy() return '','' if flag == "req": self.database.set_pac_properties(pac) for req in pac.req_by.split(","): if len(req) >= 1: to_do.append(req) else: pac.flag = 0x12 self.database.set_pac_properties(pac) pac.flag = None for dep in pac.dependencies.split(","): to_do.append(dep) return pac, to_do
def calculate_points(self): self.cur_players.execute( "select played_by from match_played where match_id like ?;", (self.comboBox.currentText(), )) get_team = self.cur_players.fetchone() if get_team != None: team = get_team[0] if team == self.comboBox_2.currentText(): sql = "select * from " + self.comboBox.currentText() + ";" self.cur_players.execute(sql) get_all = self.cur_players.fetchall() total_points = 0 for player_score in get_all: player_dict = {} player_dict['name'] = player_score[0] player_dict['runs'] = player_score[1] player_dict['balls'] = player_score[2] player_dict['4'] = player_score[3] player_dict['6'] = player_score[4] player_dict['wkts'] = player_score[8] player_dict['field'] = 0 player_dict['field'] += player_score[9] player_dict['field'] += player_score[10] player_dict['field'] += player_score[11] player_dict['bowled'] = player_score[5] player_dict['overs'] = player_score[5] / 6 points = get_points(self, player_dict) new_match.correction(self) for i in range(self.listWidget_3.count()): if player_dict['name'] == self.listWidget_3.item(i).text(): self.listWidget_4.item(i).setText(str(points)) total_points += points self.label_21.setText(str(total_points)) else: dialogs.error_dialog( self, "open", self.comboBox.currentText() + " is not played by team " + self.comboBox_2.currentText()) else: dialogs.error_dialog(self, "open", "Select the Match !")
def play_thematch(self, act): self.fill_thelist() if self.comboBox.currentText() == "+ Play a New Match": if act == "showButton": self.playTheMatch.show() elif act == "play": team = self.comboBox_2.currentText() #print(team) self.cur_players.execute( "select players from teams where name like ?;", (team, )) players = self.cur_players.fetchone() player_list = json.loads(players[0]) batting_lineup = [] bowlers_for_batting = [] batsman_for_batting = [] batting_value = [] player_val = {} player_ctg = {} for player in player_list: self.cur_players.execute( "select value,ctg from stats where player like ?;", (player, )) rec = self.cur_players.fetchone() player_val[player] = rec[0] player_ctg[player] = rec[1] if player_ctg[player] == "BAT" or player_ctg[ player] == "AR" or player_ctg[player] == "WK": batting_value.append(player_val[player]) batsman_for_batting.append(player) else: bowlers_for_batting.append(player) random.shuffle(bowlers_for_batting, random.random) batting_value.sort() batting_value.reverse() start = 0 last_batsman = "" for value in batting_value: for batsman in batsman_for_batting: if player_val[batsman] == value and batsman != last_batsman: batting_lineup.append(batsman) last_batsman = batsman break for player in bowlers_for_batting: batting_lineup.append(player) i = 0 scoreboard = [] total_runs = 0 for player in batting_lineup: score = match_score(self, player, player_ctg[player], player_val[player], i) scoreboard.append(score) total_runs += score[1] i = i + 1 if self.player_batted < 11: total_ballsfaced = 300 ballfaced_tillnow = 0 for score in scoreboard: plusminus = random.randint( 0, 2 * int(score[1] * 0.35)) - int(score[1] * 0.35) score[2] = score[1] + plusminus #print(score[2]) ballfaced_tillnow += score[2] #print("---------------------") new_exballs = 0 if ballfaced_tillnow != total_ballsfaced: extra_balls = ballfaced_tillnow - total_ballsfaced for score in scoreboard: score[2] -= int(extra_balls * score[1] / total_runs) #balls=score[2]-int(extra_balls*score[1]/total_runs) #print(score[2]) new_exballs += score[2] #print("----------------------") if new_exballs != total_ballsfaced: max_score = 0 for score in scoreboard: if score[2] >= max_score: max_score = score[2] for score in scoreboard: if score[2] == max_score: # score[2]-=new_exballs-total_ballsfaced balls = score[2] - (new_exballs - total_ballsfaced) score[2] = balls #print(score[2]) else: total_ballsfaced = random.randint(200, 300) ballfaced_tillnow = 0 for score in scoreboard: plusminus = random.randint( 0, 2 * int(score[1] * 0.35)) - int(score[1] * 0.35) score[2] = score[1] + plusminus #print(score[2]) ballfaced_tillnow += score[2] #print("---------------------") new_exballs = 0 if ballfaced_tillnow != total_ballsfaced: extra_balls = ballfaced_tillnow - total_ballsfaced for score in scoreboard: score[2] -= int(extra_balls * score[1] / total_runs) #balls=score[2]-int(extra_balls*score[1]/total_runs) #print(score[2]) new_exballs += score[2] #print("----------------------") if new_exballs != total_ballsfaced: max_score = 0 for score in scoreboard: if score[2] >= max_score: max_score = score[2] for score in scoreboard: if score[2] == max_score: # score[2]-=new_exballs-total_ballsfaced balls = score[2] - (new_exballs - total_ballsfaced) score[2] = balls bll = random.randint(30, 60) bowled_5 = [bll, 48, 60, 56, 60] bowled_6 = [60, 60, bll, 42, 48, 30] bowled_7 = bowled_6 bowled_7.append(0) random.shuffle(bowled_5, random.random) random.shuffle(bowled_6, random.random) random.shuffle(bowled_7, random.random) i = 0 bowlers = [] all_rounders = [] if len(bowlers_for_batting) < 5: for bowler in bowlers_for_batting: bowlers.append(bowler) for player in player_list: if player_ctg[player] == "AR": all_rounders.append(player) for i in range(5 - len(bowlers_for_batting)): bowlers.append(all_rounders[i]) else: bowlers = bowlers_for_batting for bowler in bowlers: for score in scoreboard: if bowler == score[0]: if len(bowlers) == 5: score.append(bowled_5[i]) i = i + 1 elif len(bowlers) == 6: score.append(bowled_6[i]) i = i + 1 elif len(bowlers) == 7: score.append(bowled_7[i]) i = i + 1 maiden = [0, 0, 1, 0, 2, 0, 1] given = [] for i in range(6): given.append(random.randint(20, 80)) wickets = [0, 0, 0, 0, 0, 0] total_wickets = random.randint(0, 10) for k in range(6): wickets[random.randint(0, 6) - 1] += 1 i = 0 random.shuffle(maiden, random.random) for bowler in bowlers: for score in scoreboard: if bowler == score[0] and score[5] != 0: #print("{}--maiden:{},given:{},wickets:{}".format(score[0],maiden[i],given[i],wickets[i])) score.append(maiden[i]) score.append(given[i]) score.append(wickets[i]) #print(score) i = i + 1 break elif bowler == score[0] and score[5] == 0: score.append(0) score.append(0) score.append(0) break flag = False for player in player_list: flag = False for bowler in bowlers: if player == bowler: flag = True break if flag == False: for score in scoreboard: if player == score[0]: score.append(0) score.append(0) score.append(0) score.append(0) break max_wicksleft = 10 - total_wickets total_wicks = random.randint(1, max_wicksleft) - 1 total_catches = 0 total_stumps = 0 total_ro = 0 for i in range(total_wicks): type_wkt = random.randint(1, 3) if type_wkt == 1: total_catches += 1 elif type_wkt == 2: total_stumps += 1 elif type_wkt == 3: total_ro += 1 for score in scoreboard: score.append(0) catch_index = len(scoreboard[1]) - 1 for i in range(total_catches): lucky_catch = random.randint(0, 11) - 1 scoreboard[lucky_catch][catch_index] += 1 for score in scoreboard: score.append(0) stump_index = len(scoreboard[1]) - 1 wkt_keeper = "" for player in player_list: if player_ctg[player] == "WK": wkt_keeper = player break for score in scoreboard: if score[0] == wkt_keeper: score[stump_index] = total_stumps for score in scoreboard: score.append(0) ro_index = len(scoreboard[1]) - 1 for i in range(total_ro): lucky_ro = random.randint(0, 11) - 1 scoreboard[lucky_ro][ro_index] += 1 #for score in scoreboard: # print(score) playedby = self.comboBox_2.currentText() setme = "" for i in range(11): for j in range(12): if j == 0: if scoreboard[i][0].find(' ') > 0: setme = scoreboard[i][0][0] + ". " + scoreboard[i][ 0][scoreboard[i][0].index(' ') + 1:] else: setme = str(scoreboard[i][j]) self.scoretext[i][j].setText(setme) self.scoretext[i][j].setAlignment(QtCore.Qt.AlignCenter) self.widget_8.show() self.score_board = scoreboard self.playedby_ = playedby #self.create_match(scoreboard,playedby) self.label_31.setText(playedby) self.cur_players.execute("select count(*) from match_played") get_count = self.cur_players.fetchone() count = get_count[0] + 1 match_id = "Match_" + str(count) self.label_29.setText(match_id) else: self.playTheMatch.hide() self.cur_players.execute( "select played_by from match_played where match_id like ?;", (self.comboBox.currentText(), )) cnf = self.cur_players.fetchone() confirmation = False if cnf[0] == self.comboBox_2.currentText(): confirmation = True if confirmation == True: correction(self) else: dialogs.error_dialog( self, "open", self.comboBox.currentText() + " is not played by team " + self.comboBox_2.currentText())
def execute(self, widget=None, data=None): pacs_queues = { "add": [], "remove": [] } for name in self.queues["add"]: try: pac = self.database.get_by_name(name) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%s is not in the database.\nThis is probably a bug in gtkpacman. If you think it's so, please send me a bug report.") %name, self.icon) dlg.run() dlg.destroy() continue if not pac.prop_setted: self.database.set_pac_properties(pac) pacs_queues["add"].append(pac) deps = pac.dependencies.split(", ") for dep in deps: if dep.count(">="): dep = dep.split(">=")[0] try: dep_pac = self.database.get_by_name(dep) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%(dep)s is not in the database. %(dep)s is required by %(pkg)s.\nThis maybe either an error in %(pkg)s packaging or a gtkpacman's bug.\nIf you think it's the first, contact the %(pkg)s maintainer, else fill a bug report for gtkpacman, please.") %{'dep': dep, "pkg": name}, self.icon) dlg.run() dlg.destroy() pacs_queues["add"].remove(pac) self.queues["add"].remove(name) break if not dep_pac.installed: pacs_queues["add"].append(dep_pac) continue for name in self.queues["remove"]: pac = self.database.get_by_name(name) if not pac.prop_setted: self.database.set_pac_properties(pac) pacs_queues["remove"].append(pac) if pac.req_by: req_pacs = [] for req in pac.req_by.split(", "): if not (req in self.queues["remove"]): req_pac = self.database.get_by_name(req) req_pacs.append(req_pac) if req_pacs: dlg = warning_dialog(self.gld.get_widget("main_win"), req_pacs, self.icon) if dlg.run() == RESPONSE_YES: pacs_queues["remove"].extend(req_pacs) else: self.queues["remove"].remove(name) pacs_queues["remove"].remove(pac) dlg.destroy() continue if not (pacs_queues["add"] or pacs_queues["remove"]): self._refresh_trees_and_queues() return retcode = self._confirm(pacs_queues) if retcode: stat_bar = self.gld.get_widget("statusbar") stat_bar.pop(self.stat_id) stat_bar.push(self.stat_id, _("Executing queued operations")) dlg = do_dialog(pacs_queues, self.icon) dlg.connect("destroy", self._refresh_trees_and_queues, pacs_queues) dlg.run() else: self.queues["add"] = [] self.queues["remove"] = [] self._refresh_trees_and_queues() return
def execute(self, widget=None, data=None): def _req_pac_check(to_check, flag): to_do = [] try: pac = self.database.get_by_name(to_check) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%(dep)s is not in the database. %(dep)s is required by %(pkg)s.\nThis maybe either an error in %(pkg)s packaging or a gtkpacman's bug.\nIf you think it's the first, contact the %(pkg)s maintainer, else fill a bug report for gtkpacman, please.") %{'dep': dep, "pkg": name}, self.icon) dlg.run() dlg.destroy() pacs_queues["add"].remove(pac) self.queues["add"].remove(name) return try: if not pac.prop_setted: self.database.set_pac_properties(pac) except: return pac, to_do if flag == "req": for req in pac.req_by.split(", "): if len(req) >= 1: to_do.append(req) else: if not pac.installed: for dep in pac.dependencies.split(", "): if len(dep) >= 1: to_do.append(dep) else: pac = None return pac, to_do pac = None return pac, to_do pacs_queues = { "add": [], "remove": [] } deps = [] for name in self.queues["add"]: try: pac = self.database.get_by_name(name) except NameError: dlg = error_dialog(self.gld.get_widget("main_win"), _("%s is not in the database.\nThis is probably a bug in gtkpacman. If you think it's so, please send me a bug report.") %name, self.icon) dlg.run() dlg.destroy() continue if not pac.prop_setted: self.database.set_pac_properties(pac) pacs_queues["add"].append(pac) if pac.dependencies: dep_todo_list = [] dep_black_list = [] deps = pac.dependencies.split(", ") for dep in deps: if not dep in self.queues["add"]: dep_todo_list.append(dep) while dep_todo_list: dep = dep_todo_list.pop(0) if dep.count(">="): dep = dep.split(">=")[0] if not (dep in self.queues["add"]): done, to_do = _req_pac_check(dep, "dep") if done and not done in pacs_queues["add"]: pacs_queues["add"].append(done) for add in to_do: if not add in dep_black_list: dep_todo_list.append(add) dep_black_list.append(add) for name in self.queues["remove"]: pac = self.database.get_by_name(name) if not pac.prop_setted: self.database.set_pac_properties(pac) pacs_queues["remove"].append(pac) if pac.req_by: req_pacs = [] req_todo_list = [] req_black_list = [] for req in pac.req_by.split(", "): if not (req in self.queues["remove"]): req_todo_list.append(req) while req_todo_list: req = req_todo_list.pop(0) if not (req in self.queues["remove"]): done, to_do = _req_pac_check(req, "req") if done and not done in req_pacs: req_pacs.append(done) for add in to_do: if not add in req_black_list: req_todo_list.append(add) req_black_list.append(add) continue if req_pacs: dlg = warning_dialog(self.gld.get_widget("main_win"), req_pacs, self.icon) if dlg.run() == RESPONSE_YES: pacs_queues["remove"].extend(req_pacs) else: self.queues["remove"].remove(name) pacs_queues["remove"].remove(pac) dlg.destroy() continue if not (pacs_queues["add"] or pacs_queues["remove"]): self._refresh_trees_and_queues() return retcode = self._confirm(pacs_queues) if retcode: self._statusbar(_("Executing queued operations...")) dlg = do_dialog(pacs_queues, self.icon) dlg.connect("destroy", self._refresh_trees_and_queues, pacs_queues) dlg.run() else: self.queues["add"] = [] self.queues["remove"] = [] self._refresh_trees_and_queues() return