示例#1
0
    def build_ui(self):
        #roll odd/even
        self.main_grid = QGridLayout()
        self.btn_roll_odd = QPushButton("Roll odd")

        self.edit_roll_amount = BTCAmountEdit(self.parent.get_decimal_point)
        self.edit_roll_amount.setMaximumWidth(200)
        self.edit_roll_amount.setPlaceholderText("Roll Amount (Min 25)")
        self.edit_roll_amount.setValidator(
            QDoubleValidator(self.edit_roll_amount))
        self.edit_roll_amount.textChanged.connect(self.amountChanged)

        self.fiat_c = AmountEdit(
            self.parent.fx.get_currency if self.parent.fx else '')
        if not self.parent.fx or not self.parent.fx.is_enabled():
            self.fiat_c.setVisible(False)

        self.edit_roll_amount.frozen.connect(
            lambda: self.fiat_c.setFrozen(self.edit_roll_amount.isReadOnly()))

        self.btn_roll_even = QPushButton("Roll even")

        self.btn_roll_odd.clicked.connect(lambda: self.do_roll("ODD"))
        self.btn_roll_even.clicked.connect(lambda: self.do_roll("EVEN"))

        self.btn_roll_odd.setDisabled(True)
        self.btn_roll_even.setDisabled(True)

        self.roll_control_widget = QWidget()

        self.roll_control_vbox = QVBoxLayout(self.roll_control_widget)

        self.roll_control_grid = QGridLayout()
        self.roll_control_grid.addWidget(self.btn_roll_odd, 0, 1)
        self.roll_control_grid.addWidget(self.edit_roll_amount, 0, 2)
        self.roll_control_grid.addWidget(self.btn_roll_even, 0, 3)
        self.roll_control_grid.setSpacing(20)

        self.lbl_pr_odd = QLabel("")
        self.lbl_pr_odd.setStyleSheet("color:black;font-weight:bold;")
        self.lbl_pr_odd.setAlignment(Qt.AlignCenter)

        self.lbl_pr_label = QLabel("")
        self.lbl_pr_label.setAlignment(Qt.AlignCenter)
        self.lbl_pr_label.setStyleSheet("color:black;font-weight:bold;")

        self.lbl_pr_even = QLabel("")
        self.lbl_pr_even.setStyleSheet("color:black;font-weight:bold;")
        self.lbl_pr_even.setAlignment(Qt.AlignCenter)

        self.roll_control_grid.addWidget(self.lbl_pr_odd, 1, 1)
        self.roll_control_grid.addWidget(self.lbl_pr_label, 1, 2)
        self.roll_control_grid.addWidget(self.lbl_pr_even, 1, 3)

        self.roll_control_vbox.addLayout(self.roll_control_grid)

        self.roll_control_widget.setFixedWidth(500)
        self.main_grid.addWidget(self.roll_control_widget)

        self.setLayout(self.main_grid)
示例#2
0
 def auth_dialog(self, window):
     d = WindowModalDialog(window, _("Authorization"))
     vbox = QVBoxLayout(d)
     pw = AmountEdit(None, is_int = True)
     msg = _('Please enter your Google Authenticator code')
     vbox.addWidget(QLabel(msg))
     grid = QGridLayout()
     grid.setSpacing(8)
     grid.addWidget(QLabel(_('Code')), 1, 0)
     grid.addWidget(pw, 1, 1)
     vbox.addLayout(grid)
     msg = _('If you have lost your second factor, you need to restore your wallet from seed in order to request a new code.')
     label = QLabel(msg)
     label.setWordWrap(1)
     vbox.addWidget(label)
     vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
     if not d.exec_():
         return
     return pw.get_amount()
示例#3
0
文件: qt.py 项目: ahmedbodi/electrum
 def auth_dialog(self, window):
     d = WindowModalDialog(window, _("Authorization"))
     vbox = QVBoxLayout(d)
     pw = AmountEdit(None, is_int = True)
     msg = _('Please enter your Google Authenticator code')
     vbox.addWidget(QLabel(msg))
     grid = QGridLayout()
     grid.setSpacing(8)
     grid.addWidget(QLabel(_('Code')), 1, 0)
     grid.addWidget(pw, 1, 1)
     vbox.addLayout(grid)
     msg = _('If you have lost your second factor, you need to restore your wallet from seed in order to request a new code.')
     label = QLabel(msg)
     label.setWordWrap(1)
     vbox.addWidget(label)
     vbox.addLayout(Buttons(CancelButton(d), OkButton(d)))
     if not d.exec_():
         return
     return pw.get_amount()
示例#4
0
    def request_otp_dialog(self, window, short_id, otp_secret, xpub3):
        vbox = QVBoxLayout()
        if otp_secret is not None:
            uri = "otpauth://totp/%s?secret=%s" % ('trustedcoin.com',
                                                   otp_secret)
            l = QLabel(
                "Please scan the following QR code in Google Authenticator. You may as well use the following key: %s"
                % otp_secret)
            l.setWordWrap(True)
            vbox.addWidget(l)
            qrw = QRCodeWidget(uri)
            vbox.addWidget(qrw, 1)
            msg = _('Then, enter your Google Authenticator code:')
        else:
            label = QLabel(
                "This wallet is already registered with TrustedCoin. "
                "To finalize wallet creation, please enter your Google Authenticator Code. "
            )
            label.setWordWrap(1)
            vbox.addWidget(label)
            msg = _('Google Authenticator code:')
        hbox = QHBoxLayout()
        hbox.addWidget(WWLabel(msg))
        pw = AmountEdit(None, is_int=True)
        pw.setFocus(True)
        pw.setMaximumWidth(50)
        hbox.addWidget(pw)
        vbox.addLayout(hbox)
        cb_lost = QCheckBox(_("I have lost my Google Authenticator account"))
        cb_lost.setToolTip(
            _("Check this box to request a new secret. You will need to retype your seed."
              ))
        vbox.addWidget(cb_lost)
        cb_lost.setVisible(otp_secret is None)

        def set_enabled():
            b = True if cb_lost.isChecked() else len(pw.text()) == 6
            window.next_button.setEnabled(b)

        pw.textChanged.connect(set_enabled)
        cb_lost.toggled.connect(set_enabled)
        window.exec_layout(vbox, next_enabled=False, raise_on_cancel=False)
        self.check_otp(window, short_id, otp_secret, xpub3, pw.get_amount(),
                       cb_lost.isChecked())
示例#5
0
文件: qt.py 项目: ahmedbodi/electrum
 def request_otp_dialog(self, window, short_id, otp_secret, xpub3):
     vbox = QVBoxLayout()
     if otp_secret is not None:
         uri = "otpauth://totp/%s?secret=%s"%('trustedcoin.com', otp_secret)
         l = QLabel("Please scan the following QR code in Google Authenticator. You may as well use the following key: %s"%otp_secret)
         l.setWordWrap(True)
         vbox.addWidget(l)
         qrw = QRCodeWidget(uri)
         vbox.addWidget(qrw, 1)
         msg = _('Then, enter your Google Authenticator code:')
     else:
         label = QLabel(
             "This wallet is already registered with TrustedCoin. "
             "To finalize wallet creation, please enter your Google Authenticator Code. "
         )
         label.setWordWrap(1)
         vbox.addWidget(label)
         msg = _('Google Authenticator code:')
     hbox = QHBoxLayout()
     hbox.addWidget(WWLabel(msg))
     pw = AmountEdit(None, is_int = True)
     pw.setFocus(True)
     pw.setMaximumWidth(50)
     hbox.addWidget(pw)
     vbox.addLayout(hbox)
     cb_lost = QCheckBox(_("I have lost my Google Authenticator account"))
     cb_lost.setToolTip(_("Check this box to request a new secret. You will need to retype your seed."))
     vbox.addWidget(cb_lost)
     cb_lost.setVisible(otp_secret is None)
     def set_enabled():
         b = True if cb_lost.isChecked() else len(pw.text()) == 6
         window.next_button.setEnabled(b)
     pw.textChanged.connect(set_enabled)
     cb_lost.toggled.connect(set_enabled)
     window.exec_layout(vbox, next_enabled=False, raise_on_cancel=False)
     self.check_otp(window, short_id, otp_secret, xpub3, pw.get_amount(), cb_lost.isChecked())
示例#6
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.parent = parent

        self.event = Event.getInstance()
        self.event.register_callback(self.on_parlaybet_list_update,["parlay_list_updated"])

        self.setAttribute(QtCore.Qt.WA_StyledBackground, True)
        self.setStyleSheet("background-color:black;color:white")
        
        self.vbox_parlay_betting = QVBoxLayout(self)
        self.h0 = QHBoxLayout()
        self.totalLegs = QLabel("Total Legs: 0")
        self.totalodds = QLabel("Total Odds: 0")
        self.h0.addWidget(self.totalLegs)
        self.h0.addWidget(self.totalodds)
        
        self.editBettingAmount = BTCAmountEdit(self.parent.get_decimal_point)
        self.editBettingAmount.setPlaceholderText("0")
        self.editBettingAmount.setValidator(QDoubleValidator(self.editBettingAmount))
        self.editBettingAmount.textChanged.connect(self.betAmountChanged)

        self.fiat_c = AmountEdit(self.parent.fx.get_currency if self.parent.fx else '')
        if not self.parent.fx or not self.parent.fx.is_enabled():
            self.fiat_c.setVisible(False)

        self.editBettingAmount.frozen.connect(
            lambda: self.fiat_c.setFrozen(self.editBettingAmount.isReadOnly()))

        

        self.h = QHBoxLayout()
        self.h.addWidget(QLabel("BET"))
        self.h.addWidget(self.editBettingAmount)
        
        self.h1 = QHBoxLayout()
        self.h1.addWidget(QLabel("Potential Returns:"))
        self.totalWin = QLabel("0.0000000 {}".format(constants.net.SYMBOL))
        self.h1.addWidget(self.totalWin)

        self.errText = "Incorrect bet amount. Please ensure your bet is between 25-10000 {} inclusive.".format(constants.net.SYMBOL)
        self.lblLimitError = QLabel(self.errText)
        self.lblLimitError.setStyleSheet("font-weight: bold;")
        
        self.lblLimitError.setWordWrap(True)
        self.lblLimitError.setMinimumSize(self.lblLimitError.sizeHint())

        self.btnBet = QPushButton("PLACE BET")
        self.btnBet.setStyleSheet("QPushButton{" 
                                    "background-color:#BD0000"
                                 "}"
                                 "QPushButton:disabled{"
                                    "background-color:grey;"
                                 "}")
                            
        self.btnBet.setDisabled(True)
        self.btnBet.clicked.connect(self.btnBetClicked)

        self.vbox_parlay_betting.addLayout(self.h0)
        self.vbox_parlay_betting.addLayout(self.h)
        self.vbox_parlay_betting.addLayout(self.h1)
        self.vbox_parlay_betting.addWidget(self.lblLimitError)
        self.lblLimitError.setText("")
        self.vbox_parlay_betting.addWidget(self.btnBet)
        
        self.setLayout(self.vbox_parlay_betting)
示例#7
0
class ParlayBetBoxWidget(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.parent = parent

        self.event = Event.getInstance()
        self.event.register_callback(self.on_parlaybet_list_update,["parlay_list_updated"])

        self.setAttribute(QtCore.Qt.WA_StyledBackground, True)
        self.setStyleSheet("background-color:black;color:white")
        
        self.vbox_parlay_betting = QVBoxLayout(self)
        self.h0 = QHBoxLayout()
        self.totalLegs = QLabel("Total Legs: 0")
        self.totalodds = QLabel("Total Odds: 0")
        self.h0.addWidget(self.totalLegs)
        self.h0.addWidget(self.totalodds)
        
        self.editBettingAmount = BTCAmountEdit(self.parent.get_decimal_point)
        self.editBettingAmount.setPlaceholderText("0")
        self.editBettingAmount.setValidator(QDoubleValidator(self.editBettingAmount))
        self.editBettingAmount.textChanged.connect(self.betAmountChanged)

        self.fiat_c = AmountEdit(self.parent.fx.get_currency if self.parent.fx else '')
        if not self.parent.fx or not self.parent.fx.is_enabled():
            self.fiat_c.setVisible(False)

        self.editBettingAmount.frozen.connect(
            lambda: self.fiat_c.setFrozen(self.editBettingAmount.isReadOnly()))

        

        self.h = QHBoxLayout()
        self.h.addWidget(QLabel("BET"))
        self.h.addWidget(self.editBettingAmount)
        
        self.h1 = QHBoxLayout()
        self.h1.addWidget(QLabel("Potential Returns:"))
        self.totalWin = QLabel("0.0000000 {}".format(constants.net.SYMBOL))
        self.h1.addWidget(self.totalWin)

        self.errText = "Incorrect bet amount. Please ensure your bet is between 25-10000 {} inclusive.".format(constants.net.SYMBOL)
        self.lblLimitError = QLabel(self.errText)
        self.lblLimitError.setStyleSheet("font-weight: bold;")
        
        self.lblLimitError.setWordWrap(True)
        self.lblLimitError.setMinimumSize(self.lblLimitError.sizeHint())

        self.btnBet = QPushButton("PLACE BET")
        self.btnBet.setStyleSheet("QPushButton{" 
                                    "background-color:#BD0000"
                                 "}"
                                 "QPushButton:disabled{"
                                    "background-color:grey;"
                                 "}")
                            
        self.btnBet.setDisabled(True)
        self.btnBet.clicked.connect(self.btnBetClicked)

        self.vbox_parlay_betting.addLayout(self.h0)
        self.vbox_parlay_betting.addLayout(self.h)
        self.vbox_parlay_betting.addLayout(self.h1)
        self.vbox_parlay_betting.addWidget(self.lblLimitError)
        self.lblLimitError.setText("")
        self.vbox_parlay_betting.addWidget(self.btnBet)
        
        self.setLayout(self.vbox_parlay_betting)


    def betAmountChanged(self):
        bet_list_parlay = self.parent.betting_main_widget.bet_list_widget_parlay
        betAmtInWgr = (self.editBettingAmount.get_amount() or 0) / COIN
        if betAmtInWgr >= MIN_BET_AMT and betAmtInWgr <= MAX_BET_AMT or  betAmtInWgr == 0:
            self.lblLimitError.setText("")
        else:
            self.lblLimitError.setText(self.errText)
        bb = float(0)
        if not self.editBettingAmount.text() == "":
            bb = float(self.editBettingAmount.text())
        
        self.odds = float(0)
        self.effOddsSum = float(0)
        if bet_list_parlay.count() > 0:
            self.odds = float(1)
            self.effOddsSum = float(1)

        for i in range(0, bet_list_parlay.count()):
            item = bet_list_parlay.item(i)
            itemWidget = bet_list_parlay.itemWidget(item)
            self.odds = round(self.odds * float(itemWidget.lblSelectedOddValue.text()),2)
            
        
        for i in range(0, bet_list_parlay.count()):
            item = bet_list_parlay.item(i)
            itemWidget = bet_list_parlay.itemWidget(item)
            self.effOddsSum = round(self.effOddsSum * float(itemWidget.effectiveOddsValue),2)
        
        self.betValue = bb * float(self.effOddsSum)
        self.totalWin.setText(str("{0:.2f}".format(self.betValue))+ ' ' + self.parent.base_unit())
        self.totalLegs.setText("Total Legs: " + str(bet_list_parlay.count()))
        self.totalodds.setText("Total Odds: " + str(self.odds))
        if bet_list_parlay.count() > 1 and self.lblLimitError.text() == "" and betAmtInWgr > 0 :
           self.btnBet.setDisabled(False)
        else: 
           self.btnBet.setDisabled(True)

    
    def btnBetClicked(self):
        bet_list_parlay = self.parent.betting_main_widget.bet_list_widget_parlay
        betAmtInWgr = (self.editBettingAmount.get_amount() or 0) / COIN
        print("Betting Amount : ", betAmtInWgr)
        if betAmtInWgr >= MIN_BET_AMT and betAmtInWgr <= MAX_BET_AMT:
            self.legs = []
            for i in range(0, bet_list_parlay.count()):
                item = bet_list_parlay.item(i)
                itemWidget = bet_list_parlay.itemWidget(item)
                eventId = itemWidget.eventIdToBetOn
                outcomeType = itemWidget.betOutcome
                self.legs.append({"eventId":eventId,"outcomeType":outcomeType})
            self.parent.do_bet(self,"parlay")
        

    def on_parlaybet_list_update(self, event, *args):
        self.betAmountChanged()
示例#8
0
    def build_ui(self):
        #roll equal/notequal
        self.roll_choice = 0
        self.main_grid = QGridLayout()
        self.buttonGroup = QButtonGroup()

        btnsize = QSize(85, 70)
        for i in range(2, 13):
            button = QPushButton(str(i))
            button.setCheckable(True)
            button.setStyleSheet("background-color: white; color:red;")
            font = button.font()
            font.setPointSize(22)
            font.setBold(True)
            button.setFont(font)
            button.setFixedSize(btnsize)
            self.buttonGroup.addButton(button)
            self.main_grid.addWidget(button, 0, i)

        self.buttonGroup.buttonClicked[int].connect(self.roll_selected)

        self.btn_equal_to = QPushButton("Equal to")

        self.edit_roll_amount = BTCAmountEdit(self.parent.get_decimal_point)
        self.edit_roll_amount.setPlaceholderText("Roll Amount (Min 25)")
        self.edit_roll_amount.setValidator(
            QDoubleValidator(self.edit_roll_amount))
        self.edit_roll_amount.textChanged.connect(self.amountChanged)

        self.fiat_c = AmountEdit(
            self.parent.fx.get_currency if self.parent.fx else '')
        if not self.parent.fx or not self.parent.fx.is_enabled():
            self.fiat_c.setVisible(False)

        self.edit_roll_amount.frozen.connect(
            lambda: self.fiat_c.setFrozen(self.edit_roll_amount.isReadOnly()))

        self.btn_not_equal_to = QPushButton("Not Equal to")

        self.btn_equal_to.setDisabled(True)
        self.btn_not_equal_to.setDisabled(True)

        self.btn_equal_to.clicked.connect(lambda: self.do_roll("EQUAL"))
        self.btn_not_equal_to.clicked.connect(lambda: self.do_roll("NOTEQUAL"))

        self.roll_control_widget = QWidget()
        self.roll_control_vbox = QVBoxLayout(self.roll_control_widget)

        self.roll_control_grid = QGridLayout()
        self.roll_control_grid.addWidget(self.btn_equal_to, 0, 1)
        self.roll_control_grid.addWidget(self.edit_roll_amount, 0, 2)
        self.roll_control_grid.addWidget(self.btn_not_equal_to, 0, 3)
        self.roll_control_grid.setSpacing(20)

        self.lbl_pr_equal = QLabel("")
        self.lbl_pr_equal.setAlignment(Qt.AlignCenter)
        self.lbl_pr_equal.setStyleSheet("color:black;font-weight:bold;")

        self.lbl_pr_label = QLabel("")
        self.lbl_pr_label.setAlignment(Qt.AlignCenter)
        self.lbl_pr_label.setStyleSheet("color:black;font-weight:bold;")

        self.lbl_pr_notequal = QLabel("")
        self.lbl_pr_notequal.setAlignment(Qt.AlignCenter)
        self.lbl_pr_notequal.setStyleSheet("color:black;font-weight:bold;")

        self.roll_control_grid.addWidget(self.lbl_pr_equal, 1, 1)
        self.roll_control_grid.addWidget(self.lbl_pr_label, 1, 2)
        self.roll_control_grid.addWidget(self.lbl_pr_notequal, 1, 3)

        self.roll_control_vbox.addLayout(self.roll_control_grid)

        self.main_grid.addWidget(self.roll_control_widget, 2, 5, 1, 5)
        self.main_grid.setSpacing(10)

        self.setLayout(self.main_grid)
示例#9
0
class Equal_NotEqual(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.parent = parent
        #self.setStyleSheet("background-color:#BD0000;")
        self.build_ui()
        self.isEffectiveOdds = self.parent.config.get('iseffectiveodds', True)

    def build_ui(self):
        #roll equal/notequal
        self.roll_choice = 0
        self.main_grid = QGridLayout()
        self.buttonGroup = QButtonGroup()

        btnsize = QSize(85, 70)
        for i in range(2, 13):
            button = QPushButton(str(i))
            button.setCheckable(True)
            button.setStyleSheet("background-color: white; color:red;")
            font = button.font()
            font.setPointSize(22)
            font.setBold(True)
            button.setFont(font)
            button.setFixedSize(btnsize)
            self.buttonGroup.addButton(button)
            self.main_grid.addWidget(button, 0, i)

        self.buttonGroup.buttonClicked[int].connect(self.roll_selected)

        self.btn_equal_to = QPushButton("Equal to")

        self.edit_roll_amount = BTCAmountEdit(self.parent.get_decimal_point)
        self.edit_roll_amount.setPlaceholderText("Roll Amount (Min 25)")
        self.edit_roll_amount.setValidator(
            QDoubleValidator(self.edit_roll_amount))
        self.edit_roll_amount.textChanged.connect(self.amountChanged)

        self.fiat_c = AmountEdit(
            self.parent.fx.get_currency if self.parent.fx else '')
        if not self.parent.fx or not self.parent.fx.is_enabled():
            self.fiat_c.setVisible(False)

        self.edit_roll_amount.frozen.connect(
            lambda: self.fiat_c.setFrozen(self.edit_roll_amount.isReadOnly()))

        self.btn_not_equal_to = QPushButton("Not Equal to")

        self.btn_equal_to.setDisabled(True)
        self.btn_not_equal_to.setDisabled(True)

        self.btn_equal_to.clicked.connect(lambda: self.do_roll("EQUAL"))
        self.btn_not_equal_to.clicked.connect(lambda: self.do_roll("NOTEQUAL"))

        self.roll_control_widget = QWidget()
        self.roll_control_vbox = QVBoxLayout(self.roll_control_widget)

        self.roll_control_grid = QGridLayout()
        self.roll_control_grid.addWidget(self.btn_equal_to, 0, 1)
        self.roll_control_grid.addWidget(self.edit_roll_amount, 0, 2)
        self.roll_control_grid.addWidget(self.btn_not_equal_to, 0, 3)
        self.roll_control_grid.setSpacing(20)

        self.lbl_pr_equal = QLabel("")
        self.lbl_pr_equal.setAlignment(Qt.AlignCenter)
        self.lbl_pr_equal.setStyleSheet("color:black;font-weight:bold;")

        self.lbl_pr_label = QLabel("")
        self.lbl_pr_label.setAlignment(Qt.AlignCenter)
        self.lbl_pr_label.setStyleSheet("color:black;font-weight:bold;")

        self.lbl_pr_notequal = QLabel("")
        self.lbl_pr_notequal.setAlignment(Qt.AlignCenter)
        self.lbl_pr_notequal.setStyleSheet("color:black;font-weight:bold;")

        self.roll_control_grid.addWidget(self.lbl_pr_equal, 1, 1)
        self.roll_control_grid.addWidget(self.lbl_pr_label, 1, 2)
        self.roll_control_grid.addWidget(self.lbl_pr_notequal, 1, 3)

        self.roll_control_vbox.addLayout(self.roll_control_grid)

        self.main_grid.addWidget(self.roll_control_widget, 2, 5, 1, 5)
        self.main_grid.setSpacing(10)

        self.setLayout(self.main_grid)

    def reset_button_group(self):
        checked = self.buttonGroup.checkedButton()
        if checked:
            self.buttonGroup.setExclusive(False)
            checked.setChecked(False)
            self.buttonGroup.setExclusive(True)

    def roll_selected(self, id):
        self.roll_choice = abs(id)
        self.amountChanged()  ##recalculate PR.

    def do_roll(self, side):
        self.side = side
        self.outcome = int(self.roll_choice)
        self.amount = int(self.edit_roll_amount.get_amount())
        self.parent.do_roll(self, "dice")

    def amountChanged(self):
        rollAmtInWgr = (self.edit_roll_amount.get_amount() or 0) / COIN
        if rollAmtInWgr >= MIN_ROLL_AMT and rollAmtInWgr <= MAX_ROLL_AMT and self.roll_choice != 0:
            self.btn_equal_to.setDisabled(False)
            self.btn_not_equal_to.setDisabled(False)
        else:
            self.btn_equal_to.setDisabled(True)
            self.btn_not_equal_to.setDisabled(True)
            return

        bb = float(0)
        if not self.edit_roll_amount.text() == "":
            bb = float(self.edit_roll_amount.text())

        pr_equal = calculate_potential_return(bb, self.roll_choice, "equal")
        pr_not_equal = calculate_potential_return(bb, self.roll_choice,
                                                  "notequal")

        if not self.isEffectiveOdds:  #calculate onchain odds
            pr_equal = (pr_equal - 1) / 0.99 + 1
            pr_not_equal = (pr_not_equal - 1) / 0.99 + 1

        pr_equal_str = format_amount(pr_equal)
        pr_not_equal_str = format_amount(pr_not_equal)

        self.lbl_pr_equal.setText(pr_equal_str)
        self.lbl_pr_label.setText("<-- Potential Return -->")
        self.lbl_pr_notequal.setText(pr_not_equal_str)
示例#10
0
class Odd_Even(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.parent = parent
        #self.setStyleSheet("background-color:#BD0000;")
        self.build_ui()
        self.isEffectiveOdds = self.parent.config.get('iseffectiveodds', True)

    def build_ui(self):
        #roll odd/even
        self.main_grid = QGridLayout()
        self.btn_roll_odd = QPushButton("Roll odd")

        self.edit_roll_amount = BTCAmountEdit(self.parent.get_decimal_point)
        self.edit_roll_amount.setMaximumWidth(200)
        self.edit_roll_amount.setPlaceholderText("Roll Amount (Min 25)")
        self.edit_roll_amount.setValidator(
            QDoubleValidator(self.edit_roll_amount))
        self.edit_roll_amount.textChanged.connect(self.amountChanged)

        self.fiat_c = AmountEdit(
            self.parent.fx.get_currency if self.parent.fx else '')
        if not self.parent.fx or not self.parent.fx.is_enabled():
            self.fiat_c.setVisible(False)

        self.edit_roll_amount.frozen.connect(
            lambda: self.fiat_c.setFrozen(self.edit_roll_amount.isReadOnly()))

        self.btn_roll_even = QPushButton("Roll even")

        self.btn_roll_odd.clicked.connect(lambda: self.do_roll("ODD"))
        self.btn_roll_even.clicked.connect(lambda: self.do_roll("EVEN"))

        self.btn_roll_odd.setDisabled(True)
        self.btn_roll_even.setDisabled(True)

        self.roll_control_widget = QWidget()

        self.roll_control_vbox = QVBoxLayout(self.roll_control_widget)

        self.roll_control_grid = QGridLayout()
        self.roll_control_grid.addWidget(self.btn_roll_odd, 0, 1)
        self.roll_control_grid.addWidget(self.edit_roll_amount, 0, 2)
        self.roll_control_grid.addWidget(self.btn_roll_even, 0, 3)
        self.roll_control_grid.setSpacing(20)

        self.lbl_pr_odd = QLabel("")
        self.lbl_pr_odd.setStyleSheet("color:black;font-weight:bold;")
        self.lbl_pr_odd.setAlignment(Qt.AlignCenter)

        self.lbl_pr_label = QLabel("")
        self.lbl_pr_label.setAlignment(Qt.AlignCenter)
        self.lbl_pr_label.setStyleSheet("color:black;font-weight:bold;")

        self.lbl_pr_even = QLabel("")
        self.lbl_pr_even.setStyleSheet("color:black;font-weight:bold;")
        self.lbl_pr_even.setAlignment(Qt.AlignCenter)

        self.roll_control_grid.addWidget(self.lbl_pr_odd, 1, 1)
        self.roll_control_grid.addWidget(self.lbl_pr_label, 1, 2)
        self.roll_control_grid.addWidget(self.lbl_pr_even, 1, 3)

        self.roll_control_vbox.addLayout(self.roll_control_grid)

        self.roll_control_widget.setFixedWidth(500)
        self.main_grid.addWidget(self.roll_control_widget)

        self.setLayout(self.main_grid)

    def do_roll(self, side):
        self.side = side
        self.amount = int(self.edit_roll_amount.get_amount())
        self.parent.do_roll(self, "dice")

    def amountChanged(self):
        rollAmtInWgr = (self.edit_roll_amount.get_amount() or 0) / COIN
        if rollAmtInWgr >= MIN_ROLL_AMT and rollAmtInWgr <= MAX_ROLL_AMT:
            self.btn_roll_odd.setDisabled(False)
            self.btn_roll_even.setDisabled(False)
        else:
            self.btn_roll_odd.setDisabled(True)
            self.btn_roll_even.setDisabled(True)

        bb = float(0)
        if not self.edit_roll_amount.text() == "":
            bb = float(self.edit_roll_amount.text())

        pr_even = calculate_potential_return(bb, 0, "even")
        pr_odd = calculate_potential_return(bb, 0, "odd")

        if not self.isEffectiveOdds:  #calculate onchain odds
            pr_even = (pr_even - 1) / 0.99 + 1
            pr_odd = (pr_odd - 1) / 0.99 + 1

        pr_even_str = format_amount(pr_even)
        pr_odd_str = format_amount(pr_odd)

        self.lbl_pr_even.setText(pr_even_str)
        self.lbl_pr_label.setText("<-- Potential Return -->")
        self.lbl_pr_odd.setText(pr_odd_str)