mirror of
https://github.com/Febbweiss/mopidy-touchscreen.git
synced 2026-03-04 22:25:39 +00:00
Menu screen changed to ListView (GPIO button friendly)
This commit is contained in:
@@ -5,7 +5,7 @@ from base_screen import BaseScreen
|
|||||||
|
|
||||||
import mopidy
|
import mopidy
|
||||||
|
|
||||||
from ..graphic_utils import ScreenObjectsManager, TouchAndTextItem
|
from ..graphic_utils import ListView, TouchAndTextItem
|
||||||
from ..input import InputManager
|
from ..input import InputManager
|
||||||
|
|
||||||
|
|
||||||
@@ -13,66 +13,27 @@ class MenuScreen(BaseScreen):
|
|||||||
def __init__(self, size, base_size, manager, fonts):
|
def __init__(self, size, base_size, manager, fonts):
|
||||||
BaseScreen.__init__(self, size, base_size, manager, fonts)
|
BaseScreen.__init__(self, size, base_size, manager, fonts)
|
||||||
self.ip = None
|
self.ip = None
|
||||||
self.screen_objects = ScreenObjectsManager()
|
self.list = ListView((0, 0), size, base_size, fonts['base'])
|
||||||
|
|
||||||
# Exit mopidy button
|
self.list_items = ["Exit Mopidy", "Shutdown", "Restart", "IP: "]
|
||||||
button = TouchAndTextItem(self.manager.fonts['icon'],
|
|
||||||
u"\ue611",
|
|
||||||
(0, 0), None)
|
|
||||||
self.screen_objects.set_touch_object("exit_icon", button)
|
|
||||||
button = TouchAndTextItem(self.fonts['base'],
|
|
||||||
"Exit Mopidy",
|
|
||||||
(button.get_right_pos(),
|
|
||||||
0),
|
|
||||||
None)
|
|
||||||
self.screen_objects.set_touch_object("exit", button)
|
|
||||||
|
|
||||||
# Shutdown button
|
self.list.set_list(self.list_items)
|
||||||
button = TouchAndTextItem(self.fonts['icon'],
|
|
||||||
u"\ue60b",
|
|
||||||
(0, self.base_size * 1), None)
|
|
||||||
self.screen_objects.set_touch_object("shutdown_icon", button)
|
|
||||||
button = TouchAndTextItem(self.fonts['base'],
|
|
||||||
"Shutdown",
|
|
||||||
(button.get_right_pos(),
|
|
||||||
self.base_size * 1),
|
|
||||||
None)
|
|
||||||
self.screen_objects.set_touch_object("shutdown", button)
|
|
||||||
|
|
||||||
# Restart button
|
|
||||||
button = TouchAndTextItem(self.fonts['icon'],
|
|
||||||
u"\ue609",
|
|
||||||
(0, self.base_size * 2), None)
|
|
||||||
self.screen_objects.set_touch_object("restart_icon", button)
|
|
||||||
button = TouchAndTextItem(self.fonts['base'],
|
|
||||||
"Restart",
|
|
||||||
(button.get_right_pos(),
|
|
||||||
self.base_size * 2),
|
|
||||||
None)
|
|
||||||
self.screen_objects.set_touch_object("restart", button)
|
|
||||||
|
|
||||||
# IP addres
|
|
||||||
button = TouchAndTextItem(self.fonts['base'], "IP: ",
|
|
||||||
(0, self.base_size * 3), None)
|
|
||||||
self.screen_objects.set_touch_object("ip", button)
|
|
||||||
|
|
||||||
def update(self, screen):
|
def update(self, screen):
|
||||||
self.screen_objects.render(screen)
|
self.list.render(screen)
|
||||||
|
|
||||||
def touch_event(self, event):
|
def touch_event(self, event):
|
||||||
if event.type == InputManager.click:
|
clicked = self.list.touch_event(event)
|
||||||
clicked = self.screen_objects.get_touch_objects_in_pos(
|
if clicked is not None:
|
||||||
event.current_pos)
|
if clicked == 0:
|
||||||
for key in clicked:
|
|
||||||
if key == "exit_icon" or key == "exit":
|
|
||||||
mopidy.utils.process.exit_process()
|
mopidy.utils.process.exit_process()
|
||||||
elif key == "shutdown_icon" or key == "shutdown":
|
elif clicked == 1:
|
||||||
if os.system("gksu -- shutdown now -h") != 0:
|
if os.system("gksu -- shutdown now -h") != 0:
|
||||||
os.system("sudo shutdown now -h")
|
os.system("sudo shutdown now -h")
|
||||||
elif key == "restart_icon" or key == "restart":
|
elif clicked == 2:
|
||||||
if os.system("gksu -- shutdown -r now") != 0:
|
if os.system("gksu -- shutdown -r now") != 0:
|
||||||
os.system("sudo shutdown -r now")
|
os.system("sudo shutdown -r now")
|
||||||
elif key == "ip":
|
elif clicked == 3:
|
||||||
self.check_connection()
|
self.check_connection()
|
||||||
|
|
||||||
# Will check internet connection
|
# Will check internet connection
|
||||||
@@ -83,12 +44,12 @@ class MenuScreen(BaseScreen):
|
|||||||
s.connect(("8.8.8.8", 80))
|
s.connect(("8.8.8.8", 80))
|
||||||
self.ip = s.getsockname()[0]
|
self.ip = s.getsockname()[0]
|
||||||
s.close()
|
s.close()
|
||||||
self.screen_objects.get_touch_object("ip").set_text(
|
self.list_items[3] = "IP: " + self.ip
|
||||||
"IP: " + self.ip, "None")
|
self.list.set_list(self.list_items)
|
||||||
self.manager.set_connection(True, False)
|
self.manager.set_connection(True, False)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
s.close()
|
s.close()
|
||||||
self.ip = None
|
self.ip = None
|
||||||
self.screen_objects.get_touch_object("ip").set_text(
|
self.list_items[2] = "IP: No internet"
|
||||||
"IP: No internet", "None")
|
self.list.set_list(self.list_items)
|
||||||
self.manager.set_connection(False, False)
|
self.manager.set_connection(False, False)
|
||||||
|
|||||||
@@ -2,8 +2,12 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
|
||||||
from mopidy_touchscreen import Extension
|
from mopidy_touchscreen import Extension
|
||||||
|
|
||||||
|
from mopidy_touchscreen.graphic_utils.list_view import ListView
|
||||||
|
|
||||||
|
|
||||||
# ,touch_screen as frontend_lib
|
# ,touch_screen as frontend_lib
|
||||||
|
|
||||||
@@ -28,4 +32,8 @@ class ExtensionTest(unittest.TestCase):
|
|||||||
# self.assertIn('username', schema)
|
# self.assertIn('username', schema)
|
||||||
# self.assertIn('password', schema)
|
# self.assertIn('password', schema)
|
||||||
|
|
||||||
# TODO Write more tests
|
def test_list_view(self):
|
||||||
|
pygame.init()
|
||||||
|
font = pygame.font.SysFont("arial", 200/6)
|
||||||
|
list = ListView((0, 0), (200, 200), 200/6, font)
|
||||||
|
list.set_list(["item1", "item2", "item3"])
|
||||||
|
|||||||
Reference in New Issue
Block a user