Exemple #1
0
def setWidgetBackground(widget, color = BACKGROUND_DEFAULT):
    '''
    change the background color of a Qt widget
    
    :param str color: specified as name (mintcream), hex RGB (#dea)
    '''
    if widget is not None:
        palette = QtGui.QPalette()
        palette.setColor(widget.backgroundRole(), QtGui.QColor(color))
        widget.setPalette(palette)
Exemple #2
0
    def onDelete(self, *args, **kw):
        '''
        delete the selected key
        
        check that self.current_key is not None
        then delete that one and reset to next in list
        '''
        key = self.current_key
        if key is None: return
        if key not in self.keyword_dict.keys(): return

        box = QtGui.QMessageBox()
        box.setText('Delete: ' + key)
        box.setInformativeText('Delete this substitution key?')
        box.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)
        box.setDefaultButton(QtGui.QMessageBox.Ok)
        ret = box.exec_()

        if ret != QtGui.QMessageBox.Ok: return

        del self.keyword_dict[key]
        curr = self.listWidget.currentItem()
        if curr is not None:
            row = self.listWidget.row(curr)
            self.listWidget.takeItem(row)
        self.current_key = None
        self.selectFirstKeyword()
Exemple #3
0
def main():
    '''start the program'''
    import sys
    process_command_line()
    app = QtGui.QApplication(sys.argv)
    mw = AGUP_MainWindow()
    mw.show()
    _r = app.exec_()
    sys.exit(_r)
    def __init__(self, parent, row, label, value):
        QtCore.QObject.__init__(self)
        self.slider_factor = 100  # slider = int(slider_factor * value_widget + 0.5)

        self.slider = QtGui.QSlider(
            value=int(self.slider_factor * value),
            maximum=self.slider_factor,
            pageStep=10,
            tracking=False,
            orientation=QtCore.Qt.Horizontal,
            tickPosition=QtGui.QSlider.
            TicksAbove,  # looks like a user preference
            #tickPosition=QtGui.QSlider.TicksBothSides,
            #tickPosition=QtGui.QSlider.TicksBelow,
            #tickPosition=QtGui.QSlider.NoTicks,
            tickInterval=20)

        self.value_widget = QtGui.QLineEdit(str(value))
        self.value_widget.setMaximumWidth(self.slider_factor)
        self.validator = QtGui.QDoubleValidator()
        self.validator.setRange(0.0, 1.0)
        self.validator.setDecimals(2)
        self.value_widget.setValidator(self.validator)

        self.label = label
        self.parent = parent
        self.value = value

        parent.addWidget(QtGui.QLabel(label), row, 0)
        parent.addWidget(self.value_widget, row, 1)
        parent.addWidget(self.slider, row, 2)

        self.value_changing = False  # issue #33: avoid changing value text while editing value

        # connect slider changes with value_widget and vice versa
        self.slider.valueChanged.connect(self.onSliderChange)
        self.slider.sliderMoved.connect(self.onSliderChange)
        self.value_widget.textEdited.connect(self.onValueChange)
Exemple #5
0
def main():
    '''simple starter program to develop this code'''
    import sys
    import os
    import agup_data

    agup = agup_data.AGUP_Data()
    agup.openPrpFile('project/agup_project.xml')

    app = QtGui.QApplication(sys.argv)
    mw = AGUP_Reviewers_View(None, agup)
    mw.show()
    _r = app.exec_()
    sys.exit(_r)
def developer_main():
    '''
        create QGroupBox + QGridLayout and run the panel

        ===    ===   ===   ===   ====   =========================
        R1     #1    R2    #2    %      Reviewer Name
        ===    ===   ===   ===   ====   =========================
        [x]    1     [ ]   0     100%   Joe User
        [ ]    0     [x]   1     80%    Second Reviewer
        [ ]    0     [ ]   0     22%    Some Panel Member
        [ ]    0     [ ]   0     1%     Another Panel Member
        ===    ===   ===   ===   ====   =========================
    '''
    import sys
    import os
    import agup_data
    global layout, agup

    testfile = os.path.abspath('project/agup_project.xml')

    agup = agup_data.AGUP_Data()
    agup.openPrpFile(testfile)

    app = QtGui.QApplication(sys.argv)
    grid = QtGui.QGroupBox('prop_revu_grid demo')

    layout = ReviewerAssignmentGridLayout(grid, agup)
    layout.addReviewers(agup.reviewers)
    layout.setReviewersValues(agup.reviewers)

    timer = QtCore.QTimer()
    timer.singleShot(2000, _onDelay1)
    timer.singleShot(5000, _onDelay2)
    timer.singleShot(7500, _onDelay3)

    grid.show()
    sys.exit(app.exec_())
Exemple #7
0
    def restoreWindowGeometry(self, window, group=None):
        '''
        put the window back where it was
        
        :param obj window: instance of QWidget
        '''
        group = self.getGroupName(window, group)
        width = self.getKey(group + '/width')
        height = self.getKey(group + '/height')
        if width is None or height is None:
            return
        window.resize(QtCore.QSize(int(width), int(height)))

        x = self.getKey(group + '/x')
        y = self.getKey(group + '/y')
        if x is None or y is None:
            return

        # is this window on any available screen?
        qdw = QtGui.QDesktopWidget()
        x_onscreen = False
        y_onscreen = False
        for screen_num in range(qdw.screenCount()):
            # find the "available" screen dimensions
            # (excludes docks, menu bars, ...)
            available_rect = qdw.availableGeometry(screen_num)
            if available_rect.x() <= int(
                    x) < available_rect.x() + available_rect.width():
                x_onscreen = True
            if available_rect.y() <= int(
                    y) < available_rect.y() + available_rect.height():
                y_onscreen = True

        # Move the window to the primary window if it would otherwise be drawn off screen
        available_rect = qdw.availableGeometry(qdw.primaryScreen())
        if not x_onscreen:
            offset = available_rect.x() + available_rect.width() / 10
            x = available_rect.x() + offset
            width = min(int(width), available_rect.width())
        if not y_onscreen:
            offset = available_rect.y() + available_rect.height() / 10
            y = available_rect.y() + offset
            height = min(int(height), available_rect.height())

        window.setGeometry(
            QtCore.QRect(int(x), int(y), int(width), int(height)))
Exemple #8
0
 def requestConfirmation(self, 
                      message, 
                      informative_text, 
                      buttons=None, 
                      default_button=None):
     '''
     request confirmation from the user about something
     '''
     if buttons is None:
         buttons = QtGui.QMessageBox.Ok
     if default_button is None:
         default_button = QtGui.QMessageBox.Ok
     box = QtGui.QMessageBox()
     box.setText(message)
     box.setInformativeText(informative_text)
     box.setStandardButtons(buttons)
     box.setDefaultButton(default_button)
     return box.exec_()
    def onDelete(self, *args):
        '''
        remove the selected item from the list of topics
        '''
        curr = self.listWidget.currentItem()
        if curr is not None:
            box = QtGui.QMessageBox()
            box.setText('Delete topic: ' + str(curr.text()))
            box.setInformativeText('Delete this topic?')
            box.setStandardButtons(QtGui.QMessageBox.Ok
                                   | QtGui.QMessageBox.Cancel)
            box.setDefaultButton(QtGui.QMessageBox.Ok)
            ret = box.exec_()

            if ret != QtGui.QMessageBox.Ok: return

            row = self.listWidget.row(curr)
            self.listWidget.takeItem(row)
            self.topics.remove(str(curr.text()))
 def _init_basics(self):
     self.setColumnStretch(0, 1)
     self.setColumnStretch(1, 1)
     self.setColumnStretch(2, 1)
     self.setColumnStretch(3, 1)
     self.setColumnStretch(4, 1)
     self.setColumnStretch(5, 3)
     style = 'background: #888; color: white;'  #  margin: auto; width: 50%; text-align: center;
     self.addWidget(QtGui.QLabel('R1', styleSheet=style))
     self.addWidget(QtGui.QLabel('#1', styleSheet=style))
     self.addWidget(QtGui.QLabel('R2', styleSheet=style))
     self.addWidget(QtGui.QLabel('#2', styleSheet=style))
     self.addWidget(QtGui.QLabel('%', styleSheet=style))
     self.addWidget(QtGui.QLabel('Reviewer Name', styleSheet=style))
     self.rvwr_widgets = {}
def project_main():
    import sys
    import os
    import agup_data

    app = QtGui.QApplication(sys.argv)

    testfile = os.path.abspath('project/agup_project.xml')
    test_gup_id = str(941*9*5)

    agup = agup_data.AGUP_Data()    
    agup.openPrpFile(testfile)
    proposal = agup.proposals.proposals[test_gup_id]

    mw = AGUP_ProposalDetails(agup=agup)
    mw.addTopics(agup.topics.getTopicList())
    mw.addReviewers(agup.reviewers)
    mw.setupProposal(proposal)
  
    mw.show()
    sys.exit(app.exec_())
    def _init_controls_(self):
        '''
        Build one row of the GUI panel with a reviewer for this proposal::

            [ ] 5    [ ] 0      1%        I. M. A. Reviewer
        
        '''
        # FIXME: on LinuxMint, checkboxes generate this error
        # Gtk-CRITICAL **: IA__gtk_widget_get_direction: assertion 'GTK_IS_WIDGET (widget)' failed
        #
        # see: https://github.com/prjemian/assign_gup/issues/15
        self.primary = QtGui.QCheckBox()
        self.num_primary = QtGui.QLabel()
        self.secondary = QtGui.QCheckBox()
        self.num_secondary = QtGui.QLabel()
        self.percentage = QtGui.QLabel()
        self.full_name = QtGui.QLabel(self.reviewer.getFullName())
        self.setValue(-1)

        w = self.layout.addWidget(self.primary)
        # FIXME:         self.layout.setAlignment(w, QtCore.Qt.AlignCenter)
        w = self.layout.addWidget(self.num_primary)
        # self.num_primary.setStyleSheet('text-align: center;')
        w = self.layout.addWidget(self.secondary)
        # FIXME:         self.layout.setAlignment(w, QtCore.Qt.AlignCenter)
        w = self.layout.addWidget(self.num_secondary)
        w = self.layout.addWidget(self.percentage)
        # FIXME:         self.layout.setAlignment(w, QtCore.Qt.AlignRight)
        w = self.layout.addWidget(self.full_name)

        self.primary.setEnabled(self.enabled)
        self.secondary.setEnabled(self.enabled)

        self.primary.setToolTip("check to select as primary reviewer (#1)")
        self.num_primary.setToolTip(
            "number of proposals assigned as primary reviewer (#1)")
        self.secondary.setToolTip("check to select as secondary reviewer (#2)")
        self.num_secondary.setToolTip(
            "number of proposals assigned as secondary reviewer (#2)")
        self.percentage.setToolTip(
            "computed comfort factor of this reviewer with this proposal")

        self.primary.released.connect(
            lambda: self.onCheckBoxClick(self.primary))
        self.secondary.released.connect(
            lambda: self.onCheckBoxClick(self.secondary))
def main():
    import sys
    app = QtGui.QApplication(sys.argv)
    mw = AGUP_ReviewerDetails()

    mw.setFullName('Joe Reviewer')
    mw.setSortName('Reviewer')
    mw.setPhone('555-555-5555')
    mw.setEmail('*****@*****.**')
    mw.setJoined('2010-2')
    mw.setUrl('http://user.com')
    mw.setNotes('''That URL is fake.\nDo not trust it!''')

    # setup some examples for testing
    topic_object = topics.Topics()
    for k, v in dict(SAXS=0.5, XPCS=0.1, GISAXS=0.9).items():
        topic_object.add(k, v)

    w = {}
    row = 0
    for key in topic_object:
        value = topic_object.get(key)
        w[key] = topic_slider.AGUP_TopicSlider(mw.topic_layout, row, key,
                                               value)
        row += 1
    mw.topic_layout.setColumnStretch(1, 3)

    print 'getFullName', mw.getFullName()
    print 'getSortName', mw.getSortName()
    print 'getPhone', mw.getPhone()
    print 'getEmail', mw.getEmail()
    print 'getJoined', mw.getJoined()
    print 'getUrl', mw.getUrl()
    print 'getNotes', mw.getNotes()

    mw.show()
    sys.exit(app.exec_())
Exemple #14
0
 def doUrl(self, url):
     '''opening URL in default browser'''
     url = QtCore.QUrl(url)
     service = QtGui.QDesktopServices()
     service.openUrl(url)