-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.py
157 lines (130 loc) · 5.01 KB
/
controller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
""" Simple python classe to represent the controller of MVC
https://bitbucket.org/NGY_CPNV/teacherplanner
Author : Julien Ithurbide
Compagny : CPNV
VERSION : 0.1
LAST Modification :
Date | Exp.
-----------|------------------------------------
07.02.2017 | First version
"""
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from view import View
from log import Log
from ampli import Amplifier
from config import Config
from wiz import Assistant
class Controller:
def __init__(self):
self.address_ip = None
self.tn = None
self.connected = False
self.needToRun = True
self.zeroconf = None
self.listener = None
self.browser = None
self.semaphore = True
self.address = None
self._view = None
self.ampli = None
self.central_buffer = None
self.assistant = None
self.log = Log()
self.logger = self.log.get_logger()
self.config = Config(self.logger)
if self.config.check_config():
self.start_view()
self.log.set_view_label(self._view.label)
else:
self.start_wiz()
self.logger.debug("Controller is starting")
def start_wiz(self):
self.assistant = Assistant()
self.assistant.show_all()
self.assistant.connect("close", self.on_close_clicked)
def start_view(self):
self._view = View()
self._view.bt_wiz.connect("clicked",self.on_wiz_clicked)
self._view.bt_start_con.connect("clicked",self.connection)
self._view.bt_audio_select.connect("clicked", self.on_audio_click)
self._view.bt_output_selection.connect("clicked", self.on_output_click)
self._view.bt_vol_up.connect("clicked", self.on_vol_up_click)
self._view.bt_vol_down.connect("clicked", self.on_vol_down_click)
self._view.bt_dvd.connect("clicked", self.on_dvd_select)
self._view.bt_bray.connect("clicked", self.on_bray_select)
self._view.bt_dvr.connect("clicked", self.on_dvr_select)
self._view.bt_hdmi1.connect("clicked", self.on_hdmi1_select)
self._view.bt_hdmi2.connect("clicked", self.on_hdmi2_select)
self._view.bt_hdmi3.connect("clicked", self.on_hdmi3_select)
self.address_ip = self.config.read_config()
self._view.set_subtitle("Address is : " +str(self.address_ip))
self.ampli = Amplifier(self.logger)
# self.central_buffer = self._view.label2.get_buffer()
self.ampli.set_ip(self.address_ip)
def connection(self,bt):
if self.ampli.is_connected():
self.ampli.close()
else:
self.ampli.connect()
def on_wiz_clicked(self,bt):
self.logger.debug("Lu")
self._view.destroy()
self.start_wiz()
def on_close_clicked(self, *args):
print("The 'Close' button has been clicked")
ip = self.assistant.address_ip
self.logger.debug("Ip :" +str(ip))
self.config.create_config(ip)
self.assistant.destroy()
self.start_view()
def on_hdmi1_select(self, bt):
self.ampli.set_output("HDMI1")
def on_hdmi2_select(self, bt):
self.ampli.set_output("HDMI2")
def on_hdmi3_select(self, bt):
self.ampli.set_output("HDMI3")
def on_bray_select(self, bt):
self.ampli.set_output("BD")
def on_dvd_select(self, bt):
self.ampli.set_output("DVD")
def on_dvr_select(self, bt):
self.ampli.set_output("DVR")
def on_audio_click(self,button):
self._view.popover_audio.set_relative_to(button)
self._view.popover_audio.show_all()
self._view.popover_audio.popup()
def on_output_click(self,button):
self._view.popover_outpup.set_relative_to(button)
self._view.popover_outpup.show_all()
self._view.popover_outpup.popup()
def on_vol_up_click(self, bt):
vol = self.ampli.set_volume_up()
self.logger.debug("From controller volume is change to : " + str(vol))
def on_vol_down_click(self, bt):
vol = self.ampli.set_volume_down()
self.logger.debug("From controller volume is change to : " + str(vol))
def value_changed(self, volumebutton, value):
self.logger.debug("From controller volume change detected : " + str(value))
def get_volume(self):
self.semaphore = False
self.logger.debug("From controller starting getvolume")
volume = self.ampli.get_volume()
self.logger.debug("From controller volume is : " + str(volume))
self.semaphore = True
def error(self,arg):
self.logger.debug("From controller error found on discovery")
self.browser.cancel()
self.zeroconf.close()
self.logger.debug("From controller restart zeroconf")
self.start_discover()
def __del__(self):
self.logger.debug("Controler autodestructed")
#self.ampli.close()
self.logger = None
self.zeroconf = None
self.listener = None
self.browser = None
self.buffer = None
self.label = None