def initUI(self): p = Panel(self) self._target_notebook = nb(p) self.build_target_notebook(self._target_notebook) self.main_notebook = nb(p) page1 = self.build_page1(self.main_notebook) page2 = self.build_page2(self.main_notebook) page3 = self.build_page3(self.main_notebook) page4 = self.build_page4(self.main_notebook) page5 = self.build_page5(self.main_notebook) page6 = self.build_page6(self.main_notebook) self.main_notebook.AddPage(page1, '选项区(1)') self.main_notebook.AddPage(page2, '输出区(2)') self.main_notebook.AddPage(page3, '日志区(3)') self.main_notebook.AddPage(page4, 'API区(4)') self.main_notebook.AddPage(page5, '帮助(H)') self.main_notebook.AddPage(page6, '关于') vbox = BoxSizer(VERTICAL) vbox.Add(self._target_notebook, flag = EXPAND) vbox.Add(self.main_notebook, proportion = 1, flag = EXPAND) p.SetSizer(vbox) _frame_sz = BoxSizer() _frame_sz.Add(p, proportion = 1, flag = EXPAND) # 使用SetSizerAndFit方法使frame拥有最小size self.SetSizerAndFit(_frame_sz)
def build_page6(self, parent): p = Panel(parent) _version = '0.3.3.1' _timestamp = '2021-01-31 05:12:52' _url_self = 'https://github.com/needle-wang/sqlmap-wx' _url_tutorial1 = 'https://wiki.wxpython.org/' _url_tutorial2 = 'http://zetcode.com/wxpython/' _url_api = 'https://wxpython.org/Phoenix/docs/html/index.html' _url_idea = 'https://github.com/kxcode' _about_str = f''' 1. Website: {_url_self} VERSION: {_version} {_timestamp} required: python3.6+, wxPython4.0+, requests, sqlmap\n 2. use wxPython4 to recode sqlmap-gtk(driven by PyGObject) 3. thanks to the idea from sqm(by python2 + tkinter), author: KINGX, {_url_idea}\n 4. wxPython tutorial: {_url_tutorial1} {_url_tutorial2} 5. wxPython API: {_url_api} ''' hbox = BoxSizer() _page6_about = st(p, label = _about_str) # 完全居中! hbox.Add(_page6_about, flag = ALIGN_CENTER) vbox = BoxSizer(VERTICAL) vbox.Add(hbox, proportion = 1, flag = ALIGN_CENTER) p.SetSizerAndFit(vbox) return p
def build_page3(self, parent): p = Panel(parent) m = self.m # 多行文本框的默认size太小了 # 默认高度太低, 不指定个高度, 会报 滚动条相关的size 警告 m._page3_log_view.Create(p, size = (-1, 300), style = wx.TE_MULTILINE | wx.TE_READONLY) # self._handlers.clear_log_view_buffer(None) grid = GridSizer(1, 3, 0, 0) m._page3_read_target_btn.Create(p, label = '查看target文件') m._page3_clear_btn.Create(p, label = '清空(&C)') m._page3_read_log_btn.Create(p, label = '查看log文件') m._page3_read_target_btn.Bind(EVT_BUTTON, self._handlers.read_target_file) m._page3_clear_btn.Bind(EVT_BUTTON, self._handlers.clear_log_view_buffer) m._page3_read_log_btn.Bind(EVT_BUTTON, self._handlers.read_log_file) grid.Add(m._page3_read_target_btn, flag = ALIGN_CENTER) grid.Add(m._page3_clear_btn, flag = ALIGN_CENTER) grid.Add(m._page3_read_log_btn, flag = ALIGN_CENTER) vbox = BoxSizer(VERTICAL) vbox.Add(m._page3_log_view, proportion = 1, flag = EXPAND | ALL, border = 10) vbox.Add(grid, flag = EXPAND) p.SetSizerAndFit(vbox) return p
def build_page1_other(self, layout): p = Panel(self) # p = Scroll(self) # 总有一个标签会被掩盖widget, 只能使用_dummy m = self.m self.build_page1_other_general(p, m) self.build_page1_other_misc(p, m) vbox = layout.other_sizer() # p.SetSizerAndFit(vbox), 没用~, 最后一个widget还是会被掩盖 p.SetSizer(vbox) # p.SetupScrolling(scroll_x = False) return p
def build_page1_file(self, layout): p = Panel(self) m = self.m self._page1_file_note_label = st(p, label='注: 存在Stacked queries(堆查询注入)时, ' '才能使用该标签下的功能(udf功能除外)!') self.build_page1_file_read(p, m) self.build_page1_file_write(p, m) self.build_page1_file_os_access(p, m) self.build_page1_file_os_registry(p, m) vbox = layout.file_sizer() p.SetSizer(vbox) return p
def build_page1_enumeration(self, layout): p = Panel(self) m = self.m self.build_page1_enumeration_enum(p, m) self.build_page1_enumeration_dump(p, m) self.build_page1_enumeration_limit(p, m) self.build_page1_enumeration_blind(p, m) self.build_page1_enumeration_meta(p, m) self.build_page1_enumeration_runsql(p, m) self.build_page1_enumeration_brute_force(p, m) vbox = layout.enumeration_sizer() p.SetSizer(vbox) return p
def build_page1_file(self, layout): p = Panel(self) m = self.m self._page1_file_note_label = st(p, label = 'Note: only if stacked query(堆查询注入) worked, ' 'these functions below can be used except udf!') self.build_page1_file_read(p, m) self.build_page1_file_write(p, m) self.build_page1_file_os_access(p, m) self.build_page1_file_registry(p, m) vbox = layout.file_sizer() p.SetSizer(vbox) return p
def init_game_screen(self): """ init_game_screen() - Loads actual game screen objects. USES: TileGroup() TileGroup.load() ButtonGroup() self.load_option_buttons() """ panel = self.game_screen_panel = Panel() # Load the TileGroup that contains every thing required to run the game. self.TileGroup = TileGroup(self.game_screen_panel, self.timer) self.TileGroup.load() self.load_option_buttons() self.load_other_buttons() # loads flag and timer.
def build_page1(self, parent): p = Panel(parent) m = self.m # sqlmap命令语句 cmd_area = StaticBoxSizer(VERTICAL, p, 'A.收集选项 的结果显示在这:') _cmd_area = cmd_area.GetStaticBox() m._cmd_entry.Create(_cmd_area) cmd_area.Add(m._cmd_entry, flag = EXPAND) # 主构造区 self._notebook = Notebook(p, m, self._handlers) # 构造与执行 和 改善ui的使用体验 self.btn_grid = GridSizer(1, 4, 0, 0) _build_button = btn(p, label = 'A.收集选项(A)') _unselect_all_btn = btn(p, label = '反选所有复选框(S)') _clear_all_entry = btn(p, label = '清空所有输入框(D)') _build_button.Bind(EVT_BUTTON, self._handlers.build_all) _unselect_all_btn.Bind(EVT_BUTTON, self.unselect_all_ckbtn) _clear_all_entry.Bind(EVT_BUTTON, self.clear_all_entry) _run_button = btn(p, label = 'B.开始(F)') _run_button.Bind(EVT_BUTTON, self._handlers.run_cmdline) self.btn_grid.Add(_build_button, flag = ALIGN_CENTER) self.btn_grid.Add(_unselect_all_btn, flag = ALIGN_CENTER) self.btn_grid.Add(_clear_all_entry, flag = ALIGN_CENTER) self.btn_grid.Add(_run_button, flag = ALIGN_CENTER) vbox = BoxSizer(VERTICAL) vbox.Add(cmd_area, flag = EXPAND) vbox.Add(self._notebook, proportion = 1, flag = EXPAND) vbox.Add(self.btn_grid, flag = EXPAND) p.SetSizerAndFit(vbox) return p
def build_page5(self, parent): p = Panel(parent) m = self.m self._get_sqlmap_path_btn = btn(p, label = '获取帮助') self._get_sqlmap_path_btn.Disable() # 多行文本框的默认size太小了 # 默认高度太低, 不指定个高度, gtk会报 滚动条相关的size 警告 m._page5_manual_view.Create(p, size = (-1, 300), style = wx.TE_MULTILINE | wx.TE_READONLY) self._get_sqlmap_path_btn.Bind( EVT_BUTTON, lambda evt, view = m._page5_manual_view: self._make_help_thread(evt, view)) self._make_help_thread(None, m._page5_manual_view) vbox = BoxSizer(VERTICAL) vbox.Add(self._get_sqlmap_path_btn, flag = TOP | LEFT | BOTTOM, border = 10) vbox.Add(m._page5_manual_view, proportion = 1, flag = EXPAND | LEFT | RIGHT, border = 10) p.SetSizerAndFit(vbox) return p
def build_page6(self, parent): p = Panel(parent) _about_str = ''' 1. VERSION: 0.3.3 2019年 10月 16日 星期三 06:54:46 CST required: python3.5+, wxPython4.0+, sqlmap 作者: needle wang ( [email protected] ) https://github.com/needle-wang/sqlmap-wx\n 2. 使用wxPython重写sqlmap-ui(using PyGObject)\n 3. wxpython教程: https://wiki.wxpython.org/ http://zetcode.com/wxpython/ 4. wxpython API: https://wxpython.org/Phoenix/docs/html/index.html\n\n 5. 感谢sqm带来的灵感, 其作者: KINGX ( https://github.com/kxcode ), sqm UI 使用的是python2 + tkinter ''' hbox = BoxSizer() _page6_about = st(p, label = _about_str) # 完全居中! hbox.Add(_page6_about, flag = ALIGN_CENTER) vbox = BoxSizer(VERTICAL) vbox.Add(hbox, proportion = 1, flag = ALIGN_CENTER) p.SetSizerAndFit(vbox) return p
def build_page4(self, parent): p = Panel(parent) m = self.m border = SizerFlags().Border(LEFT | RIGHT, 5).Align(ALIGN_CENTER) proportion_border = SizerFlags(1).Border(LEFT | RIGHT, 5).Align(ALIGN_CENTER) row1, row2 = (BoxSizer() for _ in range(2)) m._page4_api_server_label.Create(p, label = 'REST-JSON API server:') m._page4_api_server_entry.Create(p, value = '127.0.0.1:8775') m._page4_admin_token_label.Create(p, label = 'Admin (secret) token:') m._page4_admin_token_entry.Create(p) m._page4_admin_token_entry.SetMaxLength(32) row1.Add(m._page4_api_server_label, border) row1.Add(m._page4_api_server_entry, proportion_border) row1.Add(m._page4_admin_token_label, border) row1.Add(m._page4_admin_token_entry, proportion_border) m._page4_task_new_btn.Create(p, label = '创建任务') m._page4_admin_list_btn.Create(p, label = '显示任务') m._page4_admin_flush_btn.Create(p, label = '删除所有任务') m._page4_clear_task_view_btn.Create(p, label = '清空反馈的结果') m._page4_username_label.Create(p, label = '用户名:') m._page4_username_entry.Create(p) m._page4_password_label.Create(p, label = '密码:') m._page4_password_entry.Create(p) _arrow_down = wx.ArtProvider.GetBitmap(wx.ART_GO_DOWN, wx.ART_BUTTON) m._page4_admin_list_btn.SetBitmap(_arrow_down, dir = RIGHT) m._page4_task_new_btn.Bind(EVT_BUTTON, self._handlers.api.task_new) m._page4_admin_list_btn.Bind(EVT_BUTTON, self._handlers.api.admin_list) m._page4_admin_flush_btn.Bind(EVT_BUTTON, self._handlers.api.admin_flush) m._page4_clear_task_view_btn.Bind(EVT_BUTTON, self._handlers.clear_task_view_buffer) row2.Add(m._page4_task_new_btn, border) row2.Add(m._page4_admin_list_btn, border) row2.Add(m._page4_admin_flush_btn, border) row2.Add(m._page4_clear_task_view_btn, border) row2.Add(m._page4_username_label, flag = ALIGN_CENTER | LEFT, border = 200) row2.Add(m._page4_username_entry, proportion_border) row2.Add(m._page4_password_label, border) row2.Add(m._page4_password_entry, proportion_border) row3 = SplitterWindow(p, style = wx.SP_LIVE_UPDATE | wx.BORDER_SUNKEN) # 不能放在SplitVertically后面, 不然gravity会无效 # row3.SetSashGravity(0.5) row3.SetMinimumPaneSize(400) lpane = Scroll(row3) self._api_admin_list_rows = lpane lpane.SetSizer(BoxSizer(VERTICAL)) rpane = Panel(row3) _rbox = BoxSizer(VERTICAL) m._page4_option_get_entry.Create(rpane, value = 'url risk level') _page4_option_set_view_tip = st(rpane, label = '所有选项见sqlmap目录中的optiondict.py') _options_example = ("{\n" " 'url': 'http://www.site.com/vuln.php?id=1',\n" " 'level': 1, 'risk': 1,\n\n" "}\n") m._page4_option_set_view.Create(rpane, value = _options_example, style = wx.TE_MULTILINE) _rbox.Add(m._page4_option_get_entry, flag = EXPAND | ALL, border = 2) _rbox.Add(_page4_option_set_view_tip, flag = ALL, border = 2) _rbox.Add(m._page4_option_set_view, proportion = 1, flag = EXPAND | ALL, border = 2) rpane.SetSizer(_rbox) row3.SplitVertically(lpane, rpane) # win下, lpane是灰色的, 将row3设下颜色, 又是兼容代码... row3.SetBackgroundColour(m._page4_option_set_view.GetBackgroundColour()) row3.SetSashPosition(lpane.GetMinWidth()) m._page4_task_view.Create(p, value = '此处显示反馈的结果:\n', style = wx.TE_MULTILINE | wx.TE_READONLY) vbox = BoxSizer(VERTICAL) vbox.Add(row1, flag = EXPAND | ALL, border = 5) vbox.Add(row2, flag = EXPAND | ALL, border = 5) vbox.Add(row3, proportion = 1, flag = EXPAND | LEFT | RIGHT, border = 10) vbox.Add(m._page4_task_view, proportion = 1, flag = EXPAND | ALL, border = 10) p.SetSizerAndFit(vbox) return p
def init_custom_screen(self): panel = self.custom_screen_panel = Panel() dheight, dwidth = pygame.display.get_surface().get_size() cx, cy = dheight/2, dwidth/2 self.custom_screen_sprite_list = TextField() digits = [str(i) for i in range(0, 10) ] size = pygame.display.get_surface().get_size() # Row inputfield. row = TextFieldSingleLine(panel, "16") row.set_name("row") row.set_max_char_length(4) row.rect.center = cx, cy - 50 row.set_allowed_chars(digits) row.rect.centerx = size[0]/2 + row.rect.width/2 self.custom_screen_sprite_list.add(row) # Row text. row_text = TextLine(font = "Serif", text="Row : ") row_text.text_color= 75, 75, 75 row_text.rect.center = size[0]/2 - (row_text.rect.width)/2, size[1]/2 - 50 # Col text. col_text = TextLine(font = "Serif", text="Col : ") col_text.text_color= 75, 75, 75 col_text.rect.center = size[0]/2 - (col_text.rect.width)/2, size[1]/2 - 20 # Col inputfield. col = TextFieldSingleLine(panel, "16") col.rect.y += 30*1 col.set_name("col") col.set_max_char_length(4) col.rect.center = cx, cy - 20 col.set_allowed_chars(digits) self.custom_screen_sprite_list.add(col) col.rect.centerx = size[0]/2 + col.rect.width/2 coverage_text = TextLine(font = "Serif", text="Mine % : ") coverage_text.text_color= 75, 75, 75 coverage_text.rect.center =size[0]/2-(coverage_text.rect.width)/2, size[1]/2 +15 # MIne count inputfield. coverage = TextFieldSingleLine(panel, "16") coverage.rect.y += 30*2 coverage.set_name("coverage") coverage.set_max_char_length(4) coverage.rect.center = cx, cy + 15 coverage.set_allowed_values([str(i) for i in range(1, 100)]) self.custom_screen_sprite_list.add(coverage) coverage.rect.centerx = size[0]/2 + coverage.rect.width/2 self.custom_screen_sprite_list.returned(self.parase_value_to_start_game,\ (self.custom_screen_sprite_list,)) self.text_list = row_text, col_text, coverage_text
def build_page2(self, parent): p = Panel(parent) st(p, label = 'TODO') return p
def build_target_notebook(self, parent): m = self.m m._url_combobox.Create(parent, choices = ['http://www.site.com/vuln.php?id=1']) # style = wx.CB_DROPDOWN p2 = Panel(parent) hbox2 = BoxSizer() m._burp_logfile.Create(p2) m._burp_logfile_chooser.Create(p2, label = '打开') m._burp_logfile_chooser.Bind( EVT_BUTTON, lambda evt, data = [m._burp_logfile]: self._handlers.set_file_entry_text(evt, data)) hbox2.Add(m._burp_logfile, proportion = 1, flag = EXPAND) hbox2.Add(m._burp_logfile_chooser, flag = EXPAND) p2.SetSizer(hbox2) p3 = Panel(parent) hbox3 = BoxSizer() m._request_file.Create(p3) m._request_file_chooser.Create(p3, label = '打开') m._request_file_chooser.Bind( EVT_BUTTON, lambda evt, data = [m._request_file]: self._handlers.set_file_entry_text(evt, data)) hbox3.Add(m._request_file, proportion = 1, flag = EXPAND) hbox3.Add(m._request_file_chooser, flag = EXPAND) p3.SetSizer(hbox3) p4 = Panel(parent) hbox4 = BoxSizer() m._bulkfile.Create(p4) m._bulkfile_chooser.Create(p4, label = '打开') m._bulkfile_chooser.Bind( EVT_BUTTON, lambda evt, data = [m._bulkfile]: self._handlers.set_file_entry_text(evt, data)) hbox4.Add(m._bulkfile, proportion = 1, flag = EXPAND) hbox4.Add(m._bulkfile_chooser, flag = EXPAND) p4.SetSizer(hbox4) p5 = Panel(parent) hbox5 = BoxSizer() m._configfile.Create(p5) m._configfile_chooser.Create(p5, label = '打开') m._configfile_chooser.Bind( EVT_BUTTON, lambda evt, data = [m._configfile]: self._handlers.set_file_entry_text(evt, data)) hbox5.Add(m._configfile, proportion = 1, flag = EXPAND) hbox5.Add(m._configfile_chooser, flag = EXPAND) p5.SetSizer(hbox5) m._sitemap_url.Create(parent) m._google_dork.Create(parent) parent.AddPage(m._url_combobox, '目标url') parent.AddPage(p2, 'burp日志') parent.AddPage(p3, 'HTTP请求') parent.AddPage(p4, 'BULKFILE') parent.AddPage(p5, 'ini文件') parent.AddPage(m._sitemap_url, 'xml_url') parent.AddPage(m._google_dork, 'GOOGLEDORK')
def build_target_notebook(self, parent): m = self.m m._url_combobox.Create(parent, choices = ['http://www.site.com/vuln.php?id=1']) # style = wx.CB_DROPDOWN p2 = Panel(parent) hbox2 = BoxSizer() m._burp_logfile.Create(p2) m._burp_logfile_chooser.Create(p2, label = '打开') m._burp_logfile_chooser.Bind( EVT_BUTTON, lambda evt, data = [m._burp_logfile]: self._handlers.set_file_entry_text(evt, data)) hbox2.Add(m._burp_logfile, proportion = 1, flag = EXPAND) hbox2.Add(m._burp_logfile_chooser, flag = EXPAND) p2.SetSizer(hbox2) p3 = Panel(parent) hbox3 = BoxSizer() m._request_file.Create(p3) m._request_file_chooser.Create(p3, label = '打开') m._request_file_chooser.Bind( EVT_BUTTON, lambda evt, data = [m._request_file]: self._handlers.set_file_entry_text(evt, data)) hbox3.Add(m._request_file, proportion = 1, flag = EXPAND) hbox3.Add(m._request_file_chooser, flag = EXPAND) p3.SetSizer(hbox3) p4 = Panel(parent) hbox4 = BoxSizer() m._bulkfile.Create(p4) m._bulkfile_chooser.Create(p4, label = '打开') m._bulkfile_chooser.Bind( EVT_BUTTON, lambda evt, data = [m._bulkfile]: self._handlers.set_file_entry_text(evt, data)) hbox4.Add(m._bulkfile, proportion = 1, flag = EXPAND) hbox4.Add(m._bulkfile_chooser, flag = EXPAND) p4.SetSizer(hbox4) p5 = Panel(parent) hbox5 = BoxSizer() m._configfile.Create(p5) m._configfile_chooser.Create(p5, label = '打开') m._configfile_chooser.Bind( EVT_BUTTON, lambda evt, data = [m._configfile]: self._handlers.set_file_entry_text(evt, data)) hbox5.Add(m._configfile, proportion = 1, flag = EXPAND) hbox5.Add(m._configfile_chooser, flag = EXPAND) p5.SetSizer(hbox5) m._google_dork.Create(parent) m._direct_connect.Create(parent, value = 'mysql://*****:*****@DBMS_IP:DBMS_PORT/DATABASE_NAME or ' 'access://DATABASE_FILEPATH') parent.AddPage(m._url_combobox, '目标url') parent.AddPage(p2, 'burp日志') parent.AddPage(p3, 'HTTP请求') parent.AddPage(p4, 'BULKFILE') parent.AddPage(p5, 'ini文件') parent.AddPage(m._google_dork, 'GOOGLEDORK') parent.AddPage(m._direct_connect, '-d DIRECT')
def __init__(self, window): self.width = window.get_width() self.height = window.get_height() self.window = window self.running = True self.paused = False self.move = None self.mill = NineMenMorris() self.active_window = Window.MENU self.piece_being_held = False self.held_piece = -1 # Faz o rescaling das posições da tela. O jogo foi originalmente feito para o tabuleiro ter 600x600. # Mas com a adição UI foi modificado para ter 500x500. for position in range(0, 24): tile_positions[position] = [int(tile_positions[position][0] * 5 / 6 + 50), int(tile_positions[position][1] * 5 / 6 + 50)] # Carregando as imagens do jogo. self.pieces_sprites = self.load_pieces_sprites() grey_panel = pygame.image.load(os.path.join("Assets", "grey_panel.png")).convert_alpha() self.background_sprite = pygame.image.load(os.path.join("Assets", 'background.png')) self.background_sprite = pygame.transform.scale(self.background_sprite, (self.width, self.height)) self.board_sprite = pygame.image.load(os.path.join("Assets", "board.png")) self.board_sprite = pygame.transform.scale(self.board_sprite, (int(self.width * 5 / 6), int(self.height * 5 / 6))) grey_button_sprites = [ pygame.image.load(os.path.join("Assets", "grey_button.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "grey_button_pushed.png")).convert_alpha() ] pause_button_sprites = [ pygame.image.load(os.path.join("Assets", "pausar_idle.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "pausar_apertado.png")).convert_alpha() ] close_button_sprites = [ pygame.image.load(os.path.join("Assets", "fechar_idle.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "fechar_apertado.png")).convert_alpha() ] play_button_sprites = [ pygame.image.load(os.path.join("Assets", "play_idle.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "play_apertado.png")).convert_alpha() ] left_arrow_button_sprites = [ pygame.image.load(os.path.join("Assets", "grey_slider_left.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "grey_slider_left_pushed.png")).convert_alpha() ] right_arrow_button_sprites = [ pygame.image.load(os.path.join("Assets", "grey_slider_right.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "grey_slider_right_pushed.png")).convert_alpha() ] up_arrow_button_sprites = [ pygame.image.load(os.path.join("Assets", "grey_slider_up.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "grey_slider_up_pushed.png")).convert_alpha() ] down_arrow_button_sprites = [ pygame.image.load(os.path.join("Assets", "grey_slider_down.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "grey_slider_down_pushed.png")).convert_alpha() ] color_toggle_button_sprites = [ pygame.image.load(os.path.join("Assets", "white_button.png")).convert_alpha(), pygame.image.load(os.path.join("Assets", "black_button.png")).convert_alpha() ] # Cria a fonte do jogo. self.font = pygame.freetype.SysFont('Comic Sans MS', 18) # Cria os botões game_window_buttons = { 'Pause': PushButton([5, 5], 40, pause_button_sprites), 'Close': PushButton([600 - 5 - 40, 5], 40, close_button_sprites), 'Resume': PushButton([5, 5], 40, play_button_sprites), } main_window_buttons = { 'Close': PushButton([600 - 5 - 40, 5], 40, close_button_sprites), 'PlayAI': PushButton([self.width / 2 - 75, self.height / 2 - 80], [150, 40], grey_button_sprites, hint_text=Text('vs AI', 18, Color.BLACK)), 'PlayHuman': PushButton([self.width / 2 - 75, self.height / 2], [150, 40], grey_button_sprites, hint_text=Text('vs Jogador', 18, Color.BLACK)) } config_window_buttons = { 'Close': PushButton([600 - 5 - 40, 5], 40, close_button_sprites), 'Color': ToggleButton([self.width / 2 + 65, self.height / 2 - 75], [30, 30], color_toggle_button_sprites), 'Return': PushButton([40, 33], [39, 31], left_arrow_button_sprites), 'Increase': PushButton([self.width / 2 + 30, self.height / 2 + 5], [int(31*0.75), int(39*0.75)], up_arrow_button_sprites), 'Decrease': PushButton([self.width / 2 + 107, self.height / 2 + 5], [int(31*0.75), int(39*0.75)], down_arrow_button_sprites), 'Play': PushButton([self.width / 2 - 75, self.height / 2 +80], [150, 40], grey_button_sprites, hint_text=Text('JOGAR', 18, Color.BLACK)) } main_window_buttons['Close'].connect_function(self.close_game) main_window_buttons['PlayAI'].connect_function(self.change_active_window, Window.CONFIG) main_window_buttons['PlayHuman'].connect_function(self.start_match, ) game_window_buttons['Close'].connect_function(self.close_game) game_window_buttons['Pause'].connect_function(self.pause_match) game_window_buttons['Resume'].connect_function(self.resume_match) game_window_buttons['Resume'].disable() config_window_buttons['Close'].connect_function(self.close_game) config_window_buttons['Return'].connect_function(self.change_active_window, Window.MENU) config_window_buttons['Increase'].connect_function(self.change_ai_depth_level, 1) config_window_buttons['Decrease'].connect_function(self.change_ai_depth_level, -1) config_window_buttons['Play'].connect_function(self.start_match, True) main_window_panels = { 'Title': Panel([self.width / 2 - 100, 30], [200, 40], grey_panel, Border(0, Color.BLACK), Text('Trilha', 20, Color.BLACK)) } game_window_panels = { 'Move': Panel([self.width / 2 - 100, 10], [200, 30], grey_panel, Border(0, Color.BLACK), Text('Vez do Branco', 18, Color.BLACK)) } config_window_panels = { 'Title': Panel([self.width / 2 - 100, 30], [200, 40], grey_panel, Border(0, Color.BLACK), Text('Trilha', 20, Color.BLACK)), 'Color': Panel([self.width / 2 - 165, self.height / 2 - 80], [175, 40], grey_panel, Border(0, Color.BLACK), Text('Escolha sua cor:', 20, Color.BLACK)), 'Msg': Panel([self.width / 2 - 165, self.height / 2], [175, 40], grey_panel, Border(0, Color.BLACK), Text('Nível da AI:', 20, Color.BLACK)), 'AiLevel': Panel([self.width / 2 + 65, self.height / 2 + 5], [30, 30], grey_panel, Border(0, Color.BLACK), Text('1', 20, Color.BLACK)) } self.window_manager = [ Window(main_window_buttons, main_window_panels), Window(game_window_buttons, game_window_panels), Window(config_window_buttons, config_window_panels) ] self.text_stage_2 = ['Preto come uma peça', 'Branco come uma peça'] self.text_normal = ['Vez do Preto', 'Vez do Branco'] self.text_game_over = ['Preto Venceu!', 'Branco Venceu!'] self.ai_depth_level = 1 self.playing_vs_ai = None self.player_color = Player.WHITE
def init_selection_screen(self): panel = self.selection_screen_panel = Panel() # Load basic oversized images. default_surf = default_surf = pygame.image.load("button/selection/default.png") hover_surf = hover_surf = pygame.image.load("button/selection/hover.png") held_surf = held_surf = pygame.image.load("button/selection/held.png") disabled_surf = disabled_surf = pygame.image.load("button/selection/disabled.png") THEME = create_button_theme(default_surf, hover_surf, held_surf, disabled_surf) size = default_surf.get_size() scale_size = (186, 186) def draw_text(mine_size_str, mine_count_str, post_text_str, alpha_surf): """ Consider surfaces x and y with surfaces (-x-) and (-y-) respectively lying on a parent surface marked as --- ---. ---(-x-)(-y-)--- in orer to place (-x-)(-y-) in the center, the x's center is set to [(parent_surface.width/2)] - [width of (-y-)/2] """ text_surf = alpha_surf.copy().convert_alpha() rect = text_surf.get_rect() size = text_surf.get_size() # "Mines" text. text_mines = TextLine(font = "Sans",text = post_text_str) text_mines.bold = False text_mines.font_size = 14 text_mines.text_color = (60, 60, 60) # Draw 8x8 at the center of the image. text = TextLine(font = "Sans") text.text_color = (60, 60, 60) text.text = mine_size_str text.font_size = 16 text.bold = True text.rect.center = size[0]/2, size[1]/2 - text.rect.height/2 text.draw(text_surf) # Mine count. text.text = mine_count_str text.size = 16 text.bold = True x = size[0]/2 - (text_mines.rect.width)/2 y = size[1]/2 + text.rect.height/2 text.rect.center = x, y text.draw(text_surf) # "Mines" is drawn. x = size[0]/2 + text.rect.width/2 text_mines.rect.center = x, y text_mines.draw(text_surf) return text_surf # All surfaces are now generated with the corrected size. alpha_surf = pygame.Surface(scale_size).convert_alpha() alpha_surf.fill((0, 0, 0, 0), None, pygame.BLEND_RGBA_MULT) # Draw text in desired format on the alpha_surf. text_8x8_surf = draw_text("8 x 8", "10", " mines", alpha_surf) text_16x16_surf = draw_text("16 x 16", "40", " mines", alpha_surf) text_30x16_surf = draw_text("30 x 16", "99", " mines", alpha_surf) text_custom_surf = draw_text("?", "", "Custom", alpha_surf) # Generate the theme using the surface having text. def make_selection_theme(text_surface, scale_size, default_theme): """make_selection_theme() - returns theme. Uses default theme and blits textsurface over it""" theme = default_theme default = scale(theme["default"].copy(), scale_size) default.blit(text_surface, (0, 0)) hover = scale(theme["hover"].copy(), scale_size) hover.blit(text_surface, (0, 0)) held = scale(theme["pressed"].copy(), scale_size) held.blit(text_surface, (0, 0)) disabled = scale(theme["disabled"].copy(), scale_size) disabled.blit(text_surface, (0, 0)) return create_button_theme(default, hover, held, disabled) # THEMES: _8x8_selection_theme = make_selection_theme(text_8x8_surf, scale_size, THEME) _16x16_selection_theme = make_selection_theme(text_16x16_surf, scale_size, THEME) _30x16_selection_theme = make_selection_theme(text_30x16_surf, scale_size, THEME) _custom_selection_theme = make_selection_theme(text_custom_surf, scale_size, THEME) ####### # TODO: Rework this code and make it small. # # Offsetxy from center - ox, oy # cx, cy = Calculated center co-ords of buttons. # FIXME: START TRASH. def make_selection_button(cell_xy, theme, callback, params): """ make_selection_button() - returns a created selection button. Create buttons and assign themes and center coords by calculating its center from display center.""" cell_x, cell_y = cell_xy # Get display size and display center. display_size = pygame.display.get_surface().get_size() display_center_pos = display_size[0]/2, display_size[1]/2 cx = display_center_pos[0] + cell_x * (scale_size[0]/2 + 9) cy = display_center_pos[1] + cell_y * (scale_size[1]/2 + 9) print cx, cy selection_button = Button(panel) selection_button.theme = theme selection_button.rect.center = cx, cy selection_button.released(callback, params) return selection_button self.selection_button_list = ButtonGroup() # BUTTONS(THEMES): cell_xy = -1, -1 callback, params = self.start_game, ((8, 8), 10) _8x8_selection_button = make_selection_button(cell_xy, _8x8_selection_theme, callback, params) self.selection_button_list.add(_8x8_selection_button) cell_xy = 1, -1 callback, params = self.start_game, ((16, 16), 40) _16x16_selection_button = make_selection_button(cell_xy, _16x16_selection_theme, callback, params) self.selection_button_list.add(_16x16_selection_button) cell_xy = -1, 1 callback, params = self.start_game, ((16, 30), 99) _30x16_selection_button = make_selection_button(cell_xy, _30x16_selection_theme, callback, params) self.selection_button_list.add(_30x16_selection_button) cell_xy = 1, 1 callback, params = self.switch_screen, (CUSTOM_SCREEN, ) _custom_selection_button = make_selection_button(cell_xy, _custom_selection_theme, callback, params) self.selection_button_list.add(_custom_selection_button)