Beispiel #1
0
    def writeDocumentToFile(self, filename=None):
        helixOrderList = self.win.pathroot.getSelectedPartOrderedVHList()

        if helixOrderList == None:  # Do not attempt to save an empty design
            print("Cannot save empty document.")
            return False

        if filename == None:
            assert (not self._hasNoAssociatedFile)
            filename = self.filename()
        try:
            if util.isWindows() and isinstance(filename, (list, tuple)):
                filename = filename[0]
            with open(filename, 'w') as f:
                encode(self._document, helixOrderList, f)
        except IOError:
            flags = Qt.Dialog | Qt.MSWindowsFixedSizeDialogHint | Qt.WindowType.Sheet
            errorbox = QMessageBox(QMessageBox.Critical, "cadnano",
                                   "Could not write to '%s'." % filename,
                                   QMessageBox.Ok, self.win, flags)
            errorbox.setWindowModality(Qt.WindowModality.WindowModal)
            errorbox.open()
            return False
        self.undoStack().setClean()
        self.setFilename(filename)
        return True
Beispiel #2
0
 def actionCloseSlot(self):
     """This will trigger a Window closeEvent."""
     if util.isWindows():
         #print "close win"
         if self.win is not None:
             self.win.close()
         if not app().isInMaya():
             #print "exit app"
             import sys
             sys.exit(1)
Beispiel #3
0
def initAppWithGui(appArgs=sys.argv):
    util.qtFrameworkList = ['PyQt', 'PySide']
    from .cadnanoqt import CadnanoQt
    global sharedApp
    sharedApp = CadnanoQt(appArgs)
    sharedApp.finishInit()
    if util.isWindows():
        pass
        # import ctypes
        # myappid = 'harvard.cadnano.cadnano2.2' # arbitrary string
        # ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
    return sharedApp
Beispiel #4
0
    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()
        stapLoopOlgs = part.getStapleLoopOligos()
        if stapLoopOlgs:
            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 stapLoopOlgs])
            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 stapLoopOlgs:
                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.AcceptMode.AcceptSave)
            fdialog.setWindowFlags(Qt.WindowType.Sheet)
            fdialog.setWindowModality(Qt.WindowModality.WindowModal)
            self.saveStaplesDialog = fdialog
            self.saveStaplesDialog.filesSelected.connect(
                self.exportStaplesCallback)
            fdialog.open()
Beispiel #5
0
 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.AcceptMode.AcceptSave)
         fdialog.setWindowFlags(Qt.WindowType.Sheet)
         fdialog.setWindowModality(Qt.WindowModality.WindowModal)
         self.filesavedialog = fdialog
         self.filesavedialog.filesSelected.connect(
             self.saveFileDialogCallback)
         fdialog.open()
Beispiel #6
0
 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._fileOpenPath
     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.AcceptMode.AcceptOpen)
         fdialog.setWindowFlags(Qt.WindowType.Sheet)
         fdialog.setWindowModality(Qt.WindowModality.WindowModal)
         self.fileopendialog = fdialog
         self.fileopendialog.filesSelected.connect(
             self.openAfterMaybeSaveCallback)
         fdialog.open()
Beispiel #7
0
    SEQUENCEFONT.setPixelSize(SEQUENCEFONTH)
    SEQUENCEFONTMETRICS = QFontMetricsF(SEQUENCEFONT)
    SEQUENCEFONTCHARWIDTH = SEQUENCEFONTMETRICS.horizontalAdvance('A')
    SEQUENCEFONTCHARHEIGHT = SEQUENCEFONTMETRICS.height()
    SEQUENCEFONTEXTRAWIDTH = PATH_BASE_WIDTH - SEQUENCEFONTCHARWIDTH
    SEQUENCEFONT.setLetterSpacing(QFont.SpacingType.AbsoluteSpacing,
                                  SEQUENCEFONTEXTRAWIDTH)
    SEQUENCETEXTXCENTERINGOFFSET = SEQUENCEFONTEXTRAWIDTH / 4.
    SEQUENCETEXTYCENTERINGOFFSET = PATH_BASE_WIDTH * 0.6

if util.isMac():
    thefont = "Times"
    thefont = "Arial"
    thefontsize = 10
    XOVER_LABEL_FONT = QFont(thefont, thefontsize, QFont.Weight.Bold)
elif util.isWindows():
    thefont = "Segoe UI"
    thefont = "Calibri"
    thefont = "Arial"
    thefontsize = 9
    XOVER_LABEL_FONT = QFont(thefont, thefontsize, QFont.Weight.Bold)
else:  # linux
    thefont = "DejaVu Sans"
    thefontsize = 9
    XOVER_LABEL_FONT = QFont(thefont, thefontsize, QFont.Weight.Bold)

SLICE_NUM_FONT = QFont(thefont, 10, QFont.Weight.Bold)
VIRTUALHELIXHANDLEITEM_FONT = QFont(thefont, 3 * thefontsize,
                                    QFont.Weight.Bold)
XOVER_LABEL_COLOR = QColor(0, 0, 0)