示例#1
0
	def __init__(self, data, size, name=None, posn=(0,0), **kwargs):
		super().__init__(name, posn)
		self.setStyle(**kwargs)
		value = self.config(data, **kwargs)
		w, h = size
		if w == None or h == None:
			line = fontHeight(self)
			if w == None: w = line
			else: h = line
		self.size = w, h
		self.vertical = 1 if h > w else 0
		self.value = value
示例#2
0
	def __init__(self, name=None, txt="", inner=8, posn=(0,0), password=None, **kwargs):
		self.name = name
		self.setStyle(**kwargs)
		if type(inner) == int:
			if self.font == None: raise NoFont(self)
			h = fontHeight(self)
			inner = (inner * h, h)
		self.inner = inner
		self.posn = posn
		self.password = password
		self.cursor = len(txt)
		self.scroll = 0
		self.setText(txt)
示例#3
0
	def __init__(self, msg, buttons=None, cols=None, align=CENTER, validator=None, default="", password=None,
			title=None, minSize=None, name=None, posn=CENTER, allowClose=True, allowCancel=True, **kwargs):
		super().__init__(name, posn, title)
		self.validator = MsgBox.date if validator is date else validator
		self.allowClose = allowClose
		self.setStyle(**kwargs)
		if minSize != None: self.place(Ghost(minSize))
		lbl = Label(msg)

		# Buttons
		if buttons == None:
			buttons = ("Close",) if validator == None else ("OK", "Cancel")
		cntnr = Button.grid(buttons, cols=cols, align=align)
		self.buttons = cntnr.widgets
		self.buttonNames = buttons
		n = 0
		for b in buttons:
			if b.lower() == "cancel":
				self.cancelButton = cntnr.widgets[n]
				if not allowCancel: self.cancelButton.disable()
			n += 1
		cntnr.name = "Buttons"

		# Position for button Container
		x, y = lbl.below(8)
		wb = cntnr.getWidth()
		wl = lbl.getWidth()
		if minSize != None:
			w = minSize[0]
			if w > wl: wl = w
		if wb < wl: x += (wl - wb) // 2

		# Input
		self.valMsgDefault()
		if validator != None:
			w = max(wb, wl) - 2 * TextInput.pad
			if TextInput.font == None: raise NoFont("TextInput")
			h = fontHeight(TextInput)
			self.input = TextInput(txt=default, inner=(w, h), posn=(0, y), password=password)
			self.status = Status()
			self.status.posn = self.input.below(2)
		else:
			self.input = None
			self.status = None

		# Place widgets
		cntnr.posn = x, y
		self.place(lbl, self.input, self.status, cntnr)
		if self.input != None: self.setStatus(None)
示例#4
0
 def make(data, handler=None, posn=None, main=True):
     name, data = data
     if main:
         items = []
         h = fontHeight(MenuItem)
         MenuItem.back = Image(sc8prPath("icons/menu.png")).scale((h, h))
     else:
         items = [MenuItem(name, MenuItem.back, iconSize=(1,0)).backLink()]
     for i in data:
         isStr = type(i) == str
         items.append(MenuItem(i if isStr else i[0], iconSize=(0,0)))
         if not isStr:
             items[-1].link = Menu.make(i, handler, posn, False)
     menu = Menu(items, name, posn)
     if handler: menu.bind(handler)
     if main: pass
     return menu
示例#5
0
    def layout(self):
        # FileBrowser grid and location TextInput...
        fn = FileBrowser.folders if self.mode == FOLDER else FileBrowser.match
        self.browser = FileBrowser(grid=self.grid, itemFilter=(fn, self.initFilter))
        w = self.browser.getWidth() - 2 * (TextInput.pad + 1)
        self.putCwd()
        self.browser.posn = self._cwd.below(self.pad)
        self.place(self.browser)

        # Buttons and filter...
        btn = Button.grid((("Open", "Save", "Select")[self.mode], "Cancel"))
        self.done, self.cancel = btn.widgets
        if not self.allowCancel: self.cancel.disable()
        btn.posn = self.browser.below(self.pad, EAST, btn.getWidth())
        x = w - btn.getWidth() - fontHeight(Button) // 2
        self._filter = TextInput(txt=self.filter, inner=(x, None), posn=(0, btn.posn[1]))
        self.place(btn, self._filter)
示例#6
0
	def makeImages(self, style=0, mark=None):
		sz = fontHeight(self)
		if style:
			r = sz // 2
			img0 = Image.ellipse(r, fill=self.bgColor, stroke=self.color, strokeWeight=self.border)
		else:
			img0 = Image.rect((sz,sz), fill=self.bgColor, stroke=self.color, strokeWeight=self.border)
		img1 = img0.clone()
		if mark:
			if mark[0]: mark[0].blitTo(img0)
			if mark[1]: mark[1].blitTo(img1)
		elif style:
			pygame.draw.circle(img1.surface, self.color, (r,r), r//2)
		else:
			sz -= 2
			pygame.draw.line(img1.surface, self.color, (1,1), (sz,sz))
			pygame.draw.line(img1.surface, self.color, (1,sz), (sz,1))
		return img0, img1
示例#7
0
	def grid(btns, name=None, posn=(0,0), cols=None, space=None, align=CENTER, group=None, nameFrmt=None, **kwargs):
		if not cols: cols = len(btns)
		if space == None: space = fontHeight(Button) // 2
		c = Container(name, posn)
		n = 0
		for b in btns:
			btnName = nameFrmt.format(b, n) if nameFrmt else None
			n += 1
			c.place(Button(b, btnName, **kwargs))
		Button.sameSize(c, align=align, cols=cols, space=space)
		if group != None:
			if group is False:
				for b in c.widgets: b.selectable = True
			else:
				b = c.widgets[0 if group is True else group];
				b.makeGroup(*c.widgets)
				if group is True: b.selected = False
		return c
示例#8
0
 def metrics(cls):
     h = fontHeight(cls)
     l, r = cls.iconSize
     e = 2 * (cls.pad + cls.border)
     return (h * l, h), (h * r, h), (h * (l + r + cls.textSize), h), (h * (l + r + cls.textSize) + e, h + e)
示例#9
0
	def fit(cls, *imgs, font=None):
		"Scale images based on font size"
		sz = fontHeight(font if font else cls.font)
		return [Image(img).scale((sz,sz)) if img else None for img in imgs]