From bd4d215e2630e60716a02a9beb8e99f113a78617 Mon Sep 17 00:00:00 2001 From: "Lyam[BRS]" Date: Mon, 24 Apr 2023 23:04:55 -0400 Subject: [PATCH] - Fixed gitignore removing BFIO.json - Fixed BFIO.json not being pushed - Added GitHub search card to DriverMenu.py it's in Cards.py --- .gitignore | 3 +- BrSpand/BFIO/BFIO.json | 74 +++++++ Libraries/BRS_Python_Libraries | 2 +- Programs/Local/GUI/Cards.py | 191 +++++++++++++++++- Programs/Pages/DriverMenu.py | 4 + Programs/__pycache__/__init__.cpython-310.pyc | Bin 158 -> 194 bytes 6 files changed, 270 insertions(+), 4 deletions(-) create mode 100644 BrSpand/BFIO/BFIO.json diff --git a/.gitignore b/.gitignore index 85656c9..439ac78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc *.json -!Config.json \ No newline at end of file +!Config.json +!BFIO.json \ No newline at end of file diff --git a/BrSpand/BFIO/BFIO.json b/BrSpand/BFIO/BFIO.json new file mode 100644 index 0000000..3dd0e7d --- /dev/null +++ b/BrSpand/BFIO/BFIO.json @@ -0,0 +1,74 @@ +{ + "Version" : 1, + "DriverRepo" : "link_here", + + "Information" : { + "Name" : "Kontrol", + "Description" : "Universal controller of devices and BrSpand cards", + "Company" : "BRS", + "Version" : "0.0", + "Type" : "Master" + }, + + "Functions" : [ + { + "ID" : 0, + "Name" : "Ping", + "Description" : "Pings the other device", + "Parameters" : null, + "Answer" : { + "Names" : ["Pong"], + "Types" : ["bool"], + "Descriptions" : ["Returned ping"] + } + }, + { + "ID" : 1, + "Name" : "GetSatus", + "Description" : "Gets the current status of the other end device.", + "Parameters" : null, + "Answer" : { + "Names" : ["Status"], + "Types" : ["unsigned char"], + "Descriptions" : ["Status of the device"] + } + }, + { + "ID" : 2, + "Name" : "GetHandshake", + "Description" : "Gets the current status of the other end device.", + "Parameters" : { + "Names" : ["JSON"], + "Types" : ["string"], + "Descriptions" : ["The end device’s BFIO JSON string"] + }, + "Answer" : { + "Names" : ["Status"], + "Types" : ["string"], + "Descriptions" : ["Status of the device"] + } + }, + { + "ID" : 3, + "Name" : "GetErrorMessage", + "Description" : "Gets the device last error message.", + "Parameters" : null, + "Answer" : { + "Names" : ["Message"], + "Types" : ["string"], + "Descriptions" : ["The device’s error message."] + } + }, + { + "ID" : 4, + "Name" : "GetType", + "Description" : "Gets the type of the other device", + "Parameters" : null, + "Answer" : { + "Names" : ["Type"], + "Types" : ["unsigned char"], + "Descriptions" : ["The end device’s type."] + } + } + ] +} \ No newline at end of file diff --git a/Libraries/BRS_Python_Libraries b/Libraries/BRS_Python_Libraries index 0fff293..b474566 160000 --- a/Libraries/BRS_Python_Libraries +++ b/Libraries/BRS_Python_Libraries @@ -1 +1 @@ -Subproject commit 0fff29368f5efcead84e8df649e9ba7aff12e36e +Subproject commit b4745665579a2c2667c3efafb515ee45a0681be8 diff --git a/Programs/Local/GUI/Cards.py b/Programs/Local/GUI/Cards.py index 2d81c1b..9fdd3c1 100644 --- a/Programs/Local/GUI/Cards.py +++ b/Programs/Local/GUI/Cards.py @@ -11,8 +11,11 @@ #====================================================================# # Loading Logs #====================================================================# +from cgitb import text from Libraries.BRS_Python_Libraries.BRS.Debug.LoadingLog import LoadingLog -from Libraries.BRS_Python_Libraries.BRS.Utilities.Enums import FileIntegrity +from Libraries.BRS_Python_Libraries.BRS.Network.Web.web import IsWebsiteOnline +from Libraries.BRS_Python_Libraries.BRS.Utilities.Enums import Execution, FileIntegrity +from Libraries.BRS_Python_Libraries.BRS.Utilities.Information import Information LoadingLog.Start("Cards.py") #====================================================================# # Imports @@ -25,6 +28,7 @@ from Libraries.BRS_Python_Libraries.BRS.Debug.consoleLog import Debug from Libraries.BRS_Python_Libraries.BRS.GUI.Utilities.references import Shadow, Rounding from Libraries.BRS_Python_Libraries.BRS.Utilities.LanguageHandler import _ +from Libraries.BRS_Python_Libraries.BRS.Network.APIs.GitHub import ManualGitHub #endregion #region -------------------------------------------------------- Kivy LoadingLog.Import("Kivy") @@ -43,6 +47,9 @@ from kivymd.uix.floatlayout import MDFloatLayout from kivymd.uix.boxlayout import MDBoxLayout from kivymd.uix.gridlayout import MDGridLayout +from kivymd.uix.button import MDFillRoundFlatIconButton +from kivymd.uix.textfield import MDTextField +from kivymd.uix.label import MDLabel #endregion LoadingLog.Import("Local") from ..FileHandler.deviceDriver import Get_OtherDeviceButton, GetJson, CheckIntegrity, Get_BluetoothButton, Get_BrSpandButton, Get_InternetButton, Get_KontrolButton, Get_OSButton, Get_ProcessorButton @@ -106,6 +113,187 @@ def __init__(self, #endregion pass #====================================================================# +LoadingLog.Class("DeviceDriverInstallerCard") +class DeviceDriverInstallerCard(BaseButton, Widget): + #region --------------------------- DOCSTRING + ''' + DeviceDriverInstallerCard: + =========== + Summary: + -------- + This class is a widget class that builds a search card used + to download device drivers from the internet to a specific + folder path on Kontrol. + ''' + #endregion + #region --------------------------- MEMBERS + #endregion + #region --------------------------- METHODS + #region -- Public + + def CheckInternet(self, *args): + """ + Function that checks if internet is available. + Updates the card according to the execution + result. + """ + pass + + def DownloadRepository(self, *args): + """ + Function that checks if internet is available. + Then attempts to download the repository found + in it's search bar. + """ + pass + #endregion + #region -- Private + # ------------------------------------------------------ + def _RippleHandling(self, object, finished): + if(finished): + # Check if WiFi is online + result = IsWebsiteOnline() + if(not result): + remaining = ManualGitHub.GetRequestsLeft() + Debug.Log(f"Requests left: {remaining}") + if(remaining > 0): + self.Set_Normal() + else: + self.Set_NoGitHubRequests() + else: + self.Set_NoWifi() + pass + # ------------------------------------------------------ + def Set_NoWifi(self): + """ + Updates the card to display no wifi + """ + Debug.Start("Set_NoWifi") + self.BottomButton.icon = "reload" + self.BottomButton.text = _("Retry") + self.MiddleIcon.icon = "remove-wifi" + self.InformationLabel.text = _("No internet connection. Device drivers cannot be installed.") + self.SearchBox.disabled = True + self.SearchBox.text = "" + Debug.End() + + def Set_Normal(self): + """ + Updates the card to display regular + information. + """ + Debug.Start("Set_Normal") + self.BottomButton.icon = "search-web" + self.BottomButton.text = _("Search GitHub") + self.MiddleIcon.icon = "github" + self.InformationLabel.text = _("Search GitHub for device drivers to install") + self.SearchBox.disabled = False + self.SearchBox.text = "" + Debug.End() + + def Set_RepositoryNotFound(self): + """ + Updates the card to display the fact + that no github repository could be + found based off the search field. + """ + Debug.Start("Set_RepositoryNotFound") + self.BottomButton.icon = "magnify" + self.BottomButton.text = _("Search GitHub") + self.MiddleIcon.icon = "magnify-close" + self.InformationLabel.text = _("No repository could be found with that link.") + self.SearchBox.disabled = False + self.SearchBox.text = "" + Debug.End() + + def Set_NoGitHubRequests(self): + """ + Updates the card to display no Github + request. + """ + Debug.Start("Set_NoGitHubRequests") + self.BottomButton.icon = "reload" + self.BottomButton.text = _("Retry") + self.MiddleIcon.icon = "github" + self.InformationLabel.text = _("You ran out of GitHub API requests. Wait up to an hour.") + self.SearchBox.disabled = True + self.SearchBox.text = "" + Debug.End() + #endregion + #endregion + #region --------------------------- CONSTRUCTOR + def __init__(self, + **kwargs): + super(DeviceDriverInstallerCard, self).__init__(**kwargs) + Debug.Start("DeviceDriverInstallerCard") + #region --------------------------- Initial check ups + + self.padding = 0 + self.spacing = 0 + + self.Card = MDCard() + self.Card.orientation = "vertical" + self.Card.elevation = Shadow.Elevation.default + self.Card.shadow_softness = Shadow.Smoothness.default + self.Card.radius = Rounding.Cards.default + self.size = (400,425) + self.ripple_alpha = 0 + #endregion + + #region --------------------------- Widgets + self.Layout = MDFloatLayout() + self.Layout.padding = 25 + self.Layout.size_hint = (1,1) + + self.BottomButton = MDFillRoundFlatIconButton( + icon = "search-web", + text = _("Search"), + font_style = "H4", + ) + self.BottomButton.rounded_button = False + self.BottomButton.pos_hint = {'center_x': 0.5, 'center_y': 0.075} + self.BottomButton.size_hint = (1, None) + self.BottomButton.bind(_finishing_ripple = self._RippleHandling) + + self.MiddleIcon = MDIconButton( + icon = "github", + disabled = True, + icon_size = 150, + pos_hint = {'center_x': 0.5, 'center_y': 0.75} + ) + self.MiddleIcon.pos_hint = {'center_x': 0.5, 'center_y': 0.60} + + self.InformationLabel = MDLabel( + text = _("Search for a device driver repository to download."), + font_style = "H6", + ) + self.InformationLabel.pos_hint = {'center_x': 0.5, 'center_y': 0.25} + self.InformationLabel.size_hint = (0.75, None) + + self.SearchBox = MDTextField( + hint_text = _("Search") + " GitHub", + pos_hint = {'center_x': 0.5, 'center_y': 0.925} + ) + self.SearchBox.size_hint = (0.75, None) + + self.Layout.add_widget(self.SearchBox) + self.Layout.add_widget(self.MiddleIcon) + self.Layout.add_widget(self.InformationLabel) + self.Layout.add_widget(self.BottomButton) + self.Card.add_widget(self.Layout) + + if(Information.CanUse.Internet): + Debug.Log("internet can be used.") + self.Set_Normal() + else: + self.Set_NoWifi() + #endregion + + self.add_widget(self.Card) + Debug.End() + #endregion + pass +#====================================================================# LoadingLog.Class("DeviceDriverCard") class DeviceDriverCard(BaseButton, Widget): #region --------------------------- DOCSTRING @@ -266,7 +454,6 @@ def __init__(self, pass #endregion - self.Card.add_widget(self.RequirementsLayout) self.Layout.add_widget(self.Icon) self.Layout.add_widget(self.Name) diff --git a/Programs/Pages/DriverMenu.py b/Programs/Pages/DriverMenu.py index 7f102f8..c9e79c0 100644 --- a/Programs/Pages/DriverMenu.py +++ b/Programs/Pages/DriverMenu.py @@ -20,6 +20,7 @@ from Libraries.BRS_Python_Libraries.BRS.Utilities.FileHandler import FilesFinder, AppendPath from Libraries.BRS_Python_Libraries.BRS.Utilities.LanguageHandler import _ from Libraries.BRS_Python_Libraries.BRS.GUI.Containers.cards import DriverCard +from Programs.Local.GUI.Cards import DeviceDriverInstallerCard #endregion #region -------------------------------------------------------- Kivy LoadingLog.Import("Kivy") @@ -609,9 +610,12 @@ def on_pre_enter(self, *args): self.ToolBar = AppNavigationBar(pageTitle=_("Devices Driver")) #endregion #region ---------------------------- Drivers + DriverInstallerCard = DeviceDriverInstallerCard() + path = AppendPath(os.getcwd(), "/Local/Drivers") drivers = GetDrivers() + self.driversBox.add_widget(DriverInstallerCard) for driver in drivers: card = DeviceDriverCard(driverName=driver) card.PressedEnd = self.DriverPressed diff --git a/Programs/__pycache__/__init__.cpython-310.pyc b/Programs/__pycache__/__init__.cpython-310.pyc index ec6c304c7e1367e147c0360923122929cdab5696..ca84f03fdef9c407cd4984da419cf23c6ee0ee43 100644 GIT binary patch delta 98 zcmbQoc!-fFpO=@50SJP49wblXvGz($wu%WYPAw{qNzN}VHjQyfEzT~