Skip to content

Commit

Permalink
added attribute fields for each list in RelationChangeScreen.py
Browse files Browse the repository at this point in the history
  • Loading branch information
christiaan committed Oct 25, 2024
1 parent d1313a6 commit 4535f6e
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 11 deletions.
25 changes: 24 additions & 1 deletion Domain/RelationChangeDomain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import List, Optional, cast

from otlmow_converter.DotnotationDictConverter import DotnotationDictConverter
from otlmow_model.OtlmowModel.BaseClasses.OTLObject import OTLObject, dynamic_create_type_from_uri
from otlmow_model.OtlmowModel.Classes.ImplementatieElement.AIMObject import \
AIMObject
Expand Down Expand Up @@ -105,6 +106,9 @@ def set_possible_relations(cls, selected_object:AIMObject):

cls.get_screen().fill_possible_relations_list(selected_object,possible_relations_for_this_object)

object_attributes_dict = DotnotationDictConverter.to_dict(selected_object)
cls.get_screen().fill_object_attribute_field(object_attributes_dict)

@classmethod
def get_same_existing_relations(cls, relation_def: OSLORelatie,
selected_object: AIMObject,
Expand Down Expand Up @@ -265,4 +269,23 @@ def if_possible_relations_list_exists_then_add(cls, source, target, removed_rela
if target in cls.possible_object_to_object_relations[source]:
cls.possible_object_to_object_relations[source][target].append(removed_relation)
else:
cls.possible_object_to_object_relations[source][target] = [removed_relation]
cls.possible_object_to_object_relations[source][target] = [removed_relation]

@classmethod
def select_existing_relation_indices(cls, indices: list[int]) -> None:
if not indices:
return

last_index = indices[-1]
last_selected_relation = cls.existing_relations[last_index]
cls.get_screen().fill_existing_relation_attribute_field(DotnotationDictConverter.to_dict(last_selected_relation))

@classmethod
def select_possible_relation_keys(cls, relation_keys: list) -> None:
if not relation_keys:
return

last_selected_keys = relation_keys[-1]
last_selected_relation = cls.possible_object_to_object_relations[last_selected_keys.source_id][last_selected_keys.target_id][last_selected_keys.index]
cls.get_screen().fill_possible_relation_attribute_field(
DotnotationDictConverter.to_dict(last_selected_relation))
99 changes: 89 additions & 10 deletions GUI/Screens/RelationChangeScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from typing import List, Optional

import qtawesome as qta
from PyQt6.QtGui import QPixmap
from PyQt6.QtGui import QPixmap, QPalette, QColorConstants
from PyQt6.QtWidgets import QVBoxLayout, QFrame, QHBoxLayout, QPushButton, \
QWidget, QLineEdit, QLabel, QListWidget, QListWidgetItem
QWidget, QLineEdit, QLabel, QListWidget, QListWidgetItem, QHeaderView, QTreeWidget, \
QTreeWidgetItem
from otlmow_converter.DotnotationDictConverter import DotnotationDictConverter
from otlmow_model.OtlmowModel.Classes.ImplementatieElement.AIMObject import \
AIMObject
from otlmow_model.OtlmowModel.Classes.ImplementatieElement.RelatieObject import RelatieObject
Expand All @@ -31,11 +33,18 @@ def __init__(self, language_settings=None):
self.input_field = None

self.frame_layout = None

self.object_list_gui = None
self.object_attribute_field: QTreeWidget = QTreeWidget()
self.hidden_object_list_button = ButtonWidget()

self.possible_relation_list_gui = None
self.add_possible_relation_to_existing_button = ButtonWidget()
self.possible_relation_attribute_field: QTreeWidget = QTreeWidget()

self.existing_relation_list_gui = None
self.remove_existing_relation_button = ButtonWidget()
self.existing_relation_attribute_field: QTreeWidget = QTreeWidget()

self.init_ui()

Expand All @@ -53,16 +62,17 @@ def create_menu(self) -> QWidget:
self.window.setProperty('class', 'background-box')
self.window_layout = QVBoxLayout()
self.window_layout.addSpacing(10)
self.window_layout.addWidget(self.input_file_field())
self.window_layout.addWidget(self.input_file_selector())
self.window_layout.addSpacing(10)
self.window_layout.addWidget(self.horizontal_layout())
self.window.setLayout(self.window_layout)


# self.fill_relations_list()

return self.window

def input_file_field(self) -> QFrame:
def input_file_selector(self) -> QFrame:
frame = QFrame()
frame_layout = QHBoxLayout()
self.input_field = QLineEdit()
Expand All @@ -88,9 +98,24 @@ def create_object_list_gui(self) -> QFrame:

frame_layout.addWidget(class_label)
frame_layout.addWidget(self.object_list_gui)

object_attribute_label = QLabel()
object_attribute_label.setText(self._('object_attributes'))
frame_layout.addWidget(self.create_hidden_button())
frame_layout.addWidget(object_attribute_label)


frame_layout.addWidget(self.create_object_attribute_field(self.object_attribute_field))
frame.setLayout(frame_layout)

return frame

def create_hidden_button(self):
self.hidden_object_list_button.setEnabled(False)
self.hidden_object_list_button.setText("hidden")
self.hidden_object_list_button.setProperty("class", "invisible")
return self.hidden_object_list_button

def fill_object_list(self, objects: List[AIMObject]) -> None:
self.object_list_gui.clear()
for OTL_object in objects:
Expand All @@ -115,6 +140,8 @@ def object_selected(self) -> None:
if self.selected_object_col1 is not None:
RelationChangeDomain.set_possible_relations(
selected_object=self.selected_object_col1)


break

def fill_existing_relations_list(self, relations_objects: List[RelatieObject]) -> None:
Expand Down Expand Up @@ -171,12 +198,6 @@ def fill_possible_relations_list(self, source_object: AIMObject,
# sourcery skip: remove-dict-keys
self.possible_relation_list_gui.clear()

# if not relations:
# item = QListWidgetItem()
# item.
# self.possible_relation_list_gui.addItem(item)


Text = namedtuple('text', ['source_typeURI', 'direction', 'screen_name','target_typeURI'])
Data = namedtuple('data', ['source_id','target_id',"index"])

Expand Down Expand Up @@ -265,6 +286,11 @@ def create_relations_list_gui(self):
frame_layout.addWidget(self.possible_relation_list_gui)
frame_layout.addWidget(self.add_possible_relation_to_existing_button)

possible_relation_attribute_label = QLabel()
possible_relation_attribute_label.setText(self._('possible_relation_attributes'))
frame_layout.addWidget(possible_relation_attribute_label)
frame_layout.addWidget(self.create_object_attribute_field(self.possible_relation_attribute_field))

frame.setLayout(frame_layout)
return frame

Expand Down Expand Up @@ -295,6 +321,8 @@ def enable_add_relations_button_if_possible_relations_selected(self) -> None:
elif self.add_possible_relation_to_existing_button.isEnabled():
self.add_possible_relation_to_existing_button.setEnabled(False)

self.possible_relations_selected()

def enable_remove_relations_button_if_existing_relations_selected(self) -> None:

self.remove_existing_relation_button.isEnabled()
Expand All @@ -304,6 +332,8 @@ def enable_remove_relations_button_if_existing_relations_selected(self) -> None:
elif self.remove_existing_relation_button.isEnabled():
self.remove_existing_relation_button.setEnabled(False)

self.existing_relations_selected()

def create_existing_relations_list_gui(self):
frame = QFrame()
frame_layout = QVBoxLayout()
Expand All @@ -324,6 +354,10 @@ def create_existing_relations_list_gui(self):
frame_layout.addWidget(existing_rel_label)
frame_layout.addWidget(self.existing_relation_list_gui)
frame_layout.addWidget(self.remove_existing_relation_button)
existing_relation_attribute_label = QLabel()
existing_relation_attribute_label.setText(self._('existing_relation_attributes'))
frame_layout.addWidget(existing_relation_attribute_label)
frame_layout.addWidget(self.create_object_attribute_field(self.existing_relation_attribute_field))

frame.setLayout(frame_layout)
return frame
Expand All @@ -336,6 +370,13 @@ def remove_existing_relations(self):
for index in indices:
RelationChangeDomain.remove_existing_relation(index)

def existing_relations_selected(self):
indices: list[int] = [
item.data(3)
for item in self.existing_relation_list_gui.selectedItems()]

RelationChangeDomain.select_existing_relation_indices(indices)

def horizontal_layout(self):
frame = QFrame()
self.frame_layout = QHBoxLayout()
Expand All @@ -357,3 +398,41 @@ def map_widget(self):

def reset_ui(self, _):
self._ = _

def create_object_attribute_field(self, attribute_field: QTreeWidget):

attribute_field.setColumnCount(2)
attribute_field.setProperty('class', 'list')
attribute_field.setHeaderHidden(True)

header = attribute_field.header()
header.setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(0, QHeaderView.ResizeMode.ResizeToContents)
header.setStretchLastSection(False)

return attribute_field

def fill_object_attribute_field(self, object_attribute_dict:dict):
self.fill_attribute_field(self.object_attribute_field, object_attribute_dict)

def fill_possible_relation_attribute_field(self, possible_relation_attribute_dict:dict):
self.fill_attribute_field(self.possible_relation_attribute_field, possible_relation_attribute_dict)

def fill_existing_relation_attribute_field(self, existing_relation_attribute_dict: dict):
self.fill_attribute_field(self.existing_relation_attribute_field, existing_relation_attribute_dict)

def fill_attribute_field(self, field, object_attribute_dict):
field.clear()
for attribute, value in object_attribute_dict.items():
list_item = QTreeWidgetItem()
list_item.setText(0, attribute)
list_item.setText(1, str(value))
field.addTopLevelItem(list_item)

def possible_relations_selected(self):
Data = namedtuple('data', ['source_id', 'target_id', "index"])
data_list: list[Data] = [
Data(item.data(3), item.data(4), item.data(5))
for item in self.possible_relation_list_gui.selectedItems()]

RelationChangeDomain.select_possible_relation_keys(data_list)
10 changes: 10 additions & 0 deletions GUI/style/custom.qss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
font-family: Roboto;
}

.invisible{
background-color: #00000000;
color: #00000000;
height: 25px;
border-radius: 5px;
padding-left: 15px;
padding-right: 10px;
font-family: Roboto;
}

.new-project-btn{
background-color: #0E5A69;
color: #ffffff;
Expand Down

0 comments on commit 4535f6e

Please sign in to comment.