Skip to content
Snippets Groups Projects

#16 Sidebar + div. forbedringer

Merged Thomas Holene Løkkeborg requested to merge første-utkast-på-modulelist-sidebar into master
+ 74
26
"""Hovedvinduet."""
"""MainWindow.
During initial development this module will include most of the code necessary
to get our project up-and-running. When our project matures we will move code
out to separate modules.
"""
import sys
import os
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QTabWidget, QWidget, QMainWindow, \
QApplication, QHBoxLayout, QVBoxLayout, QPushButton, QTreeWidget, \
QLabel, QAction
from PySide2 import QtGui
QApplication, QHBoxLayout, QVBoxLayout, QPushButton, QLabel, \
QAbstractItemView, QListWidget, QListWidgetItem, QAction
from PySide2.QtGui import QIcon
class MainWindow(QMainWindow):
@@ -82,7 +88,7 @@ class MainWindow(QMainWindow):
# Legger til MainWidget som en tab, kanskje flytt ut til egen funksjon
tabs = QTabWidget()
tab = MainWidget()
tab = SOIWorkspaceWidget()
tabs.addTab(tab, "MainTab")
self.setCentralWidget(tabs)
@@ -91,33 +97,75 @@ class MainWindow(QMainWindow):
filename = 'media/HVlogo.PNG'
dirname = os.path.dirname(__file__)
filepath = os.path.join(dirname, filename)
self.setWindowIcon(QtGui.QIcon(filepath))
self.setWindowIcon(QIcon(filepath))
class SOIWorkspaceWidget(QWidget):
"""Contains the working area for a single SOI.
class MainWidget(QWidget):
"""Hovedwidget til applikasjonen, dette er det som blir tabs."""
The widget is used inside tabs in our application, and contains a sidebar
with a module list along with a view of the SOI.
"""
def __init__(self):
super().__init__()
layout1 = QHBoxLayout()
layout2 = QVBoxLayout()
# New module button
new_module = QPushButton("Ny modul")
new_module.setShortcut("Ctrl+m")
new_module.setStatusTip("Legg til en ny modul")
tree_view = QTreeWidget()
setup = QPushButton("Oppsett")
layout2.addWidget(tree_view)
layout2.addWidget(new_module)
layout2.addWidget(setup)
view = ViewArea()
layout1.addLayout(layout2, 2)
layout1.addWidget(view, 8)
self.setLayout(layout1)
self.layout_wrapper = QHBoxLayout()
self.layout_sidebar = QVBoxLayout()
# all widgets
self.button_new_module = QPushButton("Ny modul")
self.button_new_module.setShortcut("Ctrl+m")
self.button_new_module.setStatusTip("Legg til en ny modul")
self.button_setup = QPushButton("Oppsett")
self.list_modules = QListWidget()
self.view = ViewArea()
# prepare module list
self.setup_list_modules()
self.fill_list_modules()
# build layouts
self.layout_sidebar.addWidget(QLabel("Moduler:"))
self.layout_sidebar.addWidget(self.list_modules, 5)
self.layout_sidebar.addWidget(QLabel("Vedlegg:"))
self.layout_sidebar.addWidget(QListWidget(), 1)
self.layout_sidebar.addWidget(self.button_new_module)
self.layout_sidebar.addWidget(self.button_setup)
self.layout_wrapper.addLayout(self.layout_sidebar)
self.layout_wrapper.addWidget(self.view)
self.setFixedWidth(200)
self.setLayout(self.layout_wrapper)
def setup_list_modules(self):
"""Prepare module list.
The list contains modules that are drag-and-droppable.
"""
# enable drag-and-drop
self.list_modules.setDragEnabled(True)
self.list_modules.viewport().setAcceptDrops(True)
self.list_modules.viewport().setAcceptDrops(True)
self.list_modules.setDragDropMode(QAbstractItemView.InternalMove)
# source: https://www.qtcentre.org/threads/32500-Horizontal-Scrolling-QListWidget
self.list_modules.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
def fill_list_modules(self):
"""Fill module list with some items to manually test with.
This function will be removed when we can fill the list properly.
"""
# hardcode some items
items = [
QListWidgetItem("Frekvenstabell"),
QListWidgetItem("Sambandsdiagram"),
QListWidgetItem("Autentifiseringstavle"),
QListWidgetItem("Subtraktorkoder"),
]
for i, item in enumerate(items):
self.list_modules.insertItem(i, item)
class ViewArea(QWidget):
Loading