Permalink
Browse files

internal node view part 3

  • Loading branch information...
afourmy committed Sep 4, 2017
1 parent 4db6482 commit cf3af3581192be3a918562f7257a3fd0cca7d0f4
View
Binary file not shown.
View
@@ -42,7 +42,7 @@
def start_pyNMS(function):
def wrapper(self):
self.app = QApplication(sys.argv)
self.ct = controller.Controller(path_app)
self.ct = controller.Controller(path_app, test=True)
self.pj = self.ct.current_project
self.vw = self.pj.current_view
self.nk = self.vw.network
View
@@ -67,8 +67,9 @@
)
class Controller(QMainWindow):
def __init__(self, path_app):
def __init__(self, path_app, test=False):
super().__init__()
self.test = test
# for the update_paths decorator to work
self.controller = self
palette = self.palette()
@@ -262,6 +263,11 @@ def __init__(self, path_app):
site_view.setStatusTip('Switch to site view')
site_view.triggered.connect(self.show_site_view)
parent_view_icon = QIcon(join(self.path_icon, 'parent_view.png'))
parent_view = QAction(parent_view_icon, 'Parent view', self)
parent_view.setStatusTip('Go back to the parent view')
parent_view.triggered.connect(self.show_parent_view)
graph_generation_icon = QIcon(join(self.path_icon, 'ring.png'))
graph_generation = QAction(graph_generation_icon, 'Graph generation', self)
graph_generation.setShortcut('Ctrl+G')
@@ -312,6 +318,7 @@ def __init__(self, path_app):
toolbar.addSeparator()
toolbar.addAction(network_view)
toolbar.addAction(site_view)
toolbar.addAction(parent_view)
toolbar.addSeparator()
toolbar.addAction(graph_generation)
toolbar.addAction(stop_drawing)
@@ -329,7 +336,9 @@ def __init__(self, path_app):
self.gpixmaps = defaultdict(OrderedDict)
for color in ('default', 'red', 'purple'):
for subtype in node_subtype:
if subtype in ('shelf', 'port', 'card'):
if test:
path = ''
elif subtype in ('shelf', 'port', 'card'):
path = join(self.path_icon, ''.join((color, '_', subtype, '.png')))
else:
path = join(self.path_icon, ''.join((color, '_', subtype, '.gif')))
@@ -444,8 +453,9 @@ def yaml_import(self):
def yaml_export(self):
self.current_project.yaml_export()
@update_paths
def stop_drawing(self):
self.current_project.current_view.stop_timer()
self.view.stop_timer()
def switch_to_selection_mode(self):
self.mode = 'selection'
@@ -457,17 +467,23 @@ def show_network_view(self):
def show_site_view(self):
self.current_project.show_site_view()
@update_paths
def show_parent_view(self, _):
self.current_project.show_parent_view()
def generate_graph(self):
self.current_project.generate_graph()
def debug(self):
self.debug_window.show()
@update_paths
def show_hide_map(self):
self.current_project.current_view.world_map.show_hide_map()
self.view.world_map.show_hide_map()
@update_paths
def delete_map(self):
self.current_project.current_view.world_map.delete_map()
self.view.world_map.delete_map()
def refresh(self):
self.current_project.refresh()
@@ -484,11 +500,13 @@ def ellipse(self):
self.mode = 'creation'
self.creation_mode = 'ellipse'
@update_paths
def zoom_in(self):
self.current_project.current_view.zoom_in()
self.view.zoom_in()
@update_paths
def zoom_out(self):
self.current_project.current_view.zoom_out()
self.view.zoom_out()
@update_paths
def ssh_connection(self, _):
@@ -52,7 +52,7 @@ def mousePressEvent(self, event):
self.setFlag(QGraphicsItem.ItemIsSelectable, True)
self.setSelected(True)
menu = {
'main': MainNetworkSelectionMenu,
'network': MainNetworkSelectionMenu,
'internal': InternalSiteSelectionMenu,
}[self.view.subtype](self.controller)
menu.exec_(QCursor.pos())
@@ -6,7 +6,9 @@ class GraphicalNetworkNode(GraphicalNode):
def __init__(self, view, node=None):
super().__init__(view, node)
self.internal_view = InternalNodeView(self, view.controller)
print(self.node.subtype)
if self.node.subtype != 'port':
self.internal_view = InternalNodeView(self, view.controller)
# itemChange is overriden for a Graphical Network Node, because a site
# has no attached link. It does not need to trigger the update position
@@ -92,7 +92,7 @@ def mousePressEvent(self, event):
self.setFlag(QGraphicsItem.ItemIsSelectable, True)
self.setSelected(True)
menu = {
'main': MainNetworkSelectionMenu,
'network': MainNetworkSelectionMenu,
'insite': InternalSiteSelectionMenu,
'site': SiteSelectionMenu
}[self.view.subtype](self.controller)
@@ -16,11 +16,13 @@
from objects.objects import *
from miscellaneous.decorators import update_paths
from pyQT_widgets.Q_object_combo_box import QObjectComboBox
from PyQt5.QtGui import QStandardItem, QStandardItemModel
from PyQt5.QtWidgets import (
QGridLayout,
QGroupBox,
QLabel,
QLineEdit,
QTreeView,
QWidget
)
@@ -79,6 +81,8 @@ def __init__(self, obj, controller):
if property.multiple_values and property.choose_one_value:
pvalue = QObjectComboBox()
pvalue.addItems(property.values)
elif property.subtype == 'dict':
pvalue = QTreeView()
else:
# s = 'readonly' if property in self.read_only else 'normal'
pvalue = QLineEdit()
@@ -121,6 +125,14 @@ def __init__(self, obj, controller):
layout.addWidget(perAS_properties, 1, 0)
self.setLayout(layout)
def populate_tree(self, children, parent):
for child in sorted(children):
child_item = QStandardItem(child)
parent.appendRow(child_item)
print(bool(list(children)))
if isinstance(children, dict) and bool(list(children)):
self.populate_tree(children[child], child_item)
def update_AS_properties(self, _):
AS = self.AS_combobox.text
for property, entry in self.dict_perAS_properties.items():
@@ -201,6 +213,10 @@ def update(self):
property_widget.setText(','.join(map(str, obj_prop.keys())))
elif type(obj_prop) in (list, set):
property_widget.setText(','.join(map(str, obj_prop)))
elif property.subtype == 'dict':
root_model = QStandardItemModel()
property_widget.setModel(root_model)
self.populate_tree(obj_prop, root_model.invisibleRootItem())
else:
property_widget.setText(str(obj_prop))
@@ -361,7 +361,9 @@ class Structure(DictProperty):
# structure is a dictionnary that describes the internal structure
# of a node: shelves, cards, ports
def __new__(cls, value={}):
def __new__(cls, value=None):
if not value:
value = {}
return value
class Sites(SetProperty):
View
@@ -113,6 +113,16 @@ def show_internal_node_view(self, gnode):
self.view_type = 'innode'
self.controller.change_menu('innode')
def show_parent_view(self):
if self.current_view.subtype == 'insite':
self.show_site_view()
elif self.current_view.subtype == 'innode':
self.current_view.hide()
self.current_view = self.current_view.parent_view
self.current_view.show()
self.view_type = self.current_view.subtype
self.controller.change_menu(self.view_type)
def refresh(self):
commands = (
@@ -9,6 +9,7 @@ class InternalNodeView(BaseView):
def __init__(self, gnode, controller):
self.gnode = gnode
self.node = gnode.node
self.parent_view = gnode.view
self.network = Graph(self)
super().__init__(controller)
controller.current_project.hlayout.addWidget(self)
@@ -19,5 +20,8 @@ def dropEvent(self, event):
if event.mimeData().hasFormat('application/x-dnditemdata'):
from graphical_objects.graphical_network_node import GraphicalNetworkNode
new_gnode = GraphicalNetworkNode(self)
self.node.structure[new_gnode.node.name] = new_gnode.node.structure
if new_gnode.node.subtype != 'port':
self.node.structure[new_gnode.node.name] = new_gnode.node.structure
else:
self.node.structure[new_gnode.node.name] = []
new_gnode.setPos(pos)
@@ -11,7 +11,7 @@
class MainNetworkView(GeographicalView, NetworkView):
subtype = 'main'
subtype = 'network'
def __init__(self, controller):
self.network = Network(self)

0 comments on commit cf3af35

Please sign in to comment.