Skip to content

Commit

Permalink
Fix bugs with control player and checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Feb 6, 2019
1 parent 4873957 commit ba1c5c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
3 changes: 3 additions & 0 deletions pyforms_terminal/basewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ def load_form(self, data, path=None):
for name in self.load_order:
param = allparams[name]
if name in data:
logger.debug("[%30s]: [%s]", param.label, data[name])
param.load_form(data[name])
else:
for name, param in allparams.items():
if name in data:
logger.debug("[%30s]: [%s]", param.label, data[name])
param.load_form(data[name])


Expand All @@ -88,6 +90,7 @@ def __parse_terminal_parameters(self):
args = self._args.__dict__
if name in args:


value = args[name]

if isinstance(var, ControlFile):
Expand Down
6 changes: 4 additions & 2 deletions pyforms_terminal/controls/control_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, pickle,uuid
import uuid


class ControlBase(object):
Expand All @@ -12,6 +12,7 @@ def __init__(self, *args, **kwargs):
self._value = kwargs.get('default', None)
self._parent = 1
self._label = kwargs.get('label', args[0] if len(args)>0 else '')
self.changed_event = kwargs.get('changed_event', self.changed_event)

def init_form(self): pass

Expand Down Expand Up @@ -58,7 +59,8 @@ def value(self): return self._value
def value(self, value):
oldvalue = self._value
self._value = value
if oldvalue!=value: self.changed_event()
if oldvalue!=value:
self.changed_event()

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

Expand Down
5 changes: 5 additions & 0 deletions pyforms_terminal/controls/control_checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

class ControlCheckBox(ControlBase):

def __init__(self, *args, **kwargs):
if 'default' not in kwargs:
kwargs['default'] = False
super().__init__(*args, **kwargs)

@property
def value(self): return self._value

Expand Down
34 changes: 6 additions & 28 deletions pyforms_terminal/controls/control_player.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyforms_terminal.controls.control_base import ControlBase
from pyforms_terminal.utils.tools import groupImage
import numpy, types
import types, logging

logger = logging.getLogger(__name__)

try:
from StringIO import StringIO as BufferClass
Expand All @@ -12,19 +12,19 @@
try:
import cv2
except:
print( "cv2 not present. ControlPlayer not working")
logger.info( "cv2 not present. ControlPlayer not working")


try:
from PIL import Image
except:
print( "PIL not present. ControlPlayer not working")
logger.info( "PIL not present. ControlPlayer not working")


try:
import base64
except:
print( "base64 not present. ControlPlayer not working")
logger.info( "base64 not present. ControlPlayer not working")



Expand Down Expand Up @@ -64,29 +64,7 @@ def load_form(self, data): pass

@property
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)

if isinstance(image, list) or isinstance(image, tuple):
image = groupImage(image, True)


if len(image.shape)>2: image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
image = Image.fromarray(image)
buff = BufferClass()
image.save(buff, format="PNG")
content = buff.getvalue()
buff.close()
result['frame'] = base64.b64encode(content)

return result
return self._value

@value.setter
def value(self, value):
Expand Down

0 comments on commit ba1c5c0

Please sign in to comment.