Ejemplo n.º 1
1
    def layout(self):
        self.user = ''

        def on_text_email(instance, value):
            self.user = str(value)
            setButtonColor()

        layout = BoxLayout(
                        orientation= 'vertical',
                        padding= (dp(48),2*dp(48)),
                        spacing= dp(48),
                        )

        userField = MDTextField()
        userField.hint_text = "Enter user ID"
        userField.bind(text=on_text_email)
        layout.add_widget(userField)

        proceedButton = MDRaisedButton(text='Enter Information', size_hint=(None, None),size= (4*dp(48),dp(48)))
        proceedButton.md_bg_color = [0.9, 0, 0, 0.9]
        app = App.get_running_app()

        def setButtonColor():
            if self.user != '':
                proceedButton.text = 'Proceed'
                proceedButton.md_bg_color = app.theme_cls.primary_color
                proceedButton.bind(on_press=lambda x: self.processInformation())

        proceedAnchor = AnchorLayout(anchor_x='center',anchor_y='center')
        proceedAnchor.add_widget(proceedButton)
        layout.add_widget(proceedAnchor)

        return layout
Ejemplo n.º 2
0
    def layout(self):
        self.charge = False
        self.amount = ''
        self.ready = False

        def on_text_charge(instance, value):
            self.amount = value
            if len(value) >= 1:
                self.ready = True
            else:
                self.ready = False
            setButtonColor()

        layout = BoxLayout(orientation='vertical',
                           padding=(2 * dp(48), 2 * dp(48)))

        #Charge Box
        chargeField = MDTextField()
        chargeField.hint_text = "Enter Amount to Charge"
        chargeField.input_filter = "int"
        chargeField.bind(text=on_text_charge)
        layout.add_widget(chargeField)

        proceedButton = MDRaisedButton(text='Proceed',
                                       size_hint=(None, None),
                                       size=(4 * dp(48), dp(48)))
        proceedButton.md_bg_color = [0.9, 0, 0, 0.9]

        app = App.get_running_app()

        def setButtonColor():
            if self.ready:
                proceedButton.md_bg_color = app.theme_cls.primary_color
                proceedButton.bind(on_press=lambda x: self.createCharge())

        proceedAnchor = AnchorLayout(anchor_x='center',
                                     anchor_y='bottom',
                                     padding=[60])
        proceedAnchor.add_widget(proceedButton)
        layout.add_widget(proceedAnchor)

        content = Builder.load_string(spinner)
        self.stripepopup = Popup(title='Charging Card',
                                 title_align='center',
                                 size_hint=(None, None),
                                 size=(dp(200), dp(200)))
        self.stripepopup.add_widget(content)
        self.stripepopup.title_font = 'data/fonts/Roboto-Bold.ttf'
        self.stripepopup.title_color = App.get_running_app(
        ).theme_cls.primary_color
        self.stripepopup.separator_color = App.get_running_app(
        ).theme_cls.primary_color
        self.stripepopup.background = str(
            Atlas('{}round_shadow.atlas'.format(images_path)))

        return layout
Ejemplo n.º 3
0
    def matblock(self):
        b = MDTextField(text='0', hint_text='0', padding_x=20)
        b.bind(text=self.checktext)

        return b
Ejemplo n.º 4
0
 def generate_screens(self):
     for group in group_cells:
         for c in items[group]:
             if type(c) == dict:
                 temp_screen = Screen(name=c.keys()[0])
                 temp_items = c[c.keys()[0]]
             else:
                 temp_screen = Screen(name=c)
                 temp_items = c
             main_container = BoxLayout(id='main_container',
                                        orientation='vertical',
                                        padding=[dp(10), 0, 0, 0],
                                        spacing=dp(20))
             if not type(temp_items) == str:
                 for i, value in enumerate(temp_items):
                     #print value
                     temp_box = BoxLayout(orientation='horizontal',
                                          size_hint_y=0.1)
                     temp_label = MDLabel(id='label' + str(i),
                                          font_style="Caption",
                                          halign="left",
                                          text=value,
                                          theme_text_color='Secondary'
                                          if self._app.theme_cls.theme_style
                                          == 'Light' else 'Primary')
                     temp_checkbox = MDResetCheckbox(pass_text=value,
                                                     size_hint=(None, None),
                                                     size=(dp(48), dp(48)),
                                                     pos_hint={
                                                         'center_x': 0.25,
                                                         'center_y': 0.5
                                                     })
                     temp_checkbox.bind(state=self.aux_populate)
                     self.bind(reset=temp_checkbox.set_active_false)
                     temp_box.add_widget(temp_label)
                     temp_box.add_widget(temp_checkbox)
                     main_container.add_widget(temp_box)
             else:
                 temp_box = BoxLayout(orientation='horizontal',
                                      size_hint_y=0.1)
                 if temp_items == 'Create other type':
                     temp_checkbox = MDResetCheckbox(size_hint=(None, None),
                                                     size=(dp(48), dp(48)),
                                                     pos_hint={
                                                         'center_x': 0.25,
                                                         'center_y': 0.5
                                                     })
                     temp_text_field = MDTextField(color_mode='accent')
                     temp_text_field.bind(
                         text=temp_checkbox.setter('pass_text'))
                     temp_box.add_widget(temp_text_field)
                 else:
                     temp_label = MDLabel(id='label1',
                                          font_style="Caption",
                                          halign="left",
                                          text=temp_items,
                                          theme_text_color='Secondary'
                                          if self._app.theme_cls.theme_style
                                          == 'Light' else 'Primary')
                     temp_box.add_widget(temp_label)
                     temp_checkbox = MDResetCheckbox(pass_text=temp_items,
                                                     size_hint=(None, None),
                                                     size=(dp(48), dp(48)),
                                                     pos_hint={
                                                         'center_x': 0.25,
                                                         'center_y': 0.5
                                                     })
                 temp_checkbox.bind(state=self.aux_populate)
                 self.bind(reset=temp_checkbox.set_active_false)
                 temp_box.add_widget(temp_checkbox)
                 main_container.add_widget(temp_box)
             main_container.add_widget(BoxLayout())
             temp_screen.add_widget(main_container)
             self.add_widget(temp_screen)
Ejemplo n.º 5
0
class StripeMD(BoxLayout):
    def __init__(self, **kwargs):
        super(StripeMD, self).__init__(**kwargs)
        self.util = kwargs.get('util')
        key = kwargs.get('key')
        layout = self.layout()
        self.add_widget(layout)
        if platform in ["ios", "android"]:
            self.stripe = Stripe.StripeToken()
            self.stripeUtil = Stripe.StripeUtil()
            self.stripeUtil.stripekey = key

    def layout(self):

        self.paymentDict = {}
        self.card = False
        self.year = False
        self.month = False
        self.cvc = False

        def on_text_card(instance, value):
            if len(value) == 16:
                self.card = True
                self.paymentDict['card'] = str(value)
            else:
                self.card = False
            setButtonColor()

        def on_text_month(instance, value):
            if len(value) == 2:
                self.month = True
                self.paymentDict['month'] = str(value)
            else:
                self.month = False
            setButtonColor()

        def on_text_year(instance, value):
            if len(value) == 4:
                self.year = True
                self.paymentDict['year'] = str(value)
            else:
                self.year = False
            setButtonColor()

        def on_text_cvc(instance, value):
            if len(value) == 3:
                self.cvc = True
                self.paymentDict['cvc'] = str(value)
            else:
                self.cvc = False
            setButtonColor()

        layout = BoxLayout(orientation='vertical',
                           padding=(2 * dp(48), 2 * dp(48)))
        # Credit Card Input
        self.creditCardField = MDTextField()
        self.creditCardField.hint_text = "Credit Card Number"
        self.creditCardField.input_filter = 'int'
        self.creditCardField.max_text_length = 16
        self.creditCardField.bind(text=on_text_card)
        layout.add_widget(self.creditCardField)

        # Exp date input
        dateBox = BoxLayout()
        self.expMonth = MDTextField(
        )  # This is the color used by the textfield
        self.expMonth.hint_text = "Exp Month"
        self.expMonth.input_filter = 'int'
        self.expMonth.max_text_length = 2
        self.expMonth.bind(text=on_text_month)
        self.expYear = MDTextField()
        self.expYear.hint_text = "Exp Year"
        self.expYear.input_filter = 'int'
        self.expYear.max_text_length = 4
        self.expYear.bind(text=on_text_year)
        dateBox.add_widget(self.expMonth)
        dateBox.add_widget(self.expYear)
        layout.add_widget(dateBox)
        # CVC
        cvcBox = BoxLayout()
        self.cvcTextField = MDTextField()
        self.cvcTextField.hint_text = "CVC"
        self.cvcTextField.helper_text = "3 digit number on back of card"
        self.cvcTextField.helper_text_mode = "on_focus"
        self.cvcTextField.input_filter = "int"
        self.cvcTextField.bind(text=on_text_cvc)
        blankWidget8 = MDLabel(text='')
        cvcBox.add_widget(self.cvcTextField)
        cvcBox.add_widget(blankWidget8)
        layout.add_widget(cvcBox)

        # Combined Boxes into
        proceedButton = MDRaisedButton(text='Enter Credit Card',
                                       size_hint=(None, None),
                                       size=(4 * dp(48), dp(48)))
        proceedButton.md_bg_color = [0.9, 0, 0, 0.9]
        # proceedButton.bind(on_press=lambda x: self.processInformation(paymentDict))
        self.app = App.get_running_app()

        def setButtonColor():
            if all([self.card, self.year, self.month, self.cvc]):
                proceedButton.md_bg_color = self.app.theme_cls.primary_color
                proceedButton.text = 'Proceed'
                proceedButton.bind(
                    on_press=lambda x: self.processInformation())
            else:
                proceedButton.unbind

        proceedAnchor = AnchorLayout(anchor_x='center', anchor_y='bottom')
        proceedAnchor.add_widget(proceedButton)
        # #Combine all together
        layout.add_widget(proceedAnchor)

        content = Builder.load_string(spinner)
        self.authenPopup = Popup(title='Authorizing...',
                                 title_align='center',
                                 size_hint=(None, None),
                                 size=(dp(200), dp(200)))
        self.authenPopup.add_widget(content)
        self.authenPopup.title_font = 'data/fonts/Roboto-Bold.ttf'
        self.authenPopup.title_color = App.get_running_app(
        ).theme_cls.primary_color
        self.authenPopup.separator_color = App.get_running_app(
        ).theme_cls.primary_color
        self.authenPopup.background = str(
            Atlas('{}round_shadow.atlas'.format(images_path)))

        return layout

    def processInformation(self):
        self.card = False
        self.year = False
        self.month = False
        self.cvc = False

        self.creditCardField.text = ''
        self.expYear.text = ''
        self.expMonth.text = ''
        self.cvcTextField.text = ''

        #Create pop up for process delay
        self.authenPopup.open()

        if platform in ["ios", "android"]:
            #THIS IS WHERE STRIP STARTS
            #send all the card info to stripe
            #to generate a token
            self.stripe.genToken(self.stripeUtil, self.paymentDict['card'],
                                 int(self.paymentDict['month']),
                                 int(self.paymentDict['year']),
                                 self.paymentDict['cvc'])
            self.paymentDict = {}
            #Now we wait for stripe to generate our token
            self.event = Clock.schedule_interval(self.set_popup, 0.1)
        else:
            self.event = Clock.schedule_interval(self.os_error_popup, 0.1)

    def os_error_popup(self, dt):
        self.authenPopup.titel = "Stripe only \nWorks in ios\n and Android"
        time.sleep(2)
        self.authenPopup.dismiss()
        self.event.cancel()

    def set_popup(self, dt):
        #This section acts as a callback for our stripe token
        #Once it is no longer empty, proceed to check the token
        #for authenticity
        if self.stripeUtil.token != "":
            #Error token "Your card's number is invalid"
            if 'invalid' in self.stripeUtil.token:
                self.authenPopup.title = "Invalid Card"
                time.sleep(1)
                self.authenPopup.dismiss()
                self.event.cancel()
            else:
                #Send the stripe token to your server and wait for your rsp
                status = self.util.sendTokenToServer(self.stripeUtil.token,
                                                     self.util.user)
                if status == True:
                    self.authenPopup.content = "Created user succesfully"
                    time.sleep(1)
                    self.authenPopup.dismiss()
                    self.event.cancel()
                    self.changeScreen()
                else:
                    self.authenPopup.content = "Authenticating Failed"
                    time.sleep(1)
                    self.authenPopup.dismiss()
                    self.event.cancel()

    def clearTextFields(self):
        self.securityCode.text = ''
        self.zipcode.text = ''
        self.experationMonth.text = ''
        self.experationYear.text = ''
        self.cardNumber.text = ''
        self.Name.text = ''

    def changeScreen(self):
        if self.util.screenchange:
            self.manager.current = self.util.screenchange
Ejemplo n.º 6
0
 def show_dialog(self, dialog_type, userid='', filename=''):
     """
     :param dialog_type: offline, login, connection, file_request, refused, logout, add_friend
     :return: None
     """
     if dialog_type == 'offline':
         label_text = 'This friend is currently offline'
         dialog_text = 'Friend is offline'
     elif dialog_type == 'login':
         label_text = 'Please Check your username and password'
         dialog_text = 'Wrong username/password!'
     elif dialog_type == 'connection':
         label_text = 'Please Check your Internet Connection'
         dialog_text = 'Connection Failed'
     elif dialog_type == 'file_request':
         label_text = 'Your Friend {} want to send file {} to you, do you want to accept?'.format(
             userid, filename)
         dialog_text = 'Sending File Request'
     elif dialog_type == 'refused':
         label_text = 'Your request to send file are refused'
         dialog_text = 'Request Refused'
     elif dialog_type == 'logout':
         label_text = 'Cannot connect to server, logout failed'
         dialog_text = 'Logout Error'
     elif dialog_type == 'add_friend':
         label_text = ''
         dialog_text = "Please Input your friend's userid"
     else:
         raise Exception, 'No such dialog_type'
     if dialog_type == 'add_friend':
         content = MDTextField(id='friend_name',
                               hint_text='friend name',
                               required=True,
                               color_mode='accent',
                               helper_text='your friend userid',
                               helper_text_mode='on_focus')
     else:
         content = MDLabel(font_style='Body1',
                           theme_text_color='Secondary',
                           text=label_text,
                           size_hint_y=None,
                           valign='top')
         content.bind(texture_size=content.setter('size'))
     self.error_dialog = MDDialog(title=dialog_text,
                                  content=content,
                                  size_hint=(.8, None),
                                  height=dp(200),
                                  auto_dismiss=False)
     self.error_dialog.add_action_button(
         "OK",
         action=lambda *x: self.dialog_dismiss(dialog_type, userid, filename
                                               ))
     if dialog_type == 'file_request':
         self.error_dialog.add_action_button(
             "NO",
             action=lambda *x: self.dialog_dismiss('{}_no'.format(
                 dialog_type)))
     if dialog_type == 'add_friend':
         self.error_dialog.add_action_button(
             "Cancel",
             action=lambda *x: self.dialog_dismiss('{}_cancel'.format(
                 dialog_type)))
     self.error_dialog.open()