def draw_board(board): """Draw the board and numbers. Arguments: board -- the board """ for j in xrange(board.boardsize): for i in xrange(board.boardsize): if board.numbers[j][i] != 0: if options.getboolean("sudoku", "use_letters"): format = " %1s" text = str(Value(board.numbers[j][i])) else: lenght = int(math.log10(board.boardsize)) + 1 format = " %%%ds" % lenght text = str(Value(board.numbers[j][i]).integer()) print format % text, else: if options.getboolean("sudoku", "use_letters"): text = " _" else: lenght = int(math.log10(board.boardsize)) + 1 text = " " + "".join(["_" for x in xrange(lenght)]) print text, if (i + 1) % board.cellsize[0] == 0: print " ", print if (j + 1) % board.cellsize[1] == 0 and j != (board.boardsize - 1): print
def draw_numbers(self): """Draw the numbers.""" font = PIL.ImageFont.truetype(options.get("image", "font"), options.getint("image", "font_size")) # 5% margin + half square x = options.getint("image", "width") / 20 + self.square_width / 2 y = options.getint("image", "height") / 20 + self.square_height / 2 for i in xrange(self.boardsize): for j in xrange(self.boardsize): if self.numbers[j][i] != 0: if options.getboolean("sudoku", "use_letters"): text = str(Value(self.numbers[j][i])) else: text = str(Value(self.numbers[j][i]).integer()) size = self.draw.textsize(text, font=font) # this should be: #self.draw.text((x + i * self.square_width - size[0] / 2, # y + j * self.square_height - size[1] / 2), # text) # but it's not centered without the + 2 in the y coord self.draw.text((x + i * self.square_width - size[0] / 2, y + j * self.square_height - size[1] / 2 + 2), text, fill=options.get("image", "font_colour"), font=font)
def deal(self): self.handtype = htypes[htype] if self.handtype == "all": types = ('soft', 'hard', 'split') self.handtype = random.choice(types) h = cards.playerhand(self.handtype) d = cards.dealercard() c1 = h.c1.display c2 = h.c2.display logging.info("Value is %s", h.lookup) self.correct = chart.get_correct(h.lookup, d.value) logging.debug("%s %s" , c1, c2) self.dcard.SetLabel(d.display) self.pcard1.SetLabel(c1) self.pcard2.SetLabel(c2) if options.getboolean('main-opts', 'btn_disable'): self.ButtonDisable(h.lookup)
def draw_numbers(self): """Draw the numbers.""" self.c.setFillColor(options.get("pdf", "font_colour")) self.c.setFont(options.get("pdf", "font"), options.getint("pdf", "font_size")) face = reportlab.pdfbase.pdfmetrics.getFont("Helvetica").face height = (face.ascent - face.descent) * \ options.getint("pdf", "font_size") / 1000.0 if self.page_size[0] < self.page_size[1]: square_length = self.page_size[0] / (self.boardsize) * 0.9 x = self.page_size[0] / 20 + square_length / 2 y = (self.page_size[1] - self.page_size[0] * 0.9 + \ square_length - height) / 2 else: square_length = self.page_size[1] / (self.boardsize) * 0.9 y = self.page_size[1] / 20 + square_length / 2 x = (self.page_size[0] - self.page_size[1] * 0.9 + \ square_length - height) / 2 for i in xrange(self.boardsize): for j in xrange(self.boardsize): if self.numbers[self.boardsize - 1 - j][i] != 0: if options.getboolean("sudoku", "use_letters"): text = str(Value(self.numbers[self.boardsize - 1 - j][i])) else: text = str(Value(self.numbers[self.boardsize - 1 - j][i]).integer()) self.c.drawCentredString(x + i * square_length, y + j * square_length, text)
def create_sudoku(filename): """Create a sudoku with handicap and save it to filename. The handicap are the extra numbers given. Arguments: filename -- the file name """ while True: print _(u"Creating sudoku..."), sys.stdout.flush() sudoku = Sudoku(Board((options.getint("sudoku", "region_width"), options.getint("sudoku", "region_height"))), difficulty=options.get("sudoku", "difficulty")) sudoku.create(options.getint("sudoku", "handicap")) if options.getboolean("sudoku", "force") and \ (difficulty(sudoku.to_board()) != options.get("sudoku", "difficulty")): print _(u"sudoku with wrong difficulty!") else: sudoku.to_board().save(filename) print _(u"success!") break draw_board(sudoku.to_board()) return True
def __init__(self, parent, id=wx.ID_ANY, title="Options", size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE): super (ConfigDialog, self).__init__(parent, id, title, pos, size, style) panel = wx.Panel(self) #======================================================================= # Config (main) items... #======================================================================= ht_pref = options.get('main-opts', 'htype') ht_choices = ["A - xxxxx", "H - xxxxx", "S - xxxxx", "P - xxxxx"] ht_box = self.ht_box = wx.RadioBox(panel, -1, "HT", choices=ht_choices, majorDimension=1) ht_box.SetStringSelection(ht_pref) view_choices = ['Txt', 'Gfx'] view_box = self.view_box = wx.RadioBox(panel, -1, "View", choices=view_choices, majorDimension=1) view_box.SetStringSelection(options.get('main-opts', 'view')) bkey_label = wx.StaticText(panel, -1, "Bkey") bkey_pref = options.get('main-opts', 'bkey') bkey_letters = list('ABCEFGIJKLMNOQRTUVWXYZ') bkey_choice = self.bkey_choice = wx.Choice(panel, -1, choices=bkey_letters) bkey_choice.SetStringSelection(bkey_pref) btype_label = wx.StaticText(panel, -1, "BK Type") btype_choices = ['Grid', 'Image', 'Hide'] btype_picker = self.btype_picker = wx.Choice(panel, -1, choices=btype_choices) btype_picker.SetStringSelection(options.get('main-opts', 'bk_type')) disable_pref = options.getboolean('main-opts', 'btn_disable') # logging.info(disable_pref) btn_disable = self.btn_disable = wx.CheckBox(panel, -1, "Disable Invalid Buttons") btn_disable.SetValue(disable_pref) btn_hint = wx.StaticText(panel, -1, "Lorem ipsum dolor sit amet amet lorem ipsum dolor sit ametamet lorem ipsum dolor sit amet.") btn_hint.Wrap(150) #======================================================================= # Create GBS, add items #======================================================================= cfg_gbs = wx.GridBagSizer(5, 5) cfg_gbs.Add(ht_box, (0, 0), (3, 2), wx.ALL | wx.EXPAND | wx.ALIGN_CENTER, 5) cfg_gbs.Add(view_box, (0, 2), (3, 2), wx.ALL | wx.EXPAND | wx.CENTER, 5) cfg_gbs.Add(bkey_label, (3, 2)) cfg_gbs.Add(bkey_choice, (3, 3)) cfg_gbs.Add(btype_label, (4, 2)) cfg_gbs.Add(btype_picker, (4, 3)) cfg_gbs.Add(btn_disable, (4, 0), (1, 2), wx.EXPAND | wx.ALL, 5) cfg_gbs.Add(btn_hint, (6, 0), (2, 2), wx.EXPAND | wx.ALL, 5) # Add standard OK/Cancel buttons using Standard Dialog Button sizer sdbs = wx.StdDialogButtonSizer() ok_button = wx.Button(panel, wx.ID_OK) cancel_button = wx.Button(panel, wx.ID_CANCEL) sdbs.AddButton(ok_button) sdbs.AddButton(cancel_button) sdbs.Realize() # Add dialog button set to bottom of GBS cfg_gbs.Add(sdbs, (8, 1), (1, 4), wx.ALIGN_RIGHT | wx.EXPAND | wx.ALL , 5) panel.SetSizerAndFit(cfg_gbs) self.SetClientSize(panel.GetSize())