Skip to content

Commit

Permalink
Attempt to save plot to file
Browse files Browse the repository at this point in the history
  • Loading branch information
kinga322 committed Dec 2, 2016
1 parent b681ae9 commit 5cfa033
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions figures_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,14 @@ def reset(self):
self.fig.clear()
self.main_plot.clear()
self.create_main_plot()

def save_file(self, file_data):
"""Supported formats: eps, pdf, pgf, png, ps, raw, rgba, svg, svgz."""
file_format = file_data[1]
extension_location = file_format.find("*.")
extension = file_format[extension_location+1:len(file_format)-1]
file_name = file_data[0]
self.fig.savefig(file_name)
if extension not in file_name:
file_name += extension
self.fig.savefig(file_name)
21 changes: 21 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QLabel
import matplotlib as mpl
from dotplot import Dotplot
from sequence import DownloadFailed
from sequence import Sequence
Expand Down Expand Up @@ -41,13 +42,15 @@ def init_ui(self):
canvas_box = self.create_canvas()
sequence_form = self.create_sequence_form()


# let's have the sequence form over the canvas.
vbox = QVBoxLayout()
vbox.addLayout(sequence_form, stretch=0)
vbox.setAlignment(Qt.AlignTop)

vbox.addLayout(canvas_box, stretch=1)


interior = QWidget()
interior.setLayout(vbox)
self.setCentralWidget(interior)
Expand Down Expand Up @@ -98,6 +101,21 @@ def select_sequence_dialog(self):

return selected_file_data

def select_save_file_dialog(self):
selected_file_data = QFileDialog.getSaveFileName(
self,
'Choose a directory',
'', # use the last (or default) directory. It HAS to be str
'PNG file (*.png);;PDF file (*.pdf);;All files (*)',
None,
QFileDialog.DontUseNativeDialog
)
self.save_file(selected_file_data)

def save_file(self, file_data):
"""Supported formats: eps, pdf, pgf, png, ps, raw, rgba, svg, svgz."""
self.canvas.save_file(file_data)

def create_sequence_selector(self, seq_id):
"""Creates and handles widgets for a file selection."""
from PyQt5.QtWidgets import QToolButton
Expand Down Expand Up @@ -188,6 +206,8 @@ def create_canvas(self):
Currently TextEdit is used - only temporarily ;)
"""
self.canvas_box = QVBoxLayout()
savebutton = QPushButton('Save plot to file')
savebutton.clicked.connect(self.select_save_file_dialog)

if self.use_matplotlib:
from figures_plot import MyFigure
Expand All @@ -202,6 +222,7 @@ def create_canvas(self):
self.canvas = text_area

self.canvas_box.addWidget(self.canvas)
self.canvas_box.addWidget(savebutton)

return self.canvas_box

Expand Down

1 comment on commit 5cfa033

@kinga322
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#34

Please sign in to comment.