Exemple #1
0
    def setup(self):

        self.jig_attrs = self.grid_plane.copyable_attrs_dict(
        )  # Save the jig's attributes in case of Cancel.

        # Border color
        self.border_color = RGBf_to_QColor(
            self.grid_plane.normcolor
        )  # Used as default color by Color Chooser

        # Grid color
        self.grid_color = RGBf_to_QColor(
            self.grid_plane.grid_color
        )  # Used as default color by Color Chooser

        self.grid_color_pixmap = get_widget_with_color_palette(
            self.grid_color_pixmap, self.grid_color)

        self.border_color_pixmap = get_widget_with_color_palette(
            self.border_color_pixmap, self.border_color)

        self.name_linedit.setText(self.grid_plane.name)

        self.width_spinbox.setValue(self.grid_plane.width)
        self.height_spinbox.setValue(self.grid_plane.height)
        self.x_spacing_spinbox.setValue(self.grid_plane.x_spacing)
        self.y_spacing_spinbox.setValue(self.grid_plane.y_spacing)

        self.grid_type_combox.setCurrentIndex(self.grid_plane.grid_type)
        self.line_type_combox.setCurrentIndex(self.grid_plane.line_type)

        self._set_xyspacing_enabled(self.grid_plane.grid_type)
 def openColorChooserDialog(self):
     """
     Prompts the user to choose a color and then updates colorFrame with
     the selected color.
     """
     qcolor = RGBf_to_QColor(self.color)
     if not self.color in self.standardColorList:
         QColorDialog.setCustomColor(self.customColorCount, qcolor.rgb())
         self.customColorCount += 1
     c = QColorDialog.getColor(qcolor, self)
     if c.isValid():
         self.setColor(QColor_to_RGBf(c))
         self.colorFrame.emit(SIGNAL("editingFinished()"))
Exemple #3
0
 def openColorChooserDialog(self):
     """
     Prompts the user to choose a color and then updates colorFrame with
     the selected color.
     """
     qcolor = RGBf_to_QColor(self.color)
     if not self.color in self.standardColorList:
         QColorDialog.setCustomColor(self.customColorCount, qcolor.rgb())
         self.customColorCount += 1
     c = QColorDialog.getColor(qcolor, self)
     if c.isValid():
         self.setColor(QColor_to_RGBf(c))
         self.colorFrame.emit(SIGNAL("editingFinished()"))
Exemple #4
0
 def colorframe_bgcolor_setter(color):
     #e no convenient/clean way for Formula API to permit but not require this function to receive the formula,
     # unless we store it temporarily in env._formula (which we might as well do if this feature is ever needed)
     try:
         # make sure errors here don't stop the formula from running:
         # (Need to protect against certain kinds of erroneous color values? RGBf_to_QColor does it well enough.)
         ## Qt3 code used: colorframe.setPaletteBackgroundColor(RGBf_to_QColor(color))
         qcolor = RGBf_to_QColor(color)
         palette = QPalette(
         )  # QPalette(qcolor) would have window color set from qcolor, but that doesn't help us here
         qcolorrole = QPalette.Window
         ## http://doc.trolltech.com/4.2/qpalette.html#ColorRole-enum says:
         ##   QPalette.Window    10    A general background color.
         palette.setColor(QPalette.Active, qcolorrole,
                          qcolor)  # used when window is in fg and has focus
         palette.setColor(
             QPalette.Inactive, qcolorrole,
             qcolor)  # used when window is in bg or does not have focus
         palette.setColor(QPalette.Disabled, qcolorrole,
                          qcolor)  # used when widget is disabled
         colorframe.setPalette(palette)
         colorframe.setAutoFillBackground(True)
         # [Note: the above scheme was revised again by bruce 070430, for improved appearance
         #  (now has thin black border around color patch), based on Ninad's change in UserPrefs.py.]
         ## no longer needed: set color for qcolorrole = QPalette.ColorRole(role) for role in range(14)
         ## no longer needed: colorframe.setLineWidth(500) # width of outline of frame (at least half max possible size)
     except:
         print "data for following exception: ",
         print "colorframe %r has palette %r" % (colorframe,
                                                 colorframe.palette())
         # fyi: in Qt4, like in Qt3, colorframe is a QFrame
         print_compact_traceback(
             "bug (ignored): exception in formula-setter: "
         )  #e include formula obj in this msg?
     pass
Exemple #5
0
 def restore_current_color(self):  # mark 060129.
     """
     Slot for the Restore button.  Restores the current element color to the
     original (previous) color before any color change was made.
     """
     self.update_sliders_and_spinboxes(RGBf_to_QColor(self.original_color))
     self._updateModelDisplay()
 def resetColor(self):
     """
     Reset the paletter color of the widget (and set it to white)
     """
     self.setAutoFillBackground(True)
     color = RGBf_to_QColor(white)
     self.setPalette(getPalette(None, QPalette.Base, color))
 def getQColor(self):
     """
     Return the current QColor.
     
     @return: The current color.
     @rtype:  QColor
     """
     return RGBf_to_QColor(self.color)
Exemple #8
0
    def setDisplay(self, value):
        qt4todo('self.elementButtonGroup.setButton(value)')
        self.updateElemGraphDisplay()
        self.original_color = self.color

        element_color = RGBf_to_QColor(self.color)
        self.update_sliders_and_spinboxes(element_color)
        self.restorePB.setEnabled(0)  # Disable Restore button.
 def setColor(self, color):
     """
     Set the color of the widget to the one given by param color
     @param color: new palette color of self.
     """
     self.setAutoFillBackground(True)
     color = RGBf_to_QColor(color)
     self.setPalette(getPalette(None, QPalette.Base, color))
 def _updateAllWidgets(self):
     """
     Update all the PM widgets. This is typically called after applying
     a favorite.
     """
     self._updateBackgroundColorComboBoxIndex()
     self.updateCustomColorItemIcon(RGBf_to_QColor(env.prefs[backgroundColor_prefs_key]))
     self.hoverHighlightingStyleComboBox.setCurrentIndex(HHS_INDEXES.index(env.prefs[hoverHighlightingColorStyle_prefs_key]))
     self.hoverHighlightingColorComboBox.setColor(env.prefs[hoverHighlightingColor_prefs_key])
     self.selectionStyleComboBox.setCurrentIndex(SS_INDEXES.index(env.prefs[selectionColorStyle_prefs_key]))
     self.selectionColorComboBox.setColor(env.prefs[selectionColor_prefs_key])
     return
 def chooseCustomBackgroundColor(self):
     """
     Choose a custom background color.
     """
     c = QColorDialog.getColor(RGBf_to_QColor(self.win.glpane.getBackgroundColor()), self)
     if c.isValid():
         self.win.glpane.setBackgroundColor(QColor_to_RGBf(c))
         self.updateCustomColorItemIcon(c)
     else:
         # User cancelled. Need to reset combobox to correct index.
         self._updateBackgroundColorComboBoxIndex()
     return
Exemple #12
0
    def setup(self):

        #Default state for atoms selection
        self.selected = False

        self.jig_attrs = self.jig.copyable_attrs_dict(
        )  # Save the jig's attributes in case of Cancel.

        # Jig color
        self.fill_QColor = RGBf_to_QColor(
            self.jig.fill_color)  # Used as default color by Color Chooser
        self.border_QColor = RGBf_to_QColor(
            self.jig.normcolor)  # Used as default color by Color Chooser

        self.fill_color_pixmap = get_widget_with_color_palette(
            self.fill_color_pixmap, self.fill_QColor)

        self.border_color_pixmap = get_widget_with_color_palette(
            self.border_color_pixmap, self.border_QColor)

        self.name_linedit.setText(self.jig.name)
        self.width_linedit.setText(str(self.jig.width))
        self.image_offset_linedit.setText(str(self.jig.image_offset))
        self.edge_offset_linedit.setText(str(self.jig.edge_offset))
        self.resolution_spinbox.setValue(self.jig.resolution)

        self.show_esp_bbox_checkbox.setChecked(self.jig.show_esp_bbox)

        opacity = '%1.2f ' % self.jig.opacity
        self.opacity_linedit.setText(opacity)
        self.opacity_slider.setValue(int(self.jig.opacity * 100))

        self.highlight_atoms_in_bbox_checkbox.setChecked(
            self.jig.highlightChecked)
        self._updateSelectButtonText()

        self.xaxis_spinbox.setValue(self.jig.xaxis_orient)
        self.yaxis_spinbox.setValue(self.jig.yaxis_orient)

        self.png_fname_linedit.setText(self.jig.espimage_file)
    def setup(self):

        self.jig_attrs = self.jig.copyable_attrs_dict() # Save the jig's attributes in case of Cancel.

        # Jig color
        self.jig_QColor = RGBf_to_QColor(self.jig.normcolor) # Used as default color by Color Chooser
        self.jig_color_pixmap = get_widget_with_color_palette(
                self.jig_color_pixmap, self.jig_QColor)

        # Jig name
        self.nameLineEdit.setText(self.jig.name)

        self.molnameLineEdit.setText(self.jig.atoms[0].molecule.name)
 def setup(self):
     
     self.jig_attrs = self.jig.copyable_attrs_dict() # Save the jig's attributes in case of Cancel.
     
     # Jig color
     self.jig_QColor = RGBf_to_QColor(self.jig.normcolor) # Used as default color by Color Chooser
     self.jig_color_pixmap = get_widget_with_color_palette(
         self.jig_color_pixmap, self.jig_QColor)
     self.nameLineEdit.setText(self.jig.name)
     self.stiffnessLineEdit.setText(str(self.jig.stiffness))
     self.forceLineEdit.setText(str(self.jig.force))
     self.lengthLineEdit.setText(str(self.jig.length))
     self.widthLineEdit.setText(str(self.jig.width))
     self.sradiusLineEdit.setText(str(self.jig.sradius)) # spoke radius
     self.enable_minimize_checkbox.setChecked(self.jig.enable_minimize)
Exemple #15
0
    def setup(self):
        """
        Initializes the dialog and it's widgets 
        """
        
        # Save the jig's attributes in case of Cancel.
        self.jig_attrs = self.jig.copyable_attrs_dict() 
        
        # Jig color
        # Used as default color by Color Chooser
        self.jig_QColor = RGBf_to_QColor(self.jig.normcolor) 
        self.jig_color_pixmap = get_widget_with_color_palette(
            self.jig_color_pixmap, self.jig_QColor)

        # Jig name
        self.nameLineEdit.setText(self.jig.name)
Exemple #16
0
 def setup(self):
     
     # Chunk color
     self.original_color = self.chunk.color # Save original Chunk color in case of Cancel
     
     if self.chunk.color: # Set colortile to chunk color (without border)
         self.chunk_QColor = RGBf_to_QColor(self.chunk.color) # Used as default color by Color Chooser
     else: # Set the colortile to the dialog's bg color (no color)
         self.chunk_QColor =self.palette().color(QtGui.QPalette.Window)
     
     plt = QtGui.QPalette()      
     plt.setColor(QtGui.QPalette.Active,QtGui.QPalette.Window,self.chunk_QColor)
     plt.setColor(QtGui.QPalette.Inactive,QtGui.QPalette.Window,self.chunk_QColor)
     plt.setColor(QtGui.QPalette.Disabled,QtGui.QPalette.Window,self.chunk_QColor)        
     self.chunk_color_frame.setPalette(plt)
     
     self.nameLineEdit.setText(self.chunk.name)        
     self.atomsTextBrowser.setPlainText(self.get_chunk_props_info())
Exemple #17
0
    def setup(self):

        self.jig_attrs = self.jig.copyable_attrs_dict(
        )  # Save the jig's attributes in case of Cancel.

        # Jig color
        self.jig_QColor = RGBf_to_QColor(
            self.jig.normcolor)  # Used as default color by Color Chooser
        self.jig_color_pixmap = get_widget_with_color_palette(
            self.jig_color_pixmap, self.jig_QColor)

        self.nameLineEdit.setText(self.jig.name)
        self.torqueLineEdit.setText(str(self.jig.torque))
        self.initialSpeedLineEdit.setText(str(self.jig.initial_speed))
        self.speedLineEdit.setText(str(self.jig.speed))
        self.lengthLineEdit.setText(str(self.jig.length))
        self.radiusLineEdit.setText(str(self.jig.radius))
        self.sradiusLineEdit.setText(str(self.jig.sradius))  # spoke radius
        self.enable_minimize_checkbox.setChecked(self.jig.enable_minimize)
        self.dampers_checkbox.setChecked(
            self.jig.dampers_enabled)  # mark & bruce 060421
Exemple #18
0
def drawtext(text, color, origin, point_size, glpane):
    """
    """
    # see also: _old_code_for_drawing_text()

    if not text:
        return

    glDisable(GL_LIGHTING)
    glDisable(GL_DEPTH_TEST)

    from PyQt4.Qt import QFont, QString  ##, QColor
    font = QFont(QString("Helvetica"), point_size)
    #glpane.qglColor(QColor(75, 75, 75))
    from widgets.widget_helpers import RGBf_to_QColor
    glpane.qglColor(RGBf_to_QColor(color))
    glpane.renderText(origin[0], origin[1], origin[2], QString(text), font)

    glEnable(GL_DEPTH_TEST)
    glEnable(GL_LIGHTING)
    return
Exemple #19
0
def colorpref_edit_dialog(
        parent,
        prefs_key,
        caption="choose"):  #bruce 050805; revised 070425 in Qt4 branch
    #bruce 050805: heavily modified this from some slot methods in UserPrefs.py.
    # Note that the new code for this knows the prefs key and that it's a color,
    # and nothing else that those old slot methods needed to know!
    # It no longer needs to know about the color swatch (if any) that shows this color in the UI,
    # or what/how to update anything when the color is changed,
    # or where the color is stored besides in env.prefs.
    # That knowledge now resides with the code that defines it, or in central places.

    old_color = RGBf_to_QColor(env.prefs[prefs_key])
    c = QColorDialog.getColor(
        old_color, parent)  # In Qt3 this also had a caption argument
    if c.isValid():
        new_color = (c.red() / 255.0, c.green() / 255.0, c.blue() / 255.0)
        env.prefs[prefs_key] = new_color
        # this is change tracked, which permits the UI's color swatch
        # (as well as the glpane itself, or whatever else uses this prefs color)
        # to notice this and update its color
    return
    def setColor(self, color, default=False):
        """
        Set the color.
        
        @param color: The color.
        @type  color: tuple of 3 floats (r, g, b)
        
        @param default: If True, make I{color} the default color. Default is
                        False.
        @type  default: boolean
        """

        if color == self.color:
            return

        if default:
            self.defaultColor = color
            self.setAsDefault = default
        self.color = color

        try:
            # Try to set the current item to a color in the combobox.
            self.setCurrentIndex(self.colorList.index(color))
        except:
            # color was not in the combobox, so set current index to the last
            # item which is "Other color...". Also update the color icon to.
            otherColorIndex = len(self.colorList) - 1
            self.otherColor = color
            self.colorList[otherColorIndex] = color
            pixmap = QPixmap(16, 16)
            qcolor = RGBf_to_QColor(color)
            pixmap.fill(qcolor)
            self.setItemIcon(otherColorIndex, QIcon(pixmap))
            self.setCurrentIndex(self.colorList.index(self.otherColor))

        # Finally, emit a signal so the parent knows the color has changed.
        self.emit(SIGNAL("editingFinished()"))
        return
Exemple #21
0
    def cmEditChunkColor(self):  #Ninad 070321
        """
        Edit the color of the selected chunks using the Model Tree context menu
        """
        nodeset = self.topmost_selected_nodes()
        chunkList = []
        #Find the chunks in the selection and store them temporarily
        for m in nodeset:
            if isinstance(m, Chunk):
                chunkList.append(m)
        #Following selects the current color of the chunk
        #in the QColor dialog. If multiple chunks are selected,
        #it simply sets the selected color in the dialog as 'white'
        if len(chunkList) == 1:
            m = chunkList[0]
            if m.color:
                m_QColor = RGBf_to_QColor(m.color)
            else:
                m_QColor = None

            self.win.dispObjectColor(initialColor=m_QColor)
        else:
            self.win.dispObjectColor()
    def __init__(
        self,
        parentWidget,
        label='Color:',
        labelColumn=0,
        colorList=[],
        colorNames=[],
        color=white,
        setAsDefault=True,
        spanWidth=False,
    ):
        """
        Appends a color chooser widget to <parentWidget>, a property manager 
        group box.
        
        @param parentWidget: the parent group box containing this widget.
        @type  parentWidget: PM_GroupBox
        
        @param label: The label that appears to the left or right of the 
                      color frame (and "Browse" button). 
                      
                      If spanWidth is True, the label will be displayed on
                      its own row directly above the lineedit (and button).
                      
                      To suppress the label, set I{label} to an 
                      empty string.
        @type  label: str
        
        @param labelColumn: The column number of the label in the group box
                            grid layout. The only valid values are 0 (left 
                            column) and 1 (right column). The default is 0 
                            (left column).
        @type  labelColumn: int
        
        @param colorList: List of colors.
        @type  colorList: List where each item contains 3 floats (r, g, b)
        
        @param colorNames: List of color names.
        @type  colorNames: List of strings
        
        @param color: The initial color. White is the default. If I{color}
                      is not in I{colorList}, then the initial color will be
                      set to the last color item (i.e. "Other color...").
        @type  color: tuple of 3 floats (r, g, b)
        
        @param setAsDefault: if True, will restore L{color} when the
                    "Restore Defaults" button is clicked.
        @type  setAsDefault: boolean
        
        @param spanWidth: if True, the widget and its label will span the width
                      of the group box. Its label will appear directly above
                      the widget (unless the label is empty) and is left
                      justified.
        @type  spanWidth: boolean
        """

        if len(colorNames) and len(colorList):
            assert len(colorNames) == len(colorList)
            self.colorNames = colorNames
            self.colorList = colorList

        self.colorDict = dict(zip(self.colorNames, self.colorList))

        PM_ComboBox.__init__(
            self,
            parentWidget,
            label=label,
            labelColumn=labelColumn,
            choices=self.colorNames,
            index=0,  # Gets (re)set by setColor()
            setAsDefault=setAsDefault,
            spanWidth=spanWidth)

        # Load QComboBox widget choices and set initial choice (index).
        idx = 0
        for colorName in self.colorNames:
            pixmap = QPixmap(12, 12)
            qcolor = RGBf_to_QColor(self.colorDict[str(colorName)])
            pixmap.fill(qcolor)
            self.setItemIcon(idx, QIcon(pixmap))
            idx += 1

        self.setIconSize(QSize(12, 12))  # Default is 16x16.
        self.setColor(color)  # Sets current index.

        self.connect(self, SIGNAL("activated(QString)"),
                     self._setColorFromIndex)

        return
    def renderTextNearCursor(self, 
                             textString, 
                             offset = 10, 
                             textColor = black,
                             fontSize = 11):
        """
        Renders text near the cursor position, on the top right side of the
        cursor (slightly above it).

        See example in DNA Line mode.

        @param textString: string
        @param offset: The offset that will be added to x and y values of the 
                       cursor position to get the base position of the text 
                       to be rendered. 

        @see: DnaLineMode.Draw
        @see: self._getFontForTextNearCursor()
        @see: self.renderTextAtPosition()
        """
        if not textString:
            return 

        #Extra precaution if the caller passes a junk value such as None
        #for the color
        if not isinstance(textColor, tuple) and isinstance(textColor, list):
            textColor = black

        pos = self.cursor().pos()  
        
        # x, y coordinates need to be in window coordinate system. 
        # See QGLWidget.mapToGlobal for more details.
        pos = self.mapFromGlobal(pos)

        # Important to turn off the lighting. Otherwise the text color would 
        # be dull and may also become even more light if some other object 
        # is rendered as a transparent object. Example in DNA Line mode, when the
        # second axis end sphere is rendered as a transparent sphere, it affects
        # the text rendering as well (if GL_LIGHTING is not disabled)
        # [-- Ninad 2007-12-03]
        glDisable(GL_LIGHTING)
        
        #Add 'stoppers' for the cursor text. Example: If the cursor is near the
        #extreme right hand corner of the 3D workspace, the following code 
        #ensures that all the text string is visible. It does this check for 
        #right(x) and top(for y) borders of the glpane. 
        
        xOffset = offset
        yOffset = offset
        #signForDX and signForDY are used by the code that draws the same 
        #text in the background (offset by 1 pixel in 4 directions) 
        signForDX = 1
        signForDY = 1
             
        xLimit = self.width - pos.x()
        
        #Note that at the top edge, y coord is 0
        yLimit = pos.y()
        
        textString = QString(textString)
        font = self._getFontForTextNearCursor(fontSize = fontSize,
                                              isBold = True)
        
        #Now determine the total x and y pixels used to render the text 
        #(add some tolerance to that number) 
        fm = QFontMetrics(font)
        xPixels = fm.width(textString) + 10
        yPixels = fm.height() + 10
 
        if xLimit < xPixels:
            xOffset = - (xPixels - xLimit)
            signForDX = -1
        
        if yLimit < yPixels:
            yOffset = - (yPixels - pos.y())
            signForDY = -1
                        
        x = pos.x() + xOffset
        y = pos.y() - yOffset
        
        offset_val = 1

        deltas_for_halo_color = (( offset_val,  offset_val), 
                                 (-offset_val, -offset_val), 
                                 (-offset_val,  offset_val), 
                                 ( offset_val, -offset_val))
        
        # halo color
        halo_color = getTextHaloColor(textColor)
        
        for dx, dy in deltas_for_halo_color: 
            self.qglColor(RGBf_to_QColor(halo_color)) 

            # Note: self.renderText is QGLWidget.renderText method.
            self.renderText(x + dx*signForDX ,
                            y + dy*signForDY,
                            textString,
                            font)
##            self.qglClearColor(RGBf_to_QColor(halo_color))
##                # REVIEW: why is qglClearColor needed here? Why is it done *after* renderText?
##                # [bruce 081204 questions; same Qs for the other uses of qglClearColor in this file]

        # Note: It is necessary to set the font color, otherwise it may change!

        self.qglColor(RGBf_to_QColor(textColor))   
        x = pos.x() + xOffset
        y = pos.y() - yOffset

        self.renderText(x ,
                        y ,
                        textString,
                        font)
##        self.qglClearColor(RGBf_to_QColor(textColor))
##            # is qglClearColor related to glClearColor? [bruce 071214 question]
        glEnable(GL_LIGHTING)
    def renderTextAtPosition(self,
                             position,
                             textString,
                             textColor = black,
                             textFont = None,
                             fontSize = 11,
                             ):
        """
        Renders the text at the specified position (x, y, z coordinates)
        @param position: The x, y, z coordinates of the object at which the 
        text needs to be rendered. 
        @type position: B{A}
        @param textString:  the text to be rendered at the specified position.
        @type textString : str
        @see: self.renderTextNearCursor() This method is different than that 
        method. That method uses QPoint (the current cursor position) to 
        render the text (thus needs integers x and y) whereas this method
        uses the actual object coordinates        
        @see: MultiplednaSegment_GraphicsMode._drawDnaRubberbandLine() [obsolete class name, what is correct one?]
        @see: QGLWidget.renderText()

        @TODO: refactor to move the common code in this method and
        self.renderTextNearCursor().
        """
        
        if textFont is not None:
            font = textFont
        else:
            font = self._getFontForTextNearCursor(fontSize = fontSize, 
                                                  isBold = True)
        x = position[0]
        y = position[1]
        z = position[2]

        glDisable(GL_LIGHTING)
        
        #Convert the object coordinates to the window coordinates.
        wX, wY, wZ = gluProject(x, y, z)
        
        halo_color = getTextHaloColor(textColor)
        
        offset_val = 1
        bg_z_offset = 0
        fg_z_offset = -1e-7

        render_positions = (( offset_val,  offset_val, bg_z_offset, halo_color), 
                            (-offset_val, -offset_val, bg_z_offset, halo_color), 
                            (-offset_val,  offset_val, bg_z_offset, halo_color), 
                            ( offset_val, -offset_val, bg_z_offset, halo_color),
                            (          0,           0, fg_z_offset, textColor))

        for dx, dy, dz, color in render_positions:
            x1, y1, z1 = gluUnProject(wX + dx, wY + dy, wZ + dz)

            self.qglColor(RGBf_to_QColor(color)) 
            self.renderText(x1, y1, z1,
                            QString(textString),
                            font)
##            self.qglClearColor(RGBf_to_QColor(color))
##            # question: is this related to glClearColor? [bruce 071214 question]
##            # -- yes [Ninad 2008-08-20]

        glEnable(GL_LIGHTING)        
Exemple #25
0
    def draw(self):
        """
        Draws the rulers.
        """
        
        width = self.glpane.width
        height = self.glpane.height
        
        # These 3 attrs (scale, aspect, and ruler_position) are checked to 
        # determine if they've changed. If any of them have, 
        # getRulerDrawingParameters() must be called to get new drawing parms.
        if (self.scale  != self.glpane.scale) or \
           (self.zoomFactor  != self.glpane.zoomFactor) or \
           (self.aspect != self.glpane.aspect) or \
           (self.ruler_position != env.prefs[rulerPosition_prefs_key]):
            
            self.scale = self.glpane.scale
            self.zoomFactor = self.glpane.zoomFactor
            self.aspect = self.glpane.aspect
            self.ruler_position = env.prefs[rulerPosition_prefs_key]
    
            self.ruler_drawing_params = \
                getRulerDrawingParameters(width, height, self.aspect,
                                          self.scale, self.zoomFactor, 
                                          self.ruler_position)
            
        (draw_ticks_and_text,
         units_text, 
         units_format,
         units_scale,
         unit_label_inc,
         long_tickmark_inc,
         medium_tickmark_inc,
         num_vert_ticks,
         num_horz_ticks,
         tickmark_spacing_multiplier,
         ruler_origin, ruler_start_pt, 
         units_text_origin, origin_square_pt1, origin_square_pt2, 
         vr_thickness, vr_tickmark_spacing,
         vr_long_tick_len, vr_medium_tick_len, vr_short_tick_len,
         vr_rect_pt1, vr_rect_pt2,
         vr_line_pt1, vr_line_pt2,
         vr_units_x_offset, vr_units_y_offset,
         hr_thickness, hr_tickmark_spacing,
         hr_long_tick_len, hr_medium_tick_len, hr_short_tick_len,
         hr_rect_pt1, hr_rect_pt2,
         hr_line_pt1, hr_line_pt2,
         hr_units_x_offset, hr_units_y_offset) = self.ruler_drawing_params
            
        ruler_color = env.prefs[rulerColor_prefs_key]
        ruler_opacity = env.prefs[rulerOpacity_prefs_key]
        
        # These may become user preferences in the future.
        tickmark_color = darkgray
        text_color = black
        
        # Set up 2D (window) coordinate system.
        # Bruce - please review this section.
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glLoadIdentity() # needed!
        gluOrtho2D(0.0, float(width), 0.0, float(height))
        glMatrixMode(GL_MODELVIEW)
        # About this glMatrixMode(GL_MODELVIEW) call, Bruce wrote in a review:
        # The only reason this is desirable (it's not really needed) is if, 
        # when someone is editing the large body of drawing code after this, 
        # they inadvertently do something which is only correct if the matrix 
        # mode is GL_MODELVIEW (e.g. if they use glTranslate to shift a ruler
        # or tickmark position). Most of our drawing code assumes it can do 
        # this, so a typical NE1 OpenGL programmer may naturally assume this,
        # which is why it's good to leave the matrix mode as GL_MODELVIEW when
        # entering into a large hunk of ordinary drawing code (especially if
        # it might call other drawing functions, now or in the future).
        # Mark 2008-03-03
        
        glDisable(GL_LIGHTING)
        glDisable(GL_DEPTH_TEST)
        
        # Suppress writing into the depth buffer so anything behind the ruler
        # can still be highlighted/selected.
        glDepthMask(GL_FALSE) 
        
        # Draw v/h ruler rectangles in the user defined color and opacity. #####
    
        glColor4fv(list(ruler_color) + [ruler_opacity])
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glRectf(origin_square_pt1[0], origin_square_pt1[1], 
                origin_square_pt2[0], origin_square_pt2[1]) # Origin square
        if env.prefs[displayVertRuler_prefs_key]:
            glRectf(vr_rect_pt1[0], vr_rect_pt1[1], 
                    vr_rect_pt2[0], vr_rect_pt2[1]) # Vertical ruler
        if env.prefs[displayHorzRuler_prefs_key]:
            glRectf(hr_rect_pt1[0], hr_rect_pt1[1], 
                    hr_rect_pt2[0], hr_rect_pt2[1]) # Horizontal ruler

        glDisable(GL_BLEND)
        
        # Set color of ruler lines, tick marks and text.
        glColor3fv(tickmark_color)
        self.glpane.qglColor(RGBf_to_QColor(text_color))
        
        # Draw unit of measurement in corner (A or nm).
        # piotr 080326: replaced drawText with drawCenteredText
        self.drawCenteredText(units_text, units_text_origin)
        
        # Kludge alert. Finish drawing ruler edge(s) if we will not be
        # drawing the ruler tick marks and text (only happens when the user
        # is zoomed out to an "absured scale factor".
        if not draw_ticks_and_text:
            if env.prefs[displayVertRuler_prefs_key]:
                self.drawLine(vr_line_pt1, vr_line_pt2)
            if env.prefs[displayHorzRuler_prefs_key]:
                self.drawLine(hr_line_pt1, hr_line_pt2)
            
        # Draw vertical ruler line(s) and tick marks ##########################
        
        if env.prefs[displayVertRuler_prefs_key] and draw_ticks_and_text:
        
            # Draw vertical line along right/left edge of ruler.
            self.drawLine(vr_line_pt1, vr_line_pt2)
            
            # Initialize pt1 and pt2, the tick mark endpoints. The first tick 
            # mark will span the entire width of the ruler,  which serves as a 
            # divider b/w the unit of measure text (i.e. A or nm) and the rest
            # of the ruler.
            pt1 = ruler_start_pt
            pt2 = ruler_start_pt + V(-vr_thickness, 0.0, 0.0)
            
            # Draw vertical ruler tickmarks, including numeric unit labels
            for tick_num in range(num_horz_ticks + 1):
                
                # pt1 and pt2 are modified by each iteration of the loop.
                self.drawLine(pt1, pt2)
                
                # Draw units number beside long tickmarks.
                if not tick_num % unit_label_inc:
                    units_num_origin = pt1 \
                                     + V(vr_units_x_offset, 
                                         vr_units_y_offset, 
                                         0.0)
                    units_num = units_format % (tick_num * units_scale)
                    self.drawText(units_num, units_num_origin)
                    
                # Update tickmark endpoints for next tickmark.
                pt1 = ruler_start_pt + \
                    V(0.0, 
                      vr_tickmark_spacing * tickmark_spacing_multiplier
                      * (tick_num + 1),
                      0.0)
                
                if not (tick_num + 1) % long_tickmark_inc:
                    pt2 = pt1 + V(vr_long_tick_len, 0.0, 0.0)
                elif not (tick_num + 1) % medium_tickmark_inc:
                    pt2 = pt1 + V(vr_medium_tick_len, 0.0, 0.0)
                else:
                    pt2 = pt1 + V(vr_short_tick_len, 0.0, 0.0)
        
            # End vertical ruler
        
        # Draw horizontal ruler line(s) and tick marks #########################
        
        if env.prefs[displayHorzRuler_prefs_key] and draw_ticks_and_text:
            # Draw horizontal line along top/bottom edge of ruler.
            self.drawLine(hr_line_pt1, hr_line_pt2)
            
            # Initialize pt1 and pt2, the tick mark endpoints. The first tick
            # mark will span the entire width of the ruler,  which serves as a 
            # divider b/w the unit of measure text (i.e. A or nm) and the rest
            # of the ruler.
            pt1 = ruler_start_pt
            pt2 = ruler_start_pt + V(0.0, -hr_thickness, 0.0) 
        
            # Draw horizontal ruler (with vertical) tickmarks, including its
            # numeric unit labels
            for tick_num in range(num_vert_ticks + 1):
                
                # pt1 and pt2 are modified by each iteration of the loop.
                self.drawLine(pt1, pt2)
                
                # Draw units number beside long tickmarks.
                if not tick_num % unit_label_inc:
                    units_num_origin = pt1 \
                                     + V(hr_units_x_offset, 
                                         hr_units_y_offset, 
                                         0.0)
                    units_num = units_format % (tick_num * units_scale)
                    self.drawText(units_num, units_num_origin)
                    
                # Update tickmark endpoints for next tickmark.
                pt1 = \
                    ruler_start_pt + \
                    V(hr_tickmark_spacing * tickmark_spacing_multiplier
                      * (tick_num + 1),
                      0.0,
                      0.0)
                
                if not (tick_num + 1) % long_tickmark_inc:
                    pt2 = pt1 + V(0.0, hr_long_tick_len, 0.0)
                elif not (tick_num + 1) % medium_tickmark_inc:
                    pt2 = pt1 + V(0.0, hr_medium_tick_len, 0.0)
                else:
                    pt2 = pt1 + V(0.0, hr_short_tick_len, 0.0)
            
            # End horizontal ruler
        
        # Restore OpenGL state.
        glDepthMask(GL_TRUE) 
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_LIGHTING)
        glDepthMask(GL_TRUE)
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        return # from drawRulers
Exemple #26
0
    def dispObjectColor(self, initialColor = None):
        """
        Sets the color of the selected chunks and/or jigs to a color the user 
        chooses.

        @param initialColor: the initial color to display in the color chooser
                             dialog, or None or missing to use the default (white).
                             Not used if only one chunk or one jig is selected
                             (in those cases the object's current color is used).
        @type  initialColor: QColor

        @note: Need better method name (i.e. setObjectColor()).
        """        
        if initialColor is None:
            initialColor = Qt.white
        else:
            assert isinstance(initialColor, QColor)
        
        _cmd = greenmsg("Change Color: ")

        from operations.ops_select import objectSelected, ATOMS, CHUNKS, JIGS
        if not objectSelected(self.assy, objectFlags = CHUNKS | JIGS):
            if objectSelected(self.assy, objectFlags = ATOMS):
                _msg = redmsg("Cannot change color of individual atoms.")
            else:
                _msg = redmsg("Nothing selected.")
            env.history.message(_cmd + _msg)
            return

        _numSelectedObjects = self.assy.getNumberOfSelectedChunks() \
                            + self.assy.getNumberOfSelectedJigs()

        if _numSelectedObjects == 1 and self.assy.getNumberOfSelectedChunks() == 1:
            # If only one object is selected, and it's a chunk, 
            # assign initialColor its color.
            _selectedChunkColor = self.assy.selmols[0].color
            if _selectedChunkColor:
                from widgets.widget_helpers import RGBf_to_QColor
                initialColor = RGBf_to_QColor(_selectedChunkColor)

        elif _numSelectedObjects == 1 and self.assy.getNumberOfSelectedJigs() == 1:
            # If only one object is selected, and it's a jig, 
            # assign initialColor its color.
            _selectedJig = self.assy.getSelectedJigs()
            _selectedJigColor = _selectedJig[0].normcolor
            if _selectedJigColor:
                from widgets.widget_helpers import RGBf_to_QColor
                initialColor = RGBf_to_QColor(_selectedJigColor)

        _c = QColorDialog.getColor(initialColor, self)
        if _c.isValid():
            from widgets.widget_helpers import QColor_to_RGBf
            _newColor = QColor_to_RGBf(_c)
            list = []
            for ob in self.assy.selmols:
                ob.setcolor(_newColor)
                list.append(ob)

            for ob in self.assy.getSelectedJigs():
                ob.color = _newColor # Need jig.setColor() method! --mark
                ob.normcolor =  _newColor
                list.append(ob)

            # Ninad 070321: Since the chunk is selected as a colored selection, 
            # it should be unpicked after changing its color. 
            # The user has most likely selected the chunk to change its color 
            # and won't like it still shown 'green'(the selection color) 
            # even after changing the color. so deselect it. 	
            # The chunk is NOT unpicked IF the color is changed via chunk 
            # property dialog. see ChunkProp.change_chunk_color for details.
            # This is intentional.

            for ob in list: 		
                ob.unpick()

            self.win_update()
Exemple #27
0
    def _setup(self):
        """ 
        Setup widgets to initial (default or defined) values. Return True on error.
        """
        #To fix bug 684
        #if gamess.is_disabled():
        #    self.run_job_btn.setEnabled(False)
        #else:
        #    self.run_job_btn.setEnabled(True)

        self.jig_attrs = self.gamessJig.copyable_attrs_dict(
        )  # Save the jig's attributes in case of Cancel.

        # Jig color
        self.original_normcolor = self.gamessJig.normcolor
        self.jig_QColor = RGBf_to_QColor(
            self.gamessJig.normcolor)  # Used as default color by Color Chooser
        self.jig_color_pixmap = get_widget_with_color_palette(
            self.jig_color_pixmap, self.jig_QColor)

        # Init the top widgets (name, runtyp drop box, comment)
        self.name_linedit.setText(self.gamessJig.name)
        self.runtyp_combox.setCurrentIndex(self.pset.ui.runtyp)  # RUNTYP
        self.calculate_changed(self.pset.ui.runtyp)
        self.comment_linedit.setText(self.pset.ui.comment)

        # Electronic Structure Properties section.
        btn = self.scftyp_btngrp.button(
            self.pset.ui.scftyp)  # RHF, UHF, or ROHF
        btn.setChecked(True)
        self.icharg_spinbox.setValue(self.pset.ui.icharg)  # Charge
        self.multi_combox.setCurrentIndex(self.pset.ui.mult)  # Multiplicity
        # Disable RHF if multiplicity is not the first item.
        if self.pset.ui.mult == 0:
            self.rhf_radiobtn.setEnabled(1)  # Enable RHF
        else:
            self.rhf_radiobtn.setEnabled(0)  # Disable RHF

        # System Memory and Usage
        self.dirscf_checkbox.setChecked(self.pset.ui.dirscf)  # DIRSCF
        self.memory_spinbox.setValue(self.pset.ui.memory)  # Memory

        # Electron Correlation Method and Basis Set
        ecm = self.pset.ui.ecm
        btn = self.ecm_btngrp.button(self.pset.ui.ecm)  # None, DFT or MP2
        btn.setChecked(True)
        self.set_ecmethod(self.pset.ui.ecm)  # None, DFT or MP2
        self.gbasis_combox.setCurrentIndex(self.pset.ui.gbasis)  # Basis set

        # Load the combo box with all the valid DFT functions.
        self._load_dfttyp_combox()
        self.dfttyp_combox.setCurrentIndex(
            self.pset.ui.dfttyp)  # DFT Functional
        self.gridsize_combox.setCurrentIndex(
            self.pset.ui.gridsize)  # Grid Size
        self.core_electrons_checkbox.setChecked(
            self.pset.ui.ncore)  # Include core electrons

        # Convergence Criteria
        self.density_conv_combox.setCurrentIndex(
            self.pset.ui.conv)  # Density Convergence
        self.rmsd_combox.setCurrentIndex(
            self.pset.ui.rmsdconv)  # RMSD Convergence
        self.iterations_spinbox.setValue(self.pset.ui.iterations)  # Iterations

        # These have been removed per discussions with Damian.
        # Mark 050628
        #        self.extrap_checkbox.setChecked(self.pset.ui.extrap) # EXTRAP
        #        self.damp_checkbox.setChecked(self.pset.ui.damp) # DAMP
        #        self.diis_checkbox.setChecked(self.pset.ui.diis) # DIIS
        #        self.shift_checkbox.setChecked(self.pset.ui.shift) # SHIFT
        #        self.soscf_checkbox.setChecked(self.pset.ui.soscf) # SOSCF
        #        self.rstrct_checkbox.setChecked(self.pset.ui.rstrct) # RSTRCT

        # Load the server combo box
        #self._reloadServerList() # Not used in A6.  Mark.

        # If there is an error, return 1. NIY.
        return 0