Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Add feature: multiple windows #18

Merged
merged 6 commits into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,35 @@
app.setStyle('Fusion')

wnd = OCBWindow()
scene = wnd.ocb_widget.scene
# if hasattr(wnd, 'ocb_widget'):
# scene = wnd.ocb_widget.scene

test_block = OCBBlock(title="Other kind of block")
scene.addItem(test_block)
test_block.setPos(-250, 150)
# test_block = OCBBlock(title="Other kind of block")
# scene.addItem(test_block)
# test_block.setPos(-250, 150)

test_block_2 = OCBCodeBlock(title="Dataset", source=SOURCE_TEST)
for _ in range(2):
test_block_2.add_socket(OCBSocket(test_block_2, socket_type='input'))
for _ in range(1):
test_block_2.add_socket(OCBSocket(test_block_2, socket_type='output'))
test_block_2.setPos(-350, -100)
scene.addItem(test_block_2)
# test_block_2 = OCBCodeBlock(title="Dataset", source=SOURCE_TEST)
# for _ in range(2):
# test_block_2.add_socket(OCBSocket(test_block_2, socket_type='input'))
# for _ in range(1):
# test_block_2.add_socket(OCBSocket(test_block_2, socket_type='output'))
# test_block_2.setPos(-350, -100)
# scene.addItem(test_block_2)

test_block_3 = OCBCodeBlock(title="Mon IA (par blocks ?)", source=SOURCE_TEST_2)
for _ in range(2):
test_block_3.add_socket(OCBSocket(test_block_3, socket_type='input'))
for _ in range(1):
test_block_3.add_socket(OCBSocket(test_block_3, socket_type='output'))
test_block_3.setPos(0, -100)
scene.addItem(test_block_3)
# test_block_3 = OCBCodeBlock(title="Mon IA (par blocks ?)", source=SOURCE_TEST_2)
# for _ in range(2):
# test_block_3.add_socket(OCBSocket(test_block_3, socket_type='input'))
# for _ in range(1):
# test_block_3.add_socket(OCBSocket(test_block_3, socket_type='output'))
# test_block_3.setPos(0, -100)
# scene.addItem(test_block_3)

# for i in range(3):
# edge = OCBEdge(
# source_socket=test_block_3.sockets_out[0],
# destination_socket=test_block_2.sockets_in[i]
# )
# scene.addItem(edge)

scene.save('scene.ipyg')
scene.load('scene.ipyg')
# # for i in range(3):
# # edge = OCBEdge(
# # source_socket=test_block_3.sockets_out[0],
# # destination_socket=test_block_2.sockets_in[i]
# # )
# # scene.addItem(edge)

wnd.show()
sys.exit(app.exec_())
20 changes: 20 additions & 0 deletions opencodeblocks/graphics/qss/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# OpenCodeBlock an open-source tool for modular visual programing in python
# Copyright (C) 2021 Mathïs FEDERICO <https://www.gnu.org/licenses/>

""" Module for the OCB qss and styles. """

from typing import List

from PyQt5.QtCore import QFile
from PyQt5.QtWidgets import QApplication

from opencodeblocks.graphics.qss import dark_resources

def loadStylesheets(filenames:List[str]):
styles = ''
for filename in filenames:
file = QFile(filename)
file.open(QFile.ReadOnly | QFile.Text)
stylesheet = file.readAll()
styles += "\n" + str(stylesheet, encoding='utf-8')
QApplication.instance().setStyleSheet(styles)
509 changes: 509 additions & 0 deletions opencodeblocks/graphics/qss/dark_resources.py

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions opencodeblocks/graphics/qss/ocb.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
QDMNodeContentWidget {
background: transparent;
}
QDMNodeContentWidget QFrame {
background: transparent;
}
QDMNodeContentWidget QTextEdit,
QDMNodeContentWidget QLineEdit {
background: #666;
color: #fff;
}
QDMNodeContentWidget QLabel {
color: #e0e0e0;
min-width: 150px;
max-width: 150px;
min-height: 45px;
max-height: 45px;
margin-left: 10px;
margin-top: 5px;
font-size: 28px;
}
QDMNodeContentWidget QLineEdit#calc_node_input {
width: 140px;
height: 36px;
margin-top: 5px;
margin-left: 5px;
font-size: 28px;
}
QGraphicsView {
selection-background-color: #fff;
}
1 change: 1 addition & 0 deletions opencodeblocks/graphics/qss/ocb_dark.qss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
QFrame,QDialog,QMainWindow{background:#474747}QSplitter,QMainWindow::separator{background:#474747}QStatusBar{background:#474747;color:#ccc}QTabWidget{border:0}QTabBar{background:#474747;color:#ccc}QMdiArea QTabBar,QMdiArea QTabWidget,QMdiArea QTabWidget::pane,QMdiArea QTabWidget::tab-bar,QMdiArea QTabBar::tab{height:17px}QMdiArea QTabBar::tab:top:!selected,QMdiArea QTabBar::tab:top:selected,QMdiArea QTabBar::tab:top:!selected:hover{border-top-left-radius:4px;border-top-right-radius:4px;padding:2px 8px;padding-top:0;padding-bottom:3px;min-width:8ex;border:1px solid #333;border-bottom:0}QMdiArea QTabBar::tab:top:!selected,QMdiArea QTabBar::tab:top:!selected:hover{background:qlineargradient(x1 : 0,y1 : 0,x2 : 0,y2 : 1,stop : 0 #6d6d6d,stop : .1 #474747,stop : .89 #3f3f3f,stop : 1 #3f3f3f)}QMdiArea QTabBar::tab:top:selected{background:qlineargradient(x1 : 0,y1 : 0,x2 : 0,y2 : 1,stop : 0 #878787,stop : .1 #545454,stop : .89 #474747,stop : 1 #474747)}QMdiArea QTabBar::tab:top:!selected:hover{background:qlineargradient(x1 : 0,y1 : 0,x2 : 0,y2 : 1,stop : 0 #727272,stop : .1 #4c4c4c,stop : .89 #444,stop : 1 #444)}QMdiArea QTabBar QToolButton{background:qlineargradient(x1 : 0,y1 : 0,x2 : 0,y2 : 1,stop : 0 #878787,stop : .1 #616161,stop : .89 #4f4f4f,stop : 1 #4f4f4f);border:1px solid #333;border-radius:0}QMdiArea QTabBar QToolButton::left-arrow{image:url(":icons/small_arrow_left-light.png")}QMdiArea QTabBar QToolButton::right-arrow{image:url(":icons/small_arrow_right-light.png")}QMdiArea QTabBar::close-button:selected{image:url(":icons/tab_close_btn.png");subcontrol-origin:border;subcontrol-position:right bottom}QMdiArea QTabBar::close-button:!selected{image:url(":icons/tab_close_nonselected_btn.png")}QMdiSubWindow{border-style:solid;background:#616161}QTabBar::tab:selected,QTabBar::tab:hover{color:#eee}QDockWidget{color:#ddd;font-weight:bold;titlebar-close-icon:url(":icons/docktitle-close-btn-light.png");titlebar-normal-icon:url(":icons/docktitle-normal-btn-light.png")}QDockWidget::title{background:qlineargradient(x1 : 0,y1 : 0,x2 : 0,y2 : 1,stop : 0 #3b3b3b,stop : 1 #2e2e2e);padding-top:4px;padding-right:22px;font-weight:bold}QDockWidget::close-button,QDockWidget::float-button{subcontrol-position:top right;subcontrol-origin:margin;text-align:center;icon-size:16px;width:14px;position:absolute;top:0;bottom:0;left:0;right:4px}QDockWidget::close-button{right:4px}QDockWidget::float-button{right:18px}QMenuBar{background:#474747}QMenuBar::item{spacing:3px;padding:3px 5px;color:#eee;background:transparent}QMenuBar::item:selected,QMenuBar::item:pressed{background:#4f9eee}QMenu{background:#474747;border:1px solid #2e2e2e}QMenu::item{background:#474747;color:#eee}QMenu::item:selected{background:#616161}QMenu::active{background:#616161;color:#eee}QMenu::separator{height:1px;background:#2e2e2e}QMenu::disabled,QMenu::item:disabled{color:#6e6e6e}QListView{background-color:#555;alternate-background-color:#434343}QListView::item{height:22px;color:#e6e6e6}QListView::item:hover{background:#6e6e6e}QListView::item::active:hover{color:#fff}QListView::item:selected,QListView::item::active:selected{color:#fff;background:qlineargradient(x1 : 0,y1 : 0,x2 : 0,y2 : 1,stop : 0 #4f9eee,stop : 1 #2084ea);border:0}QPushButton{color:#e6e6e6;background:#555;border-color:#141414}QLabel{color:#e6e6e6}QLineEdit,QTextEdit{color:#e6e6e6;background:#5a5a5a}QLineEdit{border:1px solid #3a3a3a;border-radius:2px;padding:1px 2px}QDMNodeContentWidget{background:transparent;}QDMNodeContentWidget QFrame{background:transparent}QDMNodeContentWidget QTextEdit{background:#666}QDMNodeContentWidget QLabel{color:#e0e0e0}QGraphicsView{selection-background-color:#fff}
9 changes: 2 additions & 7 deletions opencodeblocks/graphics/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,9 @@ def has_been_modified(self):
return self._has_been_modified
@has_been_modified.setter
def has_been_modified(self, value:bool):
if not self._has_been_modified and value:
self._has_been_modified = value

# Call listeners
for callback in self._has_been_modified_listeners:
callback()

self._has_been_modified = value
for callback in self._has_been_modified_listeners:
callback()

def addHasBeenModifiedListener(self, callback:FunctionType):
""" Add a callback that will trigger when the scene has been modified. """
Expand Down
37 changes: 37 additions & 0 deletions opencodeblocks/graphics/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

""" Module for the OCB Widget """

import os

from PyQt5.QtWidgets import QVBoxLayout, QWidget
from PyQt5.QtCore import Qt

from opencodeblocks.graphics.scene import OCBScene
from opencodeblocks.graphics.view import OCBView
Expand All @@ -14,14 +17,48 @@ class OCBWidget(QWidget):

def __init__(self, parent=None):
super().__init__(parent)
self.setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose)

self.layout = QVBoxLayout()
self.layout.setContentsMargins(0, 0, 0, 0)
self.setLayout(self.layout)

# Graphics Scene
self.scene = OCBScene()
self.scene.addHasBeenModifiedListener(self.updateTitle)

# Graphics View
self.view = OCBView(self.scene)
self.layout.addWidget(self.view)

self.savepath = None

def updateTitle(self):
""" Update the window title. """
if self.savepath is None:
title = 'New Graph'
else:
title = os.path.basename(self.savepath)
if self.isModified():
title += "*"
self.setWindowTitle(title)

def isModified(self) -> bool:
""" Return True if the scene has been modified, False otherwise. """
return self.scene.has_been_modified

@property
def savepath(self):
""" Current cached file save path. Update window title when set."""
return self._savepath
@savepath.setter
def savepath(self, value:str):
self._savepath = value
self.updateTitle()

def save(self):
self.scene.save(self.savepath)

def load(self, filepath:str):
self.scene.load(filepath)
self.savepath = filepath
Loading