def fetch(self):
        if self.ui.active_radio.isChecked():
            self.gem = ActiveGem()
        elif self.ui.support_radio.isChecked():
            self.gem = SupportGem()
        else:
            self.gem = Gem()

        self.gem.name = str(self.ui.name_edit.text())
        self.gem.update(new_html=True)
        self.refresh()
        print((self.gem))
def test_update_components():
    g = Gem(name='Reave')
    soup = g.souper()

    g.update_gem_icon(soup)
    assert g.gem_icon != ''

    g.update_req_lvl(soup)
    assert g.Lvl != ''

    g.update_attr(soup)
    assert g.strength is not None
    assert g.dexterity is not None
    assert g.intelligence is not None

    g.update_description(soup)
    assert g.description != ''
class GemEdit(QDialog):
    """docstring for GemEdit"""
    def __init__(self, gem=Gem(), session=Session()):
        QDialog.__init__(self)
        self.gem = gem
        self.session = session

        # Set up ui
        self.ui = Ui_gem_edit()
        self.ui.setupUi(self)

        self.ui.reset_btn = self.ui.buttonBox.button(QDialogButtonBox.Reset)
        self.ui.apply_btn = self.ui.buttonBox.button(QDialogButtonBox.Apply)
        self.ui.ok_btn = self.ui.buttonBox.button(QDialogButtonBox.Ok)

        # Signal/Slot
        self.ui.active_radio.toggled.connect(self.toggle_active)
        self.ui.support_radio.toggled.connect(self.toggle_support)
        self.ui.reset_btn.clicked.connect(self.refresh)
        self.ui.apply_btn.clicked.connect(self.apply)
        self.ui.ok_btn.clicked.connect(self.accept)
        self.ui.fetch_btn.clicked.connect(self.fetch)

        self.refresh()

    def refresh(self):
        """Reloads data from self.gem"""
        # Basic Gem
        self.ui.name_edit.setText(self.gem.name)
        self.ui.abbrev_edit.setText(self.gem.abbrev)
        self.ui.description_edit.setText(self.gem.description)
        self.ui.gem_icon_lbl.setPixmap(QPixmap(self.gem.gem_icon))

        if self.gem.strength == 1:
            self.ui.str_chk.setChecked(True)
        if self.gem.dexterity == 1:
            self.ui.dex_chk.setChecked(True)
        if self.gem.intelligence == 1:
            self.ui.int_chk.setChecked(True)

        # Active Gem values TODO
        if self.gem.type == 'active':
            self.ui.active_radio.setChecked(True)
            self.ui.skill_icon_btn.show()
            self.ui.skill_icon_lbl.setPixmap(QPixmap(self.gem.skill_icon))

        # Support Gem values
        if self.gem.type == 'support':
            self.ui.support_radio.setChecked(True)
            self.ui.skill_icon_btn.hide()
            self.ui.mcm_edit.setText(self.gem.MCM)

    def toggle_active(self, active):
        """SLOT: when showing an active gem switch to tab_active"""
        if active is True:
            self.ui.tab_box.setCurrentWidget(self.ui.tab_active)

    def toggle_support(self, support):
        """SLOT: when showing an support gem switch to tab_support"""
        if support is True:
            self.ui.tab_box.setCurrentWidget(self.ui.tab_support)

    def apply(self):
        """SLOT: write changes to gem object"""
        pass

    def accept(self):
        """SLOT: first apply, then commit using session"""
        self.apply()
        self.session.commit()
        self.session.flush()
        self.done(1)

    def fetch(self):
        if self.ui.active_radio.isChecked():
            self.gem = ActiveGem()
        elif self.ui.support_radio.isChecked():
            self.gem = SupportGem()
        else:
            self.gem = Gem()

        self.gem.name = str(self.ui.name_edit.text())
        self.gem.update(new_html=True)
        self.refresh()
        print((self.gem))