1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright 2017, Data61
5# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
6# ABN 41 687 119 230.
7#
8# This software may be distributed and modified according to the terms of
9# the BSD 2-Clause license. Note that NO WARRANTY is provided.
10# See "LICENSE_BSD2.txt" for details.
11#
12# @TAG(DATA61_BSD)
13
14from PyQt5 import QtWidgets
15
16from Interface.Property import PropertyInterface
17import Connection_Widget
18from Instance_Widget import InstanceWidget
19
20class ConnectionPropertyWidget(QtWidgets.QGroupBox):
21    """
22    ConnectionPropertyWidget - shows the properties of a connection.
23    """
24
25    # Connection Widget that this widget represent
26    @property
27    def connection_widget(self):
28        assert self._connection_widget is not None
29        return self._connection_widget
30
31    @connection_widget.setter
32    def connection_widget(self, value):
33        assert isinstance(value, Connection_Widget.ConnectionWidget)
34        self._connection_widget = value
35
36    # views
37
38    @property
39    def name_widget(self):
40        if self._name_widget is None:
41            self._name_widget = QtWidgets.QLabel(self.connection_widget.name)
42        return self._name_widget
43
44    @property
45    def type_widget(self):
46        # When this becomes editable
47        # This will be not a label, but a drop down menu
48        if self._type_widget is None:
49            self._type_widget = QtWidgets.QLabel(self.connection_widget.connection_type)
50        return self._type_widget
51
52    @property
53    def from_interface_widget(self):
54        # When this becomes editable
55        # This will be not a label, but a drop down menu
56        if self._from_interface_widget is None:
57            self._from_interface_widget = QtWidgets.QLabel("%s : %s" % (self.connection_widget.source_interface_name, self.connection_widget.source_connection_type) )
58        return self._from_interface_widget
59
60    @property
61    def from_instance_widget(self):
62        if self._from_instance_widget is None:
63            self._from_instance_widget = QtWidgets.QLabel(self.connection_widget.source_instance_widget.name)
64        return self._from_instance_widget
65
66    @property
67    def to_interface_widget(self):
68        # When this becomes editable
69        # This will be not a label, but a drop down menu
70        if self._to_interface_widget is None:
71            self._to_interface_widget = QtWidgets.QLabel("%s : %s" % (self.connection_widget.dest_interface_name, self.connection_widget.dest_connection_type) )
72        return self._to_interface_widget
73
74    @property
75    def to_instance_widget(self):
76        if self._to_instance_widget is None:
77            self._to_instance_widget = QtWidgets.QLabel(self.connection_widget.dest_instance_widget.name)
78        return self._to_instance_widget
79
80    # --- INITIALISATION ---
81
82    def __init__(self, connection_widget):
83        self._connection_widget = None
84        self._name_widget = None
85        self._type_widget = None
86        self._from_interface_widget = None
87        self._from_instance_widget = None
88        self._to_interface_widget = None
89        self._to_instance_widget = None
90
91        self.connection_widget = connection_widget
92
93        super(ConnectionPropertyWidget, self).__init__()
94
95        grid_layout = QtWidgets.QGridLayout()
96
97        # Following must be done after setting connection widget
98        # Name
99        grid_layout.addWidget(QtWidgets.QLabel("Name: "), 0, 0)
100        grid_layout.addWidget(self.name_widget, 0, 1)
101
102        # Type
103        grid_layout.addWidget(QtWidgets.QLabel("Type: "), 1, 0)
104        grid_layout.addWidget(self.type_widget, 1, 1)
105
106        # Separator
107        separator = QtWidgets.QFrame()
108        separator.setFrameStyle(QtWidgets.QFrame.HLine | QtWidgets.QFrame.Plain)
109        grid_layout.addWidget(separator, 2, 0, 1, -1)
110
111        # Source Instance
112        grid_layout.addWidget(QtWidgets.QLabel("Source"), 3, 0, 1, -1)
113
114        grid_layout.addWidget(QtWidgets.QLabel("Interface: "), 4, 0)
115        grid_layout.addWidget(self.from_interface_widget, 4, 1)
116
117        grid_layout.addWidget(QtWidgets.QLabel("Instance: "), 5, 0)
118        grid_layout.addWidget(self.from_instance_widget, 5, 1)
119
120        # Separator
121        separator = QtWidgets.QFrame()
122        separator.setFrameStyle(QtWidgets.QFrame.HLine | QtWidgets.QFrame.Plain)
123        grid_layout.addWidget(separator, 6, 0, 1, -1)
124
125        # Destination Instance
126        grid_layout.addWidget(QtWidgets.QLabel("Destination"), 7, 0, 1, -1)
127
128        grid_layout.addWidget(QtWidgets.QLabel("Interface: "), 8, 0)
129        grid_layout.addWidget(self.to_interface_widget, 8, 1)
130
131        grid_layout.addWidget(QtWidgets.QLabel("Instance: "), 9, 0)
132        grid_layout.addWidget(self.to_instance_widget, 9, 1)
133
134        self.setLayout(grid_layout)
135