コード例 #1
0
ファイル: window_bidbox.py プロジェクト: aft90/pybridge
    def __init__(self, parent=None):
        self.window = Gtk.Window()
        if parent:
            self.window.set_transient_for(parent.window)
        self.window.set_title(_('Bidding Box'))
        self.window.connect('delete_event', self.on_delete_event)
        self.window.set_resizable(False)

        self.callButtons = {}
        self.callSelectHandler = None  # A method to invoke when a call is clicked.
        self.eventHandler = SimpleEventHandler(self)
        self.table = None
        self.position = None

        def buildButtonFromCall(call, markup):
            button = Gtk.Button()
            button.set_relief(Gtk.ReliefStyle.NONE)
            button.connect('clicked', self.on_call_clicked, call)
            # A separate label is required for marked-up text.
            label = Gtk.Label()
            label.set_markup(markup)
            label.set_use_markup(True)
            button.add(label)
            self.callButtons[call] = button
            return button

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)

        otherbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        bidtable = Gtk.Grid()
        bidtable.set_row_homogeneous(True)
        bidtable.set_column_homogeneous(True)

        vbox.pack_start(bidtable, True, True, 0)
        # Build buttons for all bids.
        for y, level in enumerate(Call.Level):
            for x, strain in enumerate(Call.Strain):
                bid = Call.Bid(level, strain)
                markup = render_call(bid)
                xy = (x, y, 1, 1)
                bidtable.attach(buildButtonFromCall(bid, markup), *xy)

        hsep = Gtk.Separator()
        hsep.set_property("orientation", Gtk.Orientation.HORIZONTAL)

        vbox.pack_start(hsep, True, True, 0)

        otherbox = Gtk.HBox()
        vbox.pack_start(otherbox, True, True, 0)
        # Build buttons for other calls.
        othercalls = [(Call.Pass(), render_call_name, True),
                      (Call.Double(), render_call, False),
                      (Call.Redouble(), render_call, False)]
        for call, renderer, expand in othercalls:
            markup = renderer(call)
            otherbox.pack_start(buildButtonFromCall(call, markup), expand, True, 0)
        self.window.add(vbox)
        self.window.show_all()
コード例 #2
0
ファイル: window_bridgetable.py プロジェクト: aft90/pybridge
    def add_call(self, call, position):
        """Adds call from specified position."""
        column = position.value
        if column == 0 or self.store.get_iter_first() == None:
            iter = self.store.append()
        else:  # Get bottom row. There must be a better way than this...
            iter = self.store.get_iter_first()
            while self.store.iter_next(iter) != None:
                iter = self.store.iter_next(iter)

        format = render_call(call)
        self.store.set(iter, column, format)
コード例 #3
0
 def test_render_call_suit_with_initial(self):
     call = Mock(spec=Call.Bid)
     call.level = Level.Two
     call.strain = Strain.Diamond
     with patch('pybridge.ui.vocabulary.config',
                {'Appearance': {
                    'Colours': {
                        'Diamond': '000000000000'
                    }
                }}), patch('pybridge.ui.vocabulary.STRAIN_SYMBOLS',
                           {Strain.Diamond: 'D'}):
         self.assertEqual("2<span color='#000000000000'>D</span>",
                          render_call(call))
コード例 #4
0
 def test_render_call_nt(self):
     call = Mock(spec=Call.Bid)
     call.level = Level.Two
     call.strain = Strain.NoTrump
     self.assertEqual('2NT', render_call(call))