Example #1
0
	def run(self):

		"""Run the item"""

		# Parse the option list
		option_list = self.var.options.split(u'\n') # split by return
		# Filter out empty options
		option_list = list(filter(lambda option: option != u'', option_list))
		# option_list.pop(len(option_list)-1) # remove last (empty) option
		if len(option_list) == 0:
			raise osexception(
				u'You must specify at least one response option in form_multiple_choice item "%s"' \
				% self.name)

		# Determine whether a button is shown and determine the number of rows
		rows = len(option_list) + 2
		if self.var.advance_immediately == u'no' \
			or self.var.allow_multiple == u'yes':
			show_button = True
			click_accepts = False
			rows += 1
		else:
			show_button = False
			click_accepts = True

		# Determine the group for the checkboxes
		if self.var.allow_multiple == u'no':
			group = u'response_group'
		else:
			group = None

		# The variable in which the response is stored
		var = self.var.form_var

		# Build the form
		try:
			margins = [float(i) for i in str(self.var.margins).split(u';')]
		except:
			raise osexception(
				_(u'margins should be numeric values separated by a semi-colon'))
		if self.var.timeout == u'infinite':
			timeout = None
		else:
			timeout = self.var.timeout
		form = widgets.form(self.experiment, cols=1, rows=rows,
			spacing=self.var.spacing, margins=margins, theme=self.var._theme,
			item=self, timeout=timeout, clicks=self.var.form_clicks==u'yes')
		form.set_widget(widgets.label(form, self.var.form_title), (0,0))
		form.set_widget(widgets.label(form, self.var.question), (0,1))
		i = 2
		for option in option_list:
			form.set_widget(widgets.checkbox(form, option,
				group=group, click_accepts=click_accepts, var=var), (0,i))
			i += 1
		if show_button:
			form.set_widget(widgets.button(form, self.var.button_text), (0,i))

		# Go!
		form._exec()
    def run(self):
        """Run the item"""

        # Parse the option list
        option_list = self.get(u'options').split(u'\n')  # split by return
        # Filter out empty options
        option_list = filter(lambda option: option != u'', option_list)
        # option_list.pop(len(option_list)-1) # remove last (empty) option
        if len(option_list) == 0:
            raise osexception( \
             u'You must specify at least one response option in form_multiple_choice item "%s"' \
             % self.name)

        # Determine whether a button is shown and determine the number of rows
        rows = len(option_list) + 2
        if self.get(u'advance_immediately') == u'no' or \
         self.get(u'allow_multiple') == u'yes':
            show_button = True
            click_accepts = False
            rows += 1
        else:
            show_button = False
            click_accepts = True

        # Determine the group for the checkboxes
        if self.get(u'allow_multiple') == u'no':
            group = u'response_group'
        else:
            group = None

        # The variable in which the response is stored
        var = self.get(u'form_var')

        # Build the form
        try:
            margins = [float(i) for i in unicode(self.margins).split(u';')]
        except:
            raise osexception( \
             _(u'margins should be numeric values separated by a semi-colon'))
        form = widgets.form(self.experiment,
                            cols=1,
                            rows=rows,
                            spacing=self.get(u'spacing'),
                            margins=margins,
                            theme=self.get(u'_theme'),
                            item=self)
        form.set_widget(widgets.label(form, self.get(u'form_title')), (0, 0))
        form.set_widget(widgets.label(form, self.get(u'question')), (0, 1))
        i = 2
        for option in option_list:
            form.set_widget(widgets.checkbox(form, option, group=group, \
             click_accepts=click_accepts, var=var), (0,i))
            i += 1
        if show_button:
            form.set_widget(widgets.button(form, self.get(u'button_text')), \
             (0,i))

        # Go!
        form._exec()
	def run(self):

		"""Run the item"""

		# Parse the option list
		option_list = self.get(u'options').split(u'\n') # split by return
		option_list.pop(len(option_list)-1) # remove last (empty) option
		if len(option_list) == 0:
			raise osexception( \
				u'You must specify at least one response option in form_multiple_choice item "%s"' \
				% self.name)

		# Determine whether a button is shown and determine the number of rows
		rows = len(option_list) + 2
		if self.get(u'advance_immediately') == u'no' or \
			self.get(u'allow_multiple') == u'yes':
			show_button = True
			click_accepts = False
			rows += 1
		else:
			show_button = False
			click_accepts = True

		# Determine the group for the checkboxes
		if self.get(u'allow_multiple') == u'no':
			group = u'response_group'
		else:
			group = None

		# The variable in which the response is stored
		var = self.get(u'form_var')

		# Build the form
		try:
			margins = [float(i) for i in unicode(self.margins).split(u';')]
		except:
			raise osexception( \
				_(u'margins should be numeric values separated by a semi-colon'))
		form = widgets.form(self.experiment, cols=1, rows=rows,
			spacing=self.get(u'spacing'), margins=margins,
			theme=self.get(u'_theme'), item=self)
		form.set_widget(widgets.label(form, self.get(u'form_title')), (0,0))
		form.set_widget(widgets.label(form, self.get(u'question')), (0,1))
		i = 2
		for option in option_list:
			form.set_widget(widgets.checkbox(form, option, group=group, \
				click_accepts=click_accepts, var=var), (0,i))
			i += 1
		if show_button:
			form.set_widget(widgets.button(form, self.get(u'button_text')), \
				(0,i))

		# Go!
		form._exec()
	def run(self):
		
		"""Run the item"""
		
		# Parse the option list
		option_list = unicode(self.get('options')).split('\n') # split by return
		option_list.pop(len(option_list)-1) # remove last (empty) option
		if len(option_list) == 0:
			raise exceptions.runtime_error( \
			'You must specify at least one response option in form_multiple_choice item "%s"' \
			% self.name)
			
		# Determine whether a button is shown and determine the number of rows
		rows = len(option_list) + 2
		if self.get('advance_immediately') == 'no' or \
			self.get('allow_multiple') == 'yes':
			show_button = True
			click_accepts = False
			rows += 1
		else:
			show_button = False
			click_accepts = True
			
		# Determine the group for the checkboxes
		if self.get('allow_multiple') == 'no':
			group = 'response_group'
		else:
			group = None			
			
		# The variable in which the response is stored
		var = self.get('form_var')
		
		# Build the form
		form = widgets.form(self.experiment, cols=1, rows=rows)		
		form.set_widget(widgets.label(form, self.get('form_title')), (0,0))
		form.set_widget(widgets.label(form, self.get('question')), (0,1))
		i = 2
		for option in option_list:
			form.set_widget(widgets.checkbox(form, option, group=group, \
				click_accepts=click_accepts, var=var), (0,i))
			i += 1
		if show_button:
			form.set_widget(widgets.button(form, self.get('button_text')), \
				(0,i))

		# Go!
		form._exec()
		return True
Example #5
0
    def run(self):
        """Run the item"""

        # Parse the option list
        option_list = unicode(self.get('options')).split(
            '\n')  # split by return
        option_list.pop(len(option_list) - 1)  # remove last (empty) option
        if len(option_list) == 0:
            raise exceptions.runtime_error( \
            'You must specify at least one response option in form_multiple_choice item "%s"' \
            % self.name)

        # Determine whether a button is shown and determine the number of rows
        rows = len(option_list) + 2
        if self.get('advance_immediately') == 'no' or \
         self.get('allow_multiple') == 'yes':
            show_button = True
            click_accepts = False
            rows += 1
        else:
            show_button = False
            click_accepts = True

        # Determine the group for the checkboxes
        if self.get('allow_multiple') == 'no':
            group = 'response_group'
        else:
            group = None

        # The variable in which the response is stored
        var = self.get('form_var')

        # Build the form
        form = widgets.form(self.experiment, cols=1, rows=rows)
        form.set_widget(widgets.label(form, self.get('form_title')), (0, 0))
        form.set_widget(widgets.label(form, self.get('question')), (0, 1))
        i = 2
        for option in option_list:
            form.set_widget(widgets.checkbox(form, option, group=group, \
             click_accepts=click_accepts, var=var), (0,i))
            i += 1
        if show_button:
            form.set_widget(widgets.button(form, self.get('button_text')), \
             (0,i))

        # Go!
        form._exec()
        return True
Example #6
0
	def run(self):

		"""The run phase of the plug-in goes here."""
		form = widgets.form(self.experiment, cols=[1,5,1], rows=self.rows, margins=[32,32,32,32])
		label_title = widgets.label(form, text=self._question)
		form.set_widget(label_title, (0,0), colspan=3)
		for i in range(len(self.responses)):
			resp = self.responses[i]
			button = widgets.button(form, text=resp)
			form.set_widget(button, (1, i+1))
		button_clicked = form._exec()
		self.experiment.set(self._variable, button_clicked)		
Example #7
0
    def _prepare_form(self):

        self._form = widgets.form(self.experiment,
                                  cols=(1),
                                  rows=(1, 5),
                                  item=self,
                                  clicks=self.var.form_clicks == u'yes')
        label = widgets.label(self._form,
                              text='Enter OMM participant identifier')
        self._text_input = widgets.text_input(
            self._form, return_accepts=True, var=self.var.participant_variable)
        self._form.set_widget(label, (0, 0))
        self._form.set_widget(self._text_input, (0, 1))
        self.run = self._run_form
Example #8
0
	def run(self):
		# Check if we should run this at all
		# TODO: For some reason, this works fine, as
		# [data_loaded]
		# [data_loaded] = 1
		# , etc, but not
		# [data_loaded] = true, or '= True', or '== true', or '== True'.
		print self._runif
		print self.compile_cond(self._runif)
		if eval(self.compile_cond(self._runif)):
			# Run the itemf
			# User input
			form = widgets.form(self.experiment, cols=[1,5,1], rows=self.rows, margins=[32,32,32,32])
			label_title = widgets.label(form, text=self._question)
			form.set_widget(label_title, (0,0), colspan=3)
			for i in range(len(self.responses)):
				resp = self.responses[i]
				button = widgets.button(form, text=resp)
				form.set_widget(button, (1, i+1))
			button_clicked = form._exec()
			# Check input
			if button_clicked == self._yes:
				# Send data
				data = self.experiment.log_list
				self.c.clear()
				self.c.text('Connecting to server...')
				self.c.show()
				
				# Try to open the connection
				#address = 'http://cogsci.nl/etravers/androidsql.php'
				address = self._address
				try:
					page = urllib.urlopen(address)#, data='position=OpeningConnection')
					page.close()
					# Connection works. Send data.
					debug.msg('Connection to server  at %s succesful...' % address)
					t = 0
					for trial in data:
						progress = int(float(t)/len(data)*680)
						#print t, len(data), progress
						self.c.clear()
						self.c.text('Sending...')
						self.c.rect(300, 600, 680, 72, False, 'grey')
						self.c.rect(303, 601, progress, 70, True, 'red')
						self.c.show()
						encode_data = urllib.urlencode(trial)
						debug.msg(encode_data)
						for i in range(5):
							# Try to send data 5 times.
							try:
								page = urllib.urlopen(address, encode_data)
								page.close()
								print 'Sent!', t
							except IOError as e:
									print str(e)
							else:
								break
						t += 1
					result = 'Data sent!'
					self.experiment.set('data_sent', 1)
					# Check for, and delete, sent datafile.
					# Find the saved data
					sdcard_folders = ['/sdcard/', '/mnt/sdcard/']
					for path in sdcard_folders:
						if os.path.isdir(path):
							print path
							break
					if os.path.exists(os.path.join(path, 'datafile.txt')):
						data_path = os.path.join(path, 'datafile.txt')
						os.remove(data_path)
					elif os.path.exists('datafile.txt'):
						data_path = 'datafile.txt'
						os.remove(data_path)
					# Otherwise, there's nothing to delete.
				except IOError as e:
					result = 'Unable to connect.\nPlease try again when connected to the internet.'
					print str(e)
					self.experiment.set('data_sent', 0)
				debug.msg(result)
				self.c.clear()
				self.c.text(result)
				self.c.text('Tap to continue.', y = 500)
				self.c.show()
				self.m.get_click()
			else:
				# Don't send data
				self.experiment.set('data_sent', 0)