Exemplo n.º 1
0
    def font(self, text_style):
        device_font = text_style.fontfacename in LIBERATION_FONT_MAP
        try:
            if device_font:
                face = self.font_map[text_style.fontfacename]
            else:
                face = self.face_map[text_style.fontfacename]
        except KeyError:  # Bad fontfacename field in LRF
            face = self.font_map['Dutch801 Rm BT Roman']

        sz = text_style.fontsize
        wt = text_style.fontweight
        style = text_style.fontstyle
        font = (
            face,
            wt,
            style,
            sz,
        )
        if font in self.cache:
            rfont = self.cache[font]
        else:
            italic = font[2] == QFont.StyleItalic
            rfont = QFont(font[0], font[3], font[1], italic)
            rfont.setPixelSize(font[3])
            rfont.setBold(wt >= 69)
            self.cache[font] = rfont
        qfont = rfont
        if text_style.emplinetype != 'none':
            qfont = QFont(rfont)
            qfont.setOverline(text_style.emplineposition == 'before')
            qfont.setUnderline(text_style.emplineposition == 'after')
        return qfont
Exemplo n.º 2
0
    def getFontFromCmnd(self, fontinfo):
        '''
        Returns a QFont based on the information in the dictionary
        fontinfo.

        Recognized keys in the font dictionary are:
            "family": font family name (string)
            "size": text size in points (1/72 inches)
            "italic": italicize? (False/True)
            "bold": make bold? (False/True)
            "underline": underline?  (False/True)
        '''
        try:
            myfont = QFont(fontinfo["family"])
        except KeyError:
            myfont = self.__viewer.font()
        try:
            myfont.setPointSizeF(fontinfo["size"])
        except KeyError:
            pass
        try:
            myfont.setItalic(fontinfo["italic"])
        except KeyError:
            pass
        try:
            myfont.setBold(fontinfo["bold"])
        except KeyError:
            pass
        try:
            myfont.setUnderline(fontinfo["underline"])
        except KeyError:
            pass
        return myfont
Exemplo n.º 3
0
def update_font(basefont,
                weight=None,
                italic=None,
                underline=None,
                pixelSize=None,
                pointSize=None):
    """
    Return a copy of `basefont` :class:`QFont` with updated properties.
    """
    font = QFont(basefont)

    if weight is not None:
        font.setWeight(weight)

    if italic is not None:
        font.setItalic(italic)

    if underline is not None:
        font.setUnderline(underline)

    if pixelSize is not None:
        font.setPixelSize(pixelSize)

    if pointSize is not None:
        font.setPointSize(pointSize)

    return font
Exemplo n.º 4
0
 def display_answer(self, question, answers, correct_answer, description, selected_index, correct):
     x, y = self.display_question(question, answers, selected_index, correct) #TODO pass what to check and if right or wrong
     y += 50
     item =  QGraphicsSimpleTextItem("Correct Answer: %s" % correct_answer)
     item.setBrush(self.TEXT_COLOR)
     font = QFont(self.BOLDISH)
     font.setUnderline(True)
     item.setFont(font) 
     item.setX(x)
     item.setY(y)
     self.qtscene.addItem(item)
     self.references.append(item)
     
     y += 60
     item =  QGraphicsSimpleTextItem(make_pretty(description, 55))
     item.setBrush(self.TEXT_COLOR)
     item.setFont(self.NORMALISH) 
     item.setX(x)
     item.setY(y)
     self.qtscene.addItem(item)
     self.references.append(item)
     
     item = QPushButton('Next')
     item.clicked.connect(self.on_next)
     item.setFont(self.BOLDISH) 
     item.move(x+700, y)
     self.qtscene.addWidget(item)
     self.references.append(item)
Exemplo n.º 5
0
    def font(self, text_style):
        device_font = text_style.fontfacename in LIBERATION_FONT_MAP
        try:
            if device_font:
                face = self.font_map[text_style.fontfacename]
            else:
                face = self.face_map[text_style.fontfacename]
        except KeyError: # Bad fontfacename field in LRF
            face = self.font_map['Dutch801 Rm BT Roman']

        sz = text_style.fontsize
        wt = text_style.fontweight
        style = text_style.fontstyle
        font = (face, wt, style, sz,)
        if font in self.cache:
            rfont = self.cache[font]
        else:
            italic = font[2] == QFont.StyleItalic
            rfont = QFont(font[0], font[3], font[1], italic)
            rfont.setPixelSize(font[3])
            rfont.setBold(wt>=69)
            self.cache[font] = rfont
        qfont = rfont
        if text_style.emplinetype != 'none':
            qfont = QFont(rfont)
            qfont.setOverline(text_style.emplineposition == 'before')
            qfont.setUnderline(text_style.emplineposition == 'after')
        return qfont
Exemplo n.º 6
0
    def setColumnLinks(self, column, links):
        font = QFont()
        font.setUnderline(True)

        for i, link in enumerate(links):
            self._roleData[gui.LinkRole][i][column] = link
            self._roleData[Qt.FontRole][i][column] = font
            self._roleData[Qt.ForegroundRole][i][column] = QColor(Qt.blue)
Exemplo n.º 7
0
    def setColumnLinks(self, column, links):
        font = QFont()
        font.setUnderline(True)

        for i, link in enumerate(links):
            self._roleData[gui.LinkRole][i][column] = link
            self._roleData[Qt.FontRole][i][column] = font
            self._roleData[Qt.ForegroundRole][i][column] = QColor(Qt.blue)
Exemplo n.º 8
0
    def __init__(self, parent, document):
        """build our info display
        """
        super(SingleLayerInfoPane, self).__init__(parent)

        self.document = document  # FUTURE: make this a weakref?

        # build our layer detail info display controls
        self.name_text = QLabel("")
        self.name_text.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.time_text = QLabel("")
        self.time_text.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.instrument_text = QLabel("")
        self.instrument_text.setSizePolicy(QSizePolicy.Fixed,
                                           QSizePolicy.Fixed)
        self.band_text = QLabel("")
        self.band_text.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.wavelength_text = QLabel("")
        self.wavelength_text.setSizePolicy(QSizePolicy.Fixed,
                                           QSizePolicy.Fixed)
        self.colormap_text = QLabel("")
        self.colormap_text.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.clims_text = QLabel("")
        self.clims_text.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.cmap_vis = QNoScrollWebView()
        self.cmap_vis.setFixedSize(3 * 100, 30)
        self.cmap_vis.page().mainFrame().setScrollBarPolicy(
            Qt.Vertical, Qt.ScrollBarAlwaysOff)
        self.composite_details = QLabel("Composite Details")
        self.composite_details.setSizePolicy(QSizePolicy.Fixed,
                                             QSizePolicy.Fixed)
        f = QFont()
        f.setUnderline(True)
        self.composite_details.setFont(f)
        self.composite_codeblock = QTextEdit()
        self.composite_codeblock.setReadOnly(True)
        self.composite_codeblock.setMinimumSize(3 * 100, 100)
        self.composite_codeblock.setDisabled(True)
        self.composite_codeblock.setSizePolicy(QSizePolicy.Minimum,
                                               QSizePolicy.Minimum)

        # set the layout
        # Note: add in a grid is (widget, row#, col#) or (widget, row#, col#, row_span, col_span)
        layout = QGridLayout()
        layout.addWidget(self.name_text, 1, 1)
        layout.addWidget(self.time_text, 2, 1)
        layout.addWidget(self.instrument_text, 3, 1)
        layout.addWidget(self.band_text, 4, 1)
        layout.addWidget(self.wavelength_text, 5, 1)
        layout.addWidget(self.colormap_text, 6, 1)
        layout.addWidget(self.clims_text, 7, 1)
        layout.addWidget(self.cmap_vis, 8, 1)
        layout.addWidget(self.composite_details, 9, 1)
        layout.addWidget(self.composite_codeblock, 10, 1)
        parent.setLayout(layout)

        # clear out the display
        self.update_display()
Exemplo n.º 9
0
 def setItemTextFormat(item, f):
     font = QFont(data.font)
     if f.hasProperty(QTextFormat.ForegroundBrush):
         item.setForeground(0, f.foreground().color())
     else:
         item.setForeground(0, data.baseColors['text'])
     if f.hasProperty(QTextFormat.BackgroundBrush):
         item.setBackground(0, f.background().color())
     else:
         item.setBackground(0, QBrush())
     font.setWeight(f.fontWeight())
     font.setItalic(f.fontItalic())
     font.setUnderline(f.fontUnderline())
     item.setFont(0, font)
Exemplo n.º 10
0
 def getFont(self,
             font_family,
             font_size=10,
             bold=False,
             italic=False,
             Underline=False):
     font = QFont()
     font.setFamily(_fromUtf8(font_family))
     font.setPixelSize(font_size)
     font.setFixedPitch(True)
     font.setBold(bold)
     font.setItalic(italic)
     font.setUnderline(Underline)
     return font
Exemplo n.º 11
0
    def __init__(self, *args, **kwargs):
        super(Button_menu, self).__init__(*args, **kwargs)

        # self.setFont(QFont("Times New Roman", 20))
        # self.setStyleSheet("width: 20px;")
        self.setIconSize(QSize(80, 80))
        self.setFocusPolicy(Qt.TabFocus)
        font = QFont()
        font.setBold(True)
        font.setItalic(True)
        font.setUnderline(True)
        font.setWeight(40)
        # font.setStrikeOut(False)
        # font.setKerning(True)
        self.setFont(font)
Exemplo n.º 12
0
    def set_pythonshell_font(self, font=None):
        """Python Shell only"""
        if font is None:
            font = QFont()

        for format in self.formats:
            format.setFont(font)
        
        getstyleconf = lambda name, prop: CONF.get('shell_appearance',
                                                   name+'/'+prop)
        for format, stylestr in self.formats.iteritems():
            foreground = getstyleconf(stylestr, 'foregroundcolor')
            format.setForeground(QColor(foreground))
            background = getstyleconf(stylestr, 'backgroundcolor')
            format.setBackground(QColor(background))
            font = format.font()
            font.setBold(getstyleconf(stylestr, 'bold'))
            font.setItalic(getstyleconf(stylestr, 'italic'))
            font.setUnderline(getstyleconf(stylestr, 'underline'))
            format.setFont(font)
Exemplo n.º 13
0
def update_font(basefont, weight=None, italic=None, underline=None, pixelSize=None, pointSize=None):
    """
    Return a copy of `basefont` :class:`QFont` with updated properties.
    """
    font = QFont(basefont)

    if weight is not None:
        font.setWeight(weight)

    if italic is not None:
        font.setItalic(italic)

    if underline is not None:
        font.setUnderline(underline)

    if pixelSize is not None:
        font.setPixelSize(pixelSize)

    if pointSize is not None:
        font.setPointSize(pointSize)

    return font
Exemplo n.º 14
0
 def font(self):        
     qFont = QFont(self._family,self._pointSize,self._weight)
     qFont.setItalic(self._italic)
     qFont.setUnderline(self._underline)
     return qFont
Exemplo n.º 15
0
class ConfigDialog(QDialog):
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self._layout = QVBoxLayout(self)
        self._tabdialog = QTabWidget(self)
        self._layout.addWidget(self._tabdialog)
        w = _config_dialog.Ui_config_dialog()
        w.setupUi(self._tabdialog)
        self.widgets = w
        
        self._buttonbox = QDialogButtonBox(QDialogButtonBox.Save|QDialogButtonBox.Cancel)
        self._buttonbox.setParent(self)
        signal_connect(self._buttonbox, SIGNAL("accepted()"), self.accept)
        signal_connect(self._buttonbox, SIGNAL("rejected()"), self.reject)
        self._layout.addWidget(self._buttonbox)
        
        self._layout.setContentsMargins(3,3,3,3)
        
        self.font = QFont()
        self.color = QColor()
        
        self.config = yobot_interfaces.component_registry.get_component("client-config")
        
        self.account_items = {}
        
        signal_connect(w.account_add, SIGNAL("clicked()"), lambda: self.add_modify_account(add=True))
        signal_connect(w.account_edit, SIGNAL("clicked()"), lambda: self.add_modify_account(add=False))
        signal_connect(w.account_del, SIGNAL("clicked()"), self.remove_account)
        
        signal_connect(w.select_color, SIGNAL("clicked()"), lambda: self.change_formatting(color=True))
        signal_connect(w.select_font, SIGNAL("clicked()"), lambda: self.change_formatting(font=True))
        
        signal_connect(w.agent_address, SIGNAL("editingFinished()"), self.change_agent)
        self.connect_global_bool(w.html_relsize, "appearance", "use_html_relsize")
        self.connect_global_bool(w.show_joinpart, "appearance", "show_joinpart")
        self.input_validated = True
        
        self.setWindowTitle("Yobot Configuration")
        
    def connect_global_bool(self, widget, dictname, optname, default=False):
        signal_connect(widget, SIGNAL("toggled(bool)"),
                       lambda b: self.config.globals.setdefault(dictname, {}).__setitem__(optname, b))
        
    def load_settings(self):
        w = self.widgets
        if not self.config:
            log_warn("config object not available! bailing")
            return
        #for font..
        appearance = self.config.globals.setdefault("appearance", {})
        family = appearance.get("font_family", None)
        size = appearance.get("font_size", None)
        color = appearance.get("font_color", None)
        
        if family: self.font.setFamily(family)
        if size: self.font.setPointSize(size)
        if color: self.color.setNamedColor(color)
        
        bold = appearance.get("font_bold", False)
        italic = appearance.get("font_italic", False)
        underline = appearance.get("font_underline", False)
        html_relsize = appearance.get("use_html_relsize", False)
        show_joinpart = appearance.get("show_joinpart", False)
        
        self.font.setBold(bold)
        self.font.setItalic(italic)
        self.font.setUnderline(underline)
        w.html_relsize.setChecked(html_relsize)
        w.show_joinpart.setChecked(show_joinpart)
        
        self.change_formatting()
        
        #for the agent...
        agent = self.config.globals.get("agent_address", None)
        if agent: w.agent_address.setText(agent)
        self.change_agent()
        #for accounts:
        for a in self.config.accounts:
            log_warn("got account", a)
            if a.get("name", None) and a.get("improto", None):
                #get name and icon
                name, icon = getProtoIconAndName(getattr(yobotproto, a["improto"], ""))
                log_debug(icon, name)
                i = QTreeWidgetItem((a["name"], name))
                i.setIcon(1, icon)
                i.setData(0, ITEM_PLACEHOLDER_ROLE, a)
                self.account_items[i] = a
                self.widgets.accounts.addTopLevelItem(i)
                
    
    def remove_account(self):
        #get current item:
        w = self.widgets
        item = w.accounts.currentItem()
        
        #get the index (ugh.. this is tedious)
        itemindex = w.accounts.indexOfTopLevelItem(item)
        if itemindex == -1:
            log_err("couldn't get index!")
            return
        
        account = self.account_items[item]
        #remove the item from the widget:
        w.accounts.takeTopLevelItem(itemindex)
        
        #find the account in our global config list
        index = -1
        for i in xrange(0, len(self.config.accounts)):
            a = self.config.accounts[i]
            if str(a["name"]) == str(account["name"]) and str(a["improto"]) == str(account["improto"]):
                index = i
                break
            else:
                pass
        if index >= 0:
            log_debug("index:", index)
            self.config.accounts.pop(index)
        #finally, remove it from the mapping
        self.account_items.pop(item)
    
    def add_modify_account(self, add=False):
        dlg = AccountSettingsDialog(self)
        if not add:
            item = self.widgets.accounts.currentItem()
            if not item:
                return
            account = self.account_items.get(item)
            if not account:
                return
            #account = item.data(0, ITEM_PLACEHOLDER_ROLE).toPyObject()
            dlg.fill_from(account)
        else:
            item = QTreeWidgetItem()
        result = dlg.exec_()
        
        if not result == QDialog.Accepted:
            return
        new_a = dlg.values
        
        item.setText(0, new_a["name"])
        #get icon and name...
        name, icon = getProtoIconAndName(getattr(yobotproto, new_a["improto"], -1))
        item.setText(1, name)
        item.setIcon(1, icon)
        if add:
            if self.account_exists(new_a):
                print "account already exists.. not adding"
                return
            item.setData(0, ITEM_PLACEHOLDER_ROLE, new_a)
            self.widgets.accounts.addTopLevelItem(item)
            self.config.accounts.append(new_a)
        else:
            account.update(new_a)
            
    def account_exists(self, d):
        for a in self.config.accounts:
            if d["name"] == a["name"] and d["improto"] == a["improto"]:
                return True
        return False
    
    def change_formatting(self, color=False, font=False):
        if color:
            _color = QColorDialog.getColor(self.color, self, "Select Color")
            if _color.isValid():
                self.color = _color
        elif font:
            self.font, _ = QFontDialog.getFont(self.font, self, "Select Font")
            
        widgetformatter(self.widgets.sample_text, self.font, self.color,
                        klass="QPlainTextEdit")
        
        #now, change the config objects..
        fmt = self.config.globals["appearance"]
        fmt.update({
            "font_family":str(self.font.family()),
            "font_size":int(self.font.pointSize()),
            "font_color":str(self.color.name()),
            "font_bold":bool(self.font.bold()),
            "font_italic":bool(self.font.italic()),
            "font_underline":bool(self.font.underline())
        })
    
    def change_agent(self):
        #bah.. the same boring thing as always
        s = str(self.widgets.agent_address.text())
        if len(s.rsplit(":", 1)) == 2 and not str.isdigit(s.rsplit(":",1)[1]):
            self.input_validated = False
            self.widgets.agent_address.setStyleSheet("background-color:red;")
        else:
            self.widgets.agent_address.setStyleSheet("background-color:green")
            if s:
                self.config.globals["agent_address"] = str(s)
            self.input_validated = True
            
            
    
    def accept(self):
        #do some stuff first, like save
        if self.input_validated:
            self.config.save()
            QDialog.accept(self)
        else:
            QErrorMessage(self).showMessage("Bad input.. (somewhere?)")
Exemplo n.º 16
0
class PluginWidget(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.pluginMetadata = {}

        # Main layout
        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        # Define size used for the underlines
        self.underlineSize = QSize()
        self.underlineSize.setHeight(1)

        # Define font used for headers
        self.font = QFont()
        self.font.setPointSize(11)
        self.font.setBold(True)
        self.font.setUnderline(True)

        # Plugins Description
        self.pluginDescription = QLabel()
        self.pluginDescription.setText(
            "Click a plugin to see more information." +
            " Plugins can be configured from the Recording tab. \n")
        self.pluginDescription.setWordWrap(True)

        # Plugins GroupBox
        self.pluginLayout = QVBoxLayout()
        self.pluginGroupBox = QGroupBox(
            "Plugins extend the functionality of Freeseer")
        self.pluginGroupBox.setLayout(self.pluginLayout)
        self.pluginLayout.insertWidget(0, self.pluginDescription)
        self.mainLayout.insertWidget(0, self.pluginGroupBox)

        # Plugins list
        self.list = QTreeWidget()
        self.list.setHeaderHidden(True)
        self.list.headerItem().setText(0, "1")
        self.pluginLayout.insertWidget(1, self.list)

        # Details
        self.detailPane = QGroupBox()
        self.detailLayout = QVBoxLayout()
        self.detailPane.setLayout(self.detailLayout)
        self.detailPaneDesc = QLabel()
        self.detailPaneDesc.setWordWrap(True)
        self.detailLayout.addWidget(self.detailPaneDesc)
        self.pluginLayout.insertWidget(2, self.detailPane)

        self.list.itemSelectionChanged.connect(self.treeViewSelect)

    def treeViewSelect(self):
        item = self.list.currentItem()
        key = str(item.text(0))
        if key in self.pluginMetadata.keys():
            self.showDetails(key)
        else:
            self.hideDetails()

    def showDetails(self, key):
        self.detailPane.setTitle(key)
        self.detailPaneDesc.setText(self.pluginMetadata[key])
        self.detailPane.show()

    def hideDetails(self):
        self.detailPane.hide()

    def getWidgetPlugin(self, plugin, plugin_category, plugman):
        plugin_name = plugin.plugin_object.get_name()
        item = QTreeWidgetItem()

        # Display Plugin's meta data in a tooltip
        pluginDetails = """
        <table>
        <tr>
            <td>Name: </td>
            <td><b>%(name)s</b></td>
        </tr>
        <tr>
            <td>Version: </td>
            <td><b>%(version)s</b></td>
        <tr>
            <td>Author: </td>
            <td><b>%(author)s</b></td>
        </tr>
        <tr>
            <td>Website: </td>
            <td><b>%(website)s</b></td>
        </tr>
        <tr>
            <td>Description: </td>
            <td><b>%(description)s</b></td>
        </tr>
        </table>
        """ % {
            "name": plugin.name,
            "version": plugin.version,
            "author": plugin.author,
            "website": plugin.website,
            "description": plugin.description
        }

        # put the details in the hash table
        self.pluginMetadata[plugin_name] = pluginDetails

        item.setText(0, plugin_name)
        return item
Exemplo n.º 17
0
    def setupTabs(self, elmerDefs, Section, ID):
        """Creates the tabs of the dynamic widget according to the elmerDefs

        Args:
        -----
        elmerDefs: QDomDocument
            contents of the Elmder efs files in xml-format
        Section: str
            Type of base layout
        ID: int
            ID of the dynamiceditor-instance        
        """
        self.ID = ID
        self.qhash.clear()

        layout = self.layout()
        if (layout is not None):
            item = layout.takeAt(0)
            while (item != 0):
                item = None
                if (self.tabWidget is not None):
                    self.tabWidget.clear()
                    self.tabWidget = None
                item = layout.takeAt(0)
            self.layout = None

        # get root element
        self._root = elmerDefs.documentElement()

        self.tabWidget = QtGui.QTabWidget()
        self.tabWidget.setUsesScrollButtons(True)
        self.tabWidget.setElideMode(QtCore.Qt.ElideNone)

        self._all_stuff = self._root.firstChildElement("ALL")
        self._element = self._root.firstChildElement("PDE")

        self.tabs = 0

        while (self._element.isNull() is False):
            self._name = self._element.firstChildElement("Name")
            grid = QtGui.QGridLayout()
            params = 0
            for x in range(0, 2):
                if (x == 0):
                    if (str(self._name.text()).strip() == "General"):
                        continue
                    self._section = self._all_stuff.firstChildElement(Section)
                else:
                    self._section = self._element.firstChildElement(Section)

                self._param = self._section.firstChildElement("Parameter")

                while (self._param.isNull() is False):
                    h = hash_entry_t()
                    # label
                    widget_type = self._param.attribute("Widget", "Edit")
                    widget_enabled = self._param.attribute("Enabled", "True")
                    widget_visible = self._param.attribute("Visible", "True")
                    paramType = str(
                        self._param.firstChildElement("Type").text()).strip()
                    labelName = str(
                        self._param.firstChildElement("Name").text()).strip()
                    sifName = str(
                        self._param.firstChildElement(
                            "SifName").text()).strip()
                    if (sifName == ""):
                        sifName = labelName
                    paramDefault = str(
                        self._param.firstChildElement(
                            "DefaultValue").text()).strip()
                    whatis = str(
                        self._param.firstChildElement(
                            "Whatis").text()).strip()
                    statusTip = str(
                        self._param.firstChildElement(
                            "StatusTip").text()).strip()
                    fullName = "/" + str(self._name.text()).strip() + "/"
                    fullName = fullName + Section + "/" + labelName + "/" + str(
                        ID)
                    h.widget = None
                    if (widget_type == "Edit"):
                        edit = DynLineEdit()
                        h.widget = edit.lineEdit
                        edit.lineEdit.setText(paramDefault)
                        edit.name = fullName
                        edit.lineEdit.returnPressed.connect(edit.editSlot)
                        edit.lineEdit.textChanged.connect(
                            self._textChangedSlot)

                    elif (widget_type == "TextEdit"):
                        textEdit = QtGui.QTextEdit()
                        currentFont = textEdit.currentFont()
                        fontMetrics = QFontMetrics(currentFont)
                        fontHeight = fontMetrics.height()
                        textEdit.setMinimumHeight(5 * fontHeight)
                        textEdit.setMaximumHeight(8 * fontHeight)
                        h.widget = textEdit

                    elif (widget_type == "Combo"):
                        combo = QtGui.QComboBox()
                        h.widget = combo
                        count = 0
                        active = 0
                        item = self._param.firstChildElement("Item")
                        while (item.isNull() is False):
                            itemType = item.attribute("Type", "")
                            if (itemType == "Active"):
                                active = count
                            itemName = item.firstChildElement("Name")
                            count += 1
                            combo.insertItem(count,
                                             str(itemName.text()).strip())
                            item = item.nextSiblingElement("Item")
                        combo.setCurrentIndex(active)
                        combo.currentIndexChanged.connect(self._comboSlot)

                    elif (widget_type == "CheckBox"):
                        l = QtGui.QCheckBox()
                        h.widget = l
                        l.setText("")
                        l.setChecked(False)
                        if (paramDefault == "True"):
                            l.setChecked(True)
                        l.stateChanged.connect(self._lSlot)

                    elif (widget_type == "Label"):
                        label = QtGui.QLabel()
                        font = QFont()
                        font.setBold(True)
                        font.setUnderline(True)
                        label.setFont(font)
                        label.setText(labelName)
                        h.widget = label

                    if (h.widget):
                        h.widget.setWhatsThis(whatis)
                        h.widget.setStatusTip(statusTip)
                        h.widget.setProperty("dom address", fullName)
                        h.elem = self._param
                        if (widget_enabled == "False"):
                            h.widget.setEnabled(False)
                        if (widget_type != "TextEdit"):
                            h.widget.setFixedHeight(18)
                        if (widget_type == "TextEdit"):
                            textEditLabel = QtGui.QLabel()
                            textEditLabel.setText(labelName)
                            h.label = textEditLabel
                            grid.addWidget(h.widget, params, 0, 1, 2)

                            if (widget_visible == "False"):
                                h.label.hide()
                                h.widget.hide()

                        elif (widget_type != "Label"):
                            label = QtGui.QLabel()
                            label.setText(labelName)
                            h.label = label
                            grid.addWidget(h.label, params, 0)
                            grid.addWidget(h.widget, params, 1)

                            if (widget_visible == "False"):
                                h.label.hide()
                                h.widget.hide()
                        else:
                            h.label = None
                            grid.addWidget(h.widget, params, 0)
                        self.qhash.update({fullName: h})

                    self._param = self._param.nextSiblingElement("Parameter")
                    params += 1

            dummyWidget = QtGui.QWidget()
            grid.addWidget(dummyWidget, params, 0)
            grid.setRowStretch(params, 1)

            frmWidget = QtGui.QWidget()
            frmWidget.setLayout(grid)

            src = QtGui.QScrollArea()
            src.setWidget(frmWidget)
            src.setMinimumHeight(300)
            src.setWidgetResizable(True)

            if (params > 0):
                self.tabWidget.addTab(src, str(self._name.text()).strip())

            self.tabs += 1
            self._element = self._element.nextSiblingElement("PDE")

        # Buttons:
        lbl = QtGui.QLabel()
        lbl.setText("Name:")
        self.nameEdit = QtGui.QLineEdit()
        self.nameEdit.setText(Section + " " + str(ID + 1))

        self.applyButton = QtGui.QPushButton("&Apply")
        # applyButton.setIcon(addIcon)
        self.applyButton.clicked.connect(self._applyButtonClicked)

        self.discardButton = QtGui.QPushButton("&Remove")
        # discardButton.setIcon(removeIcon)
        self.discardButton.clicked.connect(self._discardButtonClicked)

        self.okButton = QtGui.QPushButton("&OK")
        # okButton.setIcon(okIcon)
        self.okButton.clicked.connect(self._okButtonClicked)

        self.newButton = QtGui.QPushButton("&New")
        # self.newButton.setIcon(newIcon)
        self.newButton.clicked.connect(self._newButtonClicked)

        nameLayout = QtGui.QHBoxLayout()
        nameLayout.addWidget(lbl)
        nameLayout.addWidget(self.nameEdit)

        buttonLayout = QtGui.QHBoxLayout()
        buttonLayout.addWidget(self.newButton)
        buttonLayout.addWidget(self.applyButton)
        buttonLayout.addWidget(self.okButton)
        buttonLayout.addWidget(self.discardButton)

        spareButtonLayout = QtGui.QHBoxLayout()
        self.spareButton = QtGui.QPushButton("SpareButton")
        self.spareButton.setVisible(False)
        spareButtonLayout.addWidget(self.spareButton)
        self.spareButton.clicked.connect(self._spareButtonClicked)

        self.spareScroll = QtGui.QScrollArea()
        self.spareScroll.hide()

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(self.tabWidget)
        mainLayout.addWidget(self.spareScroll)
        mainLayout.addLayout(spareButtonLayout)
        mainLayout.addLayout(nameLayout)
        mainLayout.addLayout(buttonLayout)
        self.setLayout(mainLayout)

        self.setWindowTitle(Section)
Exemplo n.º 18
0
class PluginWidget(QWidget):

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.pluginMetadata = {}

        # Main layout
        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        # Define size used for the underlines
        self.underlineSize = QSize()
        self.underlineSize.setHeight(1)

        # Define font used for headers
        self.font = QFont()
        self.font.setPointSize(11)
        self.font.setBold(True)
        self.font.setUnderline(True)

        # Plugins Description
        self.pluginDescription = QLabel()
        self.pluginDescription.setText("Click a plugin to see more information." +
            " Plugins can be configured from the Recording tab. \n")
        self.pluginDescription.setWordWrap(True)

        # Plugins GroupBox
        self.pluginLayout = QVBoxLayout()
        self.pluginGroupBox = QGroupBox("Plugins extend the functionality of Freeseer")
        self.pluginGroupBox.setLayout(self.pluginLayout)
        self.pluginLayout.insertWidget(0, self.pluginDescription)
        self.mainLayout.insertWidget(0, self.pluginGroupBox)

        # Plugins list
        self.list = QTreeWidget()
        self.list.setHeaderHidden(True)
        self.list.headerItem().setText(0, "1")
        self.pluginLayout.insertWidget(1, self.list)

        # Details
        self.detailPane = QGroupBox()
        self.detailLayout = QVBoxLayout()
        self.detailPane.setLayout(self.detailLayout)
        self.detailPaneDesc = QLabel()
        self.detailPaneDesc.setWordWrap(True)
        self.detailLayout.addWidget(self.detailPaneDesc)
        self.pluginLayout.insertWidget(2, self.detailPane)

        self.list.itemSelectionChanged.connect(self.treeViewSelect)

    def treeViewSelect(self):
        item = self.list.currentItem()
        key = str(item.text(0))
        if key in self.pluginMetadata.keys():
            self.showDetails(key)
        else:
            self.hideDetails()

    def showDetails(self, key):
        self.detailPane.setTitle(key)
        self.detailPaneDesc.setText(self.pluginMetadata[key])
        self.detailPane.show()

    def hideDetails(self):
        self.detailPane.hide()

    def getWidgetPlugin(self, plugin, plugin_category, plugman):
        plugin_name = plugin.plugin_object.get_name()
        item = QTreeWidgetItem()

        # Display Plugin's meta data in a tooltip
        pluginDetails = """
        <table>
        <tr>
            <td>Name: </td>
            <td><b>%(name)s</b></td>
        </tr>
        <tr>
            <td>Version: </td>
            <td><b>%(version)s</b></td>
        <tr>
            <td>Author: </td>
            <td><b>%(author)s</b></td>
        </tr>
        <tr>
            <td>Website: </td>
            <td><b>%(website)s</b></td>
        </tr>
        <tr>
            <td>Description: </td>
            <td><b>%(description)s</b></td>
        </tr>
        </table>
        """ % {"name": plugin.name,
               "version": plugin.version,
               "author": plugin.author,
               "website": plugin.website,
               "description": plugin.description}

        # put the details in the hash table
        self.pluginMetadata[plugin_name] = pluginDetails

        item.setText(0, plugin_name)
        return item