Esempio n. 1
0
    def __init__(self, title, parent=None):
        super().__init__(title, parent)

        # buttons for adding/removing a box
        self.sub = gpi.BasicPushButton()
        self.sub.set_toggle(False)
        self.sub.set_button_title(u'\u2212')
        self.sub.valueChanged.connect(self.removeBox)
        self.add = gpi.BasicPushButton()
        self.add.set_toggle(False)
        self.add.set_button_title(u'\uFF0B')
        self.add.valueChanged.connect(self.addBox)

        self.hbox = QtWidgets.QHBoxLayout()
        self.hbox.setSpacing(0)
        self.hbox.addWidget(self.sub)
        self.hbox.addWidget(self.add)

        # at least one spin box
        self.boxes = []
        self.boxes.append(gpi.BasicSpinBox())
        self.vbox = QtWidgets.QVBoxLayout()
        self.vbox.setSpacing(0)

        self.vbox.addLayout(self.hbox)
        for box in self.boxes:
            self.vbox.addWidget(box)
            box.valueChanged.connect(self.valueChanged)
        self.setLayout(self.vbox)
Esempio n. 2
0
 def __init__(self, title, parent=None):
     super().__init__(title, parent)
     self.sl = gpi.BasicCWFCSliders()
     self.sl.valueChanged.connect(self.valueChanged)
     # at least one button
     self.button_names = ['C/W']
     self.buttons = []
     cnt = 0
     wdgLayout = QtWidgets.QGridLayout()
     for name in self.button_names:
         newbutton = QtWidgets.QPushButton(name)
         newbutton.setCheckable(True)
         newbutton.setAutoExclusive(True)
         self.buttons.append(newbutton)
         newbutton.clicked.connect(self.findValue)
         newbutton.clicked.connect(self.valueChanged)
         wdgLayout.addWidget(newbutton, 0, cnt, 1, 1)
         cnt += 1
     # layout
     wdgLayout.addWidget(self.sl, 1, 0, 1, 4)
     wdgLayout.setVerticalSpacing(0)
     wdgLayout.setSpacing(0)
     self.setLayout(wdgLayout)
     # default
     self.set_min(1)
     self._selection = 0  # pass is default
     #self.buttons[self._selection].setChecked(True)
     self.sl.set_allvisible(False)
Esempio n. 3
0
    def _init_toolbar(self):
        self.basedir = os.path.join(matplotlib.rcParams[ 'datapath' ],'images')

        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                self.addSeparator()
            else:
                a = self.addAction(self._icon(image_file + '.png'),
                                         text, getattr(self, callback))
                self._actions[callback] = a
                if callback in ['zoom', 'pan']:
                    a.setCheckable(True)
                if tooltip_text is not None:
                    a.setToolTip(tooltip_text)

        # Add the x,y location widget at the right side of the toolbar
        # The stretch factor is 1 which means any resizing of the toolbar
        # will resize this label instead of the buttons.
        if self.coordinates:
            self.locLabel = QtWidgets.QLabel( "", self )
            self.locLabel.setAlignment(
                    QtCore.Qt.AlignRight | QtCore.Qt.AlignTop )
            self.locLabel.setSizePolicy(
                QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Ignored))
            labelAction = self.addWidget(self.locLabel)
            labelAction.setVisible(True)
Esempio n. 4
0
    def generateNodeSearchActions(self, txt, menu, mousemenu):

        # user query
        txt = txt.lower()

        # NODE SEARCH
        # search using txt string
        sortedMods = []
        if len(txt) > 2:  # match anywhere in name
            for node in list(self._known_GPI_nodes.values()):
                if node.name.lower().find(txt) > -1:
                    sortedMods.append(node)
        else:  # only match from start of name
            for node in list(self._known_GPI_nodes.values()):
                if node.name.lower().startswith(txt):
                    sortedMods.append(node)
        sortedMods = sorted(sortedMods, key=lambda x: x.name.lower())

        # create actions and add them to the menu
        for node in sortedMods:

            a = QtWidgets.QAction(node.name+" (" + node.thrd_sec + ")", self._parent, statusTip="Click to instantiate the \'"+str(node.name)+"\' node.")
            s = {'subsig': node}

            # The way this signal is connected, the
            # s-dict is fully copied which is required to pass the correct
            # mod name.
            a.triggered.connect(partial(self.addNodeAndCloseMouseMenu,
                                        s=s, searchmenu=menu,
                                        mousemenu=mousemenu))
            menu.addAction(a)


        # NETWORK SEARCH
        # search using txt string
        if True:
            sortedMods= []
            if len(txt) > 2:
                for net in list(self._known_GPI_networks.values()):
                    if net.name.lower().find(txt) > -1:
                        sortedMods.append(net)

            else:
                for net in list(self._known_GPI_networks.values()):
                    if net.name.lower().startswith(txt):
                        sortedMods.append(net)
            sortedMods = sorted(sortedMods, key=lambda x: x.name.lower())

            if len(sortedMods):
                menu.addSeparator()

            # create actions and add them to the menu
            for net in sortedMods:
                a = QtWidgets.QAction(net.name+" (net) (" + net.thrd_sec + ")", self._parent, statusTip="Click to instantiate the \'"+str(net.name)+"\' network.")
                s = {'sig': 'load', 'subsig': 'net', 'path': net.fullpath}
                a.triggered.connect(partial(self.addNodeAndCloseMouseMenu,
                                            s=s, searchmenu=menu,
                                            mousemenu=mousemenu))
                menu.addAction(a)
Esempio n. 5
0
 def setLayoutType(self, typ):
     '''The basic layout is VBox or HBox.
     '''
     self._layoutType = typ
     if typ == 'vbox':
         self._layout = QtWidgets.QVBoxLayout()
     elif typ == 'hbox':
         self._layout = QtWidgets.QHBoxLayout()
Esempio n. 6
0
    def __init__(self, dry_run=False):
        super().__init__()

        self._updater = CondaUpdater(dry_run=dry_run)
        self._updater.getStatus_done.connect(self.showStatus)
        self._updater.getStatus_done.connect(self.showOKorUpdateButton)
        self._updater.failed.connect(self.initFailureMode)
        self._updater.updateAllPkgs_done.connect(self.relaunchProc)

        style = '''
            QProgressBar {
                background-color: rgb(226,226,226);
                border: 1px solid rgb(222,222,222);
                border-radius: 2px;
                text-align: center;
            }

            QProgressBar::chunk {
                background-color: #0099FF;
                height: 15px;
                width: 1px;
            }
        '''
        self._pbar = QtWidgets.QProgressBar(self)
        self._pbar.setStyleSheet(style)
        self._updater.pdone.connect(self.pdone)

        self._txtbox = TextBox('')
        self._txtbox.wdg.setTextFormat(QtCore.Qt.RichText)
        self._txtbox.set_wordwrap(True)
        self._txtbox.set_openExternalLinks(True)
        self._updater.message.connect(self._txtbox.set_val)
        self._txtbox.set_val('Checking for updates...')

        self._okButton = QtWidgets.QPushButton("OK")
        self._okButton.setVisible(False)
        self._cancelButton = QtWidgets.QPushButton("Cancel")
        self._cancelButton.clicked.connect(self.close)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addStretch(1)
        hbox.addWidget(self._okButton)
        hbox.addWidget(self._cancelButton)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(self._txtbox, 1)
        vbox.addWidget(self._pbar)
        vbox.addLayout(hbox)

        self.setLayout(vbox)

        self.setGeometry(300, 300, 400, 350)
        self.setWindowTitle('GPI Update')
        self.show()
        self.raise_()

        ExecRunnable(Runnable(self._updater.getStatus))
Esempio n. 7
0
    def __init__(self, title, parent=None):
        super(TextBoxes, self).__init__(title, parent)

        # at least one text box
        self.boxes = []
        self.boxes.append(QtWidgets.QLabel())
        self.vbox = QtWidgets.QVBoxLayout()
        self.vbox.setSpacing(0)
        for box in self.boxes:
            self.vbox.addWidget(box)
        self.setLayout(self.vbox)
Esempio n. 8
0
    def __init__(self, title, parent=None):
        super(StringBoxes, self).__init__(title, parent)

        # at least one string box
        self.boxes = []
        self.boxes.append(QtWidgets.QLineEdit())
        self.vbox = QtWidgets.QVBoxLayout()
        self.vbox.setSpacing(0)
        for box in self.boxes:
            self.vbox.addWidget(box)
            box.returnPressed.connect(self.valueChanged)
        self.setLayout(self.vbox)
Esempio n. 9
0
    def __init__(self, graph, destPort, sourcePort):
        super(EdgeTracer, self).__init__()

        # show a faux copy of the delete menu
        menu = QtWidgets.QMenu()
        menu.addAction("Delete")

        # position of pipe end based on port type
        bindout_y = 5
        bindin_y = -1
        p1 = self.mapFromItem(sourcePort, 3.5, bindin_y)
        p2 = self.mapFromItem(destPort, 3.5, bindout_y)

        pos = graph.mapToGlobal(graph.mapFromScene((p1 - p2) / 2 + p2))

        # render the menu without executing it
        try:
            # PyQt4
            menupixmap = QtGui.QPixmap().grabWidget(menu)
        except AttributeError:
            menupixmap = menu.grab()  # QtGui.QPixmap().grabWidget(menu)

        # round edges
        #mask = menupixmap.createMaskFromColor(QtGui.QColor(255, 255, 255), QtCore.Qt.MaskOutColor)
        #p = QtGui.QPainter(menupixmap)
        #p.setRenderHint(QtGui.QPainter.Antialiasing)
        #p.drawRoundedRect(0,0,menupixmap.width(),menupixmap.height(), 5,5)
        #p.drawPixmap(menupixmap.rect(), mask, mask.rect())
        #p.end()

        # display the menu image (as a dummy menu as its being built)
        # TODO: this could probably be moved to the FauxMenu
        self._tracer = QtWidgets.QLabel()
        self._tracer.setWindowFlags(QtCore.Qt.Tool
                                    | QtCore.Qt.FramelessWindowHint)
        self._tracer.move(pos)
        self._tracer.setPixmap(menupixmap)
        self._tracer.show()
        self._tracer.raise_()

        # draw a faux selected line
        line = QtCore.QLineF(p1, p2)
        self.setPen(
            QtGui.QPen(QtGui.QColor(QtCore.Qt.red), 2, QtCore.Qt.DashLine,
                       QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
        self.setLine(line)
        self.setZValue(0)

        # cleanup both menu item and line by removing from scene (parent).
        self._timer = QtCore.QTimer()
        self._timer.singleShot(300, lambda: graph.scene().removeItem(self))
Esempio n. 10
0
    def startLineDraw(self, event):
        # highlight all ports that match
        startItems = self.items(event.scenePos())
        if len(startItems):
            if isinstance(startItems[0], OutPort):
                if QtCore.Qt.AltModifier == getKeyboardModifiers():
                    startItems[0].toggleMemSaver()
                    return
                self.portMatches = startItems[0].findMatchingInPorts()
                for port in self.portMatches:
                    port.scaleUp()
                self.graph.viewAndSceneForcedUpdate()

            if isinstance(startItems[0], InPort):
                self.portMatches = startItems[0].findMatchingOutPorts()
                for port in self.portMatches:
                    port.scaleUp()
                self.graph.viewAndSceneForcedUpdate()

        self.line = QtWidgets.QGraphicsLineItem(
            QtCore.QLineF(event.scenePos(), event.scenePos()))
        fade = QtGui.QColor(QtCore.Qt.red)
        fade.setAlpha(150)
        self.line.setPen(QtGui.QPen(fade, 2))
        self.line.setZValue(10)
        self.addItem(self.line)
Esempio n. 11
0
    def __init__(self, title, parent=None):
        super().__init__(title, parent)

        self._val = {}
        self._val['length'] = 1
        self._val['in_len'] = 1  # the original array length

        self.db = gpi.BasicDoubleSpinBox()  # factor
        self.db.set_label('factor:')
        self.db.set_min(0.001)
        self.db.set_max(gpi.GPI_FLOAT_MAX)
        self.db.set_decimals(3)
        self.db.set_singlestep(0.001)
        self.db.set_val(1)

        self.sb = gpi.BasicSpinBox()  # length
        self.sb.set_label('length:')
        self.sb.set_min(1)
        self.sb.set_val(1)
        self.sb.set_max(gpi.GPI_INT_MAX)

        self.db.valueChanged.connect(self.factChange)
        self.sb.valueChanged.connect(self.lenChange)

        vbox = QtWidgets.QHBoxLayout()
        vbox.addWidget(self.db)
        vbox.addWidget(self.sb)
        vbox.setStretch(0, 0)
        vbox.setStretch(1, 0)
        vbox.setStretch(2, 0)
        vbox.setContentsMargins(0, 0, 0, 0)  # we don't need margins here
        vbox.setSpacing(0)
        self.setLayout(vbox)
Esempio n. 12
0
    def __init__(self, title, parent=None):
        super(DICOM_HDR_GROUP, self).__init__(title, parent)
        self._val = {}
        self._val['tags'] = ''
        self._val['desc'] = ''
        self._val['VRs'] = ''
        self._val['values'] = ''

        self.tb1 = TextBoxes('Tags:')
        self.tb1.set_length(1)
        self.tb2 = TextBoxes('Descriptions:')
        self.tb2.set_length(1)
        self.tb3 = TextBoxes('VRs:')
        self.tb3.set_length(1)

        self.sb = StringBoxes('Values:')
        self.sb.set_length(1)
        self.sb.valueChanged.connect(self.valueChanged)

        vbox = QtWidgets.QHBoxLayout()
        vbox.addWidget(self.tb1)
        vbox.addWidget(self.tb2)
        vbox.addWidget(self.tb3)
        vbox.addWidget(self.sb)
        vbox.setStretch(0, 0)
        vbox.setStretch(1, 0)
        vbox.setStretch(2, 0)
        vbox.setStretch(3, 0)
        vbox.setContentsMargins(0, 0, 0, 0)  # we don't need margins here
        vbox.setSpacing(0)
        self.setLayout(vbox)
Esempio n. 13
0
    def __init__(self, title, parent=None):
        super().__init__(title, parent)

        self._val = {}
        self._val['image_quality_left'] = 0
        self._val['image_quality_right'] = 0

        #image_quality_left
        self.iql = gpi.ComboBox('image_quality_left')
        self.iql.set_items(['choose..', 'excellent', 'good', 'diagnostic', 'non-diagnostic'])
        #self.iql.set_val('choose..')
        self.iql.set_index(0)

        #image_quality_right
        self.iqr = gpi.ComboBox('image_quality_right')
        self.iqr.set_items(['choose..', 'excellent', 'good', 'diagnostic', 'non-diagnostic'])
        #self.iqr.set_val('choose..')
        self.iqr.set_index(0)

        self.iql.valueChanged.connect(self.iqlChange)
        self.iqr.valueChanged.connect(self.iqrChange)

        vbox = QtWidgets.QHBoxLayout()
        vbox.addWidget(self.iql)
        vbox.addWidget(self.iqr)
        vbox.setStretch(0, 0)
        vbox.setStretch(1, 0)
        vbox.setContentsMargins(0, 0, 0, 0)  # we don't need margins here
        vbox.setSpacing(0)
        self.setLayout(vbox)
Esempio n. 14
0
def launch():
    '''Starts the main application loop, parses any user config and commandline
    args.'''

    # start main application
    # for debugging force widgetcount
    #app = QtWidgets.QApplication(sys.argv+['-widgetcount'])
    app = QtWidgets.QApplication(sys.argv)

    # parse commandline arguments
    try:
        # PyQt4
        Commands.parse(app.argv())
    except AttributeError:
        # PyQt5
        Commands.parse(app.arguments())
    #print Commands

    # start a mainwindow widget instance
    widget = MainCanvas()

    # start splash
    # only raise in GUI mode, don't raise in cmdline mode.
    if not Commands.noGUI():

        if not Commands.noSplash():
            spl = Splash(PLOGO_PATH)

            def closeraise():
                spl.finish(widget)
                widget.show()
                widget.raise_()

            spl.terms_accepted.connect(closeraise)
            spl.show()
            spl.raise_()
            app.processEvents()  # allow gui to update

        else:
            dummy = QtWidgets.QSplashScreen()
            dummy.show()
            dummy.finish(widget)
            widget.show()
            widget.raise_()

    sys.exit(app.exec_())
Esempio n. 15
0
    def about(self):
        # Display
        image = QtGui.QImage(LOGO_PATH)
        dispbox = DisplayBox('')
        dispbox.set_pixmap(QtGui.QPixmap.fromImage(image))
        dispbox.set_scale(0.157)
        dispbox.set_interp(True)

        # Text
        tab = '    '
        txt = '<center><font size=4><b>Graphical Programming Interface (GPI)</b></font><br><b><a href=http://gpilab.com>gpilab.com</a></b><br><br>' +\
              'Nicholas Zwart<br>Barrow Neurological Institute<br>Phoenix, Arizona' +\
              '<br><br>' +\
              tab + 'Release: '+ str(VERSION) + ' (' + str(RELEASE_DATE) +')' +\
              '<p>'+\
              'GPI is a graphical development environment designed for rapid prototyping '+\
              'of numeric algorithms.'+\
              '</p>'+\
              '<p>'+\
              'GPI development is sponsored by Philips Healthcare.'+\
              '</p></center>'
        txtbox = TextBox('')
        txtbox.set_val(txt)
        txtbox.set_wordwrap(True)
        txtbox.set_openExternalLinks(True)

        # set layout
        wdgvbox = QtWidgets.QVBoxLayout()
        wdgvbox.addWidget(dispbox)
        wdgvbox.addWidget(txtbox)
        wdgvbox.setStretch(0, 2)

        # set master widget
        self.aboutWdg = QtWidgets.QWidget()
        self.aboutWdg.setLayout(wdgvbox)
        # self.aboutWdg.setSizePolicy(QtWidgets.QSizePolicy.Minimum, \
        #   QtWidgets.QSizePolicy.Preferred)
        # self.aboutWdg.setMaximumWidth(420)
        self.aboutWdg.show()
        self.aboutWdg.raise_()
        log.debug(str(dispbox.sizeHint()))
Esempio n. 16
0
    def set_length(self, length):
        # add specified number of text boxes
        while length > len(self.boxes):
            newbox = QtWidgets.QLabel()
            self.boxes.append(newbox)
            self.vbox.addWidget(newbox)
        while length < len(self.boxes):
            oldbox = self.boxes.pop()
            oldbox.setParent(None)

        if length != len(self.boxes):
            log.critical("StringBoxes: length not properly set!")
Esempio n. 17
0
    def console(self):
        log.debug("MainCanvas(): console()")
        self.txtbox = TextEdit('Console')

        # Redirect stdio
        sys.stdout = Tee(sys.stdout)
        sys.stderr = Tee(sys.stderr)

        # NOTE: this is only good for QThread NOT Multiprocess.
        sys.stdout.newStreamTxt.connect(self.consoleWrite)
        sys.stderr.newStreamTxt.connect(self.consoleWrite)

        # set layout
        wdgvbox = QtWidgets.QVBoxLayout()
        wdgvbox.addWidget(self.txtbox)

        # set master widget
        self.consoleWdg = QtWidgets.QWidget()
        self.consoleWdg.setLayout(wdgvbox)
        self.consoleWdg.show()
        self.consoleWdg.raise_()
Esempio n. 18
0
    def __init__(self, title, parent=None):
        super().__init__(title, parent)

        # at least one button
        wdgLayout = QtWidgets.QGridLayout()
        self.wdg = GPITabBar()
        self.wdg.addTab('0')
        self.wdg.setMovable(True)
        self.wdg.currentChanged.connect(self.valueChanged.emit)
        # layout
        wdgLayout.addWidget(self.wdg)
        self.setLayout(wdgLayout)
Esempio n. 19
0
    def set_length(self, length):
        # add specified number of string boxes
        while length > len(self.boxes):
            newbox = QtWidgets.QLineEdit()
            self.boxes.append(newbox)
            newbox.returnPressed.connect(self.valueChanged)
            self.vbox.addWidget(newbox)
        while length < len(self.boxes):
            oldbox = self.boxes.pop()
            oldbox.setParent(None)

        if length != len(self.boxes):
            log.critical("StringBoxes: length not properly set!")
Esempio n. 20
0
    def __init__(self, title, parent=None):
        super().__init__(title, parent)

        self._val = {}
        self._val['size'] = 1
        self._val['width'] = 1

        self.sb = gpi.BasicSpinBox()  # size
        self.sb.set_label('size:')
        self.sb.set_min(1)
        self.sb.set_val(1)
        self.sb.set_max(gpi.GPI_INT_MAX)

        self.slb = gpi.BasicSlider()  # width
        self.slb.set_min(1)
        self.slb.set_val(1)
        self.slb.set_max(1)

        self.slider_label = QtWidgets.QLabel('width:')

        self.sb.valueChanged.connect(self.sizeChange)
        self.slb.valueChanged.connect(self.widthChange)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(self.slider_label)
        hbox.addWidget(self.slb)
        hbox.setStretch(0, 0)
        hbox.setSpacing(5)

        hboxGroup = QtWidgets.QHBoxLayout()
        hboxGroup.addWidget(self.sb)
        hboxGroup.addLayout(hbox)
        hboxGroup.setStretch(0, 0)
        hboxGroup.setContentsMargins(0, 0, 0, 0)  # we don't need margins here
        hboxGroup.setSpacing(30)
        self.setLayout(hboxGroup)
Esempio n. 21
0
    def create_main_frame(self):

        self.fig = Figure((5.0, 4.0), dpi=100)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(self)
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()

        self.mpl_toolbar = NavigationToolbar(self.canvas, self)

        self.canvas.mpl_connect('key_press_event', self.on_key_press)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(self.canvas)  # the matplotlib canvas
        vbox.addWidget(self.mpl_toolbar)
        self.setLayout(vbox)
Esempio n. 22
0
 def __init__(self, title, parent=None):
     super().__init__(title, parent)
     self.sl = gpi.BasicCWFCSliders()
     self.sl.valueChanged.connect(self.valueChanged)
     self.pb = gpi.BasicPushButton()
     self.pb.set_button_title('reset')
     # layout
     wdgLayout = QtWidgets.QVBoxLayout()
     wdgLayout.addWidget(self.sl)
     wdgLayout.addWidget(self.pb)
     self.setLayout(wdgLayout)
     # default
     self.set_min(0)
     self.set_max(100)
     self.sl.set_allvisible(True)
     self.reset_sliders()
     self.pb.valueChanged.connect(self.reset_sliders)
Esempio n. 23
0
    def __init__(self, title, parent=None):
        super().__init__(title, parent)

        self._val = {}
        self._val['action'] = 0
        self._val['dim_position'] = 1  # 0 - first, 1 - middle, 2 - last
        self._val['combine_dir'] = 0
        self._val['split_prod'] = 1
        self._val['split_val1'] = 1
        self._val['split_val2'] = 1

        # create exclusive push buttons to choose action
        self.action = gpi.ExclusivePushButtons('action')
        self.buttons = ['pass', 'combine', 'split']
        self.action.set_buttons(self.buttons)

        # create exclusive push buttons to choose action
        self.combdir = gpi.ExclusivePushButtons('direction')
        self.buttons = [u'\u2B06', u'\u2B07']
        self.combdir.set_buttons(self.buttons)
        self.combdir.set_visible(False)

        # create integer boxes for splitting a value
        self.sb1 = gpi.BasicSpinBox()
        self.sb1.set_min(1)
        self.sb1.set_val(1)
        self.sb1.set_max(gpi.GPI_INT_MAX)
        self.sb2 = gpi.BasicSpinBox()
        self.sb2.set_min(1)
        self.sb2.set_val(1)
        self.sb2.set_max(gpi.GPI_INT_MAX)
        self.set_sb_visible(False)

        self.action.valueChanged.connect(self.actionChange)
        self.combdir.valueChanged.connect(self.combdirChange)
        self.sb1.valueChanged.connect(self.splitChangeLeft)
        self.sb2.valueChanged.connect(self.splitChangeRight)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(self.action)
        hbox.addWidget(self.combdir)
        hbox.addWidget(self.sb1)
        hbox.addWidget(self.sb2)
        hbox.setSpacing(0)
        self.setLayout(hbox)
Esempio n. 24
0
    def newLayoutWindow(self, config):
        '''Copied from canvasGraph.
        '''

        layoutwindow = LayoutMaster(self._graph,
                                    config=config,
                                    macro=True,
                                    labelWin=True)
        layoutwindow.setWindowTitle('Macro')
        layoutwindow.wdglabel.textChanged.connect(self.setLabel)

        self._scrollArea_layoutWindow = QtWidgets.QScrollArea()
        self._scrollArea_layoutWindow.setWidget(layoutwindow)
        self._scrollArea_layoutWindow.setWidgetResizable(True)
        self._scrollArea_layoutWindow.setGeometry(50, 50, 300, 1000)

        layoutwindow.setGeometry(50, 50, 400, 300)
        self._layoutWindow = layoutwindow
Esempio n. 25
0
    def __init__(self, title, parent=None):
        super().__init__(title, parent)

        self._val = {}
        self._val['length'] = 1
        self._val['start'] = 0.
        self._val['end'] = 0. # the original array length

        self.sb = gpi.BasicSpinBox()  # length
        self.sb.set_label('# Spins:')
        self.sb.set_min(1)
        self.sb.set_val(1)
        self.sb.set_max(gpi.GPI_INT_MAX)

        self.db1 = gpi.BasicDoubleSpinBox()  # start
        self.db1.set_label('Start:')
        self.db1.set_min(gpi.GPI_FLOAT_MIN)
        self.db1.set_max(gpi.GPI_FLOAT_MAX)
        self.db1.set_decimals(3)
        self.db1.set_singlestep(1.)
        self.db1.set_val(0)

        self.db2 = gpi.BasicDoubleSpinBox()  # end
        self.db2.set_label('End:')
        self.db2.set_min(gpi.GPI_FLOAT_MIN)
        self.db2.set_max(gpi.GPI_FLOAT_MAX)
        self.db2.set_decimals(3)
        self.db2.set_singlestep(1.)
        self.db2.set_val(0)

        self.sb.valueChanged.connect(self.lenChange)
        self.db1.valueChanged.connect(self.startChange)
        self.db2.valueChanged.connect(self.endChange)

        vbox = QtWidgets.QHBoxLayout()
        vbox.addWidget(self.sb)
        vbox.addWidget(self.db1)
        vbox.addWidget(self.db2)
        vbox.setStretch(0, 0)
        vbox.setStretch(1, 0)
        vbox.setStretch(2, 0)
        vbox.setContentsMargins(0, 0, 0, 0)  # we don't need margins here
        vbox.setSpacing(0)
        self.setLayout(vbox)
Esempio n. 26
0
    def create_main_frame(self):
        self.fig = Figure((6.0, 4.8), dpi=100, facecolor='0.98', linewidth=6.0, edgecolor='0.93')
        self.axes = None
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(self)
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()

        self.canvas.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding)

        #self.mpl_toolbar = NavigationToolbar(self.canvas, self)
        self.mpl_toolbar = NavbarTools(self.canvas, self)
        self.mpl_toolbar.actionTriggered.connect(self.copySubplotSettings)

        self.canvas.mpl_connect('key_press_event', self.on_key_press)

        vbox = QtWidgets.QVBoxLayout()
        vbox.addWidget(self.canvas)  # the matplotlib canvas
        vbox.addWidget(self.mpl_toolbar)
        return vbox
Esempio n. 27
0
    def mousePressEvent(self, event):  # CANVAS SCENE
        printMouseEvent(self, event)
        modifiers = getKeyboardModifiers()

        # allow graphics view panning
        if self.graph._panning:
            event.ignore()
            return

        # if its not a port, then don't draw a line
        modmidbutton_event = (event.button() == QtCore.Qt.LeftButton
                              and modifiers == QtCore.Qt.AltModifier)

        if ((event.button() == QtCore.Qt.LeftButton) or (event.button() == QtCore.Qt.MidButton) or modmidbutton_event) \
                and isinstance(self.itemAt(event.scenePos(), QtGui.QTransform()), Port):
            event.accept()
            self.startLineDraw(event)
        # rubber band select
        # elif ((event.button() == QtCore.Qt.MidButton) or modmidbutton_event):
        elif ((event.button() == QtCore.Qt.LeftButton) \
                and not isinstance(self.itemAt(event.scenePos(), QtGui.QTransform()), Node) \
                and not isinstance(self.itemAt(event.scenePos(), QtGui.QTransform()), PortEdge)):
            event.accept()
            self.unselectAllItems()  # reset select before making another
            self.origin = event.scenePos()
            self.rubberBand = QtWidgets.QGraphicsRectItem(
                QtCore.QRectF(self.origin, QtCore.QSizeF()))
            self.rubberBand.setPen(
                QtGui.QPen(QtCore.Qt.gray, 0, QtCore.Qt.SolidLine))
            self.rubberBand.setBrush(QtGui.QBrush(QtCore.Qt.lightGray))
            self.rubberBand.setZValue(0)
            self.addItem(self.rubberBand)
        else:
            QtWidgets.QApplication.restoreOverrideCursor()
            event.ignore()
            super(CanvasScene, self).mousePressEvent(event)
Esempio n. 28
0
    def generateNewNodeListWindow(self):
        # the New Node window
        self._list_win = QtWidgets.QWidget()
        self._list_win.setFixedWidth(500)
        self._new_node_list = QtWidgets.QListWidget(self._list_win)

        self._create_button = QtWidgets.QPushButton("Create Node", self._list_win)
        self._create_button.setDisabled(True)
        self._create_button.clicked.connect(self._createNewNode)
        button_layout = QtWidgets.QHBoxLayout()
        button_layout.addStretch(1)
        button_layout.addWidget(self._create_button)

        self._new_node_list.itemDoubleClicked.connect(self._listItemDoubleClicked)
        self._new_node_list.itemClicked.connect(self._listItemClicked)

        self._list_label = QtWidgets.QLabel("GPI Libraries", self._list_win)

        node_name_layout = QtWidgets.QHBoxLayout()
        new_node_name_label = QtWidgets.QLabel("Name:", self._list_win)
        self._new_node_name_field = QtWidgets.QLineEdit(self._list_win)
        self._new_node_name_field.setPlaceholderText("NewNodeName_GPI.py")
        self._new_node_name_field.textChanged.connect(self._newNodeNameEdited)
        node_name_layout.addWidget(new_node_name_label)
        node_name_layout.addWidget(self._new_node_name_field)

        new_node_path_label = QtWidgets.QLabel("Path:", self._list_win)
        self._new_node_path = ''
        self._new_node_path_field = QtWidgets.QLabel(NOPATH_MESSAGE, self._list_win)
        self._new_node_path_field.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed))
        path_layout = QtWidgets.QHBoxLayout()
        path_layout.addWidget(new_node_path_label)
        path_layout.addWidget(self._new_node_path_field)

        list_layout = QtWidgets.QVBoxLayout()
        list_layout.addWidget(self._list_label)
        list_layout.addWidget(self._new_node_list)
        list_layout.addLayout(node_name_layout)
        list_layout.addLayout(path_layout)
        list_layout.addLayout(button_layout)
        self._list_win.setLayout(list_layout)
Esempio n. 29
0
    def generateLibMenus(self):
        # default menu if no libraries are found
        numnodes = len(list(self._known_GPI_nodes.keys()))
        if numnodes == 0:
            self._lib_menus['No Nodes Found'] = QtWidgets.QMenu('No Nodes Found')
            buf = 'Check your ~/.gpirc for the correct LIB_DIRS.'
            act = QtWidgets.QAction(buf, self._parent, triggered = self.openLIBDIRSHelp)
            self._lib_menus['No Nodes Found'].addAction(act)

            for m in sorted(list(self._lib_menus.keys()), key=lambda x: x.lower()):
                mm = self._lib_menus[m]
                mm.setTearOffEnabled(False)
                self._lib_menu.append(mm)

            return

        # NODE MENU
        # setup libs using node id. ex: core.mathematics.sum
        # the ids of
        for k in sorted(self._known_GPI_nodes.keys(), key=lambda x: x.lower()):
            node = self._known_GPI_nodes.get(k)
            if node.third not in self._lib_menus:
                #self._lib_menus[node.third] = QtWidgets.QMenu(node.third.capitalize())
                self._lib_menus[node.third] = QtWidgets.QMenu(node.third)
                self._lib_menus[node.third].setTearOffEnabled(True)

            if node.thrd_sec not in self._lib_second:
                self._lib_second[node.thrd_sec] = QtWidgets.QMenu(node.second)
                self._lib_second[node.thrd_sec].setTearOffEnabled(True)
                ma = self._lib_menus[node.third].addMenu(self._lib_second[node.thrd_sec])

            sm = self._lib_second[node.thrd_sec]

            # TODO: try setting up hotkeys/shortcuts for specific nodes
            a = QtWidgets.QAction(node.name, self._parent, statusTip="Click to instantiate the \'"+str(node.name)+"\' node.")
            s = {'subsig': node}
            a.triggered.connect(partial(self._parent.addNodeRun, sig=s))
            sm.addAction(a)

        # NETWORK MENU
        for sm in list(self._lib_second.values()):
            sm.addSeparator()

        for k in sorted(list(self._known_GPI_networks.keys()), key=lambda x: x.lower()):
            net = self._known_GPI_networks.get(k)
            if net.third not in self._lib_menus:
                #self._lib_menus[net.third] = QtWidgets.QMenu(net.third.capitalize())
                self._lib_menus[net.third] = QtWidgets.QMenu(net.third)
                self._lib_menus[net.third].setTearOffEnabled(True)

            if net.thrd_sec not in self._lib_second:
                self._lib_second[net.thrd_sec] = QtWidgets.QMenu(net.second)
                self._lib_second[net.thrd_sec].setTearOffEnabled(True)
                self._lib_menus[net.third].addMenu(self._lib_second[node.thrd_sec])

            sm = self._lib_second[net.thrd_sec]
            a = QtWidgets.QAction(net.name + ' (net)', self._parent, statusTip="Click to instantiate the \'"+str(net.name)+"\' network.")
            s = {'sig': 'load', 'subsig': 'net', 'path': net.fullpath}
            a.triggered.connect(partial(self._parent.addNodeRun, sig=s))
            sm.addAction(a)

        for m in sorted(list(self._lib_menus.keys()), key=lambda x: x.lower()):
            mm = self._lib_menus[m]
            mm.setTearOffEnabled(True)
            self._lib_menu.append(mm)
Esempio n. 30
0
    def initLayout(self, config):
        '''Given the config initialize all layout objects overwriting any
        existing layouts.
        '''
        self._config = config
        self._lwList = []

        # delete layout if one exists
        # TODO: this needs to work if Layouts are to be re-initialized
        #if self.layout():
        #    print "delete layout before setting a new one."
        #    for lw in self._lwList:
        #        for c in lw.children():
        #            c.setParent(None)
        #        lw.setParent(None)
        #    self.layout().setParent(None)

        hbox = QtWidgets.QVBoxLayout(self)

        if config == 0:
            top = LayoutWindow(self._graph, 'vbox', 'top')
            top.setFrameShape(QtWidgets.QFrame.StyledPanel)
            hbox.addWidget(top)
            self._lwList.append(top)

        elif config == 1:
            top = LayoutWindow(self._graph, 'hbox', 'top')
            top.setFrameShape(QtWidgets.QFrame.StyledPanel)
            hbox.addWidget(top)
            self._lwList.append(top)

        elif config == 2:
            top = LayoutWindow(self._graph, 'hbox', 'top')
            top.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self._lwList.append(top)

            mid = LayoutWindow(self._graph, 'hbox', 'mid')
            mid.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self._lwList.append(mid)

            bottomleft = LayoutWindow(self._graph, 'vbox', 'bottomleft')
            bottomleft.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self._lwList.append(bottomleft)
            bottommid = LayoutWindow(self._graph, 'vbox', 'bottommid')
            bottommid.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self._lwList.append(bottommid)
            bottomright = LayoutWindow(self._graph, 'vbox', 'bottomright')
            bottomright.setFrameShape(QtWidgets.QFrame.StyledPanel)
            self._lwList.append(bottomright)

            splitter1 = QtWidgets.QSplitter(QtCore.Qt.Vertical)
            splitter1.addWidget(top)
            splitter1.addWidget(mid)

            splitter2 = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
            splitter2.addWidget(bottomleft)
            splitter2.addWidget(bottommid)
            splitter2.addWidget(bottomright)

            splitter3 = QtWidgets.QSplitter(QtCore.Qt.Vertical)
            splitter3.addWidget(splitter1)
            splitter3.addWidget(splitter2)

            hbox.addWidget(splitter3)

        elif config == 3:
            top = LayoutWindow(self._graph, 'vbox', 'top')
            top.setFrameShape(QtWidgets.QFrame.StyledPanel)
            top.changed.connect(self.columnAdjust)
            self.topsplitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
            self.topsplitter.addWidget(top)

            bottom = LayoutWindow(self._graph, 'vbox', 'bottom')
            bottom.setFrameShape(QtWidgets.QFrame.StyledPanel)
            bottom.changed.connect(self.columnAdjust)
            self.bottomsplitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
            self.bottomsplitter.addWidget(bottom)

            vsplitter = QtWidgets.QSplitter(QtCore.Qt.Vertical)
            vsplitter.addWidget(self.topsplitter)
            vsplitter.addWidget(self.bottomsplitter)

            hbox.addWidget(vsplitter)

        if self._labelWin:
            # make a label box with the unique id
            self.wdglabel = QtWidgets.QLineEdit('')
            labelGroup = HidableGroupBox("Node Label")
            labelLayout = QtWidgets.QVBoxLayout()
            labelLayout.addWidget(self.wdglabel)
            labelGroup.setLayout(labelLayout)
            hbox.addWidget(labelGroup)
            labelGroup.set_collapsed(True)
            labelGroup.setToolTip(
                "Displays the Label on the Canvas (Double Click)")

        self.setLayout(hbox)