def new_project(self): """ Get the file path to a new project """ # dirpath will be None or a string msg, pth = RegistryHelpers.GetFilenameFromUserQT( self, RegistryKey='klusterintel', Title='Create a new Kluster project', AppName='klusterintel', fFilter="*.json", bSave=True, DefaultFile='kluster_project.json') if pth: # the project name is mandatory, just so that we can find it later, I ask for a file path for the project # file and override the filename, kind of messy but works for now if os.path.exists(pth): os.remove(pth) directory, filename = os.path.split(pth) project_file = os.path.join(directory, 'kluster_project.json') self.fil_text.setText(project_file) self.project_file = project_file self.project = FqprProject(is_gui=True) self.project.new_project_from_directory(directory) if self.parent: self.parent.set_project(self.project) self._load_from_project()
def __init__(self, parent=None): super().__init__(parent) self.resize(450, 800) self.setWindowTitle('Kluster Project Tree') self.top_widget = QtWidgets.QWidget() self.setCentralWidget(self.top_widget) layout = QtWidgets.QHBoxLayout() self.top_widget.setLayout(layout) self.project = FqprProject() self.k_tree = KlusterProjectTree(self) self.k_tree.setObjectName('kluster_project_tree') self.k_tree.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.k_tree.setMinimumWidth(300) layout.addWidget(self.k_tree) self.k_tree.file_added.connect(self.update_ktree) layout.layout() self.setLayout(layout) self.centralWidget().setLayout(layout) self.show()
def build_from_project(self, project_path: str): """ Load from a new project file, will close the active project and repopulate the gui Parameters ---------- project_path path to a kluster project, kluster_project.json file """ if os.path.exists(project_path): self.clear_project() self.project_file = project_path self.project = FqprProject(is_gui=True) self.project.open_project(self.project_file, skip_dask=True) if self.parent: self.parent.set_project(self.project) self._load_from_project() print('Loaded {}'.format(project_path)) else: print('Unable to load from file, does not exist: {}'.format( project_path))
class OutWindow(QtWidgets.QMainWindow): """ Simple Window for viewing the KlusterProjectTree for testing """ def __init__(self, parent=None): super().__init__(parent) self.resize(450, 800) self.setWindowTitle('Kluster Project Tree') self.top_widget = QtWidgets.QWidget() self.setCentralWidget(self.top_widget) layout = QtWidgets.QHBoxLayout() self.top_widget.setLayout(layout) self.project = FqprProject() self.k_tree = KlusterProjectTree(self) self.k_tree.setObjectName('kluster_project_tree') self.k_tree.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.k_tree.setMinimumWidth(300) layout.addWidget(self.k_tree) self.k_tree.file_added.connect(self.update_ktree) layout.layout() self.setLayout(layout) self.centralWidget().setLayout(layout) self.show() def update_ktree(self, fil): for f in fil: fqpr_entry, already_in = self.project.add_fqpr(f, skip_dask=True) if fqpr_entry is None: print('update_ktree: Unable to add to Project: {}'.format(f)) self.k_tree.refresh_project(self.project)
class KlusterProjectView(QtWidgets.QWidget): """ QTableWidget to display the data from an fqpr_intelligence IntelModule. """ file_added = QtCore.Signal(str) def __init__(self, parent=None, *args, **kwargs): super().__init__(*args, **kwargs) self.parent = parent self.project_file = None self.project = None self.loaded_fqpr_views = [] self.loaded_collapsible = [] self.mainlayout = QtWidgets.QVBoxLayout() self.hlayout = QtWidgets.QHBoxLayout() self.fil_text = QtWidgets.QLineEdit('') self.fil_text.setMinimumWidth(400) self.fil_text.setReadOnly(True) self.hlayout.addWidget(self.fil_text) self.newproj_button = QtWidgets.QPushButton("New Project") self.hlayout.addWidget(self.newproj_button) self.openproj_button = QtWidgets.QPushButton("Open Project") self.hlayout.addWidget(self.openproj_button) self.mainlayout.addLayout(self.hlayout) scroll = QtWidgets.QScrollArea() scroll.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) scroll_content = QtWidgets.QWidget() scroll_layout = QtWidgets.QVBoxLayout(scroll_content) scroll_content.setLayout(scroll_layout) self.datalayout = QtWidgets.QVBoxLayout() scroll_layout.addLayout(self.datalayout) scroll.setWidget(scroll_content) scroll.setWidgetResizable(True) self.mainlayout.addWidget(scroll) self.setLayout(self.mainlayout) self.setMinimumSize(1000, 600) self.newproj_button.clicked.connect(self.new_project) self.openproj_button.clicked.connect(self.open_project) def _load_from_project(self): """ Build out the gui from the loaded project. Each fqpr instance gets it's own collapsible section """ for fqpr_name, fqpr_inst in self.project.fqpr_instances.items(): fqprview = KlusterFqprView(self, fqpr_inst) new_expand = CollapsibleWidget(self, fqpr_name, 100, set_expanded_height=800) new_layout = QtWidgets.QVBoxLayout() new_layout.addWidget(fqprview) new_expand.setContentLayout(new_layout) self.datalayout.addWidget(new_expand) self.loaded_fqpr_views.append(fqprview) self.loaded_collapsible.append(new_expand) self.datalayout.addStretch() self.datalayout.layout() def new_project(self): """ Get the file path to a new project """ # dirpath will be None or a string msg, pth = RegistryHelpers.GetFilenameFromUserQT( self, RegistryKey='klusterintel', Title='Create a new Kluster project', AppName='klusterintel', fFilter="*.json", bSave=True, DefaultFile='kluster_project.json') if pth: # the project name is mandatory, just so that we can find it later, I ask for a file path for the project # file and override the filename, kind of messy but works for now if os.path.exists(pth): os.remove(pth) directory, filename = os.path.split(pth) project_file = os.path.join(directory, 'kluster_project.json') self.fil_text.setText(project_file) self.project_file = project_file self.project = FqprProject(is_gui=True) self.project.new_project_from_directory(directory) if self.parent: self.parent.set_project(self.project) self._load_from_project() def open_project(self): """ Get the file path to a new project """ # dirpath will be None or a string msg, pth = RegistryHelpers.GetFilenameFromUserQT( self, RegistryKey='klusterintel', Title='Open an existing Kluster project', AppName='klusterintel', fFilter="*.json", bSave=False) if pth: self.fil_text.setText(pth) self.build_from_project(pth) def close_project(self): self.fil_text.setText('') self.project = None if self.parent: self.parent.set_project(self.project) def build_from_project(self, project_path: str): """ Load from a new project file, will close the active project and repopulate the gui Parameters ---------- project_path path to a kluster project, kluster_project.json file """ if os.path.exists(project_path): self.clear_project() self.project_file = project_path self.project = FqprProject(is_gui=True) self.project.open_project(self.project_file, skip_dask=True) if self.parent: self.parent.set_project(self.project) self._load_from_project() print('Loaded {}'.format(project_path)) else: print('Unable to load from file, does not exist: {}'.format( project_path)) def clear_project(self): """ Clear the datalayout layout widget """ clear_layout(self.datalayout)