Exemplo n.º 1
0
 def errormsg(self):
     self.popup.dismiss()
     self.box1 = BoxLayout(orientation='horizontal', spacing=15, padding=20)
     self.box = BoxLayout(orientation='vertical', spacing=15, padding=20)
     self.box.add_widget(
         MDLabel(halign="center",
                 text="Connection Error....",
                 font_style="H4",
                 theme_text_color="Primary"))
     self.box.add_widget(self.box1)
     self.box1.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Retry",
                               theme_text_color="Custom",
                               text_color=(0, 0, 0, 0),
                               on_release=self.retry))
     self.box1.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Exit",
                               theme_text_color="Custom",
                               text_color=(0, 0, 0, 0),
                               on_release=self.PopDismiss))
     self.popup2 = Popup(
         auto_dismiss=False,
         separator_height=0,
         title="",
         content=self.box,
         size_hint=(1, .5),
     )
     self.popup2.open()
Exemplo n.º 2
0
 def loadscreen(self):
     self.box1 = BoxLayout(orientation='horizontal', spacing=15)
     self.box = BoxLayout(orientation='vertical', spacing=15, padding=20)
     self.box.add_widget(
         MDLabel(halign="center",
                 text="It Will Take Some Time....",
                 font_style="H4",
                 theme_text_color="Primary"))
     self.box.add_widget(self.box1)
     self.box1.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Ok",
                               on_release=self.get_info))
     self.box1.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Exit",
                               on_release=self.PopDismiss))
     self.popup = Popup(
         auto_dismiss=False,
         separator_height=0,
         title="",
         content=self.box,
         size_hint=(1, .5),
     )
     self.popup.open()
Exemplo n.º 3
0
    def makeButtonForStream(self, name):
        "Make a button that, when pressed, edits the stream in the title"

        btn = Button(text=name)

        def f(*a):
            self.editStream(name)

        btn.bind(on_press=f)
        return btn
    def makeButtonForLocalService(self, name, c=None):
        "Make a button that, when pressed, edits the local service in the title"

        btn = Button(text=name)

        def f(*a):
            self.editLocalService(name, c)

        btn.bind(on_press=f)

        return btn
Exemplo n.º 5
0
 def create_special_row(self):
     """Creates the last row, which contains the button to get the 'analysis' """
     row = MDBoxLayout(spacing=dp(50))
     button = MDFillRoundFlatButton(
         text='Get more info!',
         on_release=lambda x: self.show_confirmation_dialog())
     button.text_color = (1, 1, 1, 1)
     button.font_name = 'fonts/Montserrat-Regular.ttf'
     button.md_bg_color = (0.91, 0.46, 0.07, 1)
     row.add_widget(Widget())  # To center the button
     row.add_widget(button)
     row.add_widget(Widget())
     return row
Exemplo n.º 6
0
    def goToGlobalSettings(self, *a):
        if os.path.exists(hardline.globalSettingsPath):
            with open(hardline.globalSettingsPath) as f:
                globalConfig = toml.load(f)
        else:
            globalConfig = {}

        self.localSettingsBox.clear_widgets()

        self.localSettingsBox.add_widget(
            Label(size_hint=(1, 6), halign="center", text='OpenDHT Proxies'))
        self.localSettingsBox.add_widget(
            Label(size_hint=(1, None),
                  text='Proxies are tried in order from 1-3'))

        self.localSettingsBox.add_widget(
            self.settingButton(globalConfig, "DHTProxy", 'server1'))
        self.localSettingsBox.add_widget(
            self.settingButton(globalConfig, "DHTProxy", 'server2'))
        self.localSettingsBox.add_widget(
            self.settingButton(globalConfig, "DHTProxy", 'server3'))

        self.localSettingsBox.add_widget(
            Label(size_hint=(1, 6), halign="center", text='Stream Server'))
        self.localSettingsBox.add_widget(
            Label(
                size_hint=(1, None),
                text=
                'To allow others to sync to this node as a DrayerDB Stream server, set a server title to expose a service'
            ))

        self.localSettingsBox.add_widget(
            self.settingButton(globalConfig, "DrayerDB", 'serverName'))

        btn1 = Button(text='Save')

        def save(*a):
            with open(hardline.globalSettingsPath, 'w') as f:
                toml.dump(globalConfig, f)
            if platform == 'android':
                self.stop_service()
                self.start_service()
            else:
                daemonconfig.loadDrayerServerConfig()

            self.screenManager.current = "Main"

        btn1.bind(on_press=save)
        self.localSettingsBox.add_widget(btn1)
        self.screenManager.current = "GlobalSettings"
Exemplo n.º 7
0
def thirdPopup():
    show = P3()
    # create content for the Popup
    bl = BoxLayout(orientation='vertical', padding=30)
    label = Label(
        text=
        ' Dimensional measurements \n missing. Please fill all the \n required measurements.',
        halign='center',
        valign='middle',
        color=[1, 1, 1, 1],
        font_size='18dp')

    bl.add_widget(label)
    popupWindow = Popup(title="ERROR",
                        title_color=[1, 0, 0, 1],
                        title_size='25dp',
                        separator_color=[1, 0.4, 0, 1],
                        content=bl,
                        size_hint=(None, None),
                        size=('350dp', '350dp'))

    btn = MDFillRoundFlatButton(text='OK got it !!!',
                                size_hint=(0.7, 0.3),
                                pos_hint={'center_x': 0.5},
                                on_release=popupWindow.dismiss)

    bl.add_widget(btn)
    popupWindow.open()
Exemplo n.º 8
0
def diamPopup():
    show = Pdiam()
    # create content for the Popup
    bl = BoxLayout(orientation='vertical', padding=30)
    label = Label(
        text=
        ' Diameter  has to be positive number. \n Please try again with a positive value',
        halign='center',
        valign='middle',
        color=[1, 1, 1, 1],
        font_size='18dp')

    bl.add_widget(label)
    popupWindow = Popup(title="ERROR",
                        title_color=[1, 0, 0, 1],
                        title_size='25dp',
                        separator_color=[1, 0.4, 0, 1],
                        content=bl,
                        size_hint=(None, None),
                        size=('350dp', '350dp'))

    btn = MDFillRoundFlatButton(text='OK got it !!!',
                                size_hint=(0.7, 0.3),
                                pos_hint={'center_x': 0.5},
                                on_release=popupWindow.dismiss)

    bl.add_widget(btn)
    popupWindow.open()
Exemplo n.º 9
0
def firstPopup():
    show = P()
    #create content for the Popup
    bl = BoxLayout(orientation='vertical', padding=30)
    label = Label(
        text='You should put exactly 3 \n variables at the first segment',
        halign='center',
        valign='middle',
        color=[1, 1, 1, 1],
        font_size='18dp')
    bl.add_widget(label)

    popupWindow = Popup(title="ERROR",
                        title_color=[1, 0, 0, 1],
                        title_size='25dp',
                        separator_color=[1, 0.4, 0, 1],
                        content=bl,
                        size_hint=(None, None),
                        size=('350dp', '350dp'))

    btn = MDFillRoundFlatButton(text='OK got it !!!',
                                size_hint=(0.7, 0.3),
                                pos_hint={'center_x': 0.5},
                                on_release=popupWindow.dismiss)

    bl.add_widget(btn)
    popupWindow.open()
Exemplo n.º 10
0
def error_Popup():
    # show = P()
    #create content for the Popup
    bl = BoxLayout(orientation='vertical', padding=30)
    label = Label(text ='This combination of non dimensional \n'\
                        'input has infinite solutions. Please \n'\
                        'fill in one more coefficient or angle ',halign = 'center',
                  valign = 'middle', color =[1, 1, 1, 1],font_size = '18dp')

    bl.add_widget(label)

    popupWindow = Popup(title="ERROR",
                        title_color=[1, 0, 0, 1],
                        title_size='25dp',
                        separator_color=[1, 0.4, 0, 1],
                        content=bl,
                        size_hint=(None, None),
                        size=('350dp', '350dp'))

    btn = MDFillRoundFlatButton(text='OK got it !!!',
                                size_hint=(0.7, 0.3),
                                pos_hint={'center_x': 0.5},
                                on_release=popupWindow.dismiss)

    bl.add_widget(btn)
    popupWindow.open()
Exemplo n.º 11
0
def secondPopup():
    show = P2()
    # create content for the Popup
    bl = BoxLayout(orientation='vertical', padding=30)
    label = Label(text='  This combination of variables\n'
                  '  is   not  valid.   \u03B11   has  to   be \n'
                  '  greater  than  \u03B21  and \u03B12  has \n'
                  '  to be greater than \u03B22. Please\n'
                  '  try  again with new  variables',
                  halign='center',
                  valign='middle',
                  color=[1, 1, 1, 1],
                  font_size='18dp')

    bl.add_widget(label)
    popupWindow = Popup(title="ERROR",
                        title_color=[1, 0, 0, 1],
                        title_size='25dp',
                        separator_color=[1, 0.4, 0, 1],
                        content=bl,
                        size_hint=(None, None),
                        size=('350dp', '350dp'))

    btn = MDFillRoundFlatButton(text='OK got it !!!',
                                text_color=[0.5, 1, 1, 1],
                                size_hint=(0.7, 0.3),
                                pos_hint={'center_x': 0.5},
                                on_release=popupWindow.dismiss)

    bl.add_widget(btn)
    popupWindow.open()
    def __init__(self, **kwargs):
        super().__init__()
        self.app = MDApp.get_running_app()

        self.buttonPDF = MDFillRoundFlatButton(  # BOTON PARA GENERAR PDF
            pos_hint={
                "x": .05,
                "y": .1
            },
            size_hint=(.40, .1),
            text="Crear PDF",
            on_release=lambda x: self.opcionPDF())

        self.buttonEXP = MDFillRoundFlatButton(  # BOTON PARA EXPORTAR PDF
            pos_hint={
                "x": .55,
                "y": .1
            },
            size_hint=(.40, .1),
            text="Exportar PDF a Drive",
            on_release=lambda x: self.exportarPDF())

        self.buttontabla = MDFillRoundFlatButton(  #Boton para mostrar tabla
            pos_hint={
                "x": .3,
                "y": .3
            },
            size_hint=(.40, .1),
            text="Consultar Productos",
            on_release=lambda x: self.tablaproductos())

        self.buttonconsulta = MDFillRoundFlatButton(  # Boton para mostrar tabla
            pos_hint={
                "x": .5,
                "y": .3
            },
            size_hint=(.40, .1),
            text="Consulta de prueba",
            on_release=lambda x: self.prueba())

        #self.add_widget(self.buttonconsulta)

        #self.add_widget(self.data_tables)#####
        self.add_widget(self.buttonPDF)
        self.add_widget(self.buttonEXP)
        self.add_widget(self.buttontabla)
Exemplo n.º 13
0
    def makeLocalServicesPage(self):

        screen = Screen(name='LocalServices')
        self.servicesScreen = screen

        layout = BoxLayout(orientation='vertical', spacing=10)
        screen.add_widget(layout)

        label = Label(
            size_hint=(1, None),
            halign="center",
            text=
            'WARNING: Running a local service may use a lot of data and battery.\nChanges may require service restart.'
        )

        labelw = Label(
            size_hint=(1, None),
            halign="center",
            text=
            'WARNING 2: This app currently prefers the external SD card for almost everything including the keys.'
        )

        layout.add_widget(self.makeBackButton())

        layout.add_widget(label)
        layout.add_widget(labelw)

        btn2 = Button(text='Create a service')

        btn2.bind(on_press=self.promptAddService)
        layout.add_widget(btn2)

        self.localServicesListBoxScroll = ScrollView(size_hint=(1, 1))

        self.localServicesListBox = BoxLayout(orientation='vertical',
                                              size_hint=(1, None),
                                              spacing=10)
        self.localServicesListBox.bind(
            minimum_height=self.localServicesListBox.setter('height'))

        self.localServicesListBoxScroll.add_widget(self.localServicesListBox)

        layout.add_widget(self.localServicesListBoxScroll)

        return screen
Exemplo n.º 14
0
 def sh_delete_item(self):
     yes_button = MDFillRoundFlatButton(text="Zmazať",
                                        on_release=self.close_del_dialog,
                                        on_press=self.delete_item)
     no_button = MDRoundFlatButton(text="Zrušiť",
                                   on_release=self.close_del_dialog)
     self.del_dialog = MDDialog(title="Naozaj zmazať test?",
                                size_hint=[0.8, 0.5],
                                auto_dismiss=False,
                                buttons=[no_button, yes_button])
     self.del_dialog.open()
Exemplo n.º 15
0
    def _update(self):  
        
        if not self.button:
            self.button= MDFillRoundFlatButton(text="Ok")

        if not self.spinner:
            self.spinner= AKSpinnerDoubleBounce()
            
        self.button.pos_hint= {'center_x': .5, 'center_y': .5}
        self.button.bind(on_release=self._submit)

        self.spinner.pos_hint= {'center_x': .5, 'center_y': .5}

        self.ids.float_box.add_widget(self.button)
        self.ids.float_box.add_widget(self.spinner)

        self.ids.float_box.size = self.button.size
        self.spinner.spinner_size= self.button.height

        self._success_box_size= [0,self.button.height ]
        self._failure_box_size= [0,self.button.height ]
Exemplo n.º 16
0
                def scope(info):
                    btn = Button(text="Open in Browser")

                    def f(*a):
                        self.openInBrowser("http://" + info['hash'] +
                                           ".localhost:7009")

                    btn.bind(on_press=f)

                    l.add_widget(btn)

                    btn = Button(text="Copy URL")

                    def f(*a):
                        try:
                            from kivy.core.clipboard import Clipboard
                            Clipboard.copy("http://" + info['hash'] +
                                           ".localhost:7009")
                        except:
                            logging.exception("Could not copy to clipboard")

                    btn.bind(on_press=f)

                    self.localServicesListBox.add_widget(
                        MDToolbar(title=str(info.get('title', 'no title'))))

                    l.add_widget(btn)
Exemplo n.º 17
0
 def retry(self, *args):
     self.promtmsg = False
     self.againmsg = True
     self.error.dismiss()
     self.boxwithbutton = BoxLayout(orientation="horizontal",
                                    padding=15,
                                    spacing=15)
     self.boxwithmsg = BoxLayout(orientation="vertical",
                                 padding=15,
                                 spacing=15)
     self.boxcontain = BoxLayout(orientation="vertical",
                                 padding=15,
                                 spacing=15)
     self.boxwithmsg.add_widget(
         MDLabel(halign="center",
                 font_style="H4",
                 theme_text_color="Primary",
                 text="This Will Take Some Time!"))
     self.boxwithbutton.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Okay",
                               theme_text_color="Custom",
                               text_color=(0, 0, 0, 0),
                               on_release=self.getinfo))
     self.boxwithbutton.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Exit",
                               theme_text_color="Custom",
                               text_color=(0, 0, 0, 0),
                               on_release=self.close))
     self.boxcontain.add_widget(self.boxwithmsg)
     self.boxcontain.add_widget(self.boxwithbutton)
     self.again = Popup(
         auto_dismiss=False,
         separator_height=0,
         title="",
         content=self.boxcontain,
         size_hint=(1, .5),
     )
     self.again.open()
Exemplo n.º 18
0
 def errormsg(self, *args):
     self.confirm.dismiss()
     self.boxwithbutton = BoxLayout(orientation="horizontal",
                                    padding=15,
                                    spacing=15)
     self.boxwithmsg = BoxLayout(orientation="vertical",
                                 padding=15,
                                 spacing=15)
     self.boxcontain = BoxLayout(orientation="vertical",
                                 padding=15,
                                 spacing=15)
     self.boxwithmsg.add_widget(
         MDLabel(halign="center",
                 font_style="H4",
                 theme_text_color="Primary",
                 text="Unable To Contact The Server!"))
     self.boxwithbutton.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Try Again",
                               theme_text_color="Custom",
                               text_color=(0, 0, 0, 0),
                               on_release=self.retry))
     self.boxwithbutton.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Exit",
                               theme_text_color="Custom",
                               text_color=(0, 0, 0, 0),
                               on_release=self.close))
     self.boxcontain.add_widget(self.boxwithmsg)
     self.boxcontain.add_widget(self.boxwithbutton)
     self.error = Popup(
         auto_dismiss=False,
         separator_height=0,
         title="",
         content=self.boxcontain,
         size_hint=(1, .5),
     )
     self.error.open()
Exemplo n.º 19
0
 def load_resources_page(self):
     self.ids['float_lay'].clear_widgets()
     ContentNavigationDrawer.populateNavDrawerValues(self)
     query = f'''SELECT NAME,SUM(UNITS) AS UNITS, SUM(AMOUNT) AS AMOUNT
     FROM RESOURCES WHERE ACTIVITY_ID = {globalvariables.var_act_id}
     GROUP BY NAME ORDER BY NAME   '''
     # run direct SQL
     stmt = ibm_db.exec_immediate(connection.conn, query)
     txnlist = ibm_db.fetch_both(stmt)
     if txnlist is False :
         warn_label = MDLabel(pos_hint = {'center_x':0.5, 'center_y':0.5},font_size = '10sp',
         text = "No Resources yet")
         self.ids['float_lay'].add_widget(warn_label)
     else:
         print(txnlist)
         tlist=[]
         while(txnlist):
             tlist.append([txnlist[0],str(txnlist[1]),str(txnlist[2])])
             txnlist = ibm_db.fetch_both(stmt)
         data_tables = MDDataTable(
             size_hint=(0.8, 0.8),
             rows_num=100,
             background_color=[1,0,0,1],
             pos_hint = {'center_x':0.5, 'center_y':0.5},
             column_data=[
                 ("Resource", dp(50)),
                 ("Units", dp(50)),
                 ("Amount", dp(50)),
             ],
             row_data=[(f"{i[0]}",f"{i[1]}",f"{i[2]}") for i in tlist]
             )
         self.ids['float_lay'].add_widget(data_tables)
         self.ids['float_lay'].add_widget(MDFillRoundFlatButton(text="BACK",
         pos_hint={'center_x':0.3, 'center_y':0.1}, theme_text_color="Custom", 
         text_color= (0, 0, 1, 1), on_release=lambda x: self.to_previous_page() ))
         self.ids['float_lay'].add_widget(MDFillRoundFlatButton(text="DETAILS",
         pos_hint={'center_x':0.7, 'center_y':0.1}, theme_text_color="Custom", 
         text_color= (0, 0, 1, 1), on_release=lambda x: self.to_details_page() ))
Exemplo n.º 20
0
 def askif(self, *args):
     self.boxwithbutton = BoxLayout(orientation="horizontal",
                                    padding=15,
                                    spacing=15)
     self.boxwithmsg = BoxLayout(orientation="vertical",
                                 padding=15,
                                 spacing=15)
     self.boxcontain = BoxLayout(orientation="vertical",
                                 padding=15,
                                 spacing=15)
     self.boxwithmsg.add_widget(
         MDLabel(halign="center",
                 font_style="H4",
                 theme_text_color="Primary",
                 text="Are You Sure?"))
     self.boxwithbutton.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="Yes",
                               theme_text_color="Custom",
                               text_color=(0, 0, 0, 0),
                               on_release=self.close))
     self.boxwithbutton.add_widget(
         MDFillRoundFlatButton(font_size=20,
                               text="No",
                               theme_text_color="Custom",
                               text_color=(0, 0, 0, 0),
                               on_release=self.dis))
     self.boxcontain.add_widget(self.boxwithmsg)
     self.boxcontain.add_widget(self.boxwithbutton)
     self.askmsg = Popup(
         auto_dismiss=False,
         separator_height=0,
         title="",
         content=self.boxcontain,
         size_hint=(1, .5),
     )
     self.askmsg.open()
Exemplo n.º 21
0
 def load_hist_page(self):
     self.ids['float_lay'].clear_widgets()
     ContentNavigationDrawer.populateNavDrawerValues(self)
     query = f'''SELECT RES.DATE, CON.FIRST_NAME||' '||CON.LAST_NAME AS NAME, 
     RES.NAME AS ITEM, RES.DESC AS DESC, RES.UNITS, RES.AMOUNT
     FROM RESOURCES RES, CONTACT CON 
     WHERE RES.ACTIVITY_ID = {globalvariables.var_act_id}
     AND CON.CONTACT_ID = RES.CONTACT_ID  ORDER BY RES.DATE DESC '''
     # run direct SQL
     stmt = ibm_db.exec_immediate(connection.conn, query)
     txnlist = ibm_db.fetch_both(stmt)
     if txnlist is False :
         warn_label = MDLabel(pos_hint = {'center_x':0.5, 'center_y':0.5},font_size = '10sp',
         text = "No Resources yet")
         self.ids['float_lay'].add_widget(warn_label)
     else:
         print(txnlist)
         tlist=[]
         while(txnlist):
             tlist.append([txnlist[0],txnlist[1],txnlist[2], str(txnlist[3]), str(txnlist[4]), str(txnlist[5]) ])
             txnlist = ibm_db.fetch_both(stmt)
         data_tables = MDDataTable(
             size_hint=(0.8, 0.8),
             rows_num=100,
             background_color=[1,0,0,1],
             pos_hint = {'center_x':0.5, 'center_y':0.5},
             column_data=[
                 ("Date", dp(30)),
                 ("Name", dp(30)),
                 ("Item", dp(30)),
                 ("Description", dp(30)),
                 ("Units", dp(30)),
                 ("Amount", dp(30)),
             ],
             row_data=[(f"{i[0]}",f"{i[1]}",f"{i[2]}",f"{i[3]}",f"{i[4]}",f"{i[5]}") for i in tlist]
             )
         self.ids['float_lay'].add_widget(data_tables)
         self.ids['float_lay'].add_widget(MDFillRoundFlatButton(text="BACK",
         pos_hint={'center_x':0.5, 'center_y':0.1}, theme_text_color="Custom", 
         text_color= (0, 0, 1, 1), on_release=lambda x: self.to_previous_page() ))
Exemplo n.º 22
0
 def __init__(self, **kwargs):
     super(Class_Screen1, self).__init__(**kwargs)
     ###
     self.Drawing = Draw_Stuff()
     ###
     self.Now_Press_Me_Button = MDFillRoundFlatButton()
     self.Press_Me_Button = MDFillRoundFlatButton()
     self.Clear_Screen_Button = MDFillRoundFlatButton()
     self.BStop = MDFillRoundFlatButton()
     self.TFDisplay = MDTextField()
     ###
     self.LH = 0
     self.LW = 0
     self.Xo = 0
     self.Xf = 0
     self.Xc = 0
     self.Yo = 0
     self.Yf = 0
     self.Yc = 0
     self.StrTime = ''
     self.To = time.time()
     self.Tf = time.time()
     ###
     return
Exemplo n.º 23
0
class AKProgressbutton(BoxLayout):
    
    success_icon= StringProperty('check')
    success_text= StringProperty('Success')
    success_color= ListProperty([0,0.7,0,1])

    failure_icon= StringProperty('close')
    failure_text= StringProperty('Failed')
    failure_color= ListProperty([1,0,0,1])

    duration= NumericProperty(0.2)
    animation = StringProperty('out_quad')

    _success_box_size= ListProperty([0,0])
    _failure_box_size= ListProperty([0,0])
    _success_opacity= NumericProperty(0)
    _failure_opacity=NumericProperty(0)

    reset_timeout= NumericProperty(2)

    def __init__(self,button=None,spinner=None, **kwargs):
        super().__init__(**kwargs) 
        Clock.schedule_once(lambda x: self._update())
        self.button= button
        self.spinner= spinner

    def _update(self):  
        
        if not self.button:
            self.button= MDFillRoundFlatButton(text="Ok")

        if not self.spinner:
            self.spinner= AKSpinnerDoubleBounce()
            
        self.button.pos_hint= {'center_x': .5, 'center_y': .5}
        self.button.bind(on_release=self._submit)

        self.spinner.pos_hint= {'center_x': .5, 'center_y': .5}

        self.ids.float_box.add_widget(self.button)
        self.ids.float_box.add_widget(self.spinner)

        self.ids.float_box.size = self.button.size
        self.spinner.spinner_size= self.button.height

        self._success_box_size= [0,self.button.height ]
        self._failure_box_size= [0,self.button.height ]

    def _spinner_state(self,state):
        self.spinner.active= state

    def _submit(self, instance):
        self._spinner_state(True)
        self._hide_button()

    def _hide_button(self,*args):
        anim = Animation(opacity=0, duration=self.duration, t=self.animation)
        anim.start(self.button )
        self.button.disabled= True

    def success(self):
        self._spinner_state(False)
        anim_box = Animation(_success_opacity=1,_success_box_size=self.button.size, duration=self.duration, t=self.animation)
        anim_label = Animation(opacity=1, duration=self.duration, t=self.animation)
        
        anim_box.start(self)
        anim_label.start(self.ids._success_label)

        Clock.schedule_once(lambda x: self._reset(), self.reset_timeout+self.duration)

    def failure(self):
        self._spinner_state(False)
        anim_box = Animation(_failure_opacity=1,_failure_box_size=self.button.size, duration=self.duration, t=self.animation)
        anim_label = Animation(opacity=1, duration=self.duration, t=self.animation)
        
        anim_box.start(self)
        anim_label.start(self.ids._failure_label)

        Clock.schedule_once(lambda x: self._reset(), self.reset_timeout+self.duration)

    def _reset(self):
        self.button.disabled= False
        self._spinner_state(False)
        button_anim = Animation(opacity=1, duration=self.duration, t=self.animation)

        success_box = Animation(_success_opacity=0,_success_box_size=[0,self.button.height], duration=self.duration, t=self.animation)
        success_label = Animation(opacity=0, duration=self.duration, t=self.animation)

        failure_box = Animation(_failure_opacity=0,_failure_box_size=[0,self.button.height], duration=self.duration, t=self.animation)
        failure_label = Animation(opacity=0, duration=self.duration, t=self.animation)
        
        button_anim.start(self.button )
        success_box.start(self)
        success_label.start(self.ids._success_label)
        failure_box.start(self)
        failure_label.start(self.ids._failure_label)
Exemplo n.º 24
0
    def __init__(self, **kwargs):
        super(MDRaisedButton).__init__(**kwargs)
        super().__init__(**kwargs)
        self.i = Image()
        self.incoming = MDFillRoundFlatButton()
        self.msg = MDFillRoundFlatButton()
        self.incoming_text = MDLabel()
        self.text_msg = MDLabel()
        self.Box = MDBoxLayout()
        self.count = 0
        self.count_the_length = 0
        self.screen = MDGridLayout(
            cols=1,
            rows=2,
            md_bg_color=hex8("#00ffff"),
            size_hint=[1, 1])

        self.size = [1, 1]

        self.Scroll = ScrollView()
        self.Scroll.scroll_type = ["content", "bars"]
        self.Scroll.bar_color = hex8("#000000")
        self.Scroll.bar_width = "5dp"
        self.text = TextInput(
            font_name="Default.ttf",
            size_hint=[1, 1],
            font_size=23,
            multiline=False)

        self.button = MDRaisedButton(
            size_hint=[0.124, 0.124],
            font_name="Arial",
            on_press=lambda message:self.send_it(self.text.text))
        self.button.md_bg_color = hex8("#ff00ff")
        self.button.text = "send"
        self.button.text_color = hex8("#000000")

        self.Top = MDGridLayout(
            cols=2,
            rows=1,
            md_bg_color=hex8("#00ffff"),
            size_hint_x=1,
            size_hint_y=1,
            minimum_height=20)

        self.Container = MDBoxLayout(
            md_bg_color=hex8("#00ffff"),
            orientation="vertical",
            width=self.screen.width,
            height=self.screen.height)

        self.Bot = MDBoxLayout(
            md_bg_color=hex8("##00ffff"),
            orientation="vertical",
            width=self.screen.width,
            height=self.screen.height)

        self.bottom = MDGridLayout(
            cols=2,
            rows=1,
            md_bg_color=hex8("#00ffff"),
            width=200,
            height=200,
            size_hint=[.07, .07])

        self.bottom.add_widget(self.text)
        self.bottom.add_widget(self.button)
        self.Top.add_widget(self.Container)
        self.Top.add_widget(self.Bot)
        self.Scroll.size = [self.screen.width, self.screen.height]
        self.Scroll.add_widget(self.Top)
        self.screen.add_widget(self.Scroll)
        self.screen.add_widget(self.bottom)
        self.add_widget(self.screen)
Exemplo n.º 25
0
    def editStreamSettings(self, name):
        db = daemonconfig.userDatabases[name]
        c = db.config

        self.streamEditPanel.clear_widgets()

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None), halign="center", text=name))
        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  text="file:" + db.filename))

        self.streamEditPanel.add_widget(self.makeBackButton())

        def save(*a):
            logging.info("SAVE BUTTON WAS PRESSED")
            # On android this is the bg service's job
            db.saveConfig()

            if platform == 'android':
                self.stop_service()
                self.start_service()
            else:
                db.close()
                daemonconfig.loadUserDatabases(
                    None,
                    only=name,
                    callbackFunction=self.onDrayerRecordChange)

        def delete(*a):
            def f(n):
                if n and n == name:
                    daemonconfig.delDatabase(None, n)
                    if platform == 'android':
                        self.stop_service()
                        self.start_service()
                    self.goToStreams()

            self.askQuestion("Really delete?", name, f)

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  font_size="24sp",
                  text='Sync'))

        self.streamEditPanel.add_widget(
            keyBox := self.settingButton(c, "Sync", "syncKey"))

        self.streamEditPanel.add_widget(
            pBox := self.settingButton(c, "Sync", "writePassword"))

        self.streamEditPanel.add_widget(
            Label(
                size_hint=(1, None),
                halign="center",
                font_size="12sp",
                text=
                'Keys have a special format, you must use the generator to change them.'
            ))

        def promptNewKeys(*a, **k):
            def makeKeys(a):
                if a == 'yes':
                    import base64
                    vk, sk = libnacl.crypto_sign_keypair()
                    vk = base64.b64encode(vk).decode()
                    sk = base64.b64encode(sk).decode()
                    keyBox.text = vk
                    pBox.text = sk

            self.askQuestion("Overwrite with random keys?", 'yes', makeKeys)

        keyButton = Button(text='Generate New Keys')
        keyButton.bind(on_press=promptNewKeys)
        self.streamEditPanel.add_widget(keyButton)

        self.streamEditPanel.add_widget(
            serverBox := self.settingButton(c, "Sync", "server"))

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  text='Do not include the http:// '))

        self.streamEditPanel.add_widget(
            self.settingButton(c, "Sync", "serve", 'yes'))

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  text='Set serve=no to forbid clients to sync'))

        self.streamEditPanel.add_widget(
            Label(size_hint=(1, None),
                  halign="center",
                  font_size="24sp",
                  text='Application'))

        self.streamEditPanel.add_widget(
            self.settingButton(c, "Application", "notifications", 'no'))

        def f(*a):
            def g(a):
                try:
                    import json
                    a = json.loads(a)
                    serverBox.text = c['Sync'][
                        'server'] = a['sv'] or c['Sync']['server']
                    keyBox.text = c['Sync']['syncKey'] = a['vk']
                    pBox.text = c['Sync']['writePassword'] = a['sk']

                except:
                    pass

            self.askQuestion("Enter Sharing Code", cb=g, multiline=True)

        keyButton = Button(text='Load from Code')
        keyButton.bind(on_press=f)
        self.streamEditPanel.add_widget(keyButton)

        def f(*a):
            self.showSharingCode(name, c)

        keyButton = Button(text='Show Sharing Code')
        keyButton.bind(on_press=f)
        self.streamEditPanel.add_widget(keyButton)

        def f(*a):
            self.showSharingCode(name, c, wp=False)

        keyButton = Button(text='Readonly Sharing Code')
        keyButton.bind(on_press=f)
        self.streamEditPanel.add_widget(keyButton)

        btn1 = Button(text='Save Changes')

        btn1.bind(on_press=save)
        self.streamEditPanel.add_widget(btn1)

        btn2 = Button(text='Delete this stream')

        btn2.bind(on_press=delete)
        self.streamEditPanel.add_widget(btn2)

        def gotoOrphans(*a, **k):
            self.gotoStreamPosts(name, orphansMode=True)

        oButton = Button(text='Show Unreachable Garbage')
        oButton.bind(on_press=gotoOrphans)
        self.streamEditPanel.add_widget(oButton)

        noSpreadsheet = Button(text="Spreadsheet on/off")

        def promptSet(*a):
            from .kivymdfmfork import MDFileManager
            from .. import directories
            try:
                #Needed for android
                self.getPermission('files')
            except:
                logging.exception("cant ask permission")

            def f(selection):
                if selection == 'on':
                    daemonconfig.userDatabases[
                        name].enableSpreadsheetEval = True
                else:
                    daemonconfig.userDatabases[
                        name].enableSpreadsheetEval = False

            if hasattr(daemonconfig.userDatabases[name],
                       'enableSpreadsheetEval'):
                esf = daemonconfig.userDatabases[name].enableSpreadsheetEval
            else:
                esf = True

            self.askQuestion("Allow Spreadsheet Functions?",
                             'on' if esf else 'off', f)

        noSpreadsheet.bind(on_release=promptSet)
        self.streamEditPanel.add_widget(noSpreadsheet)
        self.streamEditPanel.add_widget(
            self.saneLabel(
                "Disabling only takes effect for this session. Use this feature if a stream is loading too slowly, to allow you to fix the offending expression.",
                self.streamEditPanel))

        self.screenManager.current = "EditStream"
Exemplo n.º 26
0
    def editStream(self, name):
        if not name in daemonconfig.userDatabases:
            self.goToStreams()
        db = daemonconfig.userDatabases[name]
        c = db.config
        try:
            c.add_section("Service")
        except:
            pass
        try:
            c.add_section("Info")
        except:
            pass

        self.streamEditPanel.clear_widgets()
        topbar = BoxLayout(size_hint=(1, None),
                           adaptive_height=True,
                           spacing=5)

        stack = StackLayout(size_hint=(1, None),
                            adaptive_height=True,
                            spacing=5)

        def upOne(*a):
            self.goToStreams()

        btn1 = Button(text='Up')

        btn1.bind(on_press=upOne)

        topbar.add_widget(btn1)

        topbar.add_widget(self.makeBackButton())

        self.streamEditPanel.add_widget(topbar)
        self.streamEditPanel.add_widget(MDToolbar(title=name))

        def goHere():
            self.editStream(name)

        self.backStack.append(goHere)
        self.backStack = self.backStack[-50:]

        btn2 = Button(text='Notebook View')

        def goPosts(*a):
            self.gotoStreamPosts(name)

        btn2.bind(on_press=goPosts)
        stack.add_widget(btn2)

        btn2 = Button(text='Feed View')

        def goPosts(*a):
            self.gotoStreamPosts(name, parent=None)

        btn2.bind(on_press=goPosts)
        stack.add_widget(btn2)

        btn2 = Button(text='Stream Settings')

        def goSettings(*a):
            self.editStreamSettings(name)

        btn2.bind(on_press=goSettings)
        stack.add_widget(btn2)

        if name.startswith('file:'):
            btn2 = Button(text='Close Stream')

            def close(*a):
                daemonconfig.closeUserDatabase(name)
                self.goToStreams()

            btn2.bind(on_press=close)
            stack.add_widget(btn2)

        importData = Button(text="Import Data File")

        def promptSet(*a):
            try:
                #Needed for android
                self.getPermission('files')
            except:
                logging.exception("cant ask permission")

            def f(selection):
                if selection:

                    def f2(x):
                        if x:
                            with daemonconfig.userDatabases[name]:
                                with open(selection) as f:
                                    daemonconfig.userDatabases[
                                        name].importFromToml(f.read())
                            daemonconfig.userDatabases[name].commit()

                    self.askQuestion("Really import?", "yes", cb=f2)
                self.openFM.close()

            from .kivymdfmfork import MDFileManager
            from . import directories
            self.openFM = MDFileManager(select_path=f)

            if os.path.exists("/storage/emulated/0/Documents") and os.access(
                    "/storage/emulated/0/Documents", os.W_OK):
                self.openFM.show("/storage/emulated/0/Documents")
            elif os.path.exists(
                    os.path.expanduser("~/Documents")) and os.access(
                        os.path.expanduser("~/Documents"), os.W_OK):
                self.openFM.show(os.path.expanduser("~/Documents"))
            else:
                self.openFM.show(directories.externalStorageDir
                                 or directories.settings_path)

        importData.bind(on_release=promptSet)
        stack.add_widget(importData)

        export = Button(text="Export All Posts")

        def promptSet(*a):
            from .kivymdfmfork import MDFileManager
            from .. import directories
            try:
                #Needed for android
                self.getPermission('files')
            except:
                logging.exception("cant ask permission")

            def f(selection):
                if selection:
                    if not selection.endswith(".toml"):
                        selection = selection + ".toml"

                    def g(a):
                        if a == 'yes':

                            r = daemonconfig.userDatabases[
                                name].getDocumentsByType('post', parent='')
                            data = daemonconfig.userDatabases[
                                name].exportRecordSetToTOML(
                                    [i['id'] for i in r])

                            logging.info("Exporting data to:" + selection)
                            with open(selection, 'w') as f:
                                f.write(data)
                        self.openFM.close()

                    if os.path.exists(selection):
                        self.askQuestion("Overwrite?", 'yes', g)
                    else:
                        g('yes')

            #Autocorrect had some fun with the kivymd devs
            self.openFM = MDFileManager(select_path=f,
                                        save_mode=(name + '.toml'))

            if os.path.exists("/storage/emulated/0/Documents") and os.access(
                    "/storage/emulated/0/Documents", os.W_OK):
                self.openFM.show("/storage/emulated/0/Documents")
            elif os.path.exists(
                    os.path.expanduser("~/Documents")) and os.access(
                        os.path.expanduser("~/Documents"), os.W_OK):
                self.openFM.show(os.path.expanduser("~/Documents"))
            else:
                self.openFM.show(directories.externalStorageDir
                                 or directories.settings_path)

        export.bind(on_release=promptSet)

        stack.add_widget(export)

        self.streamEditPanel.add_widget(stack)

        #Show recent changes no matter where they are in the tree.
        #TODO needs to be hideable for anti-spoiler purposes in fiction.
        self.streamEditPanel.add_widget(MDToolbar(title="Recent Changes:"))

        for i in daemonconfig.userDatabases[name].getDocumentsByType(
                'post', orderBy='arrival DESC', limit=5):
            x = self.makePostWidget(name, i, includeParent=True)
            self.streamEditPanel.add_widget(x)

        self.screenManager.current = "EditStream"
Exemplo n.º 27
0
    def goToStreams(self, *a):

        "Go to a page wherein we can list user-modifiable services."
        self.streamsEditPanel.clear_widgets()

        layout = self.streamsEditPanel

        bar = BoxLayout(spacing=10, adaptive_height=True, size_hint=(1, None))

        stack = StackLayout(spacing=10,
                            adaptive_height=True,
                            size_hint=(1, None))
        layout.add_widget(bar)
        layout.add_widget(MDToolbar(title="My Streams"))

        layout.add_widget(stack)

        def upOne(*a):
            self.gotoMainScreen()

        btn1 = Button(text='Up')

        btn1.bind(on_press=upOne)

        bar.add_widget(btn1)
        bar.add_widget(self.makeBackButton())

        btn2 = Button(text='Create a Stream')

        btn2.bind(on_press=self.promptAddStream)
        stack.add_widget(btn2)

        def f(selection):
            if selection:
                dn = 'file:' + os.path.basename(selection)
                while dn in daemonconfig.userDatabases:
                    dn = dn + '2'
                try:
                    daemonconfig.loadUserDatabase(selection, dn)
                    self.editStream(dn)
                except:
                    logging.exception(dn)

            self.openFM.close()

        #This lets us view notebook files that aren't installed.
        def promptOpen(*a):

            try:
                #Needed for android
                self.getPermission('files')
            except:
                logging.exception("cant ask permission")

            from .kivymdfmfork import MDFileManager
            from . import directories
            self.openFM = MDFileManager(select_path=f)

            if os.path.exists("/storage/emulated/0/Documents") and os.access(
                    "/storage/emulated/0/Documents", os.W_OK):
                self.openFM.show("/storage/emulated/0/Documents")
            elif os.path.exists(
                    os.path.expanduser("~/Documents")) and os.access(
                        os.path.expanduser("~/Documents"), os.W_OK):
                self.openFM.show(os.path.expanduser("~/Documents"))
            else:
                self.openFM.show(directories.externalStorageDir
                                 or directories.settings_path)

        btn1 = Button(text='Open Book File')

        btn1.bind(on_press=promptOpen)

        stack.add_widget(btn1)

        def goHere():
            self.screenManager.current = "Streams"

        self.backStack.append(goHere)
        self.backStack = self.backStack[-50:]

        layout.add_widget(MDToolbar(title="Open Streams:"))

        try:
            s = daemonconfig.userDatabases
            time.sleep(0.5)
            for i in s:
                layout.add_widget(self.makeButtonForStream(i))
                try:
                    for j in daemonconfig.userDatabases[i].connectedServers:
                        if daemonconfig.userDatabases[i].connectedServers[
                                j] > (time.time() - (10 * 60)):
                            w = 'online'
                        else:
                            w = 'idle/offline'
                        layout.add_widget(
                            self.saneLabel(j[:28] + ": " + w, layout))
                except:
                    logging.exception("Error showing node status")

        except Exception:
            logging.info(traceback.format_exc())

        self.screenManager.current = "Streams"
Exemplo n.º 28
0
    def makeSettingsPage(self):
        page = Screen(name='Settings')

        layout = BoxLayout(orientation='vertical')
        page.add_widget(layout)
        label = MDToolbar(title="Settings and Tools")
        layout.add_widget(label)

        layout.add_widget(self.makeBackButton())

        log = Button(text='System Logs')

        btn1 = Button(text='Local Services')
        label1 = Label(halign="center",
                       text='Share a local webservice with the world')

        log.bind(on_release=self.gotoLogs)
        btn1.bind(on_press=self.goToLocalServices)
        layout.add_widget(log)

        layout.add_widget(btn1)
        layout.add_widget(label1)

        btn = Button(text='Global Settings')

        btn.bind(on_press=self.goToGlobalSettings)
        layout.add_widget(btn)

        # Start/Stop
        btn3 = Button(text='Stop')
        btn3.bind(on_press=self.stop_service)
        label3 = Label(
            size_hint=(1, None),
            halign="center",
            text=
            'Stop the background process.  It must be running to acess hardline sites.  Starting may take a few seconds.'
        )
        layout.add_widget(btn3)
        layout.add_widget(label3)

        btn4 = Button(text='Start or Restart.')
        btn4.bind(on_press=self.start_service)
        label4 = Label(
            size_hint=(1, None),
            halign="center",
            text='Restart the process. It will show in your notifications.')
        layout.add_widget(btn4)
        layout.add_widget(label4)

        layout.add_widget(Widget())

        return page
Exemplo n.º 29
0
class Class_Screen1(MDFloatLayout):

    #################################################
    def __init__(self, **kwargs):
        super(Class_Screen1, self).__init__(**kwargs)
        ###
        self.Drawing = Draw_Stuff()
        ###
        self.Now_Press_Me_Button = MDFillRoundFlatButton()
        self.Press_Me_Button = MDFillRoundFlatButton()
        self.Clear_Screen_Button = MDFillRoundFlatButton()
        self.BStop = MDFillRoundFlatButton()
        self.TFDisplay = MDTextField()
        ###
        self.LH = 0
        self.LW = 0
        self.Xo = 0
        self.Xf = 0
        self.Xc = 0
        self.Yo = 0
        self.Yf = 0
        self.Yc = 0
        self.StrTime = ''
        self.To = time.time()
        self.Tf = time.time()
        ###
        return

    #################################################
    def Initialize(self):
        ##############################
        # Universal Screen Dimensions
        self.size = Window.size
        self.LW = self.width
        self.LH = self.height
        if (self.LW >= self.LH):
            min = self.LH
        else:
            min = self.LW
        self.LW = int(min * 0.5)
        self.LH = int(min * 0.5)
        ##############################
        self.Xc = int(self.width * 0.5)
        self.Yc = int(self.height * 0.5)
        self.Xo = self.Xc - int(self.LW * 0.5)
        self.Xf = self.width - 5
        self.Yo = self.Yc - int(self.height * 0.5) + 5
        self.Yf = self.height - 5
        ##############################
        LHeight = self.height
        LHeight = int(LHeight / 16)
        ##############################
        self.Clear_Drawing_Window()
        self.Drawing.Draw_Frame(pScreen=self,
                                pXo=self.Xo,
                                pXf=self.Xf,
                                pYo=self.Yo,
                                pYf=self.Yf)
        self.Drawing.Show_Instructions(pScreen=self)
        ##############################
        self.Now_Press_Me_Button.size_hint_y = None
        self.Now_Press_Me_Button.text = 'NOW PRESS ME'
        self.Now_Press_Me_Button.height = LHeight
        self.Now_Press_Me_Button.x = int(self.Xo * 0.1)
        self.Now_Press_Me_Button.y = self.height - int(LHeight * 2)
        if (self.Now_Press_Me_Button.parent != None):
            self.remove_widget(self.Now_Press_Me_Button)
        ##############################
        self.BStop.size_hint_y = None
        self.BStop.text = 'TIMER'
        self.BStop.height = self.Now_Press_Me_Button.height
        self.BStop.x = self.Now_Press_Me_Button.x
        self.BStop.y = self.Now_Press_Me_Button.y - int(LHeight * 2)
        if (self.BStop.parent != None):
            self.remove_widget(self.BStop)
        ##############################
        self.Press_Me_Button.size_hint_y = None
        self.Press_Me_Button.text = 'PRESS ME'
        self.Press_Me_Button.height = self.Now_Press_Me_Button.height
        self.Press_Me_Button.x = self.Now_Press_Me_Button.x
        self.Press_Me_Button.y = self.BStop.y - int(LHeight * 2)
        if (self.Press_Me_Button.parent == None):
            self.add_widget(self.Press_Me_Button)
        ##############################
        self.Clear_Screen_Button.size_hint_y = None
        self.Clear_Screen_Button.text = 'Clear Screen'
        self.Clear_Screen_Button.height = self.Now_Press_Me_Button.height
        self.Clear_Screen_Button.x = self.Now_Press_Me_Button.x
        self.Clear_Screen_Button.y = self.Press_Me_Button.y - int(LHeight * 2)
        if (self.Clear_Screen_Button.parent == None):
            self.add_widget(self.Clear_Screen_Button)
        ##############################
        Y1 = self.Clear_Screen_Button.y - LHeight
        self.TFDisplay.size_hint = (None, None)
        self.TFDisplay.height = int(Y1 * 0.9)
        self.TFDisplay.width = int(self.Xo * 0.8)
        self.TFDisplay.x = self.Now_Press_Me_Button.x
        self.TFDisplay.y = self.Clear_Screen_Button.y - int(
            LHeight * 2) - self.TFDisplay.height
        self.TFDisplay.text = self.StrTime
        self.TFDisplay.multiline = True
        self.TFDisplay.readonly = True
        self.TFDisplay.hint_text = 'Time (sec)'
        self.TFDisplay.helper_text = 'Press TIMER when you see it'
        self.TFDisplay.helper_text_mode = 'persistent'
        self.TFDisplay.line_color_normal = (0, 0, 0, 1)
        self.TFDisplay.current_hint_text_color = (0, 0, 0, 1)
        if (self.TFDisplay.parent == None):
            self.add_widget(self.TFDisplay)
        ##############################
        self.Now_Press_Me_Button.bind(
            on_release=self.Press_Now_Press_Me_Button)
        self.Press_Me_Button.bind(on_release=self.Press_Press_Me_Button)
        self.Clear_Screen_Button.bind(
            on_release=self.Press_Clear_Screen_Button)
        self.BStop.bind(on_release=self.Press_STOP_Button)
        ##############################
        return

    #################################################
    def Press_Now_Press_Me_Button(self, instance):
        self.To = time.time()
        self.Clear_Drawing_Window()
        self.Drawing.Draw_ManyLines(pScreen = self, \
                                    pXo = self.Xo, \
                                    pXf = self.Xf, \
                                    pYo = self.Yo, \
                                    pYf = self.Yf, \
                                    pR  = 0, \
                                    pG  = 1, \
                                    pB  = 1, \
                                    pOffset = 2)
        self.Drawing.Show_Instructions(pScreen=self)
        #############################################
        if (self.TFDisplay.parent == None):
            self.add_widget(self.TFDisplay)
        if (self.Clear_Screen_Button.parent == None):
            self.add_widget(self.Clear_Screen_Button)
        if (self.BStop.parent == None):
            self.add_widget(self.BStop)
        if (self.Press_Me_Button.parent == None):
            self.add_widget(self.Press_Me_Button)
        #############################################
        if (self.Now_Press_Me_Button.parent != None):
            self.remove_widget(self.Now_Press_Me_Button)
        #############################################
        return

    #################################################
    def Press_STOP_Button(self, instance):
        self.Tf = time.time()
        Tdiff = self.Tf - self.To
        Ftmp = round(Tdiff, 6)
        self.StrTime += 't = ' + str(Ftmp) + ' (sec)\n'
        self.TFDisplay.text = self.StrTime
        #############################################
        if (self.BStop.parent != None):
            self.remove_widget(self.BStop)
        #############################################
        return

    #################################################
    def Press_Press_Me_Button(self, instance):
        self.Clear_Drawing_Window()
        self.Drawing.Draw_Frame(pScreen=self,
                                pXo=self.Xo,
                                pXf=self.Xf,
                                pYo=self.Yo,
                                pYf=self.Yf)
        self.Drawing.Show_Instructions(pScreen=self)
        #############################################
        if (self.Now_Press_Me_Button.parent == None):
            self.add_widget(self.Now_Press_Me_Button)
        if (self.TFDisplay.parent == None):
            self.add_widget(self.TFDisplay)
        if (self.Clear_Screen_Button.parent == None):
            self.add_widget(self.Clear_Screen_Button)
        #############################################
        if (self.BStop.parent != None):
            self.remove_widget(self.BStop)
        if (self.Press_Me_Button.parent != None):
            self.remove_widget(self.Press_Me_Button)
        #############################################
        return

    #################################################
    def Press_Clear_Screen_Button(self, instance):
        self.StrTime = ''
        self.Clear_Screen()
        self.Initialize()
        #############################################
        if (self.Now_Press_Me_Button.parent == None):
            self.add_widget(self.Now_Press_Me_Button)
        if (self.TFDisplay.parent == None):
            self.add_widget(self.TFDisplay)
        if (self.Press_Me_Button.parent == None):
            self.add_widget(self.Press_Me_Button)
        if (self.Clear_Screen_Button.parent == None):
            self.add_widget(self.Clear_Screen_Button)
        #############################################
        if (self.Now_Press_Me_Button.parent != None):
            self.remove_widget(self.Now_Press_Me_Button)
        if (self.BStop.parent != None):
            self.remove_widget(self.BStop)
        #############################################
        return

    #################################################
    def Unbind_All(self):
        self.Now_Press_Me_Button.unbind(
            on_release=self.Press_Now_Press_Me_Button)
        self.Press_Me_Button.unbind(on_release=self.Press_Press_Me_Button)
        self.Clear_Screen_Button.unbind(
            on_release=self.Press_Clear_Screen_Button)
        self.BStop.unbind(on_release=self.Press_STOP_Button)
        return

    #################################################
    def Clear_Drawing_Window(self):
        self.Drawing.Clear_IG()
        return

    #################################################
    def Clear_Screen(self):
        self.Unbind_All()
        self.Clear_Drawing_Window()
        self.clear_widgets()
        self.canvas.clear()
        return
Exemplo n.º 30
0
    def build(self):
        screen = MDScreen()
        # Top toolbar:
        self.toolbar = MDToolbar(title="Ledstrips", elevation=20)
        self.toolbar.pos_hint = {"top": 1}
        self.toolbar.right_action_items = [
            # Icon list: https://materialdesignicons.com/
            ["exit-to-app", lambda x: self.exit()]
        ]
        screen.add_widget(self.toolbar)
        # Version line:
        screen.add_widget(
            MDLabel(text=self._version,
                    font_size=12,
                    pos_hint={
                        "center_x": 0.5,
                        "center_y": 0.95
                    },
                    halign="center"))
        # Log line:
        self.text_log = MDLabel(font_size=18,
                                pos_hint={
                                    "center_x": 0.5,
                                    "center_y": 0.10
                                },
                                halign="center",
                                theme_text_color="Error")
        screen.add_widget(self.text_log)

        #
        # Button Loft:
        #
        # Get the status of the ledstrip:
        try:
            req = urllib.request.urlopen("http://192.168.1.11:8888/light/Loft")
            res = req.read()
            contents = json.loads(res.decode("utf-8"))
            #      self.text_log.text = str(contents)
            print(contents)
            self._loftStatus = contents["light"]["state"]
            self._loftBrightness = contents["light"]["brightness"]
            self._loftRed = contents["light"]["color"]["red"]
            self._loftGreen = contents["light"]["color"]["green"]
            self._loftBlue = contents["light"]["color"]["blue"]
        except Exception as e:
            self.text_log.text = str(e)

        _loft_pos = 0.80
        screen.add_widget(
            MDFillRoundFlatButton(text="Loft",
                                  font_size=24,
                                  pos_hint={
                                      "center_x": 0.5,
                                      "center_y": _loft_pos
                                  },
                                  on_press=self.loft))
        self.sliderRed_loft = MDSlider(min=0,
                                       max=255,
                                       value=self._loftRed,
                                       color='red',
                                       hint=True,
                                       hint_radius=4,
                                       hint_bg_color='red',
                                       hint_text_color='black',
                                       pos_hint={
                                           "center_x": 0.5,
                                           "center_y": _loft_pos - 0.07
                                       },
                                       size_hint_x=0.9,
                                       size_hint_y=0.05)
        screen.add_widget(self.sliderRed_loft)
        self.sliderGreen_loft = MDSlider(min=0,
                                         max=255,
                                         value=self._loftGreen,
                                         color='green',
                                         hint=True,
                                         hint_radius=4,
                                         hint_bg_color='green',
                                         hint_text_color='black',
                                         pos_hint={
                                             "center_x": 0.5,
                                             "center_y": _loft_pos - 0.10
                                         },
                                         size_hint_x=0.9,
                                         size_hint_y=0.05)
        screen.add_widget(self.sliderGreen_loft)
        self.sliderBlue_loft = MDSlider(min=0,
                                        max=255,
                                        value=self._loftBlue,
                                        color='blue',
                                        hint=True,
                                        hint_radius=4,
                                        hint_bg_color='blue',
                                        hint_text_color='black',
                                        pos_hint={
                                            "center_x": 0.5,
                                            "center_y": _loft_pos - 0.13
                                        },
                                        size_hint_x=0.9,
                                        size_hint_y=0.05)
        screen.add_widget(self.sliderBlue_loft)
        self.sliderBrightness_loft = MDSlider(min=1,
                                              max=255,
                                              value=self._loftBrightness,
                                              color='black',
                                              hint=True,
                                              hint_radius=4,
                                              hint_bg_color='black',
                                              hint_text_color='black',
                                              pos_hint={
                                                  "center_x": 0.5,
                                                  "center_y": _loft_pos - 0.16
                                              },
                                              size_hint_x=0.9,
                                              size_hint_y=0.05)
        screen.add_widget(self.sliderBrightness_loft)

        #
        # Button Bedroom:
        #
        # Get the status of the ledstrip:
        try:
            req = urllib.request.urlopen(
                "http://192.168.1.10:8888/light/Bedroom")
            res = req.read()
            contents = json.loads(res.decode("utf-8"))
            #      self.text_log.text = str(contents)
            self._bedroomStatus = contents["light"]["state"]
            self._bedroomBrightness = contents["light"]["brightness"]
            self._bedroomRed = contents["light"]["color"]["red"]
            self._bedroomGreen = contents["light"]["color"]["green"]
            self._bedroomBlue = contents["light"]["color"]["blue"]
        except Exception as e:
            self.text_log.text = str(e)

        _bedroom_pos = 0.55
        screen.add_widget(
            MDFillRoundFlatButton(text="Bedroom",
                                  font_size=24,
                                  pos_hint={
                                      "center_x": 0.5,
                                      "center_y": _bedroom_pos
                                  },
                                  on_press=self.bedroom))
        self.sliderRed_bedroom = MDSlider(min=0,
                                          max=255,
                                          value=self._bedroomRed,
                                          color='red',
                                          hint=True,
                                          hint_radius=4,
                                          hint_bg_color='red',
                                          hint_text_color='black',
                                          pos_hint={
                                              "center_x": 0.5,
                                              "center_y": _bedroom_pos - 0.07
                                          },
                                          size_hint_x=0.9,
                                          size_hint_y=0.05)
        screen.add_widget(self.sliderRed_bedroom)
        self.sliderGreen_bedroom = MDSlider(min=0,
                                            max=255,
                                            value=self._bedroomGreen,
                                            color='green',
                                            hint=True,
                                            hint_radius=4,
                                            hint_bg_color='green',
                                            hint_text_color='black',
                                            pos_hint={
                                                "center_x": 0.5,
                                                "center_y": _bedroom_pos - 0.10
                                            },
                                            size_hint_x=0.9,
                                            size_hint_y=0.05)
        screen.add_widget(self.sliderGreen_bedroom)
        self.sliderBlue_bedroom = MDSlider(min=0,
                                           max=255,
                                           value=self._bedroomBlue,
                                           color='blue',
                                           hint=True,
                                           hint_radius=4,
                                           hint_bg_color='blue',
                                           hint_text_color='black',
                                           pos_hint={
                                               "center_x": 0.5,
                                               "center_y": _bedroom_pos - 0.13
                                           },
                                           size_hint_x=0.9,
                                           size_hint_y=0.05)
        screen.add_widget(self.sliderBlue_bedroom)
        self.sliderBrightness_bedroom = MDSlider(min=1,
                                                 max=255,
                                                 value=self._bedroomBrightness,
                                                 color='black',
                                                 hint=True,
                                                 hint_radius=4,
                                                 hint_bg_color='black',
                                                 hint_text_color='black',
                                                 pos_hint={
                                                     "center_x":
                                                     0.5,
                                                     "center_y":
                                                     _bedroom_pos - 0.16
                                                 },
                                                 size_hint_x=0.9,
                                                 size_hint_y=0.05)
        screen.add_widget(self.sliderBrightness_bedroom)

        #
        # Button Bureau:
        #
        # Get the status of the ledstrip:
        # {
        #    "self": "http://192.168.1.12:8888/light/Bureau",
        #    "light": {
        #      "name": "Bureau",
        #      "uri": "http://192.168.1.12:8888/light/Bureau",
        #      "state": false,
        #      "color": {
        #        "red": 1,
        #        "green": 1,
        #        "blue": 1
        #      },
        #      "brightness": 255
        #    },
        #    "switches": [
        #      {
        #        "name": "Desk",
        #        "uri": "http://192.168.1.12:8888/light/Bureau/switch/Desk",
        #        "state": 1
        #      }
        #    ]
        #  }
        try:
            req = urllib.request.urlopen(
                "http://192.168.1.12:8888/light/Bureau")
            res = req.read()
            contents = json.loads(res.decode("utf-8"))
            #      self.text_log.text = str(contents)
            self._bureauStatus = contents["light"]["state"]
            self._bureauBrightness = contents["light"]["brightness"]
            self._bureauRed = contents["light"]["color"]["red"]
            self._bureauGreen = contents["light"]["color"]["green"]
            self._bureauBlue = contents["light"]["color"]["blue"]
        except Exception as e:
            self.text_log.text = str(e)

        _bureau_pos = 0.30
        screen.add_widget(
            MDFillRoundFlatButton(text="Bureau",
                                  font_size=24,
                                  pos_hint={
                                      "center_x": 0.5,
                                      "center_y": _bureau_pos
                                  },
                                  on_press=self.bureau))
        self.sliderRed_bureau = MDSlider(min=0,
                                         max=255,
                                         value=self._bureauRed,
                                         color='red',
                                         hint=True,
                                         hint_radius=4,
                                         hint_bg_color='red',
                                         hint_text_color='black',
                                         pos_hint={
                                             "center_x": 0.5,
                                             "center_y": _bureau_pos - 0.07
                                         },
                                         size_hint_x=0.9,
                                         size_hint_y=0.05)
        screen.add_widget(self.sliderRed_bureau)
        self.sliderGreen_bureau = MDSlider(min=0,
                                           max=255,
                                           value=self._bureauGreen,
                                           color='green',
                                           hint=True,
                                           hint_radius=4,
                                           hint_bg_color='green',
                                           hint_text_color='black',
                                           pos_hint={
                                               "center_x": 0.5,
                                               "center_y": _bureau_pos - 0.10
                                           },
                                           size_hint_x=0.9,
                                           size_hint_y=0.05)
        screen.add_widget(self.sliderGreen_bureau)
        self.sliderBlue_bureau = MDSlider(min=0,
                                          max=255,
                                          value=self._bureauBlue,
                                          color='blue',
                                          hint=True,
                                          hint_radius=4,
                                          hint_bg_color='blue',
                                          hint_text_color='black',
                                          pos_hint={
                                              "center_x": 0.5,
                                              "center_y": _bureau_pos - 0.13
                                          },
                                          size_hint_x=0.9,
                                          size_hint_y=0.05)
        screen.add_widget(self.sliderBlue_bureau)
        self.sliderBrightness_bureau = MDSlider(min=1,
                                                max=255,
                                                value=self._bureauBrightness,
                                                color='black',
                                                hint=True,
                                                hint_radius=4,
                                                hint_bg_color='black',
                                                hint_text_color='black',
                                                pos_hint={
                                                    "center_x": 0.5,
                                                    "center_y":
                                                    _bureau_pos - 0.16
                                                },
                                                size_hint_x=0.9,
                                                size_hint_y=0.05)
        screen.add_widget(self.sliderBrightness_bureau)

        # Setting it in stone:
        return screen