Skip to content

Commit

Permalink
- Fixed gitignore removing BFIO.json
Browse files Browse the repository at this point in the history
- Fixed BFIO.json not being pushed
- Added GitHub search card to DriverMenu.py it's in Cards.py
  • Loading branch information
LyamBRS committed Apr 25, 2023
1 parent 89500e3 commit bd4d215
Show file tree
Hide file tree
Showing 6 changed files with 270 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.pyc
*.json
!Config.json
!Config.json
!BFIO.json
74 changes: 74 additions & 0 deletions BrSpand/BFIO/BFIO.json
Original file line number Diff line number Diff line change
@@ -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."]
}
}
]
}
2 changes: 1 addition & 1 deletion Libraries/BRS_Python_Libraries
191 changes: 189 additions & 2 deletions Programs/Local/GUI/Cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions Programs/Pages/DriverMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Binary file modified Programs/__pycache__/__init__.cpython-310.pyc
Binary file not shown.

0 comments on commit bd4d215

Please sign in to comment.