Skip to content

Commit

Permalink
Call init_form in all controls
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Sep 5, 2018
1 parent 3e43958 commit d0f4cb8
Show file tree
Hide file tree
Showing 24 changed files with 1,267 additions and 1,228 deletions.
3 changes: 3 additions & 0 deletions pyforms_gui/controls/control_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, *args, **kwargs):
self._help = kwargs.get('helptext', None)
self._value = kwargs.get('default', None)
self._label = kwargs.get('label', args[0] if len(args)>0 else '')
self._style = kwargs.get('style', None)

self.init_form()

Expand All @@ -53,6 +54,8 @@ def init_form(self):
Load the control UI and initiate all the events.
"""
if self.help: self.form.setToolTip(self.help)

if self._style: self.form.setStyleSheet(self._style)



Expand Down
177 changes: 89 additions & 88 deletions pyforms_gui/controls/control_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,100 +3,101 @@

from confapp import conf

from AnyQt import uic
from AnyQt import uic
from AnyQt.QtWidgets import QPushButton, QSizePolicy
from AnyQt.QtGui import QIcon
from AnyQt.QtGui import QIcon

from pyforms_gui.controls.control_base import ControlBase


class ControlButton(ControlBase):
def __init__(self, *args, **kwargs):
"""
...
def __init__(self, *args, **kwargs):
"""
...
:param str icon: Button icon
:param str icon: Button icon
:param bool checkable: Flag to set the button checkable.
"""
self._checkable = kwargs.get('checkable', False)
super(ControlButton, self).__init__(*args, **kwargs)

default = kwargs.get('default', None)
if default: self.value = default

icon = kwargs.get('icon', None)
if icon: self.icon = icon

def init_form(self):
self._form = QPushButton()
self._form.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self._form.setCheckable(self._checkable)
self.label = self._label
self._form.setToolTip(self.help)

def click(self):
"""
Trigger a click event
"""
self._form.click()

def load_form(self, data, path=None):
pass

def save_form(self, data, path=None):
pass

##########################################################################

@property
def label(self):
return ControlBase.label.fget(self)

@label.setter
def label(self, value):
ControlBase.label.fset(self, value)
self._form.setText(self._label)

@property
def icon(self):
"""
Sets and gets the icon of the button.
"""
return self._form.icon()

@icon.setter
def icon(self, value):
if isinstance(value, (str, bytes)):
self._form.setIcon(QIcon(value))
else:
self._form.setIcon(value)

##########################################################################

@property
def value(self):
"""
Sets and gets the value of the Button. The value should be a function
"""
return None

@value.setter
def value(self, value):
try:
self._form.clicked.disconnect() # ignore previous signals if any
except TypeError as err:
# http://stackoverflow.com/questions/21586643/pyqt-widget-connect-and-disconnect
pass
self._form.clicked[bool].connect(value)

@property
def checked(self):
"""
Sets and gets the button checked state
"""
return self._form.isChecked()

@checked.setter
def checked(self, value):
self._form.setChecked(value)
"""
self._checkable = kwargs.get('checkable', False)
super(ControlButton, self).__init__(*args, **kwargs)

default = kwargs.get('default', None)
if default: self.value = default

icon = kwargs.get('icon', None)
if icon: self.icon = icon

def init_form(self):
self._form = QPushButton()
self._form.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
self._form.setCheckable(self._checkable)
self.label = self._label
self._form.setToolTip(self.help)
super().init_form()

def click(self):
"""
Trigger a click event
"""
self._form.click()

def load_form(self, data, path=None):
pass

def save_form(self, data, path=None):
pass

##########################################################################

@property
def label(self):
return ControlBase.label.fget(self)

@label.setter
def label(self, value):
ControlBase.label.fset(self, value)
self._form.setText(self._label)

@property
def icon(self):
"""
Sets and gets the icon of the button.
"""
return self._form.icon()

@icon.setter
def icon(self, value):
if isinstance(value, (str, bytes)):
self._form.setIcon(QIcon(value))
else:
self._form.setIcon(value)

##########################################################################

@property
def value(self):
"""
Sets and gets the value of the Button. The value should be a function
"""
return None

@value.setter
def value(self, value):
try:
self._form.clicked.disconnect() # ignore previous signals if any
except TypeError as err:
# http://stackoverflow.com/questions/21586643/pyqt-widget-connect-and-disconnect
pass
self._form.clicked[bool].connect(value)

@property
def checked(self):
"""
Sets and gets the button checked state
"""
return self._form.isChecked()

@checked.setter
def checked(self, value):
self._form.setChecked(value)
65 changes: 33 additions & 32 deletions pyforms_gui/controls/control_checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,43 @@

from confapp import conf

from AnyQt import uic, QtCore
from AnyQt import uic, QtCore


import pyforms_gui.utils.tools as tools
from pyforms_gui.controls.control_base import ControlBase


class ControlCheckBox(ControlBase):
def init_form(self):
control_path = tools.getFileInSameDirectory(__file__, "checkbox.ui")
self._form = uic.loadUi(control_path)
self._form.checkBox.setText(self._label)
self._form.checkBox.stateChanged.connect(self.__checkedToggle)

if self._value and self._value != '':
self._form.checkBox.setCheckState(QtCore.Qt.Checked)
else:
self._form.checkBox.setCheckState(QtCore.Qt.Unchecked)

if self.help: self.form.setToolTip(self.help)

def __checkedToggle(self):
self.changed_event()

def load_form(self, data, path=None):
if 'value' in data:
self._form.checkBox.setChecked(data['value'] == 'True' or data['value'] == True)

def save_form(self, data, path=None):
data['value'] = str(self._form.checkBox.isChecked())

@property
def value(self):
return self._form.checkBox.isChecked()

@value.setter
def value(self, value):
ControlBase.value.fset(self, value)
self._form.checkBox.setChecked(value)
def init_form(self):
control_path = tools.getFileInSameDirectory(__file__, "checkbox.ui")
self._form = uic.loadUi(control_path)
self._form.checkBox.setText(self._label)
self._form.checkBox.stateChanged.connect(self.__checkedToggle)

if self._value and self._value != '':
self._form.checkBox.setCheckState(QtCore.Qt.Checked)
else:
self._form.checkBox.setCheckState(QtCore.Qt.Unchecked)

if self.help: self.form.setToolTip(self.help)
super().init_form()

def __checkedToggle(self):
self.changed_event()

def load_form(self, data, path=None):
if 'value' in data:
self._form.checkBox.setChecked(data['value'] == 'True' or data['value'] == True)

def save_form(self, data, path=None):
data['value'] = str(self._form.checkBox.isChecked())

@property
def value(self):
return self._form.checkBox.isChecked()

@value.setter
def value(self, value):
ControlBase.value.fset(self, value)
self._form.checkBox.setChecked(value)
1 change: 1 addition & 0 deletions pyforms_gui/controls/control_checkboxlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def init_form(self):
self._form.listWidget.itemSelectionChanged.connect(self.__itemSelectionChanged)

if self.help: self.form.setToolTip(self.help)
super().init_form()



Expand Down

0 comments on commit d0f4cb8

Please sign in to comment.