def openAfterMaybeSave(self): """ This is the method that initiates file opening. It is called by actionOpenSlot to spawn a QFileDialog and connect it to a callback method. """ path = self._file_open_path if util.isWindows(): # required for native looking file window#"/", fname = QFileDialog.getOpenFileName( None, "Open Document", path, "cadnano1 / cadnano2 Files (*.nno *.json *.cadnano)") self.filesavedialog = None self.openAfterMaybeSaveCallback(fname) else: # access through non-blocking callback fdialog = QFileDialog( self.win, "Open Document", path, "cadnano1 / cadnano2 Files (*.nno *.json *.cadnano)") fdialog.setAcceptMode(QFileDialog.AcceptOpen) fdialog.setWindowFlags(Qt.Sheet) fdialog.setWindowModality(Qt.WindowModal) self.fileopendialog = fdialog self.fileopendialog.filesSelected.connect(self.openAfterMaybeSaveCallback) fdialog.open()
def saveFileDialog(self): fname = self.filename() if fname == None: directory = "." else: directory = QFileInfo(fname).path() if util.isWindows(): # required for native looking file window fname = QFileDialog.getSaveFileName( self.win, "%s - Save As" % QApplication.applicationName(), directory, "%s (*.json)" % QApplication.applicationName()) self.writeDocumentToFile(fname) else: # access through non-blocking callback fdialog = QFileDialog( self.win, "%s - Save As" % QApplication.applicationName(), directory, "%s (*.json)" % QApplication.applicationName()) fdialog.setAcceptMode(QFileDialog.AcceptSave) fdialog.setWindowFlags(Qt.Sheet) fdialog.setWindowModality(Qt.WindowModal) self.filesavedialog = fdialog self.filesavedialog.filesSelected.connect( self.saveFileDialogCallback) fdialog.open()
def actionExportStaplesSlot(self): """ Triggered by clicking Export Staples button. Opens a file dialog to determine where the staples should be saved. The callback is exportStaplesCallback which collects the staple sequences and exports the file. """ # Validate that no staple oligos are loops. part = self.activePart() if part is None: return stap_loop_olgs = part.getStapleLoopOligos() if stap_loop_olgs: from ui.dialogs.ui_warning import Ui_Warning dialog = QDialog() dialogWarning = Ui_Warning() # reusing this dialog, should rename dialog.setStyleSheet("QDialog { background-image: url(ui/dialogs/images/cadnano2-about.png); background-repeat: none; }") dialogWarning.setupUi(dialog) locs = ", ".join([o.locString() for o in stap_loop_olgs]) msg = "Part contains staple loop(s) at %s.\n\nUse the break tool to introduce 5' & 3' ends before exporting. Loops have been colored red; use undo to revert." % locs dialogWarning.title.setText("Staple validation failed") dialogWarning.message.setText(msg) for o in stap_loop_olgs: o.applyColor(styles.stapColors[0].name()) dialog.exec_() return # Proceed with staple export. fname = self.filename() if fname == None: directory = "." else: directory = QFileInfo(fname).path() if util.isWindows(): # required for native looking file window fname = QFileDialog.getSaveFileName( self.win, "%s - Export As" % QApplication.applicationName(), directory, "(*.csv)") self.saveStaplesDialog = None self.exportStaplesCallback(fname) else: # access through non-blocking callback fdialog = QFileDialog( self.win, "%s - Export As" % QApplication.applicationName(), directory, "(*.csv)") fdialog.setAcceptMode(QFileDialog.AcceptSave) fdialog.setWindowFlags(Qt.Sheet) fdialog.setWindowModality(Qt.WindowModal) self.saveStaplesDialog = fdialog self.saveStaplesDialog.filesSelected.connect(self.exportStaplesCallback) fdialog.open()
def actionExportSequencesSlot(self): """ Triggered by clicking Export Staples button. Opens a file dialog to determine where the staples should be saved. The callback is exportStaplesCallback which collects the staple sequences and exports the file. """ # Validate that no staple oligos are circular. part = self._document.activePart() if part is None: return circ_olgs = part.getCircularOligos() if circ_olgs: from cadnano.gui.ui.dialogs.ui_warning import Ui_Warning dialog = QDialog() dialogWarning = Ui_Warning() # reusing this dialog, should rename dialog.setStyleSheet( "QDialog { background-image: url(ui/dialogs/images/cadnano2-about.png); background-repeat: none; }" ) dialogWarning.setupUi(dialog) locs = ", ".join([o.locString() for o in circ_olgs]) msg = "Part contains staple loop(s) at %s.\n\nUse the break tool to introduce 5' & 3' ends before exporting. Loops have been colored red; use undo to revert." % locs dialogWarning.title.setText("Staple validation failed") dialogWarning.message.setText(msg) for o in circ_olgs: o.applyColor(styles.stapColors[0]) dialog.exec_() return # Proceed with staple export. fname = self.fileName() if fname is None: directory = "." else: directory = QFileInfo(fname).path() if util.isWindows(): # required for native looking file window fname = QFileDialog.getSaveFileName( self.win, "%s - Export As" % QApplication.applicationName(), directory, "(*.txt)") self.saveStaplesDialog = None self.exportStaplesCallback(fname) else: # access through non-blocking callback fdialog = QFileDialog( self.win, "%s - Export As" % QApplication.applicationName(), directory, "(*.txt)") fdialog.setAcceptMode(QFileDialog.AcceptSave) fdialog.setWindowFlags(Qt.Sheet) fdialog.setWindowModality(Qt.WindowModal) self.saveStaplesDialog = fdialog self.saveStaplesDialog.filesSelected.connect( self.exportStaplesCallback) fdialog.open()
def openAfterMaybeSave(self): '''This is the method that initiates file opening. It is called by actionOpenSlot to spawn a QFileDialog and connect it to a callback method. ''' path = self._file_open_path if util.isWindows(): # required for native looking file window#"/", fname = QFileDialog.getOpenFileName( None, "Open Document", path, "cadnano1 / cadnano2 Files (*.nno *.json *.c25)") self.filesavedialog = None self.openAfterMaybeSaveCallback(fname) else: # access through non-blocking callback fdialog = QFileDialog( self.win, "Open Document", path, "cadnano1 / cadnano2 Files (*.nno *.json *.c25)") fdialog.setAcceptMode(QFileDialog.AcceptOpen) fdialog.setWindowFlags(Qt.Sheet) fdialog.setWindowModality(Qt.WindowModal) self.fileopendialog = fdialog self.fileopendialog.filesSelected.connect( self.openAfterMaybeSaveCallback) fdialog.open()
def saveFileDialog(self): fname = self.fileName() if fname is None: directory = "." else: directory = QFileInfo(fname).path() if util.isWindows(): # required for native looking file window fname = QFileDialog.getSaveFileName( self.win, "%s - Save As" % QApplication.applicationName(), directory, "%s (*.json)" % QApplication.applicationName()) if isinstance(fname, (list, tuple)): fname = fname[0] self.writeDocumentToFile(fname) else: # access through non-blocking callback fdialog = QFileDialog( self.win, "%s - Save As" % QApplication.applicationName(), directory, "%s (*.json)" % QApplication.applicationName()) fdialog.setAcceptMode(QFileDialog.AcceptSave) fdialog.setWindowFlags(Qt.Sheet) fdialog.setWindowModality(Qt.WindowModal) self.filesavedialog = fdialog self.filesavedialog.filesSelected.connect( self.saveFileDialogCallback) fdialog.open()
# -*- coding: utf-8 -*- from PyQt5.QtGui import QFont from cadnano import util THE_FONT = None THE_FONT_SIZE = None if util.isMac(): THE_FONT = "Times" THE_FONT = "Arial" THE_FONT_SIZE = 10 elif util.isWindows(): THE_FONT = "Segoe UI" THE_FONT = "Calibri" THE_FONT = "Arial" THE_FONT_SIZE = 9 else: # linux THE_FONT = "DejaVu Sans" THE_FONT_SIZE = 9 VIEW_BG_COLOR = '#f6f6f6' BLUE_FILL = '#99ccff' BLUE_STROKE = '#0066cc' # BLUISH_STROKE = '#00b6fa' ORANGE_FILL = '#ffcc99' ORANGE_STROKE = '#cc6633' # PINK_STROKE = '#cc00cc' # LIGHT_ORANGE_FILL = '#ffeab7' # LIGHT_ORANGE_STROKE = '#ea8451' GRAY_FILL = '#eeeeee' # (was #a1a1a1) # MIDGRAY_FILL = '#9a9a9a'
SEQUENCEFONTMETRICS = QFontMetricsF(SEQUENCEFONT) SEQUENCEFONTCHARWIDTH = SEQUENCEFONTMETRICS.width("A") SEQUENCEFONTCHARHEIGHT = SEQUENCEFONTMETRICS.height() SEQUENCEFONTEXTRAWIDTH = PATH_BASE_WIDTH - SEQUENCEFONTCHARWIDTH SEQUENCEFONT.setLetterSpacing(QFont.AbsoluteSpacing, SEQUENCEFONTEXTRAWIDTH) SEQUENCETEXTXCENTERINGOFFSET = SEQUENCEFONTEXTRAWIDTH / 4. SEQUENCETEXTYCENTERINGOFFSET = PATH_BASE_WIDTH * 0.6 #end def if util.isMac(): THE_FONT = "Times" THE_FONT = "Arial" THE_FONT_SIZE = 10 XOVER_LABEL_FONT = QFont(THE_FONT, THE_FONT_SIZE, QFont.Bold) elif util.isWindows(): THE_FONT = "Segoe UI" THE_FONT = "Calibri" THE_FONT = "Arial" THE_FONT_SIZE = 9 XOVER_LABEL_FONT = QFont(THE_FONT, THE_FONT_SIZE, QFont.Bold) else: # linux THE_FONT = "DejaVu Sans" THE_FONT_SIZE = 9 XOVER_LABEL_FONT = QFont(THE_FONT, THE_FONT_SIZE, QFont.Bold) SLICE_NUM_FONT = QFont(THE_FONT, 10, QFont.Bold) VIRTUALHELIXHANDLEITEM_FONT = QFont(THE_FONT, 3*THE_FONT_SIZE, QFont.Bold) XOVER_LABEL_COLOR = QColor(0,0,0) # Overwrite for Maya