Ejemplo n.º 1
0
    def startDrag(self):
        """ this method is called whenever a user start to drag one of the label """

        #D( ALL, "dragging started..." )
        v = self._view
        lp = v.painter()
        fm = lp.fontmetrics()
        idx, _ = v.xy2coord( 0, self._startpos.y() )
        self._dragidx = idx
        label = self.model()[idx].label
        lineheight = v.lineheight()
        baseline = (lineheight + fm.ascent())/2
        width = fm.width(label)
        hotspot = QtCore.QPoint( width/2, lineheight/2 )
        drag = QtGui.QDrag(v)

        pixmap = QtGui.QPixmap(width, lineheight)
        p = QtGui.QPainter(pixmap)
        p.fillRect(pixmap.rect(), QtGui.QColor(191, 191, 127))
        p.setPen( QtCore.Qt.white )
        p.setFont( lp.font() )
        p.drawText(0, baseline, label)
        p.end()
        
        # fill in the data
        seq = self.model()[idx]
        mimedata = QtCore.QMimeData()
        text_data = ">%s\n%s\n" % (seq.label, seq.seq)
        mimedata.setText( text_data )
        mimedata.setData("application/x-fasta", text_data.encode('UTF-8'))

        drag.setMimeData(mimedata)
        drag.setPixmap(pixmap)
        drag.setHotSpot(hotspot)
        drag.exec_(QtCore.Qt.CopyAction)
Ejemplo n.º 2
0
def start_app(arg):
    global app
    cout("Starting GUI\n")

    if not app:
        app = QtGui.QApplication.instance()
        if not app:
            if type(arg) == list:
                app = QtGui.QApplication(arg)
            else:
                app = QtGui.QApplication(['__builtin__'])

    w = IMainWindow()

    if type(arg) == list and len(arg) >= 2:
        w.load(arg[1])
    elif type(arg) == str:
        w.load(arg)
    else:
        cout('viewing...')
        w.view(arg)
        #w.setFocus()
    w.show()
    app.exec_()

    try:
        w.hide()
        del w
    except RuntimeError:
        pass
Ejemplo n.º 3
0
 def __init__(self,
              typeface='Monospace',
              fontsize=6,
              charwidth=8,
              lineheight=12):
     self.typeface = typeface
     self.fontsize = fontsize
     self.charwidth = charwidth
     self.lineheight = lineheight
     self.font = QtGui.QFont(typeface, fontsize)
     self.fontmetrics = QtGui.QFontMetrics(self.font)
Ejemplo n.º 4
0
 def decrease_font(self):
     self.set_lineheight( self.lineheight() - 3 )
     self.set_charwidth( self.charwidth() - 2 )
     self.fonts = {
         'sequence': ('Monospace', self.fonts['sequence'][1] - 2 ),
         'label': QtGui.QFont('Monospace', self.fonts['label'].pointSize() - 2 )
     }
Ejemplo n.º 5
0
    def __init__(self, label_pane, label_font, offset_x=0):

        self._label_pane = label_pane
        self._font = label_font
        self._fontmetrics = QtGui.QFontMetrics(label_font)
        self._offset_x = offset_x or self._fontmetrics.width('0000: ')
        self._margin = 5
Ejemplo n.º 6
0
    def paintEvent(self, ev):

        # get the rectanguler area of visible view
        r = ev.rect()
        x, y, w, h = r.x(), r.y(), r.width(), r.height()
        y_end = y + h

        # prepare painter & other variables
        p = QtGui.QPainter(self)
        model = self.model()
        lineheight = self.lineheight()
        lp = self.painter()

        # prepare font and painter state
        p.setFont(lp.font())
        baseline = (lineheight + lp.fontmetrics().ascent()) / 2

        # check the visible sequences
        start_idx, _ = self.xy2coord(0, y)
        stop_idx, _ = self.xy2coord(0, y_end)

        # iterate to paint the label
        selection = self.selection() if isinstance(self.selection(),
                                                   LabelSelection) else None
        for i in range(max(0, start_idx - 1), min(stop_idx + 1, len(model))):
            p.save()
            p.translate(0, i * lineheight)
            if selection and i in selection:
                lp.draw_label(p, i, baseline, model[i].label, selected=True)
            else:
                lp.draw_label(p, i, baseline, model[i].label)
            p.restore()
Ejemplo n.º 7
0
    def init_toolbar(self):
        self._xscale_slider = PopupSlider( orientation = QtCore.Qt.Horizontal )
        xslider = self._xscale_slider.slider()
        xslider.setRange(2, 42)
        xslider.setSingleStep(1)
        xslider.valueChanged.connect( self.set_xscale )
        xslider.setValue(10)
        self.add_popup( '\u2194', self._xscale_slider )

        self._yscale_slider = PopupSlider( orientation = QtCore.Qt.Vertical )
        yslider = self._yscale_slider.slider()
        yslider.setRange(1, 21)
        yslider.setSingleStep(1)
        yslider.valueChanged.connect( self.set_yscale )
        yslider.setValue(10)
        self.add_popup( '\u2195', self._yscale_slider )

        self._searchbox = QtGui.QLineEdit('Search')
        self._searchbox.setMaxLength(32)
        self._searchbox.returnPressed.connect( self.do_search )
        self._toolbar.addWidget( self._searchbox )

        self._prevsearch = self._toolbar.addAction( '\u226a', self.do_prevsearch)
        self._prevsearch.setEnabled(False)
        self._nextsearch = self._toolbar.addAction( '\u226b', self.do_nextsearch)
        self._nextsearch.setEnabled(False)

        self._panesplit = QtGui.QSpinBox()
        self._panesplit.setRange(1, 8)
        self._panesplit.setSingleStep(1)
        self._panesplit.valueChanged.connect( self.set_split )
        self._panesplit.setValue( 4 )
        self._toolbar.addWidget( self._panesplit )

        self._peaks = {}
        for i in range(len(trace_set)):
            tb = QtGui.QToolButton()
            tb.setText(trace_set[i])
            tb.setDown(True)
            self._toolbar.addWidget( tb )
            self._peaks[i] = tb
            tb.clicked.connect( lambda x, button_no = i: self.tracebutton_changed( x, button_no ) )
Ejemplo n.º 8
0
    def paintEvent(self, ev):

        r = ev.rect()
        x, y, w, h = r.x(), r.y(), r.width(), r.height()
        evrect = (x, y, w, h)

        p = QtGui.QPainter(self)

        # drawing sequence
        self.draw_region(evrect, p, self.caret())

        # drawing auxiliary region (such as selection, markers, etc)
        self.draw_region_aux(r, p)
Ejemplo n.º 9
0
def test_tracepane():
    import sys
    import ienv

    app = QtGui.QApplication( sys.argv )
    tracedata = trace.open_trace( sys.argv[1] ).tracedata()

    pane = TracePane( tracedata, TraceView )
    pane.set_env( ienv.IEnv() )
    pane.init_layout()
    pane.set_split(4)
    pane.show()
    app.exec_()
Ejemplo n.º 10
0
def test_labelpane():
    import sys
    import msa
    import ienv

    app = QtGui.QApplication(sys.argv)
    msa = msa.MSA()
    msa.open(sys.argv[1])
    msa.set_type()

    pane = LabelPane(msa, LabelView)
    pane.set_env(ienv.IEnv())
    pane.init_layout()
    pane.show()
    app.exec_()
Ejemplo n.º 11
0
def test_sequencepane():
    import sys
    import msa
    import ienv

    app = QtGui.QApplication(sys.argv)
    msa = msa.MSA()
    msa.open(sys.argv[1])
    msa.set_type()

    pane = SequencePane(msa, SequenceView)
    pane.set_env(ienv.IEnv())
    pane.init_layout(header=RulerView(pane))
    pane.show()
    app.exec_()
Ejemplo n.º 12
0
 def create_action(self, text, slot=None, shortcut=None, icon=None,
             tip=None, checkable=False):
     action = QtWidgets.QAction(text, self.pane())
     if icon is not None:
         action.setIcon( QtGui.QIcon(":/images%s.png" % icon) )
     if shortcut is not None:
         action.setShortcut( shortcut )
     if tip is not None:
         action.setToolTip( tip )
         action.setStatusTip( tip )
     if slot is not None:
         action.triggered.connect( slot )
     if checkable:
         action.setCheckable( True )
     return action
Ejemplo n.º 13
0
    def __init__(self):

        # for A, C, G, T, N
        self.base_colors = [    QtGui.QColor(x) for x in ('forestgreen', 'blue', ' black',
                                    'red', 'grey') ]

        self.trace_pens = [ QtGui.QPen(x, 1) for x in self.base_colors ]
        self.quality_pens = [ QtGui.QPen(
                    QtGui.QColor(*x), 5, QtCore.Qt.SolidLine, QtCore.Qt.FlatCap )
                    for x in ( (255,20,255), (255,25,25), (20,155,20) ) ]

        self.ruler_pen = QtGui.QPen( QtGui.QColor('black'))
        self.ruler_font = QtGui.QFont('Monospace', 8)
        self.ruler_fontmetrics = QtGui.QFontMetrics( self.ruler_font )
        self.ruler_fontmetrics_halfwidth = self.ruler_fontmetrics.width('A')/2

        self._show = [ True, True, True, True ]
Ejemplo n.º 14
0
    def paintEvent(self, ev):
        # print '<RulerView>.paintEvent'
        r = ev.rect()
        x, w = r.x(), r.width()
        height = self.height()

        # print x,w,height

        model = self.model()

        p = QtGui.QPainter(self)

        cw = self.pane().charwidth()
        start = x // cw
        end = start + w // cw
        midl = cw // 2
        p.setFont(self._font)
        p.translate(0, height - 4)
        # print "ruler from %d -> %d" % (start, end)

        # print ticks
        for i in range(start - 10, end + 10):
            pos = i + self.pane().ruler_startpos()
            line_x = i * cw + midl

            if self.pane().ruler_atgframe() > 0:
                if pos % 3 == self.pane().ruler_atgframe():
                    p.setPen(QtCore.Qt.red)
                else:
                    p.setPen(QtCore.Qt.black)

            if pos % 5 == 0:
                if pos % 10 == 0:
                    text = str(pos)
                    tw = self._fontmetrics.width(text)
                    p.setPen(QtCore.Qt.black)
                    p.drawText(line_x - tw - 2, -self.smalltick - 3, text)
                    p.drawLine(line_x, 0, line_x, -13)
                else:
                    p.drawLine(line_x, 0, line_x, -self.bigtick)

            else:
                p.drawLine(line_x, 0, line_x, -self.smalltick)
Ejemplo n.º 15
0
 def _create_image(self, c, color):
     p = QtGui.QPixmap(self.charwidth(), self.lineheight())
     painter = QtGui.QPainter(p)
     #painter.translate(0, self.font_height - 2)
     if self.shaded:
         fg_color = QtGui.QColor(*color[1])
         bg_color = QtGui.QColor(*color[0])
     else:
         fg_color = QtGui.QColor(*color[0])
         bg_color = QtGui.QColor(255, 255, 255)
     bg_brush = QtGui.QBrush(bg_color)
     painter.setBackground(bg_brush)
     painter.setBrush(bg_brush)
     painter.setPen(bg_color)
     painter.drawRect(0, 0, self.charwidth(), self.lineheight())
     painter.setPen(fg_color)
     painter.setFont(self.seqfont.font)
     painter.drawText(
         1, (self.lineheight() + self.seqfont.fontmetrics.ascent()) / 2,
         chr(c))
     painter.end()
     return p
Ejemplo n.º 16
0
    def paintEvent(self, ev):

        r = ev.rect()
        x,y,w,h = r.x(), r.y(), r.width(), r.height()

        D(INFO, "(%s) -> [%d,%d,%d,%d]" % ( self, x,y,w,h ) )
        p = QtGui.QPainter(self)
        
        # below makes the trace pretty, but consume more time to display
        p.setRenderHint( QtGui.QPainter.Antialiasing )
        p.setRenderHint( QtGui.QPainter.TextAntialiasing )

        caret_box = self.caret().box()
        if caret_box:
            intersection = r.intersected( caret_box )
            p.fillRect( intersection, self.env().brushes['trace-selection'] )

        selection = self.selection()
        if selection:
            intersection = r.intersected( selection.box(self) )
            p.fillRect( intersection, self.env().brushes['trace-selection'] )

        height = self._scrollarea.height()
        self.painter().draw_region( self.model(), x, w, height, p )
Ejemplo n.º 17
0
    def paintEvent(self, ev):
        r = ev.rect()
        x, w = r.x(), r.width()
        height = self.height()

        model = self.model()

        p = QtGui.QPainter()

        start = max(0, x // cw - 1)
        end = min(len(model[0]), start + w // cw + 1)
        midl = cw // 2
        p.setFont(self._font)
        p.translate(0, height - 4)
        p.rotate(90)

        th = self._fontmetrics.height('0')

        for i in range(start, end):
            line_y = i * cw + midl

            text = str(i)
            p.setPen(QtCore.Qt.black)
            p.drawText(0, line_y - th - 2, text)
Ejemplo n.º 18
0
    def __init__(self):
        super(IEnv, self).__init__()
        self._lineheight = LINEHEIGHT           # global lineheight
        self._charwidth = CHARWIDTH             # global charwidth
        self._nascheme = EasyNA()               # default NA scheme
        self._aascheme = AESSN3()               # default AA scheme
        self._header = True
        self._footer = False
        self._split = 1
        self._panesplit = 1
        self._activeview = None
        self._tracesplit = 4

        # basic preference
        self.fonts = {
            'sequence': ('Monospace', 7 ),
            'label': QtGui.QFont('Monospace', 8 )
        }

        # colors
        self.colors = {
            'general-background': QtGui.QColor( 244, 244, 232 ),
            'sequence-selection': QtGui.QColor( 191, 191, 191, 64 ),
            'trace-selection': QtGui.QColor( 'lightblue' ),
        }

        # brush
        self.brushes = {
            'sequence-selection': QtGui.QBrush( self.colors['sequence-selection'] ),
            'trace-selection': QtGui.QBrush( self.colors['trace-selection'] ),
        }

        # pens
        self.pens = {
            'sequence-selection': QtGui.QPen( self.brushes['sequence-selection'], 0 )
        }
Ejemplo n.º 19
0
 def width_hint(self):
     """ return the width of vertical scroll bar """
     if self.__width_hint < 0:
         self.__width_hint = QtGui.QScrollBar(
             QtCore.Qt.Vertical).sizeHint().width()
     return self.__width_hint
Ejemplo n.º 20
0
    def __init__(self, pane, parent=None):
        super().__init__(pane, parent)

        self._font = QtGui.QFont('Monospace', 4)
        self._fontmetrics = QtGui.QFontMetrics(self._font)
Ejemplo n.º 21
0
 def prepare_statusbar(self, ):
     self._statusbar = QtGui.QStatusBar()
     self.init_statusbar()
Ejemplo n.º 22
0
 def xxx_ContextMenuEvent(self, ev):
     menu = QtGui.QMenu()
     self.pane().custom_actions().populate_contextmenu(menu)
     menu.exec_(ev.globalPos())
Ejemplo n.º 23
0
    def __init__(self, pane, parent=None):
        super(RulerView, self).__init__(pane, parent)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        self._font = QtGui.QFont('Monospace', 7)
        self._fontmetrics = QtGui.QFontMetrics(self._font)
Ejemplo n.º 24
0
 def prepare_toolbar(self, title):
     if title:
         self._toolbar = QtGui.QToolBar( title )
     else:
         self._toolbar = QtGui.QToolBar()
     self.init_toolbar()
Ejemplo n.º 25
0
    def draw_single_trace(self, minTp, maxTp, data, pen, p, scaleX, scaleY):

        p.setPen( pen )
        points = [ QtCore.QPoint( x * scaleX, data[x] * scaleY)
                        for x in range(max(0, minTp - 5), min(maxTp+5, len(data))) ]
        p.drawPolyline( QtGui.QPolygon(points) )
Ejemplo n.º 26
0
 def prepare_menu(self):
     self._menubar = QtGui.QMenuBar()
     self.init_menu()