예제 #1
0
    def __init__(self, app_window):
        super(ScriptsDialog, self).__init__(app_window)

        self.script = None
        self._app_window = app_window
        self._script_manager = ScriptsManager()
        self._git = Git()

        self.setMinimumWidth(800)

        box = QVBoxLayout()
        self.table = ScriptsTable(self)
        self.table.onScriptSelected.connect(self._item_selected)
        self.table.setMinimumWidth(800)

        # create a centered dot icon
        _section_width = self.table.header().sectionSize(3)
        self._new_pixmap = QPixmap(max(_section_width, 40), 20)
        self._new_pixmap.fill(Qt.transparent)
        painter = QPainter(self._new_pixmap)
        rect = QRect((_section_width * 0.5) - 5, 0, 20, 20)
        painter.setBrush(QColor('#666'))
        painter.setPen(QColor('#666'))
        painter.drawEllipse(rect)
        self._dot_icon = QIcon(self._new_pixmap)

        box.addWidget(self.table)
        lbl = QLabel('OS Support - A: Android I: IOS W: Windows')
        box.addWidget(lbl)
        self.setLayout(box)
        self._init_list()
예제 #2
0
class ScriptsDialog(QDialog):
    """ Scripts
    """
    def __init__(self, app_window):
        super(ScriptsDialog, self).__init__(app_window)

        self.script = None
        self._app_window = app_window
        self._script_manager = ScriptsManager()
        self._git = Git()

        self.setMinimumWidth(800)

        box = QVBoxLayout()
        self.table = ScriptsTable(self)
        self.table.onScriptSelected.connect(self._item_selected)
        self.table.setMinimumWidth(800)

        # create a centered dot icon
        _section_width = self.table.header().sectionSize(3)
        self._new_pixmap = QPixmap(max(_section_width, 40), 20)
        self._new_pixmap.fill(Qt.transparent)
        painter = QPainter(self._new_pixmap)
        rect = QRect((_section_width * 0.5) - 5, 0, 20, 20)
        painter.setBrush(QColor('#666'))
        painter.setPen(QColor('#666'))
        painter.drawEllipse(rect)
        self._dot_icon = QIcon(self._new_pixmap)

        box.addWidget(self.table)
        lbl = QLabel('OS Support - A: Android I: IOS W: Windows')
        box.addWidget(lbl)
        self.setLayout(box)
        self._init_list()

    def _init_list(self):
        for script_name in sorted(self._script_manager.get_scripts().keys()):
            script = self._script_manager.get_script(script_name)
            info = script['info']

            if 'dwarf' in info:
                continue

            _name = QStandardItem()
            _name.setText(script_name)
            _name.setToolTip(info['name'])

            _author = QStandardItem()
            if 'author' in info:
                _author.setTextAlignment(Qt.AlignCenter)
                _author.setText(info['author'])

            _android = QStandardItem()
            if 'android' in info:
                _android.setIcon(self._dot_icon)

            _ios = QStandardItem()
            if 'ios' in info:
                _ios.setIcon(self._dot_icon)

            _windows = QStandardItem()
            if 'windows' in info:
                _windows.setIcon(self._dot_icon)

            _desc = QStandardItem()
            if 'description' in info:
                _desc.setText(info['description'])

            self.table.add_item(
                [_name, _author, _android, _ios, _windows, _desc])

    def _item_selected(self, script_name):
        script_url = self._script_manager.get_script(script_name)['script']
        script = self._git.get_script(script_url)
        self.script = script
        self.accept()

    @staticmethod
    def pick(app):
        """ helper
        """
        dialog = ScriptsDialog(app)
        result = dialog.exec_()
        return result == QDialog.Accepted, dialog.script