Jump to content

[Q] How to get value from editline?


Recommended Posts

qdh5b7.jpg

I want to make red label same as entered value in editbox, after I click run.

Here is my code:

import ui
import dbg
import os

class Dialog1(ui.ThinBoard):
	
	
	def __init__(self):
		ui.ThinBoard.__init__(self)
		self.BuildWindow()

	def __del__(self):
		ui.ThinBoard.__del__(self)

	def BuildWindow(self):
		self.SetSize(600, 40)
		self.SetPosition(10, 40)
		self.AddFlag('float')
		self.comp = Component()
		self.HeaderLabe3 = self.comp.TextLine(self, '-----', 230, 9, self.comp.RGB(255, 0, 0))
		self.Close = self.comp.Button(self, '', '', 575, 10, self.Close_func, 'd:/ymir work/ui/public/close_button_01.sub', 'd:/ymir work/ui/public/close_button_02.sub', 'd:/ymir work/ui/public/close_button_03.sub')	
		self.EditLine1 = self.comp.EditLine(self, '', 70, 8, 61, 18, 6)
		self.Run = self.comp.Button(self, 'Run', '', 185, 8, self.Run_func, 'd:/ymir work/ui/public/small_button_01.sub', 'd:/ymir work/ui/public/small_button_02.sub', 'd:/ymir work/ui/public/small_button_03.sub')
		
	
	def Run_func(self):
		self.HeaderLabe3.SetText(self.EditLine1)
	
	def Close_func(self):
		self.Hide()
		
		
	def Close(self):
		self.Hide()
	
	
		
		

class Component:
	def Button(self, parent, buttonName, tooltipText, x, y, func, UpVisual, OverVisual, DownVisual):
		button = ui.Button()
		button.SetParent(parent)
		button.SetPosition(x, y)
		button.SetUpVisual(UpVisual)
		button.SetOverVisual(OverVisual)
		button.SetDownVisual(DownVisual)
		button.SetText(buttonName)
		button.SetToolTipText(tooltipText)
		button.Show()
		button.SetEvent(func)
		return button

	def ToggleButton(self, parent, buttonName, tooltipText, x, y, funcUp, funcDown, UpVisual, OverVisual, DownVisual):
		button = ui.ToggleButton()
		button.SetParent(parent)
		button.SetPosition(x, y)
		button.SetUpVisual(UpVisual)
		button.SetOverVisual(OverVisual)
		button.SetDownVisual(DownVisual)
		button.SetText(buttonName)
		button.SetToolTipText(tooltipText)
		button.Show()
		button.SetToggleUpEvent(funcUp)
		button.SetToggleDownEvent(funcDown)
		return button

	def EditLine(self, parent, editlineText, x, y, width, heigh, max):
		SlotBar = ui.SlotBar()
		SlotBar.SetParent(parent)
		SlotBar.SetSize(width, heigh)
		SlotBar.SetPosition(x, y)
		SlotBar.Show()
		Value = ui.EditLine()
		Value.SetParent(SlotBar)
		Value.SetSize(width, heigh)
		Value.SetPosition(5, 1)
		Value.SetMax(max)
		Value.SetText(editlineText)
		Value.Show()
		return SlotBar, Value

	def TextLine(self, parent, textlineText, x, y, color):
		textline = ui.TextLine()
		textline.SetParent(parent)
		textline.SetPosition(x, y)
		if color != None:
			textline.SetFontColor(color[0], color[1], color[2])
		textline.SetText(textlineText)
		textline.Show()
		return textline

	def RGB(self, r, g, b):
		return (r*255, g*255, b*255)

	def SliderBar(self, parent, sliderPos, func, x, y):
		Slider = ui.SliderBar()
		Slider.SetParent(parent)
		Slider.SetPosition(x, y)
		Slider.SetSliderPos(sliderPos / 100)
		Slider.Show()
		Slider.SetEvent(func)
		return Slider

	def ExpandedImage(self, parent, x, y, img):
		image = ui.ExpandedImageBox()
		image.SetParent(parent)
		image.SetPosition(x, y)
		image.LoadImage(img)
		image.Show()
		return image

	def ComboBox(self, parent, text, x, y, width):
		combo = ui.ComboBox()
		combo.SetParent(parent)
		combo.SetPosition(x, y)
		combo.SetSize(width, 15)
		combo.SetCurrentItem(text)
		combo.Show()
		return combo

	def ThinBoard(self, parent, moveable, x, y, width, heigh, center):
		thin = ui.ThinBoard()
		if parent != None:
			thin.SetParent(parent)
		if moveable == TRUE:
			thin.AddFlag('movable')
			thin.AddFlag('float')
		thin.SetSize(width, heigh)
		thin.SetPosition(x, y)
		if center == TRUE:
			thin.SetCenterPosition()
		thin.Show()
		return thin

Dialog1().Show()

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Premium

Then:

	def Run_func(self):
		self.HeaderLabe3.SetText(self.EditLine1[1].GetText())

or 

self.EditLine1_slotbar, self.EditLine1 = self.comp.EditLine(self, '', 70, 8, 61, 18, 6)

and then the function:

	def Run_func(self):
		self.HeaderLabe3.SetText(self.EditLine1.GetText())
  • Love 1

The one and only UI programming guideline

Link to comment
Share on other sites

	def Run_func(self):
		self.HeaderLabe3.SetText(self.EditLine1.GetText())

 

0930 21:33:11104 :: self.HeaderLabe3.SetText(self.EditLine1.GetText())

0930 21:33:11104 :: AttributeError
0930 21:33:11104 :: : 
0930 21:33:11104 :: 'tuple' object has no attribute 'GetText'

This happens 'cause your function returns more than 1 value. Try this: self.EditLine[1].GetText()

Edited by Shang
  • Love 1
Link to comment
Share on other sites

Then:

	def Run_func(self):
		self.HeaderLabe3.SetText(str(self.EditLine1.GetText()))

Same error.

	def Run_func(self):
		self.HeaderLabe3.SetText(self.EditLine1.GetText())

 

0930 21:33:11104 :: self.HeaderLabe3.SetText(self.EditLine1.GetText())

0930 21:33:11104 :: AttributeError
0930 21:33:11104 :: : 
0930 21:33:11104 :: 'tuple' object has no attribute 'GetText'

This happens 'cause your function returns more than 1 value. Try this: self.HeaderLabe3[1].GetText()

self.HeaderLabe3.SetText(self.EditLine1[1].GetText()) works fine! Thx guys for help :)

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.