server almost running - Second display working
This commit is contained in:
Binary file not shown.
BIN
showcaseScreen/handlers/__pycache__/csv_parsers.cpython-310.pyc
Normal file
BIN
showcaseScreen/handlers/__pycache__/csv_parsers.cpython-310.pyc
Normal file
Binary file not shown.
@@ -6,7 +6,10 @@ class Com:
|
||||
pass
|
||||
|
||||
def connect(self, url):
|
||||
self.x = requests.get(f"{url}/tryconnect")
|
||||
try:
|
||||
self.x = requests.get(f"{url}/tryconnect")
|
||||
except Exception:
|
||||
return False
|
||||
print(self.x.text)
|
||||
if self.x.text == "ok":
|
||||
return True
|
||||
@@ -14,13 +17,40 @@ class Com:
|
||||
return False
|
||||
|
||||
def getcurrentsong(self, url):
|
||||
return "Testsong"
|
||||
try:
|
||||
self.x = requests.get(f"{url}/currentsong")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return "Error"
|
||||
return self.x.text
|
||||
|
||||
def getsonglength(self, url):
|
||||
return 100
|
||||
try:
|
||||
self.x = requests.get(f"{url}/songmaxlength")
|
||||
except Exception:
|
||||
return 100
|
||||
return int(self.x.text)
|
||||
|
||||
def getupcomingsongs(self, url):
|
||||
return "Test1\nTest2"
|
||||
try:
|
||||
self.x = requests.get(f"{url}/upcomingsongs")
|
||||
except Exception:
|
||||
return "Error"
|
||||
return self.x.text
|
||||
|
||||
def getsongpos(self, url):
|
||||
return 2
|
||||
try:
|
||||
self.x = requests.get(f"{url}/playbackpos")
|
||||
except Exception:
|
||||
return 0
|
||||
return int(self.x.text)
|
||||
|
||||
def checkiffullscreen(self, url):
|
||||
try:
|
||||
self.x = requests.get(f"{url}/currentsong")
|
||||
except Exception:
|
||||
return False
|
||||
if self.x.text == "True":
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
122
showcaseScreen/handlers/csv_parsers.py
Executable file
122
showcaseScreen/handlers/csv_parsers.py
Executable file
@@ -0,0 +1,122 @@
|
||||
"""@package docstring
|
||||
This is a simplification of the csv module"""
|
||||
|
||||
import csv
|
||||
|
||||
|
||||
class CsvRead:
|
||||
"""This is a class that reads csv files and depending on the module selected does do different things with it"""
|
||||
def __init__(self):
|
||||
self.__imp = ""
|
||||
self.__raw = ""
|
||||
self.__raw_list = ""
|
||||
|
||||
def importing(self, path):
|
||||
"""Returns a list of the imported csv-file, requires path, either direct system path or relative path"""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__raw_list = list(self.__raw)
|
||||
self.__imp.close()
|
||||
return self.__raw_list
|
||||
|
||||
|
||||
class CsvWrite:
|
||||
"""This is a class that modifies csv files"""
|
||||
def __init__(self):
|
||||
self.__impl = []
|
||||
self.__strpop = []
|
||||
self.__removed = []
|
||||
self.__removing = 0
|
||||
self.__change = 0
|
||||
self.__appending = 0
|
||||
self.__imp = []
|
||||
self.__raw = []
|
||||
|
||||
def rem_str(self, path, row):
|
||||
"""Opens the csv-file in write mode which is specified as an argument either as direct or relative path"""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__impl = list(self.__raw)
|
||||
self.__removed = self.__impl.pop(row + 1)
|
||||
with open(path, "w") as removedata:
|
||||
self.__removing = csv.writer(removedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
while len(self.__impl) > 0:
|
||||
with open(path, "a") as removedata:
|
||||
self.__removing = csv.writer(removedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
self.__imp.close()
|
||||
removedata.close()
|
||||
|
||||
|
||||
def chg_str(self, path, row, pos, new_value):
|
||||
"""Opens the csv-file in write mode to change a value, e.g. if a recipe is changed."""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__impl = list(self.__raw)
|
||||
self.__strpop = self.__impl.pop(row)
|
||||
self.__strpop.pop(pos)
|
||||
self.__strpop.insert(pos, new_value)
|
||||
self.__impl.insert(row, self.__strpop)
|
||||
with open(path, "w") as changedata:
|
||||
self.__change = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__change.writerow(self.__impl.pop(0))
|
||||
while len(self.__impl) > 0:
|
||||
with open(path, "a") as changedata:
|
||||
self.__removing = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
self.__imp.close()
|
||||
changedata.close()
|
||||
|
||||
def chg_str_rem(self, path, row, pos):
|
||||
"""Opens the csv-file in write mode to change a value, e.g. if a recipes is changed."""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__impl = list(self.__raw)
|
||||
self.__strpop = self.__impl.pop(row)
|
||||
self.__strpop.pop(pos)
|
||||
self.__strpop.pop(pos)
|
||||
self.__impl.insert(row, self.__strpop)
|
||||
with open(path, "w") as changedata:
|
||||
self.__change = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__change.writerow(self.__impl.pop(0))
|
||||
while len(self.__impl) > 0:
|
||||
with open(path, "a") as changedata:
|
||||
self.__removing = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
self.__imp.close()
|
||||
changedata.close()
|
||||
|
||||
def chg_str_add(self, path, row, new_value1, new_value2):
|
||||
"""Opens the csv-file in write mode to change a value, e.g. if a recipes is changed."""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__impl = list(self.__raw)
|
||||
self.__strpop = self.__impl.pop(row)
|
||||
self.__strpop.append(new_value1)
|
||||
self.__strpop.append(new_value2)
|
||||
self.__impl.insert(row, self.__strpop)
|
||||
with open(path, "w") as changedata:
|
||||
self.__change = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__change.writerow(self.__impl.pop(0))
|
||||
while len(self.__impl) > 0:
|
||||
with open(path, "a") as changedata:
|
||||
self.__removing = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
self.__imp.close()
|
||||
changedata.close()
|
||||
|
||||
def app_str(self, path, value):
|
||||
"""Opens the csv-file in append mode and writes given input. CsvWrite.app_str(path, value).
|
||||
Path can be specified both as direct or relative. value is a list. Will return an error if type of value is
|
||||
not a list."""
|
||||
with open(path, "a") as appenddata:
|
||||
self.__appending = csv.writer(appenddata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__appending.writerow(value)
|
||||
appenddata.close()
|
||||
|
||||
def write_str(self, path, value):
|
||||
with open(path, "w") as writedata:
|
||||
self.__change = csv.writer(writedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__change.writerow(value)
|
||||
writedata.close()
|
||||
@@ -1,3 +1,4 @@
|
||||
from audioop import add
|
||||
from kivy.core.window import Window
|
||||
from kivy.uix.screenmanager import ScreenManager
|
||||
from kivymd.uix.screen import MDScreen
|
||||
@@ -7,11 +8,11 @@ from kivy.uix.popup import Popup
|
||||
from kivy.clock import Clock
|
||||
import handlers.comHandler
|
||||
import math
|
||||
import bin.csv_parsers
|
||||
import handlers.csv_parsers
|
||||
Builder.load_file('./ui/connectionPU.kv')
|
||||
|
||||
comHandler = handlers.comHandler.Com()
|
||||
cvr = bin.csv_parsers.CsvRead()
|
||||
cvr = handlers.csv_parsers.CsvRead()
|
||||
|
||||
class ConnectionPU(Popup):
|
||||
pass
|
||||
@@ -27,21 +28,30 @@ class LoginWindow(MDScreen):
|
||||
else:
|
||||
pass
|
||||
self.connectionurl = ""
|
||||
if self.url[:8] != "https://" and self.url[:7] != "http://" and self.url[len(self.url) - 1:] == "/" and not self.containsPort:
|
||||
if self.url[:8] != "https://" and self.url[:7] != "http://" and self.url[len(self.url) - 1:] == "/" and not self.containsPort and len(self.url) > 2:
|
||||
self.connectionurl = f"http://{self.url[:len(self.url) - 1]}:8000"
|
||||
print(comHandler.connect(self.connectionurl))
|
||||
elif self.url[:8] != "https://" and self.url[:7] != "http://" and self.url[len(self.url) - 1:] != "/" and not self.containsPort:
|
||||
elif self.url[:8] != "https://" and self.url[:7] != "http://" and self.url[len(self.url) - 1:] != "/" and not self.containsPort and len(self.url) > 2:
|
||||
self.connectionurl = f"http://{self.url}:8000"
|
||||
print(comHandler.connect(self.connectionurl))
|
||||
else:
|
||||
ConnectionPU().open()
|
||||
global address
|
||||
address = self.url
|
||||
address = self.connectionurl
|
||||
screen_manager.current = "ShowcaseScreen"
|
||||
|
||||
|
||||
class ShowcaseScreen(MDScreen):
|
||||
def updateScreen(self):
|
||||
def beginUpdating(self):
|
||||
Clock.schedule_interval(self.updateScreen, 0.5)
|
||||
self.lastsongpos = 200
|
||||
self.__current = comHandler.getcurrentsong(address)
|
||||
self.__upcoming = comHandler.getupcomingsongs(address)
|
||||
self.songlength = comHandler.getsonglength(address)
|
||||
|
||||
def updateScreen(self, dmp):
|
||||
global address
|
||||
Window.fullscreen = comHandler.checkiffullscreen(address)
|
||||
self.__windowsize = Window._get_size()
|
||||
self.__windowsize_x = self.__windowsize[0]
|
||||
self.__windowsize_y = self.__windowsize[1]
|
||||
@@ -50,33 +60,18 @@ class ShowcaseScreen(MDScreen):
|
||||
self.ids.upcoming_songs.font_size = self.__text_size - 5
|
||||
self.ids.titleinfo.font_size = self.__text_size * 2.2
|
||||
self.ids.upcoming_ind.font_size = self.__text_size + 10
|
||||
self.__current = comHandler.getcurrentsong(address)
|
||||
self.__upcoming = comHandler.getupcomingsongs(address)
|
||||
self.__songdisplay = int(comHandler.getsonglength(address) / float(comHandler.getsongpos(address)) * 100)
|
||||
self.songpos = comHandler.getsongpos(address)
|
||||
if self.songpos < self.lastsongpos:
|
||||
self.__current = comHandler.getcurrentsong(address)
|
||||
self.__upcoming = comHandler.getupcomingsongs(address)
|
||||
self.songlength = comHandler.getsonglength(address)
|
||||
else:
|
||||
pass
|
||||
self.lastsongpos = self.songpos
|
||||
self.__songdisplay = int(self.songpos / float(self.songlength) * 100)
|
||||
self.ids.progressbars.value = self.__songdisplay
|
||||
if self.__config == ["1"]:
|
||||
self.ids.current_song.text = self.__current[:(len(self.__current) - 4)]
|
||||
else:
|
||||
self.ids.current_song.text = self.__current
|
||||
if len(self.__upcoming) <= self.__currents:
|
||||
self.ids.upcoming_songs.text = "No more songs in Queue"
|
||||
else:
|
||||
if self.__config == ["1"]:
|
||||
self.__upcoming_output = self.__upcoming[:(len(self.__upcoming) - 4)]
|
||||
else:
|
||||
self.__upcoming_output = self.__upcoming
|
||||
|
||||
self.__length_output = 0
|
||||
for i in range(len(self.__upcoming) - self.__currents):
|
||||
if self.__length_output > 5:
|
||||
pass
|
||||
else:
|
||||
if self.__config == ["1"]:
|
||||
self.__upcoming_output += f"\n{self.__upcoming[:(len(self.__upcoming) - 4)]}"
|
||||
else:
|
||||
self.__upcoming_output += f"\n{self.__upcoming}"
|
||||
self.__length_output += 1
|
||||
self.ids.upcoming_songs.text = self.__upcoming_output
|
||||
self.ids.current_song.text = self.__current
|
||||
self.ids.upcoming_songs.text = self.__upcoming
|
||||
|
||||
|
||||
class MusicPlayerShowcaseScreen(MDApp):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
ShowcaseScreen:
|
||||
name: "ShowcaseScreen"
|
||||
on_pre_enter: root.beginUpdating()
|
||||
md_bg_color: (0, 0, 0, 1)
|
||||
FloatLayout:
|
||||
Label:
|
||||
@@ -45,13 +46,6 @@ ShowcaseScreen:
|
||||
color: app.theme_cls.primary_color
|
||||
shorten: False
|
||||
halign: "center"
|
||||
Button:
|
||||
text: "back"
|
||||
font_size: 10
|
||||
size_hint: 0.05, 0.05
|
||||
background_color: app.theme_cls.accent_light
|
||||
on_release:
|
||||
root.leave_screen()
|
||||
Label:
|
||||
text: "Designed and developed by Janis Hutz"
|
||||
font_size: 7
|
||||
|
||||
Reference in New Issue
Block a user