Ejemplo n.º 1
0
    def __init__(self, data, **kwargs):
        super(DataGridRow, self).__init__(**kwargs)
        self.index = kwargs.get('index')
        self.cells = []
        self.listWidth = kwargs.get('listWidth')

        for colIndex in range(0, self.cols):
            cell = None
            # label cell
            if data[colIndex]['type'] == 'Label':
                cell = Label()
                cell.valign = 'middle'
                cell.halign = 'center'
            # border lable cell
            elif data[colIndex]['type'] == 'BorderLabel':
                cell = BorderLabel()
                cell.valign = 'middle'
                cell.halign = 'center'
                if data[colIndex].get('borders'):
                    cell.borders = data[colIndex]['borders']
                else:
                    cell.borders = (.5, 'solid', (1, 1, 1, 0.3))
            # button cell define
            elif data[colIndex]['type'] == 'Button':
                self.bgColorProperty = Color(1, 1, 1, 0)
                cell = Button()
                if data[colIndex].get('callback'):
                    callback = data[colIndex].get('callback')
                    param_kwargs = data[colIndex].get('params')
                    if not param_kwargs:
                        param_kwargs = {}
                    cell.bind(on_press=partial(callback, **param_kwargs))
            # border button cell define
            elif data[colIndex]['type'] == 'BorderButton':
                self.bgColorProperty = Color(1, 1, 1, 0)
                cell = BorderButton()
                if data[colIndex].get('borders'):
                    cell.borders = data[colIndex]['borders']
                else:
                    cell.borders = (.5, 'solid', (1, 1, 1, 0.3))
                if data[colIndex].get('callback'):
                    callback = data[colIndex].get('callback')
                    param_kwargs = data[colIndex].get('params')
                    if not param_kwargs:
                        param_kwargs = {}
                    cell.bind(on_press=partial(callback, **param_kwargs))

            cell.size_hint = (None, 1)
            cell.text = data[colIndex]['text']
            cell.width = self.listWidth[colIndex]
            self.add_widget(cell)
            self.cells.append(cell)

        with self.canvas.before:
            self.bgColor = Color(rgba=self.bgColorProperty.rgba)
            self.rect = Rectangle(pos=self.center,
                                  size=(self.width / 2., self.height / 2.))
        self.bind(pos=self.updateRect,
                  size=self.updateRect,
                  bgColorProperty=self.updateRect)
Ejemplo n.º 2
0
	def __init__(self, data, **kwargs):
		super(DataGridRow, self).__init__(**kwargs)
		self.index = kwargs.get('index');
		self.cells = []
		self.listWidth = kwargs.get('listWidth');

		for colIndex in range(0, self.cols):
			cell = None
			# label cell
			if data[colIndex]['type'] == 'Label':
				cell = Label()
				cell.valign = 'middle'
				cell.halign = 'center'
			# border lable cell
			elif data[colIndex]['type'] == 'BorderLabel':
				cell = BorderLabel()
				cell.valign = 'middle'
				cell.halign = 'center'
				if data[colIndex].get('borders'):
					cell.borders= data[colIndex]['borders']
				else:
					cell.borders= (.5, 'solid', (1,1,1,0.3))
			# button cell define
			elif data[colIndex]['type'] == 'Button':
				self.bgColorProperty = Color(1,1,1,0)
				cell = Button()
				if data[colIndex].get('callback'):
					callback =  data[colIndex].get('callback')
					param_kwargs = data[colIndex].get('params')
					if not param_kwargs:
						param_kwargs = {}
					cell.bind(on_press=partial(callback, **param_kwargs))
			# border button cell define
			elif data[colIndex]['type'] == 'BorderButton':
				self.bgColorProperty = Color(1,1,1,0)
				cell = BorderButton()
				if data[colIndex].get('borders'):
					cell.borders= data[colIndex]['borders']
				else:
					cell.borders= (.5, 'solid', (1,1,1,0.3))
				if data[colIndex].get('callback'):
					callback =  data[colIndex].get('callback')
					param_kwargs = data[colIndex].get('params')
					if not param_kwargs:
						param_kwargs = {}
					cell.bind(on_press=partial(callback, **param_kwargs))

			cell.size_hint = (None, 1)
			cell.text = data[colIndex]['text']
			cell.width = self.listWidth[colIndex]
			self.add_widget(cell)
			self.cells.append(cell)

		with self.canvas.before:
			self.bgColor = Color(rgba=self.bgColorProperty.rgba)
			self.rect = Rectangle(pos=self.center, size=(self.width/2., self.height/2.))
		self.bind(pos=self.updateRect,size=self.updateRect,bgColorProperty=self.updateRect)