Example #1
0
def get_oligos_with_color(color):
    """
    Returns the set of oligos that has color <color>.
    """
    if isinstance(color, basestring):
        util.qtWrapImport('QtCore', globals(), ['QString'])
        if color[0] != "#" and len(color) == 6:
            # Probably forgot to add '#' in #ff00ff:
            color = '#'+color
        color = QString(color.lower())  # colors should be lower-case
    return set(oligo for oligo in get_all_oligos() if oligo.color() == color)
Example #2
0
def get_oligos_with_color(color):
    """
    Returns the set of oligos that has color <color>.
    """
    if isinstance(color, basestring):
        util.qtWrapImport('QtCore', globals(), ['QString'])
        if color[0] != "#" and len(color) == 6:
            # Probably forgot to add '#' in #ff00ff:
            color = '#' + color
        color = QString(color.lower())  # colors should be lower-case
    return set(oligo for oligo in get_all_oligos() if oligo.color() == color)
Example #3
0
def set_oligos_color(color, enableRedo=True):
    """
    Sets the color of all selected oligos to <color>.
    """
    if isinstance(color, basestring):
        util.qtWrapImport('QtCore', globals(), ['QString'])
        # PySide uses standard str as QString, but that should not be a problem.
        color = QString(color)
    selectedOs = get_selected_oligos()
    if enableRedo:
        # If A LOT of oligos are selected, this could add considerable overhead.
        # (There will be one undo command in the undo stack for EACH oligo.)
        for oligo in selectedOs:
            oligo.applyColor(color)
    else:
        for oligo in selectedOs:
            oligo.setColor(color) # setColor does not emit the
            oligo.oligoAppearanceChangedSignal(oligo)
Example #4
0
def set_oligos_color(color, enableRedo=True):
    """
    Sets the color of all selected oligos to <color>.
    """
    if isinstance(color, basestring):
        util.qtWrapImport('QtCore', globals(), ['QString'])
        # PySide uses standard str as QString, but that should not be a problem.
        color = QString(color)
    selectedOs = get_selected_oligos()
    if enableRedo:
        # If A LOT of oligos are selected, this could add considerable overhead.
        # (There will be one undo command in the undo stack for EACH oligo.)
        for oligo in selectedOs:
            oligo.applyColor(color)
    else:
        for oligo in selectedOs:
            oligo.setColor(color)  # setColor does not emit the
            oligo.oligoAppearanceChangedSignal(oligo)
Example #5
0
CustomQGraphicsView.py
.. module:: CustomQGraphicsView
   :platform: Unix, Windows, Mac OS X
   :synopsis: A Custom QGraphicsView module to allow focus input events
   like mouse clicks and panning and zooming

.. moduleauthor::  Nick Conway on 2011-01-17.
Copyright (c) 2010 . All rights reserved.

"""
from cadnano import app
from views import styles

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(),
                  ['Qt', 'QTimer', 'pyqtSignal', 'QTimeLine'])
util.qtWrapImport(
    'QtGui', globals(),
    ['QGraphicsView', 'QGraphicsScene', 'qApp', 'QPen', 'QPaintEngine'])

# for OpenGL mode
try:
    from PyQt4.QtGui import QWidget
    from OpenGL import GL
    from PyQt4.QtOpenGL import QGLWidget, QGLFormat, QGL
except:
    GL = False

GL = False

import os
from cadnano import app
from .selecttool import SelectTool
from .penciltool import PencilTool
from .breaktool import BreakTool
from .erasetool import EraseTool
from .insertiontool import InsertionTool
from .skiptool import SkipTool
from .painttool import PaintTool
from .addseqtool import AddSeqTool
import util

# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QObject', 'pyqtSignal'])
util.qtWrapImport('QtWidgets', globals(), [ 'QActionGroup'])


class PathToolManager(QObject):
    """
    Manages the interactions between Path widgets / UI elements and the model.
    """
    def __init__(self, win):
        super(PathToolManager, self).__init__()
        self.window = win
        self._activeTool = None
        self._activePart = None
        self.selectTool = SelectTool(self)
        self.pencilTool = PencilTool(self)
        self.breakTool = BreakTool(self)
        self.eraseTool = EraseTool(self)
        self.insertionTool = InsertionTool(self)
Example #7
0
# encoding: utf-8

from collections import defaultdict
from math import ceil
from .activesliceitem import ActiveSliceItem
from controllers.itemcontrollers.partitemcontroller import PartItemController
from .prexoveritem import PreXoverItem
from .strand.xoveritem import XoverNode3
from ui.mainwindow.svgbutton import SVGButton
from views import styles
from .virtualhelixitem import VirtualHelixItem
import util
from cadnano import app

# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QPointF', 'QRectF', 'Qt'])
util.qtWrapImport('QtGui', globals(), ['QBrush', 'QPen'])
util.qtWrapImport('QtWidgets', globals(), [
    'QGraphicsPathItem', 'QGraphicsItem', 'QGraphicsRectItem', 'QInputDialog'
])

_baseWidth = _bw = styles.PATH_BASE_WIDTH
_defaultRect = QRectF(0, 0, _baseWidth, _baseWidth)
_modPen = QPen(styles.bluestroke)


class ProxyParentItem(QGraphicsRectItem):
    """an invisible container that allows one to play with Z-ordering"""
    findChild = util.findChild  # for debug

Example #8
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

from parts.honeycombpart import HoneycombPart
from parts.squarepart import SquarePart
from parts.part import Part
from strand import Strand
from operator import itemgetter
import util, cadnano
util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'QObject'])
util.qtWrapImport('QtGui', globals(), ['QUndoCommand', 'QUndoStack'])


class Document(QObject):
    """
    The Document class is the root of the model. It has two main purposes:
    1. Serve as the parent all Part objects within the model.
    2. Track all sub-model actions on its undoStack.
    """
    def __init__(self):
        super(Document, self).__init__()
        self._undoStack = QUndoStack()
        self._parts = []
        self._assemblies = []
        self._controller = None
Example #9
0
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
"""
base.py
Created by Shawn Douglas on 2011-02-08.
"""
from .enum import StrandType
from random import Random
from views import styles
prng = Random()

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtGui', globals(), [ 'QColor'])

class Base(object):
    """
    A POD class that lives in the private API of virtualhelix.
    (Why not put it inside VirtualHelix? Because it's already quite crowded)
    Provides information about which bases are connected to which other bases.
    """
    def __init__(self, vhelix, strandtype, index):
        super(Base, self).__init__()
        self._5pBase = None
        self._3pBase = None
        self._color = None
        self._vhelix = vhelix
        self._strandtype = strandtype
        self._n = index
Example #10
0
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

from cadnano import app
from pathview.colorpanel import ColorPanel
from pathview.tools.pathtoolmanager import PathToolManager
from sliceview.slicerootitem import SliceRootItem
from pathview.pathrootitem import PathRootItem

from sliceview.tools.slicetoolmanager import SliceToolManager
import ui.mainwindow.ui_mainwindow as ui_mainwindow
import util

util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'Qt', 'QFileInfo',
                                        'QPoint', 'QSettings', 'QSize',
                                        'QString'])
util.qtWrapImport('QtGui', globals(), ['QAction', 'QApplication',
                                       'QGraphicsObject', 'QGraphicsScene',
                                       'QGraphicsView', 'QMainWindow',
                                       'QGraphicsItem', 'QGraphicsRectItem',
                                       'QWidget', 'QPaintEngine'])
# for OpenGL mode
try:
    from OpenGL import GL
except:
    GL = False

GL = False

class DocumentWindow(QMainWindow, ui_mainwindow.Ui_MainWindow):
Example #11
0
# http://www.opensource.org/licenses/mit-license.php

"""
virtualhelixitem.py

Created by Shawn on 2010-06-15.
"""

from views import styles
from model.virtualhelix import VirtualHelix
from model.enum import Parity, StrandType
from controllers.itemcontrollers.virtualhelixitemcontroller import VirtualHelixItemController

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['Qt', 'QEvent', 'QString', 'QRectF',\
                                        'QPointF'])
util.qtWrapImport('QtGui', globals(), ['QGraphicsEllipseItem', 'QGraphicsItem',\
                                'QGraphicsSimpleTextItem', 'QBrush', 'QPen', \
                                'QPainterPath', 'QPolygonF', 'QGraphicsLineItem', 'QColor'])

class VirtualHelixItem(QGraphicsEllipseItem):
    """
    The VirtualHelixItem is an individual circle that gets drawn in the SliceView
    as a child of the PartItem. Taken as a group, many SliceHelix
    instances make up the crossection of the DNAPart. Clicking on a SliceHelix
    adds a VirtualHelix to the DNAPart. The SliceHelix then changes appearence
    and paints its corresponding VirtualHelix number.
    """
    # set up default, hover, and active drawing styles
    _useBrush = QBrush(styles.orangefill)
    _usePen = QPen(styles.orangestroke, styles.SLICE_HELIX_STROKE_WIDTH)
Example #12
0
import math
import re
from cadnano import app
from model.enum import StrandType
from views import styles
import util

try:
    from OpenGL import GL
except:
    GL = False

GL = False

# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QPointF', 'QRectF', 'Qt'])
util.qtWrapImport('QtGui', globals(), ['QBrush', 'QFont', 'QGraphicsItem',\
                                       'QGraphicsSimpleTextItem', 'QPen',\
                                       'QGraphicsTextItem', 'QDrag', \
                                       'QUndoCommand', 'QGraphicsEllipseItem',\
                                       'QTransform', 'QStyle'])

# strand addition stores some meta information in the UndoCommand's text
_strand_re = re.compile("\((\d+),(\d+)\)\.0\^(\d+)")

class EmptyHelixItem(QGraphicsEllipseItem):
    """docstring for EmptyHelixItem"""
    # set up default, hover, and active drawing styles
    _defaultBrush = QBrush(styles.grayfill)
    _defaultPen = QPen(styles.graystroke, styles.SLICE_HELIX_STROKE_WIDTH)
    _hoverBrush = QBrush(styles.bluefill)
Example #13
0
import maya.OpenMayaMPx as OpenMayaMPx
import maya.cmds as cmds
import maya.OpenMayaUI as OpenMayaUI
import maya.mel as mel
import sip

sys.path.insert(0, os.environ['CADNANO_PATH'])
# cmds.flushUndo()
# cmds.undoInfo(state=False)

import views.solidview.mayaHotKeys as mayaHotKeys
import views.solidview.mayaUI as mayaUI

import util
util.qtFrameworkList = ['PyQt'] # necessary to overide defaults
util.qtWrapImport('QtGui', globals(), ['qApp', 'QDockWidget', 'QSizePolicy'])

util.qtWrapImport('QtCore', globals(), ['Qt', 'QObject'])

kPluginName = "spCadNano"
gCadNanoButton = None
gCadNanoToolbar = None
fMayaExitingCB = None

gCadNanoApp = None

gIconPath = (
        os.environ['CADNANO_PATH'] +
        "/ui/mainwindow/images/cadnano2-app-icon_shelf.png")

Example #14
0
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
import re
from abstractpathtool import AbstractPathTool
from model.enum import StrandType
from data.dnasequences import sequences
from ui.dialogs.ui_addseq import Ui_AddSeqDialog
from views import styles
import util

util.qtWrapImport('QtGui', globals(), ['QBrush','QColor', 'QDialog', \
                                       'QDialogButtonBox', 'QFont', 'QPen', \
                                       'QRadioButton', 'QSyntaxHighlighter', \
                                       'QTextCharFormat'])
util.qtWrapImport('QtCore', globals(), ['Qt', 'QObject', 'QPointF', \
                                        'QRegExp', \
                                        'QString', 'QSignalMapper', \
                                        'pyqtSignal', 'pyqtSlot'])
dnapattern = QRegExp("[^ACGTacgt]")


class DNAHighlighter(QSyntaxHighlighter):
    def __init__(self, parent):
        QSyntaxHighlighter.__init__(self, parent)
        self.parent = parent
        self.format = QTextCharFormat()
        self.format.setForeground(QBrush(styles.INVALID_DNA_COLOR))
        if styles.UNDERLINE_INVALID_DNA:
Example #15
0
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created: Tue Jul  5 15:37:53 2011
#      by: PyQt4 UI code generator 4.8.3
#
# WARNING! All changes made in this file will be lost!

import util

util.qtWrapImport(None, globals(), ["QtCore", "QtGui"])

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(1100, 800)
        MainWindow.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
        MainWindow.setStatusTip(_fromUtf8(""))
        MainWindow.setIconSize(QtCore.QSize(32, 32))
        MainWindow.setDockNestingEnabled(True)
        MainWindow.setDockOptions(
            QtGui.QMainWindow.AllowNestedDocks | QtGui.QMainWindow.AllowTabbedDocks | QtGui.QMainWindow.AnimatedDocks
        )
        self.centralwidget = QtGui.QWidget(MainWindow)
Example #16
0
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

import bisect

# from PyQt4.QtCore import QAbstractItemModel, QModelIndex, Qt, QByteArray, QString, QStringList, QVariant
# from PyQt4.QtCore import QXmlStreamReader, QXmlStreamWriter

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QAbstractItemModel', 'QModelIndex', \
                                        'Qt', 'QByteArray', 'QString', \
                                        'QStringList', 'QVariant', \
                                        'QXmlStreamReader', \
                                        'QXmlStreamWriter'])


NODETAG = "node"
NAMETAG = "NAMETAG"
OBJ_ID = "objectid"
INST_ID = "instanceid"

KEY, NODE = range(2)

NAME,HIDDEN,LOCKED = range(3)

class Node(object):
    """
Example #17
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

import json
from exceptions import ImportError
from legacydecoder import import_legacy_dict
from ui.dialogs.ui_latticetype import Ui_LatticeType
import util, cadnano
if cadnano.app().isGui():#headless:
    from ui.dialogs.ui_latticetype import Ui_LatticeType
    util.qtWrapImport('QtGui', globals(),  ['QDialog', 'QDialogButtonBox'])


def decode(document, string):
    if cadnano.app().isGui():
        # from ui.dialogs.ui_latticetype import Ui_LatticeType
        # util.qtWrapImport('QtGui', globals(),  ['QDialog', 'QDialogButtonBox'])
        dialog = QDialog()
        dialogLT = Ui_LatticeType()  # reusing this dialog, should rename
        dialogLT.setupUi(dialog)

    # try:  # try to do it fast
    #     try:
    #         import cjson
    #         packageObject = cjson.decode(string)
    #     except:  # fall back to if cjson not available or on decode error
Example #18
0
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

from exceptions import ImportError
from controllers.viewrootcontroller import ViewRootController
from partitem import PartItem
import util
util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'QObject'])
util.qtWrapImport('QtGui', globals(), ['QGraphicsRectItem'])


class SliceRootItem(QGraphicsRectItem):
    """
    PathRootItem is the root item in the PathView. It gets added directly
    to the pathscene by DocumentWindow. It receives two signals
    (partAddedSignal and selectedPartChangedSignal) via its ViewRootController.

    PathRootItem must instantiate its own controller to receive signals
    from the model.
    """
    def __init__(self, rect, parent, window, document):
        super(SliceRootItem, self).__init__(rect, parent)
        self._window = window
Example #19
0
#
# http://www.opensource.org/licenses/mit-license.php

"""
assembly.py

Created by Nick Conway on 2011-01-19.
"""

from collections import defaultdict
from idbank import IdBank

# from PyQt4.QtCore import QObject
import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QObject'])



class Assembly(QObject):
    """
    """
    def __init__(self, parent=None):
        super(Assembly,self).__init__()
        """
        this is gonna be a list of non-specific attributes for an assembly
        self.object_instances = defaultdict(list)  # default dictionary as a list?
        """
        self.parent = parent    # or parent hash?
        self.node_type = "assembly"
        self.color = 0
Example #20
0
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

from math import floor
from controllers.itemcontrollers.virtualhelixitemcontroller import VirtualHelixItemController
from model.enum import StrandType
from strand.stranditem import StrandItem
from views import styles
from virtualhelixhandleitem import VirtualHelixHandleItem
import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'QObject', 'Qt', 'QRectF'])
util.qtWrapImport('QtGui', globals(), ['QBrush', 'QGraphicsItem', \
                                       'QGraphicsPathItem',  'QGraphicsRectItem', \
                                       'QPainterPath', 'QPen', 'QBrush', 'QColor'])
_baseWidth = styles.PATH_BASE_WIDTH
# _gridPen = QPen(styles.minorgridstroke, styles.MINOR_GRID_STROKE_WIDTH)
# _gridPen.setCosmetic(True)


class VirtualHelixItem(QGraphicsPathItem):
    """VirtualHelixItem for PathView"""
    findChild = util.findChild  # for debug

    def __init__(self, partItem, modelVirtualHelix, viewroot, activeTool):
        super(VirtualHelixItem, self).__init__(partItem.proxy())
        self._partItem = partItem
Example #21
0
"""
activeslicehandle.py
Created by Shawn on 2011-02-05.
"""

# from exceptions import IndexError
from math import floor

from controllers.itemcontrollers.activesliceitemcontroller import ActiveSliceItemController
from views import styles
import util

# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport(
    'QtCore', globals(),
    ['QPointF', 'QRectF', 'Qt', 'QObject', 'pyqtSignal', 'pyqtSlot', 'QEvent'])
util.qtWrapImport('QtGui', globals(), ['QBrush', 'QFont', 'QPen', 'QDrag'])
util.qtWrapImport('QtWidgets', globals(), [
    'QGraphicsItem', 'QGraphicsSimpleTextItem', 'QGraphicsRectItem',
    'QUndoCommand'
])

_baseWidth = styles.PATH_BASE_WIDTH
_brush = QBrush(styles.activeslicehandlefill)
_labelbrush = QBrush(styles.orangestroke)
_pen = QPen(styles.activeslicehandlestroke,\
            styles.SLICE_HANDLE_STROKE_WIDTH)
_font = QFont(styles.thefont, 12, QFont.Bold)


class ActiveSliceItem(QGraphicsRectItem):
Example #22
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

"""
config
Created by Jonathan deWerd on 2012-01-19.
"""
import util, cadnano
import autobreakconfig_ui
import autobreak
util.qtWrapImport('QtGui', globals(), ['QDialog', 'QKeySequence', 'QDialogButtonBox'])
util.qtWrapImport('QtCore', globals(), ['Qt'])

class AutobreakConfig(QDialog, autobreakconfig_ui.Ui_Dialog):
    def __init__(self, parent, handler):
        QDialog.__init__(self, parent, Qt.Sheet)
        self.setupUi(self)
        self.handler = handler
        fb = self.buttonBox.button(QDialogButtonBox.Cancel)
        fb.setShortcut(QKeySequence(Qt.CTRL | Qt.Key_R ))

    def keyPressEvent(self, e):
        return QDialog.keyPressEvent(self, e)

    def closeDialog(self):
        self.close()
Example #23
0
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
"""
recorder.py

Created by Shawn on 2011-06-30.
"""

import os
import glob
from cadnano import app
from model.enum import LatticeType
import util

util.qtWrapImport("QtCore", globals(), ["Qt", "QPoint", "QPointF", "QEvent", "pyqtSlot"])


class TestRecorder(object):
    """
    TestRecorder can be used to auto-generate functional tests based on
    user input.

    It is currently set up for specific workflow, which assumes the first
    step is creating a part, followed by mousePress, mouseMove, and
    mouseRelease events in the slice and path views.
    
    INSTRUCTIONS:
    To record a new test, call "python main.py -r" from the cadnano2
    root directory. The resulting test will be saved in two places:
    
Example #24
0
#!/usr/bin/env python
# encoding: utf-8

import util
import copy
from .strand import Strand
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'QObject'])
util.qtWrapImport('QtWidgets', globals(), ['QUndoCommand'])


class Oligo(QObject):
    """
    Oligo is a group of Strands that are connected via 5' and/or 3'
    connections. It corresponds to the physical DNA strand, and is thus
    used tracking and storing properties that are common to a single strand,
    such as its color.

    Commands that affect Strands (e.g. create, remove, merge, split) are also
    responsible for updating the affected Oligos.
    """
    def __init__(self, part, color=None):
        super(Oligo, self).__init__(part)
        self._part = part
        self._strand5p = None
        self._length = 0
        self._isLoop = False
        self._color = color if color else "#0066cc"

    # end def
Example #25
0
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
import util
import sys
from abstractpathtool import AbstractPathTool

util.qtWrapImport('QtCore', globals(), ['Qt', 'QPointF'])
util.qtWrapImport('QtGui', globals(), ['QGraphicsItem', 'QBrush', 'QFont',
                                       'QGraphicsSimpleTextItem', 'QPen',
                                       'QPolygonF', 'QPainterPath'])


class BreakTool(AbstractPathTool):
    """
    BreakTool is the default tool. It allows editing of breakpoints
    (by clicking and dragging) and toggling of crossovers.
    """
    # And we actually use those PartGraphicsItem events
    mouseMovePartGraphicsItemUnused = False
    mouseReleasePartGraphicsItemUnused = False
    mousePressPartGraphicsItemUnused = False
    logger = None
Example #26
0
import re
from .abstractpathtool import AbstractPathTool
from data.dnasequences import sequences
from ui.dialogs.ui_addseq import Ui_AddSeqDialog
from views import styles
import util

util.qtWrapImport('QtCore', globals(), [
    'Qt', 'QObject', 'QPointF', 'QRegExp', 'QSignalMapper', 'pyqtSignal',
    'pyqtSlot'
])
util.qtWrapImport('QtGui', globals(), [
    'QBrush', 'QColor', 'QFont', 'QPen', 'QSyntaxHighlighter',
    'QTextCharFormat'
])
util.qtWrapImport('QtWidgets', globals(), [
    'QDialog',
    'QDialogButtonBox',
    'QRadioButton',
])

dnapattern = QRegExp("[^ACGTacgt]+")


class DNAHighlighter(QSyntaxHighlighter):
    def __init__(self, parent):
        QSyntaxHighlighter.__init__(self, parent)
        self.parent = parent
        self.format = QTextCharFormat()
        self.format.setBackground(QBrush(styles.INVALID_DNA_COLOR))
        if styles.UNDERLINE_INVALID_DNA:
Example #27
0
Created by Simon Breslav on 2011-10-05.
"""

from controllers.mayacontrollers.mayaObjectManager import Mom
from controllers.itemcontrollers.strand.stranditemcontroller \
                                                import StrandItemController
from model.enum import StrandType
from model.enum import LatticeType

from cadnano import app
import maya.OpenMayaUI as mui
import maya.OpenMaya as mo
import maya.cmds as cmds
import util

util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'pyqtSlot', \
                                        'QObject', 'Qt'])
util.qtWrapImport('QtGui', globals(), ['QColor'])


class StrandItem(object):
    """
    StrandItem is the visual representation of the strand in the 3D SolidView.
    For this visual representation, StrandItem creates HalfCylinderHelixNode
    Node inside of Maya, so while the StrandItem itself does not get drawn in
    any way, it is the object that communicates with Maya Nodes associated
    with a given strand.
    """
    def __init__(self, mID, modelStrand, virtualHelixItem):
        """
        The parent should be a VirtualHelixItem.
        Initialize function creates the Maya Node for the strand, and setups
Example #28
0
from views import styles
from model.enum import EndType, LatticeType, StrandType
from model.virtualhelix import VirtualHelix
from weakref import ref
from handles.pathhelixhandle import PathHelixHandle
from handles.loophandle import LoopItem, SkipItem
from handles.precrossoverhandle import PreCrossoverHandle
from math import floor, pi, ceil
from cadnano import app
from itertools import product
from ui.svgbutton import SVGButton

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['Qt', 'QRect', 'QLine', 'QRectF',\
                                        'QPointF', 'QPoint', 'pyqtSlot',\
                                        'QEvent', 'SLOT'])
util.qtWrapImport('QtGui', globals(), ['QBrush', 'QColor', 'QFont',\
                                       'QGraphicsObject', 'QFontMetricsF',\
                                       'QGraphicsSimpleTextItem',\
                                       'QPainter', 'QPainterPath', 'QPen',\
                                       'QDrag', 'QPolygonF', 'QUndoCommand',
                                       'QInputDialog', 'QGraphicsItem'])

baseWidth = styles.PATH_BASE_WIDTH
ppL5 = QPainterPath()  # Left 5' PainterPath
ppR5 = QPainterPath()  # Right 5' PainterPath
ppL3 = QPainterPath()  # Left 3' PainterPath
ppR3 = QPainterPath()  # Right 3' PainterPath
# set up ppL5 (left 5' blue square)
ppL5.addRect(0.25 * baseWidth, 0.125 * baseWidth,\
Example #29
0
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

from collections import defaultdict
from model.document import Document
from model.enum import LatticeType, StrandType
from model.parts.honeycombpart import HoneycombPart
from model.parts.squarepart import SquarePart
from model.virtualhelix import VirtualHelix
from views import styles
import util, cadnano
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtGui', globals(), ['QColor'])
if cadnano.app().isGui():
    from ui.dialogs.ui_latticetype import Ui_LatticeType
    util.qtWrapImport('QtGui', globals(), ['QDialog', 'QDialogButtonBox'])

NODETAG = "node"
NAME = "name"
OBJ_ID = "objectid"
INST_ID = "instanceid"
DONE = "done"
CHECKED = "check"
LOCKED = "locked"

VHELIX = "vhelix"
NUM = "num"
COL = "col"
Example #30
0
#!/usr/bin/env python
# encoding: utf-8

import util
from views import styles

from model.enum import StrandType

# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QPointF', 'QRectF', 'Qt'])
util.qtWrapImport(
    'QtGui', globals(),
    ['QBrush', 'QFont', 'QFontMetrics', 'QPainterPath', 'QPolygonF', 'QPen'])
util.qtWrapImport('QtWidgets', globals(), [
    'QGraphicsPathItem', 'QGraphicsRectItem', 'QGraphicsSimpleTextItem',
    'QUndoCommand'
])


# construct paths for breakpoint handles
def _hashMarkGen(path, p1, p2, p3):
    path.moveTo(p1)
    path.lineTo(p2)
    path.lineTo(p3)


# end

# create hash marks QPainterPaths only once
_ppRect = QRectF(0, 0, styles.PATH_BASE_WIDTH, styles.PATH_BASE_WIDTH)
_pathCenter = QPointF(styles.PATH_BASE_WIDTH / 2,\
Example #31
0
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

"""
selecttool
Created by Shawn Douglas on 2011-06-21.
"""

from abstractpathtool import AbstractPathTool
import util
util.qtWrapImport('QtGui', globals(), ['QPen', 'QColor', 'QInputDialog'])
util.qtWrapImport('QtCore', globals(), ['Qt', 'QPointF', 'SLOT', 'pyqtSlot'])
from model.enum import StrandType
from data.dnasequences import sequences

class AddSeqTool(AbstractPathTool):
    def __init__(self, controller, parent=None):
        AbstractPathTool.__init__(self, controller, parent)

    def mousePressPathHelix(self, pathHelix, event):
        strandType, idx = self.baseAtPoint(pathHelix, event.pos())
        dialog = QInputDialog(self.window())
        dialog.setWindowFlags(Qt.Dialog | Qt.Sheet)
        dialog.setWindowModality(Qt.WindowModal)
        dialog.setLabelText('Choose the sequence to be applied from 5\' to 3\' in the\n oligo you clicked on by name, or enter a sequence by hand:')
        dialog.setWindowTitle('Choose Sequence')
Example #32
0

import json
from .legacydecoder import import_legacy_dict
from ui.dialogs.ui_latticetype import Ui_LatticeType
import util, cadnano
if cadnano.app().isGui():  # headless:
    from ui.dialogs.ui_latticetype import Ui_LatticeType
    util.qtWrapImport('QtWidgets', globals(),  ['QDialog', 'QDialogButtonBox'])


def decode(document, string):
    if cadnano.app().isGui():
        # from ui.dialogs.ui_latticetype import Ui_LatticeType
        # util.qtWrapImport('QtGui', globals(),  ['QDialog', 'QDialogButtonBox'])
        dialog = QDialog()
        dialogLT = Ui_LatticeType()  # reusing this dialog, should rename
        dialogLT.setupUi(dialog)

    # try:  # try to do it fast
    #     try:
    #         import cjson
    #         packageObject = cjson.decode(string)
    #     except:  # fall back to if cjson not available or on decode error
    #         packageObject = json.loads(string)
    # except ValueError:
    #     dialogLT.label.setText("Error decoding JSON object.")
    #     dialogLT.buttonBox.setStandardButtons(QDialogButtonBox.Ok)
    #     dialog.exec_()
    #     return
    packageObject = json.loads(string)
Example #33
0
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

"""
part
Created by Jonathan deWerd on 2011-01-26.
"""
from exceptions import NotImplementedError
from cadnano import app

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'QObject'])

class Part(QObject):
    # this is for removing a part from scenes
    partRemoved = pyqtSignal()
    
    def __init__(self, id, *args, **kargs):
        super(Part, self).__init__()
        app().p = self
    
    def document(self):
        return self._document
    
    def _setDocument(self, newDoc):
        "Should only be called by Document"
        self._document = newDoc
Example #34
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
"""
cadnanoqt
Created by Jonathan deWerd on 2012-01-11.
"""
import util, sys, os
import cadnano
from code import interact
util.qtWrapImport('QtGui', globals(),  ['qApp', 'QApplication', 'QIcon',\
                                        'QUndoGroup'])
util.qtWrapImport('QtCore', globals(), ['QObject', 'QCoreApplication', 'Qt',\
                                        'QEventLoop', 'pyqtSignal'])


class CadnanoQt(QObject):
    dontAskAndJustDiscardUnsavedChanges = False
    shouldPerformBoilerplateStartupScript = False
    documentWasCreatedSignal = pyqtSignal(object)  # doc
    documentWindowWasCreatedSignal = pyqtSignal(object, object)  # doc, window

    def __init__(self, argv):
        self.argv = argv
        if QCoreApplication.instance() == None:
            self.qApp = QApplication(argv)
            assert (QCoreApplication.instance() != None)
Example #35
0
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'QObject'])
util.qtWrapImport('QtGui', globals(), [ 'QActionGroup'])


class SliceToolManager(QObject):
    """Manages interactions between the slice widgets/UI and the model."""
    def __init__(self, win):
        """
        We store mainWindow because a controller's got to have
        references to both the layer above (UI) and the layer below (model)
        """
        super(SliceToolManager, self).__init__()
        self._window = win
        self._connectWindowSignalsToSelf()

    ### SIGNALS ###
Example #36
0
# from model.strands.normalstrand import NormalStrand
# from model.strands.xoverstrand import XoverStrand3, XoverStrand5

from controllers.mayacontrollers.mayaObjectManager import Mom
from controllers.itemcontrollers.virtualhelixitemcontroller import VirtualHelixItemController

import maya.OpenMayaUI as mui
import maya.OpenMaya as mo
import maya.cmds as cmds
import util

from .stranditem import StrandItem

# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport("QtCore", globals(), ["pyqtSignal", "pyqtSlot", "QObject"])
util.qtWrapImport("QtGui", globals(), ["QColor"])


class VirtualHelixItem(object):
    """
    VirtualHelixItem is the container for StrandItems for is the Maya 3D View,
    it does not get visualized in any way right now.
    """

    baseWidth = styles.PATH_BASE_WIDTH

    def __init__(self, partItem, modelVirtualHelix, x, y):
        """
        Initialize member variables.
        Setup VirtualHelixItemController, that takes care of all the
Example #37
0
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
import sys
from abstractpathtool import AbstractPathTool
import util
util.qtWrapImport('QtCore', globals(), [])
util.qtWrapImport('QtGui', globals(), [])


class SelectTool(AbstractPathTool):
    """
    SelectTool is the default tool. It allows editing of breakpoints
    (by clicking and dragging) and toggling of crossovers.
    """
    def __init__(self, controller):
        super(SelectTool, self).__init__(controller)

    def __repr__(self):
        return "selectTool"  # first letter should be lowercase
Example #38
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

# from model.enum import StrandType
from views import styles
from model.enum import StrandType

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QPointF', 'QRectF', 'Qt'])
util.qtWrapImport('QtGui', globals(), [ 'QGraphicsItem', 'QGraphicsItemGroup', \
                                        'QBrush', 'QFont', 'QPen', \
                                        'QGraphicsObject'])

_bw = styles.PATH_BASE_WIDTH
_toolRect = QRectF(0, 0, _bw, _bw)  # protected not private
_rect = QRectF(-styles.PATH_BASE_HL_STROKE_WIDTH,\
               -styles.PATH_BASE_HL_STROKE_WIDTH,\
               _bw + 2*styles.PATH_BASE_HL_STROKE_WIDTH,\
               _bw + 2*styles.PATH_BASE_HL_STROKE_WIDTH)
_pen = QPen(styles.redstroke, styles.PATH_BASE_HL_STROKE_WIDTH)
_brush = QBrush(Qt.NoBrush)

# There's a bug where C++ will free orphaned graphics items out from
# under pyqt. To avoid this, "_mother" adopts orphaned graphics items.
Example #39
0
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

import util
util.qtWrapImport('QtCore', globals(), ['QObject', 'pyqtSignal', 'Qt'])
util.qtWrapImport('QtGui', globals(), ['QGraphicsObject'])
util.qtWrapImport('QtSvg', globals(), ['QSvgRenderer'])

class SVGButton(QGraphicsObject):
    def __init__(self, fname, parent=None):
        super(SVGButton, self).__init__(parent)
        self.svg = QSvgRenderer(fname)

    def paint(self, painter, options, widget):
        self.svg.render(painter, self.boundingRect())

    def boundingRect(self):
        return self.svg.viewBoxF()

    clicked = pyqtSignal()
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
"""
recordinggraphicsitem.py

Created by Shawn on 2011-07-01.
"""

import util


util.qtWrapImport('QtCore', globals(), ['Qt', 'QEvent', 'QString', 'QRectF'])
util.qtWrapImport('QtGui', globals(), ['QGraphicsItem', 'QGraphicsObject'])

class SceneType:
    Slice = 0
    Path = 1

class RecordableQGraphicsItem(object):
    """QGraphicsItems that need to report actions to the test recorder
    via sceneEvent should also inherit from this class."""

    def __init__(self, controller, sceneType):
        """docstring for __init__"""
        print "init RecordableQGraphicsItem"
        self.controller = controller
        self.sceneType = sceneType
Example #41
0
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
import sys
from abstractpathtool import AbstractPathTool
import util
util.qtWrapImport('QtCore', globals(), [])
util.qtWrapImport('QtGui', globals(), [])


class PaintTool(AbstractPathTool):
    """
    Handles visibility and color cycling for the paint tool.
    """
    def __init__(self, controller):
        super(PaintTool, self).__init__(controller)
        self._isMacrod = False

    def __repr__(self):
        return "paintTool"  # first letter should be lowercase

    def setActive(self, willBeActive):
Example #42
0
import re
import os
import inspect
from collections import deque

try:
    import readline
    import rlcompleter
except ImportError:
    readline = None

## CADNANO MODULE imports ##
import cadnano
import util

util.qtWrapImport('QtGui', globals(), ['QTransform'])
util.qtWrapImport(
    'QtCore', globals(),
    ['QPropertyAnimation', 'pyqtProperty', 'QObject', 'QEasingCurve'])

## SETTINGS ##

#### Constants / settings for API functions #####

ANIMATE_DURATION_MSEC = 500
ANIMATE_ENABLED_DEFAULT = True

# PySide QEasingCurve is NOT instantiated with an integer, but takes a QtCore.Type instance.
ANIMATE_EASINGCURVE = QEasingCurve.Linear  # This should work for both PyQt4 and PySide and is also more readable.
# http://qt-project.org/doc/qt-4.8/qeasingcurve.html
Example #43
0
#
# http://www.opensource.org/licenses/mit-license.php
"""
virtualhelixitem.py

Created by Shawn on 2010-06-15.
"""

from views import styles
from model.virtualhelix import VirtualHelix
from model.enum import Parity, StrandType
from controllers.itemcontrollers.virtualhelixitemcontroller import VirtualHelixItemController

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['Qt', 'QEvent', 'QString', 'QRectF',\
                                        'QPointF'])
util.qtWrapImport('QtGui', globals(), ['QGraphicsEllipseItem', 'QGraphicsItem',\
                                'QGraphicsSimpleTextItem', 'QBrush', 'QPen'])


class VirtualHelixItem(QGraphicsEllipseItem):
    """
    The VirtualHelixItem is an individual circle that gets drawn in the SliceView
    as a child of the PartItem. Taken as a group, many SliceHelix
    instances make up the crossection of the DNAPart. Clicking on a SliceHelix
    adds a VirtualHelix to the DNAPart. The SliceHelix then changes appearence
    and paints its corresponding VirtualHelix number.
    """
    # set up default, hover, and active drawing styles
    _useBrush = QBrush(styles.orangefill)
    _usePen = QPen(styles.orangestroke, styles.SLICE_HELIX_STROKE_WIDTH)
Example #44
0
from controllers.itemcontrollers.partitemcontroller import PartItemController
from .emptyhelixitem import EmptyHelixItem
from .virtualhelixitem import VirtualHelixItem
from .activesliceitem import ActiveSliceItem
from views import styles
import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QRectF', 'QPointF', 'QEvent', 'Qt',
                                        'pyqtSignal', 'pyqtSlot', 'QObject'])
util.qtWrapImport('QtGui', globals(), ['QBrush',
                                       'QPainterPath',
                                       'QPen'])
util.qtWrapImport('QtWidgets', globals(), ['QGraphicsItem',
                                           'QGraphicsEllipseItem'])

_radius = styles.SLICE_HELIX_RADIUS
_defaultRect = QRectF(0, 0, 2 * _radius, 2 * _radius)
highlightWidth = styles.SLICE_HELIX_MOD_HILIGHT_WIDTH
delta = (highlightWidth - styles.SLICE_HELIX_STROKE_WIDTH)/2.
_hoverRect = _defaultRect.adjusted(-delta, -delta, delta, delta)
_modPen = QPen(styles.bluestroke, highlightWidth)


class PartItem(QGraphicsItem):
    _radius = styles.SLICE_HELIX_RADIUS

    def __init__(self, modelPart, parent=None):
        """
        Parent should be either a SliceRootItem, or an AssemblyItem.

        Invariant: keys in _emptyhelixhash = range(_nrows) x range(_ncols)
Example #45
0
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

from views import styles
import util
util.qtWrapImport('QtCore', globals(), ['QRectF', 'Qt'])
util.qtWrapImport('QtGui', globals(),  ['QBrush', 'QColorDialog', 'QFont',
                                        'QGraphicsItem',
                                        'QGraphicsSimpleTextItem'])

_font = QFont(styles.thefont, 12, QFont.Bold)


class ColorPanel(QGraphicsItem):
    _scafColors = styles.scafColors
    _stapColors = styles.stapColors
    _pen = Qt.NoPen

    def __init__(self, parent=None):
        super(ColorPanel, self).__init__(parent)
        self.rect = QRectF(0, 0, 30, 30)
Example #46
0
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

import os
from cadnano import app
from model.document import Document
from model.io.decoder import decode
from model.io.encoder import encode
from views.documentwindow import DocumentWindow
from views import styles
import util
util.qtWrapImport('QtCore', globals(), ['QDir', 'QFileInfo', 'QRect',
                                        'QString', 'QStringList', 'QSettings',
                                        'QSize', 'Qt'])
util.qtWrapImport('QtGui', globals(), ['QApplication', 'QDialog',
                                       'QDockWidget', 'QFileDialog',
                                       'QKeySequence', 'QGraphicsItem',
                                       'QMainWindow',
                                       'QMessageBox', 'QPainter', 'QIcon',
                                       'QStyleOptionGraphicsItem'])
util.qtWrapImport('QtSvg', globals(), ['QSvgGenerator'])

class DocumentController():
    """
    Connects UI buttons to their corresponding actions in the model.
    """
    ### INIT METHODS ###
    def __init__(self):
Example #47
0
from math import floor
from .abstractpathtool import AbstractPathTool
from views import styles

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['Qt', 'QEvent', 'QPointF', 'QRectF'])
util.qtWrapImport('QtGui', globals(), [
    'QBrush', 'QColor', 'QFont', 'QFontMetrics', 'QPainterPath', 'QPolygonF',
    'QPen'
])
util.qtWrapImport('QtWidgets', globals(), [
    'QGraphicsItem', 'QGraphicsLineItem', 'QGraphicsPathItem',
    'QGraphicsRectItem', 'QGraphicsSimpleTextItem'
])

_baseWidth = styles.PATH_BASE_WIDTH
_pencilcolor = styles.redstroke
_defaultRect = QRectF(0, 0, _baseWidth, _baseWidth)
_noPen = QPen(Qt.NoPen)


class PencilTool(AbstractPathTool):
    """
    docstring for PencilTool
    """
    def __init__(self, controller):
        super(PencilTool, self).__init__(controller)
        self._tempXover = ForcedXoverItem(self, None, None)
        self._tempStrandItem = ForcedStrandItem(self, None)
        self._tempStrandItem.hide()
Example #48
0
from .autobreakconfig import AutobreakConfig
import cadnano, util
util.qtWrapImport('QtGui', globals(), ['QAction', 'QIcon', 'QPixmap'])


class AutobreakHandler(object):
    def __init__(self, document, window):
        self.doc, self.win = document, window
        icon10 = QIcon()
        icon10.addPixmap(QPixmap(":/pathtools/autobreak"), QIcon.Mode.Normal,
                         QIcon.State.Off)
        self.actionAutoBreak = QAction(window)
        self.actionAutoBreak.setIcon(icon10)
        self.actionAutoBreak.setText('AutoBreak')
        self.actionAutoBreak.setToolTip(
            "Click this button to generate a default set of staples.")
        self.actionAutoBreak.setObjectName("actionAutoBreak")
        self.actionAutoBreak.triggered.connect(self.actionAutobreakSlot)
        self.win.menuPlugins.addAction(self.actionAutoBreak)
        # add to main tool bar
        self.win.topToolBar.insertAction(self.win.actionFiltersLabel,
                                         self.actionAutoBreak)
        self.win.topToolBar.insertSeparator(self.win.actionFiltersLabel)
        self.configDialog = None

    def actionAutobreakSlot(self):
        """Only show the dialog if staple strands exist."""
        part = self.doc.controller().activePart()
        if part != None:  # is there a part?
            for o in list(part.oligos()):
                if o.isStaple():  # is there a staple oligo?
Example #49
0
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php

from exceptions import NotImplementedError
from math import floor
from views import styles

import views.pathview.pathselection as pathselection

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(),
                  ['pyqtSignal', 'QObject', 'QPointF', 'QRectF', 'Qt'])
util.qtWrapImport('QtGui', globals(), ['QGraphicsPathItem', 'QPen', \
                                        'QGraphicsItem', 'QPainterPath', \
                                        'QPolygonF', 'QGraphicsRectItem', \
                                        'QBrush', 'QColor'])

_baseWidth = styles.PATH_BASE_WIDTH

ppL5 = QPainterPath()  # Left 5' PainterPath
ppR5 = QPainterPath()  # Right 5' PainterPath
ppL3 = QPainterPath()  # Left 3' PainterPath
ppR3 = QPainterPath()  # Right 3' PainterPath
pp53 = QPainterPath()  # Left 5', Right 3' PainterPath
pp35 = QPainterPath()  # Left 5', Right 3' PainterPath
# set up ppL5 (left 5' blue square)
ppL5.addRect(0.25 * _baseWidth, 0.125 * _baseWidth, 0.75 * _baseWidth,
Example #50
0
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
from ui.dialogs.ui_preferences import Ui_Preferences
from views import styles
import util
import cadnano
import os.path, zipfile, shutil, platform, subprocess, tempfile, errno
util.qtWrapImport('QtCore', globals(), ['QObject', 'QSettings', 'pyqtSlot', 'Qt'])
util.qtWrapImport('QtGui', globals(), ['QWidget', 'QDialogButtonBox',\
                                       'QTableWidgetItem', 'QFileDialog',\
                                       'QMessageBox'])

class Preferences(object):
    """
    Preferences class used to:
    1) Create a preferences Qt widget, self.uiPrefs, which is bound to another new parent, self.widget.
    2) Read settings and set up event bindings (So changes in UI status is linked to the settings store).
    """
    def __init__(self):
        self.qs = QSettings()
        self.uiPrefs = Ui_Preferences()
        self.widget = QWidget()
        self.uiPrefs.setupUi(self.widget)
Example #51
0
import util
util.qtWrapImport('QtCore', globals(), ['QObject', 'pyqtSignal', 'Qt'])
util.qtWrapImport('QtWidgets', globals(), ['QGraphicsObject'])
util.qtWrapImport('QtSvg', globals(), ['QSvgRenderer'])


class SVGButton(QGraphicsObject):
    def __init__(self, fname, parent=None):
        super(SVGButton, self).__init__(parent)
        self.svg = QSvgRenderer(fname)

    def paint(self, painter, options, widget):
        self.svg.render(painter, self.boundingRect())

    def boundingRect(self):
        return self.svg.viewBoxF()

    clicked = pyqtSignal()

    def mousePressEvent(self, event):
        self.clicked.emit()
Example #52
0
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
from abstractpathtool import AbstractPathTool
from views import styles
import util
util.qtWrapImport('QtCore', globals(), ['QPointF', 'QRectF', 'Qt'])
util.qtWrapImport(
    'QtGui', globals(),
    ['QGraphicsItem', 'QBrush', 'QFont', 'QPainterPath', 'QPen', 'QPolygonF'])

_bw = styles.PATH_BASE_WIDTH
_pen = QPen(styles.redstroke, 1)
_rect = QRectF(0, 0, _bw, _bw)
_pathArrowLeft = QPainterPath()
_l3poly = QPolygonF()
_l3poly.append(QPointF(_bw, 0))
_l3poly.append(QPointF(0.25 * _bw, 0.5 * _bw))
_l3poly.append(QPointF(_bw, _bw))
_pathArrowLeft.addPolygon(_l3poly)
_pathArrowRight = QPainterPath()
_r3poly = QPolygonF()  # right-hand 3' arr
Example #53
0
# http://www.opensource.org/licenses/mit-license.php

"""
document.py
Created by Jonathan deWerd on 2011-01-26.
"""

import json
from views import styles
from .dnahoneycombpart import DNAHoneycombPart
from .dnasquarepart import DNASquarePart
from .enum import LatticeType

import util
# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['pyqtSignal', 'QObject'])
util.qtWrapImport('QtGui', globals(), [ 'QUndoCommand'])

class Document(QObject):
    def __init__(self, incompleteArchivedDict=None):
        super(Document, self).__init__()
        self._parts = []
        self._selectedPart = None
        self._controller = None
    
    def fsck(self):
        for p in self._parts:
            p.fsck()

    def controller(self):
        return self._controller
Example #54
0
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
"""
config
Created by Jonathan deWerd on 2012-01-19.
"""
import util, cadnano
import autobreakconfig_ui
import autobreak
util.qtWrapImport('QtGui', globals(),
                  ['QDialog', 'QKeySequence', 'QDialogButtonBox'])
util.qtWrapImport('QtCore', globals(), ['Qt'])


class AutobreakConfig(QDialog, autobreakconfig_ui.Ui_Dialog):
    def __init__(self, parent, handler):
        QDialog.__init__(self, parent, Qt.Sheet)
        self.setupUi(self)
        self.handler = handler
        fb = self.buttonBox.button(QDialogButtonBox.Cancel)
        fb.setShortcut(QKeySequence(Qt.CTRL | Qt.Key_R))

    def keyPressEvent(self, e):
        return QDialog.keyPressEvent(self, e)

    def closeDialog(self):
Example #55
0
from views import styles
import util
util.qtWrapImport('QtCore', globals(), ['QRectF', 'Qt'])
util.qtWrapImport('QtGui', globals(), ['QBrush', 'QFont'])
util.qtWrapImport('QtWidgets', globals(),
                  ['QColorDialog', 'QGraphicsItem', 'QGraphicsSimpleTextItem'])

_font = QFont(styles.thefont, 12, QFont.Bold)


class ColorPanel(QGraphicsItem):
    _scafColors = styles.scafColors
    _stapColors = styles.stapColors
    _pen = Qt.NoPen

    def __init__(self, parent=None):
        super(ColorPanel, self).__init__(parent)
        self.rect = QRectF(0, 0, 30, 30)
        self.setFlag(QGraphicsItem.ItemIgnoresTransformations)
        self.colordialog = QColorDialog()
        # self.colordialog.setOption(QColorDialog.DontUseNativeDialog)
        self._scafColorIndex = -1  # init on -1, painttool will cycle to 0
        self._stapColorIndex = -1  # init on -1, painttool will cycle to 0
        self._scafColor = self._scafColors[self._scafColorIndex]
        self._stapColor = self._stapColors[self._stapColorIndex]
        self._scafBrush = QBrush(self._scafColor)
        self._stapBrush = QBrush(self._stapColor)
        self._initLabel()
        self.hide()

    def _initLabel(self):
#
# http://www.opensource.org/licenses/mit-license.php
"""
activeslicehandle.py
Created by Shawn on 2011-02-05.
"""

from exceptions import IndexError
from math import floor

from controllers.itemcontrollers.activesliceitemcontroller import ActiveSliceItemController
from views import styles
import util

# import Qt stuff into the module namespace with PySide, PyQt4 independence
util.qtWrapImport('QtCore', globals(), ['QPointF', 'QRectF', 'Qt', 'QObject',\
                                        'pyqtSignal', 'pyqtSlot', 'QEvent'])
util.qtWrapImport('QtGui', globals(), ['QBrush', 'QFont', 'QGraphicsItem',\
                                       'QGraphicsSimpleTextItem', 'QPen',\
                                       'QDrag', 'QUndoCommand', 'QGraphicsRectItem'])


_baseWidth = styles.PATH_BASE_WIDTH
_brush = QBrush(styles.activeslicehandlefill)
_labelbrush = QBrush(styles.orangestroke)
_pen = QPen(styles.activeslicehandlestroke,\
            styles.SLICE_HANDLE_STROKE_WIDTH)
_font = QFont(styles.thefont, 12, QFont.Bold)


class ActiveSliceItem(QGraphicsRectItem):
    """ActiveSliceItem for the Path View"""