add py_env and simple shell menu
This commit is contained in:
1
src/python/python_fmpi/src/ui/__init__.py
Normal file
1
src/python/python_fmpi/src/ui/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'dev'
|
||||
1
src/python/python_fmpi/src/ui/console/__init__.py
Normal file
1
src/python/python_fmpi/src/ui/console/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'dev'
|
||||
1
src/python/python_fmpi/src/ui/console/button/__init__.py
Normal file
1
src/python/python_fmpi/src/ui/console/button/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'dev'
|
||||
10
src/python/python_fmpi/src/ui/console/button/click_button.py
Normal file
10
src/python/python_fmpi/src/ui/console/button/click_button.py
Normal file
@@ -0,0 +1,10 @@
|
||||
__author__ = 'dev'
|
||||
from ui.console.button.console_button import ConsoleButton
|
||||
|
||||
SIGNAL_NAME = "click"
|
||||
|
||||
|
||||
class ClickButton(ConsoleButton):
|
||||
|
||||
def setup_button(self):
|
||||
self._connect(SIGNAL_NAME)
|
||||
@@ -0,0 +1,16 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
import urwid
|
||||
|
||||
|
||||
class ConsoleButton(urwid.Button):
|
||||
|
||||
def __init__(self, label):
|
||||
super().__init__(label)
|
||||
self.setup_button()
|
||||
|
||||
def _connect(self, signal_name, user_args=None):
|
||||
urwid.connect_signal(self, signal_name, self._action)
|
||||
|
||||
def _action(self, sender):
|
||||
pass
|
||||
12
src/python/python_fmpi/src/ui/console/button/exit_button.py
Normal file
12
src/python/python_fmpi/src/ui/console/button/exit_button.py
Normal file
@@ -0,0 +1,12 @@
|
||||
__author__ = 'dev'
|
||||
import urwid
|
||||
|
||||
from ui.console.button.click_button import ClickButton
|
||||
|
||||
|
||||
class ExitButton(ClickButton):
|
||||
def __init__(self, label="Exit"):
|
||||
super().__init__(label)
|
||||
|
||||
def _action(self, sender):
|
||||
raise urwid.ExitMainLoop()
|
||||
@@ -0,0 +1,13 @@
|
||||
__author__ = 'dev'
|
||||
from ui.console.button.click_button import ClickButton
|
||||
|
||||
|
||||
class PlayStreamButton(ClickButton):
|
||||
|
||||
def __init__(self, stream_name, player):
|
||||
super().__init__(stream_name)
|
||||
self.__player = player
|
||||
self.__stream_name = stream_name
|
||||
|
||||
def _action(self, sender):
|
||||
self.__player.play_stream(self.__stream_name)
|
||||
7
src/python/python_fmpi/src/ui/console/console.py
Normal file
7
src/python/python_fmpi/src/ui/console/console.py
Normal file
@@ -0,0 +1,7 @@
|
||||
__author__ = 'dev'
|
||||
import sys
|
||||
sys.path.append("/home/dev/projects/fmpi/src/python/python_fmpi/src")
|
||||
from ui.console.menu.stream_list_menu import StreamListMenu
|
||||
|
||||
if __name__ == '__main__':
|
||||
StreamListMenu().show(palette=[('reversed', 'standout', '')])
|
||||
1
src/python/python_fmpi/src/ui/console/menu/__init__.py
Normal file
1
src/python/python_fmpi/src/ui/console/menu/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'dev'
|
||||
22
src/python/python_fmpi/src/ui/console/menu/console_menu.py
Normal file
22
src/python/python_fmpi/src/ui/console/menu/console_menu.py
Normal file
@@ -0,0 +1,22 @@
|
||||
__author__ = 'dev'
|
||||
import urwid
|
||||
|
||||
FOCUS_MAP_REVERSED = "reversed"
|
||||
|
||||
class ConsoleMenu():
|
||||
|
||||
def __init__(self):
|
||||
self.__widget = self._create_widget()
|
||||
|
||||
def _create_widget(self):
|
||||
pass
|
||||
|
||||
def _clean_menu(self):
|
||||
pass
|
||||
|
||||
def show(self, **kwargs):
|
||||
main_loop = urwid.MainLoop(self.__widget, **kwargs)
|
||||
try:
|
||||
main_loop.run()
|
||||
finally:
|
||||
self._clean_menu()
|
||||
@@ -0,0 +1,27 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
import urwid
|
||||
from ui.console.button.exit_button import ExitButton
|
||||
from ui.console.button.play_stream_button import PlayStreamButton
|
||||
from config.stream_list import web_stream_list as wsl
|
||||
from web_streams.web_stream_player import WebStreamPlayer
|
||||
from ui.console.menu.console_menu import ConsoleMenu, FOCUS_MAP_REVERSED
|
||||
|
||||
LISTBOX_TITLE = "Streamlist"
|
||||
|
||||
class StreamListMenu(ConsoleMenu):
|
||||
|
||||
def __init__(self):
|
||||
self.__player = WebStreamPlayer()
|
||||
super().__init__()
|
||||
|
||||
def _create_widget(self):
|
||||
body = [urwid.Text(LISTBOX_TITLE), urwid.Divider()]
|
||||
for stream in wsl.keys():
|
||||
body.append(urwid.AttrMap(PlayStreamButton(stream, self.__player), None, focus_map=FOCUS_MAP_REVERSED))
|
||||
body.append(urwid.AttrMap(ExitButton(), None, focus_map=FOCUS_MAP_REVERSED))
|
||||
return urwid.ListBox(urwid.SimpleFocusListWalker(body))
|
||||
|
||||
def _clean_menu(self):
|
||||
if self.__player is not None:
|
||||
self.__player.stop_stream()
|
||||
@@ -15,8 +15,8 @@ class SubprocessDict:
|
||||
|
||||
self.__process_dict.clear()
|
||||
|
||||
def add_process(self, args):
|
||||
new_process = subprocess.Popen(args)
|
||||
def add_process(self, args, **kwargs):
|
||||
new_process = subprocess.Popen(args, **kwargs)
|
||||
self.__process_dict[new_process.pid] = new_process
|
||||
|
||||
def get_process_dict(self):
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
import subprocess
|
||||
from config.stream_list import web_stream_list as wsl
|
||||
from config.commands import web_stream_commands as wcmd
|
||||
from utility.subprocess_dict import SubprocessDict
|
||||
|
||||
SDT_OUT_DST = open('/dev/null', 'w')
|
||||
SDT_ERR_DST = open('/dev/null', 'w')
|
||||
|
||||
class WebStreamPlayer:
|
||||
|
||||
@@ -18,8 +20,9 @@ class WebStreamPlayer:
|
||||
|
||||
def play_stream(self, stream_name):
|
||||
if stream_name in self.__stream_list:
|
||||
self.__process_list.clear_dict()
|
||||
self.__process_list.add_process([self.__player_command, self.__stream_list[stream_name]])
|
||||
self.stop_stream()
|
||||
self.__process_list.add_process([self.__player_command, self.__stream_list[stream_name]],
|
||||
stdout=SDT_OUT_DST, stderr=SDT_ERR_DST)
|
||||
self.__current_stream_name = stream_name
|
||||
|
||||
def stop_stream(self):
|
||||
|
||||
1
src/python/python_fmpi/test/__init__.py
Normal file
1
src/python/python_fmpi/test/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'dev'
|
||||
1
src/python/python_fmpi/test/ui/__init__.py
Normal file
1
src/python/python_fmpi/test/ui/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
__author__ = 'dev'
|
||||
12
src/python/python_fmpi/test/ui/console.py
Normal file
12
src/python/python_fmpi/test/ui/console.py
Normal file
@@ -0,0 +1,12 @@
|
||||
__author__ = 'dev'
|
||||
|
||||
import unittest
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def test_something(self):
|
||||
self.assertEqual(True, False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user