def start_old_game(self, *a): self.stack.set_visible_child_name('n1') self.hd_bar.show_hide_action_buttons() self.started = True list_saved = load_game_scrabble() for a in list_saved[0].keys(): self.dict_chequer[a] = list_saved[0][a] self.text_words_with_points = list_saved[1] self.list_letters_repeated = list_saved[2] self.list_07_letters_player = list_saved[3] self.list_07_letters_computer = list_saved[4] self.points_player = list_saved[5] self.points_computer = list_saved[6] self.cells_empty_letter = list_saved[7] self.computer_empty_letter = list_saved[8] self.sideinfo.lab_points_computer.set_label(str(self.points_computer)) self.sideinfo.lab_points_player.set_label(str(self.points_player)) if config.getn('point_words') == 0: self.sideinfo.wordviewer_buf.set_text( re.sub('=\d*', '', self.text_words_with_points)) else: self.sideinfo.wordviewer_buf.set_text(self.text_words_with_points) self.sideinfo.wordviewer.with_tag( ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '=']) self.sideletters.liststore_letters_player.clear() self.sideletters.add_letters(self.list_07_letters_player) self.sideinfo.sel_count_pieces(config.getn('count_pieces')) self.add_timer(_('Previous game')) time.sleep(0.1) while (Gtk.events_pending()): Gtk.main_iteration() self.rounds.load_words_help()
def start_new_game(self, *a): self.started = True self.ended = False self.last_round_player = True self.last_round_computer = True self.sideinfo.sel_count_pieces(config.getn('count_pieces')) self.add_timer(_('New game')) self.rounds.round_starting(self.started_player)
def load(self, *a): lang = config.getv('language_scrabble') if lang in self.list_language_ready: self.load_language_game() if config.getn('saved') == 1: try: self.start_old_game() return except: pass self.stack.set_visible_child_name('n0') self.hd_bar.show_hide_action_buttons()
def select_word_computer_on_grade(self, list_words_computer): l = len(list_words_computer) h = int(l / 2) g = config.getn('grade') if l >= 2: if g == 0: ls = list_words_computer[0] elif g == 1: ls = random.choice(list_words_computer[:h]) elif g == 2: ls = list_words_computer[h] elif g == 3: ls = random.choice(list_words_computer[h:]) elif g == 4: ls = list_words_computer[-1] else: ls = list_words_computer[0] return ls
def motion_notify_cb(self, widget, ev): if ev.x < 7 and config.getn( 'autohide_info') == 1 and self.pt.sideinfo.get_no_show_all(): self.pt.sideinfo.set_no_show_all(False) self.pt.sideinfo.show_all() elif ev.x > 7 and config.getn( 'autohide_info' ) == 1 and not self.pt.sideinfo.get_no_show_all(): self.pt.sideinfo.set_no_show_all(True) self.pt.sideinfo.hide() #------------------------------------------------------------------------------- if ev.x > self.w - 7 and config.getn( 'autohide_letters' ) == 1 and self.pt.vb_letters.get_no_show_all(): self.pt.vb_letters.set_no_show_all(False) self.pt.vb_letters.show_all() elif ev.x < self.w - 7 and config.getn( 'autohide_letters' ) == 1 and not self.pt.vb_letters.get_no_show_all(): self.pt.vb_letters.set_no_show_all(True) self.pt.vb_letters.hide()
def chose_letters_computer(self, *a): n = 7 - len(self.pt.list_07_letters_computer) l = len(self.pt.list_letters_repeated) if l == 0: return a = 0 while a < n: if len(self.pt.list_letters_repeated) == 0: break letter = random.choice(self.pt.list_letters_repeated) if letter == '*': self.slect_letter_4_empty_tile_computer() else: self.pt.list_07_letters_computer.append(letter) self.pt.list_letters_repeated.remove(letter) a += 1 self.pt.sideinfo.sel_count_pieces(config.getn('count_pieces'))
def play_sound(name): frequency = config.getf('pipe_{}'.format(name,)) ms = config.getf('pipe_{}_ms'.format(name,)) if config.getn('sound') == 1: from gi.repository import Gst, GObject Gst.init(None) pipeline = Gst.Pipeline(name='note') source = Gst.ElementFactory.make('audiotestsrc', 'src') sink = Gst.ElementFactory.make('autoaudiosink', 'output') source.set_property('freq', frequency) pipeline.add(source) pipeline.add(sink) source.link(sink) pipeline.set_state(Gst.State.PLAYING) GObject.timeout_add(ms, pipeline_stop, pipeline, Gst)
def sel_language_scrabble(self, btn): name = btn.get_active_text() if name == config.getv('language_scrabble'): return self.pt.hd_bar.btn_pref.set_active(False) if list(self.pt.dict_chequer.values()) == [0,]*225 or self.pt.ended == True: pass else: res = sure(self.pt, _('If you want to change the language you will need to start a new game. \n Do you want that?')) if res == -8: pass else: btn.set_active(config.getn('language_scrabble')) return config.setv('language_scrabble', name) self.pt.sideinfo.label_language_scrabble.set_label(name) self.pt.pagestarting.label_language_scrabble.set_label(_('Playing language:')+' '+name) self.pt.pagestarting.restor_to_starting_page() self.pt.restart_game()
def chose_letters_player(self, *a): n = 7 - len(self.pt.list_07_letters_player) l = len(self.pt.list_letters_repeated) if l == 0: return list_new = [] a = 0 while a < n: if len(self.pt.list_letters_repeated) == 0: break letter = random.choice(self.pt.list_letters_repeated) list_new.append(letter) self.pt.list_07_letters_player.append(letter) self.pt.list_letters_repeated.remove(letter) a += 1 self.pt.sideletters.add_letters(list_new) time.sleep(0.1) while (Gtk.events_pending()): Gtk.main_iteration() self.pt.sideinfo.sel_count_pieces(config.getn('count_pieces'))
def accept_word_player_added(self, list_words_player): for a in self.pt.dict_new.keys(): self.pt.dict_chequer[a] = self.pt.dict_new[a] if a in self.pt.cells_empty_letter: self.pt.list_07_letters_player.remove('*') else: self.pt.list_07_letters_player.remove(self.pt.dict_new[a]) self.pt.add_timer(_('Well done, \n Computer role.')) while (Gtk.events_pending()): Gtk.main_iteration() self.pt.sideinfo.add_words(list_words_player, 1) self.pt.sideletters.set_sensitive(False) while (Gtk.events_pending()): Gtk.main_iteration() self.pt.chequer.queue_draw() self.pt.sideinfo.sel_count_pieces(config.getn('count_pieces')) self.pt.last_round_player = True self.pt.last_round_computer = True self.round_computer()
def round_computer(self, *a): if self.is_ended(self.pt.list_07_letters_player): return while (Gtk.events_pending()): Gtk.main_iteration() self.chose_letters_computer() list_words_computer = self.pt.dict_chequer.find_words_computer() if len(list_words_computer) == 0: self.pt.add_timer(_('The computer does not have any words.')) if not self.change_computer_letters(): if self.pt.last_round_player == False: if len(self.pt.hd_bar.list_help_words) == 0: self.end_game() return res = sure( self.pt, _('Computer does not have a word if you does not have a word, the game will end. \n Do you want that?' )) if res == -8: self.end_game() return else: self.load_words_help() else: self.pt.add_timer(_('The computer changed its letters.')) self.pt.dict_new_computer = self.pt.dict_new self.round_player() self.pt.last_round_computer = False return #------------------------------------------------------ ls = self.select_word_computer_on_grade(list_words_computer) self.pt.dict_new_computer.clear() for a in ls[2]: self.pt.dict_new_computer[a[0]] = a[1] self.accept_word_computer_added(ls) #------------------------------------------------------ time.sleep(0.01) while (Gtk.events_pending()): Gtk.main_iteration() self.round_player() self.pt.sideinfo.sel_count_pieces(config.getn('count_pieces')) self.pt.last_round_computer = True self.pt.last_round_player = True self.load_words_help()
from bs4 import BeautifulSoup from lxml import html import xml import requests from openpyxl import Workbook import openpyxl import os, sys sys.path.insert(0, '../') import config # 定义爬取n页 n = config.getn() # 打开excel文件 wb = openpyxl.load_workbook('data.xlsx') try: # 选定表格 ws = wb["招标公告"] # 删除sheet wb.remove(ws) ws = wb["招标预告"] wb.remove(ws) ws = wb["招标变更"] wb.remove(ws) ws = wb["中标结果"] wb.remove(ws) except Exception as e: print(e) ''' 招标公告 '''
def build(self, *a): Gtk.Dialog.__init__(self, parent=self.pt) area = self.get_content_area() self.set_icon_name("gscrabble") self.set_title(_('Preference')) self.set_default_size(500, 450) hbox = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL) #--------------------------- self.stack_pref = Gtk.Stack() self.stack_pref.set_border_width(7) self.stack_pref.set_transition_type(Gtk.StackTransitionType.CROSSFADE) self.stack_pref.set_transition_duration(300) stack_switcher = Gtk.StackSwitcher(spacing=1,orientation=Gtk.Orientation.VERTICAL) stack_switcher.set_homogeneous(True) stack_switcher.set_stack(self.stack_pref) hbox.pack_start(stack_switcher, False, False, 0) hbox.pack_start(self.stack_pref, True, True, 0) area.pack_start(hbox, True, True, 0) #--------------------------- view_info = Viewer(self.pt) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(view_info) view_info.view_bfr.set_text(TEXT_HOW_PLAY) list_tag = [ '=', _('''How to Play Scrabble'''), _('''This is the law of the game in fact'''), _('''1- Make sure that you have everything you need to play Scrabble:'''), _('''2- Choose a dictionary to use for challenges:'''), _('''3- Put the tiles in the bag and shake them:'''), _('''4- Determine who goes first:'''), _('''5- Draw your tiles:'''), _('''6- Play the first word:'''), _('''7- Count up your points:'''), _('''8- Draw new tiles:'''), _('''9- Build on other players’ words:'''), _('''10- Use your tiles to get the highest score possible per turn:'''), _('''11- Challenge other players to dispute a word:'''), _('''12- Exchange tiles you don’t want:'''), _('''13- Watch for Premium Score squares:'''), _('''14- Get 50 points added to your word score if you get a bingo, also known as a bonus:'''), _('''15- Add up each player’s scores at the end of the game:'''), _('''16- Announce the winner:''') ] view_info.with_tag(list_tag) self.stack_pref.add_titled(scroll, 'n0', _('Game Code')) #--------------------------- view_hotkeys = Viewer(self.pt) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(view_hotkeys) view_hotkeys.view_bfr.set_text(TEXT_HOT_KEYS) view_hotkeys.with_tag(['"A"', '"Q+Ctrl"', '"O"', '"P"', '"U"', '"C"', '"S"', '"W"', '"G"', '"F11"', _('The right button:'), _('The left button:'), _('Mouse:')]) self.stack_pref.add_titled(scroll, 'n00', _('Hot Keys')) #--------------------------- vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL) hb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL) hb.pack_start(Gtk.Label.new(_('Interface language:')), False, False, 0) self.combo_language_surface = Gtk.ComboBoxText() # self.combo_language_surface.set_wrap_width(2) self.combo_language_surface.set_size_request(150, -1) for lang in LANGUAGES_SURFACE: self.combo_language_surface.append_text(lang) self.combo_language_surface.set_active(LANGUAGES_SURFACE.index(config.getv('language_surface'))) self.combo_language_surface.connect('changed', self.sel_language_surface) hb.pack_end(self.combo_language_surface, False, False, 0) vb.pack_start(hb, False, False, 0) hb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL) hb.pack_start(Gtk.Label.new(_('Playing language:')), False, False, 0) self.combo_language_scrabble = Gtk.ComboBoxText() self.combo_language_scrabble.set_wrap_width(2) self.combo_language_scrabble.set_size_request(150, -1) self.load_languages_play() try: i = self.pt.list_language_likely.index(config.getv('language_scrabble')) except: i = -1 self.combo_language_scrabble.set_active(i) self.combo_language_scrabble.connect('changed', self.sel_language_scrabble) hb.pack_end(self.combo_language_scrabble, False, False, 0) vb.pack_start(hb, False, False, 0) vb.pack_start(Gtk.Separator(), False, False, 0) hb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL) self.check_add_lang = Gtk.RadioButton.new_with_label_from_widget(None, _('Add language')) hb.pack_start(self.check_add_lang, True, True, 0) self.check_add_dict = Gtk.RadioButton.new_with_label_from_widget(self.check_add_lang, _('Add dictionary')) hb.pack_start(self.check_add_dict, True, True, 0) vb.pack_start(hb, False, False, 0) self.view_lang_dict = Viewer(self.pt) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.IN) scroll.add(self.view_lang_dict) vb.pack_start(scroll, True, True, 0) hb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL) self.combo_dict_lang = Gtk.ComboBoxText() self.add_lg_dt = Add_lang_dict(self.pt, self.combo_dict_lang) btn_add_dict = Gtk.Button(_('Add')) btn_add_dict.connect('clicked', self.add_dict_lang_cb) hb.pack_start(btn_add_dict, False, False, 0) self.combo_dict_lang.set_size_request(150, -1) hb.pack_end(self.combo_dict_lang, False, False, 0) vb.pack_start(hb, False, False, 0) self.check_add_lang.connect("toggled", self.sel_added, 1) self.check_add_dict.connect("toggled", self.sel_added, 2) self.check_add_lang.set_active(True) self.sel_added() self.stack_pref.add_titled(vb, 'n1', _('Language')) #---------------------------------------------------------------------------------- vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL) vb.pack_start(Gtk.Label.new(_('Difficulty level:')), False, False, 0) btn0 = Gtk.RadioButton.new_with_label_from_widget(None, self.pt.LIST_GRADE[0]) btn0.connect("toggled", self.sel_grade, 0) vb.pack_start(btn0, False, False, 0) if config.getn('grade') == 0: btn0.set_active(True) btn1 = Gtk.RadioButton.new_with_label_from_widget(btn0, self.pt.LIST_GRADE[1]) btn1.connect("toggled", self.sel_grade, 1) vb.pack_start(btn1, False, False, 0) if config.getn('grade') == 1: btn1.set_active(True) btn2 = Gtk.RadioButton.new_with_label_from_widget(btn1, self.pt.LIST_GRADE[2]) btn2.connect("toggled", self.sel_grade, 2) vb.pack_start(btn2, False, False, 0) if config.getn('grade') == 2: btn2.set_active(True) btn3 = Gtk.RadioButton.new_with_label_from_widget(btn2, self.pt.LIST_GRADE[3]) btn3.connect("toggled", self.sel_grade, 3) vb.pack_start(btn3, False, False, 0) if config.getn('grade') == 3: btn3.set_active(True) btn4 = Gtk.RadioButton.new_with_label_from_widget(btn3, self.pt.LIST_GRADE[4]) btn4.connect("toggled", self.sel_grade, 4) vb.pack_start(btn4, False, False, 0) if config.getn('grade') == 4: btn4.set_active(True) self.stack_pref.add_titled(vb, 'n2', _('Difficulty')) #---------------------------- vb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL) vb0 = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL) vb0.set_border_width(20) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.NONE) scroll.add(vb0) ls_btn_font = [('font_pieces', _('Font of letters')), ('font_special', _('Font of cells')), ('font_msg', _('Font of notification')),('font_win', _('Font of window'))] for a in ls_btn_font: hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) btn = Gtk.FontButton.new_with_font(config.getv(a[0])) btn.set_name(a[0]) btn.connect('font-set',self.ch_font) hb.pack_start(Gtk.Label.new(a[1]), False, False, 0) hb.pack_end(btn, False, False, 0) vb0.pack_start(hb, False, False, 0) hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) adj = Gtk.Adjustment.new(1, 1, 10, 1, 5, 0) btn= Gtk.SpinButton() btn.set_adjustment(adj) btn.set_wrap(True) btn.set_value(config.getf('br_thick')) btn.connect('value-changed',self.ch_thick) hb.pack_start(Gtk.Label.new(_('Lines of grid')), False, False, 0) hb.pack_end(btn, False, False, 0) vb0.pack_start(hb, False, False, 0) vb.pack_start(scroll, True, True, 0) vb.pack_start(Gtk.Separator(), False, False, 3) btn_default = Gtk.ToolButton() btn_default.set_label(_('Prepare defaults')) vb.pack_start(btn_default, False, False, 0) btn_default.connect('clicked', self.set_default, 1) self.stack_pref.add_titled(vb, 'n3', _('Fonts')) #--------------------------- vb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL) vb0 = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL) vb0.set_border_width(20) scroll = Gtk.ScrolledWindow() scroll.set_shadow_type(Gtk.ShadowType.NONE) scroll.add(vb0) hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) ls_btn_color = [('fg_pieces',_('Color of letter')), ('fg_nbr',_('Color of number')), ('fg_cell',_('Word of cell')), ('bg_pieces',_('Background of letter')), ('bg_no_install', _('New piece')), ('bg_last_word', _('Last word')), ('br_pieces',_('Border of letter')), ('bg_area',_('Background')), ('bg_grid',_('Background of grid')), ('br_grid',_('Border of grid')),('bg_lines',_('Lines of grid')), ('fg_msg',_('Color of notification')), ('bg_start',_('Start')),('bg_hX2',_('Background of DLS')),('bg_hX3',_('Background of TLS')), ('bg_kX2',_('Background of DWS')),('bg_kX3',_('Background of TWS'))] for a in ls_btn_color: hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) btn = Gtk.ColorButton.new_with_rgba(rgba(config.getv(a[0]))) btn.set_name(a[0]) btn.connect('color-set',self.ch_color) hb.pack_start(Gtk.Label.new(a[1]), False, False, 0) hb.pack_end(btn, False, False, 0) vb0.pack_start(hb, False, False, 0) vb.pack_start(scroll, True, True, 0) vb.pack_start(Gtk.Separator(), False, False, 3) btn_default = Gtk.ToolButton() btn_default.set_label(_('Prepare defaults')) vb.pack_start(btn_default, False, False, 0) btn_default.connect('clicked', self.set_default, 2) self.stack_pref.add_titled(vb, 'n4', _('Colors')) #--------------------------- vb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL) vb0 = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL) vb0.set_border_width(20) scroll = Gtk.ScrolledWindow() scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scroll.set_shadow_type(Gtk.ShadowType.NONE) scroll.add(vb0) hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) self.switch_sound = Gtk.Switch() self.switch_sound.connect("notify::active", self.on_switch_activated) if config.getn('sound') == 1: self.switch_sound.set_active(True) else: self.switch_sound.set_active(False) hb.pack_start(Gtk.Label.new(_('Enable audio')), False, False, 0) hb.pack_start(self.switch_sound, False, False, 0) vb.pack_start(hb, False, False, 0) vb.pack_start(Gtk.Separator(), False, False, 3) ls_btn_sound = [('pipe_drop', _('Install a letter')), ('pipe_ok', _('Adoption of the word')), ('pipe_undo', _('Undo a letter')), ('pipe_add', _('Add a letters'))] for a in ls_btn_sound: hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL) adj1 = Gtk.Adjustment.new(20, 1, 1000, 1, 5, 0) btn= Gtk.SpinButton() btn.set_adjustment(adj1) btn.set_wrap(True) btn.set_value(config.getf(a[0]+"_ms")) btn.set_name(a[0]+"_ms") btn.connect('value-changed',self.ch_sound) hb.pack_end(btn, False, False, 0) #----------------------------------------- adj = Gtk.Adjustment.new(1, 0, 10000, 1, 5, 0) btn= Gtk.SpinButton() btn.set_adjustment(adj) btn.set_wrap(True) btn.set_value(config.getf(a[0])) btn.set_name(a[0]) btn.connect('value-changed',self.ch_sound) hb.pack_end(btn, False, False, 0) hb.pack_start(Gtk.Label.new(a[1]), False, False, 0) vb0.pack_start(hb, False, False, 0) vb.pack_start(scroll, True, True, 0) vb.pack_start(Gtk.Separator(), False, False, 3) btn_default = Gtk.ToolButton() btn_default.set_label(_('Prepare defaults')) vb.pack_start(btn_default, False, False, 0) btn_default.connect('clicked', self.set_default, 3) self.stack_pref.add_titled(vb, 'n5', _('Sounds')) #--------------------------- vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL) check_autohid_info = Gtk.CheckButton(_('Autohide the information box')) if config.getn('autohide_info') == 1: check_autohid_info.set_active(True) vb.pack_start(check_autohid_info, False, False, 0) check_autohid_info.connect('clicked', self.set_autohide_info) check_autohid_letters = Gtk.CheckButton(_('Autohide the letters box')) if config.getn('autohide_letters') == 1: check_autohid_letters.set_active(True) vb.pack_start(check_autohid_letters, False, False, 0) check_autohid_letters.connect('clicked', self.set_autohide_letters) self.stack_pref.add_titled(vb, 'n6', _('Others')) self.show_all()