Skip to content

Commit

Permalink
Add control matplotlib, fix control number and player
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Feb 1, 2019
1 parent 065fda4 commit 703193a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
1 change: 1 addition & 0 deletions pyforms_terminal/allcontrols.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .controls.control_image import ControlImage
from .controls.control_label import ControlLabel
from .controls.control_list import ControlList
from .controls.control_matplotlib import ControlMatplotlib
from .controls.control_number import ControlNumber
from .controls.control_player import ControlPlayer
from .controls.control_progress import ControlProgress
Expand Down
38 changes: 22 additions & 16 deletions pyforms_terminal/basewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class BaseWidget(object):

def __init__(self, *args, **kwargs):
self._parser = argparse.ArgumentParser()
self._controlsPrefix = ''
self._title = kwargs.get('title', args[0] if len(args)>0 else '')
self.stop = False
self._controlsPrefix = ''
self._title = kwargs.get('title', args[0] if len(args)>0 else '')
self.stop = False

self._conf = kwargs.get('load', None)

Expand All @@ -50,7 +50,7 @@ def init_form(self, parse=True):
ControlCombo,ControlCheckBox, ControlDir, ControlNumber, ControlBoundingSlider
)
):
self._parser.add_argument("--%s" % name, help=var.label)
self._parser.add_argument("--%s" % name, help=var.label, default=var.value)

if parse:
self._parser.add_argument('terminal_mode', type=str, default='terminal_mode', help='Flag to run pyforms in terminal mode')
Expand Down Expand Up @@ -84,10 +84,12 @@ def load_form(self, data, path=None):
def __parse_terminal_parameters(self):
for fieldname, var in self.controls.items():
name = var._name
if self._args.__dict__.get(name, None):
args = self._args.__dict__
if name in args:

value = args[name]

if isinstance(var, ControlFile):
value = self._args.__dict__[name]
if value!=None and (value.startswith('http://') or value.startswith('https://')):
local_filename = value.split('/')[-1]
outputFileName = os.path.join('input', local_filename)
Expand All @@ -97,30 +99,34 @@ def __parse_terminal_parameters(self):
var.value = value

if isinstance(var, ControlDir):
value = self._args.__dict__[name]
var.value = value

elif isinstance(var, (ControlText, ControlCombo)):
var.value = self._args.__dict__[name]
var.value = value

elif isinstance(var, ControlCheckBox):
var.value = self._args.__dict__[name]=='True'
var.value = value=='True' if value is not None and isinstance(value, str) else value

elif isinstance(var, (ControlSlider, ControlNumber) ):
var.value = int(self._args.__dict__[name])
var.value = float(value) if value is not None and isinstance(value, (str, int) ) else value

elif isinstance(var, ControlBoundingSlider):
var.value = eval(self._args.__dict__[name])
var.value = eval(value) if isinstance(value, str) and value else value

if self._args.load:
print('\n--------- LOADING CONFIG ------------------')
logger.debug('--------- LOADING CONFIG ---------')
with open(self._args.load) as infile:
data = json.load(infile)
self.load_form(data, os.path.dirname(self._args.load))
print('--------- END LOADING CONFIG --------------\n')
logger.debug('--------- END LOADING CONFIG ---------')

elif self._conf is not None:
print('\n--------- LOADING DEFAULT CONFIG ------------------')

logger.debug('--------- LOADING DEFAULT CONFI ---------')
self.load_form(self._conf, '.')
print('--------- END LOADING DEFAULT CONFIG --------------\n')
logger.debug('--------- END LOADING DEFAULT CONFIG ---------')



def __execute_events(self):
for function in self._args.__dict__.get("exec{0}".format(self._controlsPrefix), []).split('|'):
if len(function)>0:
Expand Down
5 changes: 5 additions & 0 deletions pyforms_terminal/controls/control_matplotlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pyforms_terminal.controls.control_base import ControlBase


class ControlMatplotlib(ControlBase): pass

9 changes: 4 additions & 5 deletions pyforms_terminal/controls/control_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

class ControlNumber(ControlBase):

def __init__(self, label = "", default = 0, minimum = 0, maximum = 100):
self._min = minimum
self._max = maximum

ControlBase.__init__(self, label, default)
def __init__(self, *args, **kwargs):
self._min = kwargs.get('minimum', 0)
self._max = kwargs.get('maximum', 100)
ControlBase.__init__(self, *args, **kwargs)


@property
Expand Down
4 changes: 3 additions & 1 deletion pyforms_terminal/controls/control_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy, types


import numpy as np
try:
from StringIO import StringIO as BufferClass
except ImportError:
Expand Down Expand Up @@ -68,6 +67,9 @@ def value(self):
result = {'min': self._min, 'max': self._max, 'position': self.video_index, 'frame': '', 'filename': self._filename }
capture = self._value

if capture is None:
return None

_, image = capture.read()
if isinstance(image, numpy.ndarray):
image = self.process_frame_event(image)
Expand Down

0 comments on commit 703193a

Please sign in to comment.