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

🪲 Bug/saving #105

Merged
merged 3 commits into from
Dec 9, 2021
Merged
Changes from 2 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
25 changes: 17 additions & 8 deletions opencodeblocks/graphics/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ def __init__(self):
)
loadStylesheets(
(
os.path.join(os.path.dirname(__file__), "..", "qss", "ocb_dark.qss"),
os.path.join(os.path.dirname(__file__),
"..", "qss", "ocb_dark.qss"),
self.stylesheet_filename,
)
)

self.mdiArea = QMdiArea()
self.mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
self.mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
self.mdiArea.setHorizontalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded)
self.mdiArea.setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAsNeeded)
self.mdiArea.setViewMode(QMdiArea.ViewMode.TabbedView)
self.mdiArea.setDocumentMode(True)
self.mdiArea.setTabsMovable(True)
Expand Down Expand Up @@ -306,22 +309,25 @@ def onFileNew(self):

def onFileOpen(self):
"""Open a file."""
filename, _ = QFileDialog.getOpenFileName(self, "Open ipygraph from file")
filename, _ = QFileDialog.getOpenFileName(
self, "Open ipygraph from file")
if filename == "":
return
if os.path.isfile(filename):
subwnd = self.createNewMdiChild(filename)
subwnd.show()
self.statusbar.showMessage(f"Successfully loaded {filename}", 2000)

def onFileSave(self) -> bool:
def onFileSave(self, current_window: OCBWidget = None) -> bool:
"""Save file.

Returns:
True if the file was successfully saved, False otherwise.

"""
current_window = self.activeMdiChild()
if current_window is None:
current_window = self.activeMdiChild()

if current_window is not None:
if current_window.savepath is None:
return self.onFileSaveAs()
Expand All @@ -340,11 +346,14 @@ def onFileSaveAs(self) -> bool:
"""
current_window = self.activeMdiChild()
if current_window is not None:
filename, _ = QFileDialog.getSaveFileName(self, "Save ipygraph to file")
dialog = QFileDialog()
dialog.setDefaultSuffix(".ipyg")
filename, _ = dialog.getSaveFileName(
self, "Save ipygraph to file", filter="IPython Graph (*.ipyg)")
if filename == "":
return False
current_window.savepath = filename
self.onFileSave()
self.onFileSave(current_window=current_window)
return True
return False

Expand Down