Skip to content

Commit

Permalink
Fix control file
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Sep 20, 2018
1 parent f9ce970 commit a4c9fec
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
45 changes: 34 additions & 11 deletions pyforms_gui/controls/control_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from confapp import conf

from pyforms_gui.controls.control_text import ControlText
from pyforms_gui.controls.control_base import ControlBase

import pyforms_gui.utils.tools as tools

Expand All @@ -12,23 +12,46 @@
from AnyQt.QtWidgets import QFileDialog


class ControlDir(ControlText):
class ControlDir(ControlBase):

def init_form(self):
control_path = tools.getFileInSameDirectory(__file__, "fileInput.ui")
self._form = uic.loadUi(control_path)
self._form.label.setText(self._label)
self._form.lineEdit.setText(self._value)
self._form.pushButton.clicked.connect(self.click)
self.form.lineEdit.editingFinished.connect(self.finishEditing)
self._form.pushButton.setIcon(conf.PYFORMS_ICON_FILE_OPEN)
super().init_form()


def click(self):
value = str(QFileDialog.getExistingDirectory(self._form, 'Choose a directory', self.value))
if value: self.value = value
value = QFileDialog.getExistingDirectory(self.parent, self._label, self.value)

if _api.USED_API == _api.QT_API_PYQT5:
value = value[0]
elif _api.USED_API == _api.QT_API_PYQT4:
value = str(value)

if value and len(value)>0: self.value = value

def finishEditing(self):
"""Function called when the lineEdit widget is edited"""
self.changed_event()


@property
def parent(self): return ControlText.parent.fget(self, value)
def value(self):
self._value = str(self._form.lineEdit.text())
return self._value

@parent.setter
def parent(self, value):
ControlText.parent.fset(self, value)
self._form.pushButton.clicked.connect(self.click)
@value.setter
def value(self, value):
self._form.lineEdit.setText(value)
ControlBase.value.fset(self, value)

@property
def label(self): return self.form.label.text()

@label.setter
def label(self, value):
self.form.label.setText(value)
ControlBase.label.fset(self, value)
22 changes: 20 additions & 2 deletions pyforms_gui/controls/control_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

from confapp import conf
from pyforms_gui.controls.control_text import ControlText
from pyforms_gui.controls.control_base import ControlBase

import pyforms_gui.utils.tools as tools

Expand All @@ -11,7 +11,7 @@
from AnyQt.QtWidgets import QFileDialog


class ControlFile(ControlText):
class ControlFile(ControlBase):

def __init__(self, *args, **kwargs):

Expand Down Expand Up @@ -46,3 +46,21 @@ def click(self):

if value and len(value)>0: self.value = value


@property
def value(self):
self._value = str(self._form.lineEdit.text())
return self._value

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

@property
def label(self): return self.form.label.text()

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

0 comments on commit a4c9fec

Please sign in to comment.