Esempio n. 1
0
def create_action(parent, text, shortcut=None, icon=None, tip=None,
                  toggled=None, triggered=None, data=None, menurole=None,
                  context=Qt.WindowShortcut):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        # PyQt4 old SIGNAL: parent.connect(action, SIGNAL("triggered()"), triggered)
        action.triggered.connect(triggered)
    if toggled is not None:
        # PyQt4 old SIGNAL: parent.connect(action, SIGNAL("toggled(bool)"), toggled)
        action.toggled.connect(toggled)
        action.setCheckable(True)
    if icon is not None:
        if is_text_string(icon):
            icon = get_icon(icon)
        action.setIcon(icon)
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(to_qvariant(data))
    if menurole is not None:
        action.setMenuRole(menurole)
    # TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
    # (this will avoid calling shortcuts from another dockwidget
    #  since the context thing doesn't work quite well with these widgets)
    action.setShortcutContext(context)
    return action
Esempio n. 2
0
def create_action(parent, text, shortcut=None, icon=None, tip=None,
                  toggled=None, triggered=None, data=None, menurole=None,
                  context=Qt.WindowShortcut):
    """Create a QAction"""
    action = QAction(text, parent)
    if triggered is not None:
        # PyQt4 old SIGNAL: parent.connect(action, SIGNAL("triggered()"), triggered)
        action.triggered.connect(triggered)
    if toggled is not None:
        # PyQt4 old SIGNAL: parent.connect(action, SIGNAL("toggled(bool)"), toggled)
        action.toggled.connect(toggled)
        action.setCheckable(True)
    if icon is not None:
        if is_text_string(icon):
            icon = get_icon(icon)
        action.setIcon(icon)
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    if data is not None:
        action.setData(to_qvariant(data))
    if menurole is not None:
        action.setMenuRole(menurole)
    # TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
    # (this will avoid calling shortcuts from another dockwidget
    #  since the context thing doesn't work quite well with these widgets)
    action.setShortcutContext(context)
    return action
Esempio n. 3
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if role == Qt.TextAlignmentRole:
         if orientation == Qt.Horizontal:
             return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
         return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
     if role != Qt.DisplayRole:
         return to_qvariant()
     if orientation == Qt.Horizontal:
         if section == NAME:
             return to_qvariant("Name")
         elif section == VERSION:
             return to_qvariant("Version")
         elif section == ACTION:
             return to_qvariant("Action")
         elif section == DESCRIPTION:
             return to_qvariant("Description")
     return to_qvariant()
Esempio n. 4
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if role == Qt.TextAlignmentRole:
         if orientation == Qt.Horizontal:
             return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter))
         return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
     if role != Qt.DisplayRole:
         return to_qvariant()
     if orientation == Qt.Horizontal:
         if section == NAME:
             return to_qvariant("Name")
         elif section == VERSION:
             return to_qvariant("Version")
         elif section == ACTION:
             return to_qvariant("Action")
         elif section == DESCRIPTION:
             return to_qvariant("Description")
     return to_qvariant()
Esempio n. 5
0
 def data(self, index, role=Qt.DisplayRole):
     if not index.isValid() or not (0 <= index.row() < len(self.packages)):
         return to_qvariant()
     package = self.packages[index.row()]
     column = index.column()
     if role == Qt.CheckStateRole and column == CHECK:
         return to_qvariant(package in self.checked)
     elif role == Qt.DisplayRole:
         if column == NAME:
             return to_qvariant(package.name)
         elif column == VERSION:
             return to_qvariant(package.version)
         elif column == ACTION:
             action = self.actions.get(package)
             if action is not None:
                 return to_qvariant(action)
         elif column == DESCRIPTION:
             return to_qvariant(package.description)
     elif role == Qt.TextAlignmentRole:
         if column == ACTION:
             return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
         else:
             return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole:
         if package in self.checked:
             color = QColor(Qt.darkGreen)
             color.setAlphaF(.1)
             return to_qvariant(color)
         else:
             color = QColor(Qt.lightGray)
             color.setAlphaF(.3)
             return to_qvariant(color)
     return to_qvariant()
Esempio n. 6
0
 def data(self, index, role=Qt.DisplayRole):
     if not index.isValid() or not (0 <= index.row() < len(self.packages)):
         return to_qvariant()
     package = self.packages[index.row()]
     column = index.column()
     if role == Qt.CheckStateRole and column == CHECK:
         return to_qvariant(package in self.checked)
     elif role == Qt.DisplayRole:
         if column == NAME:
             return to_qvariant(package.name)
         elif column == VERSION:
             return to_qvariant(package.version)
         elif column == ACTION:
             action = self.actions.get(package)
             if action is not None:
                 return to_qvariant(action)
         elif column == DESCRIPTION:
             return to_qvariant(package.description)
     elif role == Qt.TextAlignmentRole:
         if column == ACTION:
             return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
         else:
             return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter))
     elif role == Qt.BackgroundColorRole:
         if package in self.checked:
             color = QColor(Qt.darkGreen)
             color.setAlphaF(0.1)
             return to_qvariant(color)
         else:
             color = QColor(Qt.lightGray)
             color.setAlphaF(0.3)
             return to_qvariant(color)
     return to_qvariant()