Newer
Older
Import / projects / LGN-IP3870 / t / orig / baseui.py
# -*- coding: utf-8 -*-

import uiconfig, config, widget, runtime
import time, ntptime
from setting import setting
import utils,controls, entry
import status
#Roxia Begin jhbang 06.03.16 <ntp>
import profile
#Roxia End jhbang
from roxiadebug import *
from vdcisetting import vdci_setting
		
alarm_timer = None
title_image_layer = -10
#title_text_layer = -9
title_text_layer = -1 # -3 van duoc
videocall_bg_layer = -6
clip_layer = 99
#clip_layer = -5
videocall_detail_layer = -4
menu_layer = -1

class BaseUI(object):
	#__metaclass__ = checkdup.CheckDup
	show_bg = False
	show_bg_depth = False
	title_timer = None
	title_char_index  = 0
	title_text = ''
	def __init__(self, left='', right='', title='', menu3='', menu4=''):
		self.left = left
		self.right = right
		self.title = title
		self.widgets = []
		# KA: [20080313] new soft key
		self.menu3 = menu3
		self.menu4 = menu4

		# KA: [20080609] sms notify
		self.sms_box = None
		self.sms_icon = None
		self.sms_msg = None
		self.sms_timer = None
		self.play_timer = None
		
	def show(self):
		self.update_background_widgets()
		for w in self.widgets:
			w.show()
		if self.show_bg:
			runtime.day.hide()
			runtime.evas.bg_image.show()
		if self.show_bg_depth:
			runtime.depthBg.show()
		
		runtime.evas.render()

	def add(self, widget):
		self.widgets.append(widget)

	def remove(self, widget):
		self.widgets.remove(widget)
		widget.free()

	def hide(self):
		for w in self.widgets:
			w.hide()
		runtime.evas.bg_image.hide()
		runtime.depthBg.hide()
		runtime.evas.render()
		self.remove_title_timer()
		self.SMS_Notify_free()

	def destroy(self):
		for w in self.widgets:
			w.free()
		runtime.evas.bg_image.hide()
		runtime.depthBg.hide()
		self.remove_title_timer()
		runtime.evas.render()
		# for SMS
		#if status.mms_notify_exist:
		self.SMS_Notify_free()

	def center_align(self, label, pos):
		x, y = pos
		w, h = label.geometry[2:]
		label.move(x - w / 2, y)

	def set_left(self, left):
		self.left = left
		runtime.lb.set_text(left)
		# KT DEMO 20080125
#		runtime.lb2.set_text(self.left2)

	def set_right(self, right):
		self.right = right
		runtime.rb.set_text(right)
		# KT DEMO 20080125
#		runtime.rb2.set_text(self.right2)

# KA: [20080313] new soft key
	def set_menu3(self, menu3):
		self.menu3 = menu3
		runtime.menu3.set_text(menu3)

	def set_menu4(self, menu4):
		self.menu4 = menu4
		runtime.menu4.set_text(menu4)

# KA: [20080313] new soft key ==

	def set_title(self, title):
		self.title = title
		runtime.title.set_text(title)
		for w in runtime.title.children:
			w.layer = title_text_layer

	def handle_key(self, keyname):
		if self.notify_box:
			self.notify_msg_free()
			return True
		return False

	def remove_title_timer(self):
		if self.title_timer:
			runtime.evas.timeout_remove(self.title_timer)
			self.title_timer = None
			self.title_char_index = 0
			self.title_text = ''

	def update_background_widgets(self):
		runtime.lb.set_text(self.left)
		runtime.rb.set_text(self.right)
		runtime.menu3.set_text(self.menu3)
		runtime.menu4.set_text(self.menu4)
		runtime.title.init_title(self.title)
		runtime.title.hidden = False
		def update_timer():
			# KA: [20070921] this conversion is required for Korean text
			#new_title = self.title_text[self.title_char_index:]
			if type(self.title_text) == type('abc'):
				new_title = unicode(self.title_text, 'utf-8')[self.title_char_index:]
			else:
				new_title = self.title_text[self.title_char_index:]
			new_title  = new_title.encode('utf-8')

			if new_title == '':
				self.title_char_index = 0
				#new_title = self.title_text[self.title_char_index:]
				if type(self.title_text) == type('abc'):
					new_title = unicode(self.title_text, 'utf-8')[self.title_char_index:]
				else:
					new_title = self.title_text[self.title_char_index:]
				new_title  = new_title.encode('utf-8')				
			self.title_char_index += 1
			#if ord(new_title[0]) >  127:
			#	self.title_char_index += 1
			runtime.title.set_title(new_title)
			runtime.evas.render_now()
			return True

		self.remove_title_timer()

		# shchun: disable scrolling title : telio requested
		#if runtime.title.label_width > 240: # title width
		#	self.title_char_index = 0
		#	self.title_text = utils.get_real_lang_str(self.title)
		#	self.title_timer = runtime.evas.timeout_add(400, update_timer)
		#	#update_timer()
		runtime.title.show()

	def change_language(self):
		self.update_background_widgets()

	# KA: [20080609] sms notify
	def SMS_Notify_show(self, msg=None):
		#print 'ka..........sms_timer=',self.sms_timer
		#print 'ka..........sms_box=',self.sms_box
		#print 'ka..........sms_msg=',self.sms_msg
		#print 'ka..........play_timer=',self.play_timer
		#if self.sms_box:
		#	self.play_notify()
		#	return
		self.SMS_Notify_free()
		
		self.play_notify()	
		
		if not msg:
			msg = _('New message received.')
		icon, pos = uiconfig.sms_notify_box
		self.sms_box = utils.put_image(icon, pos)
		# ----
		utils.image_center_sized2(self.sms_box, uiconfig.sms_notify_pos, uiconfig.sms_notify_size)
		# ----
		self.sms_box.layer = 10
		self.sms_box.show()

		#icon, pos = uiconfig.second_video_call_info_icon
		#self.notify_icon = utils.put_image(icon, pos)
		#self.notify_icon.layer = 10
		#self.notify_icon.show()
		
		self.sms_msg = runtime.evas.text(text=msg,
			font=uiconfig.sms_notify_font,
			pos=uiconfig.sms_notify_pos,
			color=uiconfig.color_dark_gray)
		# ----
		x, y = uiconfig.sms_notify_pos
		self.center_align(self.sms_msg, (x, y-8))
		# ----
		self.sms_msg.layer = 10
		self.sms_msg.show()
		status.mms_notify_exist = True
		#self.notify_timer = utils.Timer(3000, self.notify_msg_free)

	def SMS_Notify_free(self):		
		if self.sms_box:
			self.sms_box.free()
		if self.sms_msg:
			self.sms_msg.free()
		self.sms_timer = None
		self.sms_box = None
		self.sms_msg = None
		self.play_timer = None
		status.mms_notify_exist = False
		
	def play_notify(self):
		utils.player.play_message_effect()

		if setting.message_interval != 1:
			self.play_timer = utils.Timer(setting.message_interval * 1000, self.playByInterval)
			#self.play_timer = utils.Timer(10000, self.playByInterval)
	def playByInterval(self):
		utils.player.play_message_effect()
		return True
		
	# KA: [20080609] sms notify ==
		

class PreviewUI(BaseUI):
	def __init__(self, left, right, title,menu3='', menu4=''):
		BaseUI.__init__(self, left, right, title, menu3, menu4)
	
		# bg image
		bg_image = utils.put_image(uiconfig.image_bg[0], (0, 0))
		bg_image.hide()
		bg_image.layer = videocall_bg_layer
		self.add(bg_image)

class WebLoadingUI(BaseUI):
	def __init__(self):
		BaseUI.__init__(self, '', '', '')
		if setting.lang == 'English':
			self.back_image = utils.put_image(uiconfig.web_waiting_image, (0, 0))
		else:
			self.back_image = utils.put_image(uiconfig.web_waiting_es_image, (0, 0))
		self.back_image.layer = 0
		self.back_image.hide()
		self.add(self.back_image)

	def show(self):
		self.update_background_widgets()
		self.back_image.show()
		runtime.evas.render()
		
class CalendarUI(BaseUI):
	def __init__(self,left,right,menu3,menu4):
		BaseUI.__init__(self,left,right,_('CALENDAR'),menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		#name,pos = uiconfig.calendar_title
		#title_image = utils.put_image(name,pos)
		#title_image.hide()
		#self.add(title_image)

		name,pos = uiconfig.calendar_bg_small
		bg_small = utils.put_image(name,pos)
		bg_small.hide()
		self.add(bg_small)


		name,pos = uiconfig.calendar_bg_note
		bg_note = utils.put_image(name,pos)
		bg_note.hide()
		self.add(bg_note)
		
#		name,pos = uiconfig.calendar_bg_large
#		bg_small = utils.put_image(name,pos)
#		bg_small.hide()
#		self.add(bg_small)

		self.focus = 0 
		self.today_focus = 0
		self.event_list = []
		
		import time,ntptime
		year,month,day,h,m,ss,w = time.localtime(setting.current_time)[:7]
		self.yy = year
		self.m = month
		self.d = day
		self.h = h
		self.min = m
		self.ss = ss
		self.w = w
		self.memo =  runtime.evas.text(text='Memo Text',font=uiconfig.alarm_font,pos=(190, 210),color=uiconfig.list_text_color)
		self.add(self.memo)
		self.show_calendar()
		self.update_calendar(year,month,day,h,m,ss,w)
		self.focus = self.today_focus
		self.set_focus(self.focus)

	def clear_events(self):
		index = 0
		while index < len(self.event_list):
			self.event_list[index].hide()
			index += 1
		
	def show(self):
		BaseUI.show(self)
		self.update_background_widgets()
		self.update_calendar(self.yy, self.m, self.d, self.h, self.min, self.ss, self.w)		
		self.set_focus(self.focus)
		
	def update_calendar(self,year,month,day,h,m,ss,w):		
		import time,ntptime
		self.month.file = uiconfig.image_dir + uiconfig.calendar_month[month-1]
		self.year1.file = uiconfig.image_dir + uiconfig.calendar_year[int(year/1000)]	
		ye = year
		ye = ye % 1000
		self.year2.file = uiconfig.image_dir + uiconfig.calendar_year[int(ye/100)]		
		ye = ye % 100
		self.year3.file = uiconfig.image_dir + uiconfig.calendar_year[int(ye/10)]		
		ye = ye % 10
		self.year4.file = uiconfig.image_dir + uiconfig.calendar_year[int(ye)]		
		c = time.localtime(time.mktime((year,month,1,h,m,0,0,0,0)))[6]		
		c = (c + 2) 

		if config.monday_first:
			c-=1
			
		if c > 7:
			c = c % 7
		i = 1
		self.calendar_today.hide()
		while i < len(self.arr_cal):
			self.arr_cal[i].hide()			
			i = i + 1
		d = 1
		i = c - 1
		j = 0
		
		while i >=1:
			if month == 1:
				self.arr_cal[i].text_set('%02d'%int(self.Max_Month(12,year) - j))
				self.date[i][0] = year - 1
				self.date[i][1] = 12
				self.date[i][2] = int(self.Max_Month(12,year) - j)
			else:
				self.arr_cal[i].text_set('%02d'%int(self.Max_Month(int(month) -1,year) - j))
				self.date[i][0] = year 
				self.date[i][1] = month - 1
				self.date[i][2] = int(self.Max_Month(int(month) -1,year) - j)
			self.arr_cal[i].color = 147,148,149,255
			self.arr_cal[i].show()
			i = i -1
			j = j + 1
		i = c

		cur_year,cur_month = time.localtime(setting.current_time)[:2]

		self.clear_events()

		# 이번 달 중 event가 등록된 날 검색
		from calendardb import calendardb
		event_days = calendardb.get_event_days_of_the_month(year, month)
		
        	while d <= self.Max_Month(month,year):
        		self.date[i][0] = year 
			self.date[i][1] = month 
			self.date[i][2] = d

			blue_index=0
			red_index=1
			if config.monday_first:
				blue_index=6
				red_index=0
			
			if i % 7 ==red_index and i > 1: 										# Sunday - RED
				self.arr_cal[i].text_set('%02d'%d)
				self.arr_cal[i].color = 227, 10, 10, 255#255,0,0,255
				if d == day and month == cur_month and year == cur_year: # TODAY
					self.arr_cal[i].color = 85,2,255,255 #uiconfig.color_white
					self.calendar_today.pos = uiconfig.calendar_select_pos[i-1]
					self.calendar_today.show()
					self.today_focus = i - 1
				elif d in event_days:									# EVENT DAY
					self.arr_cal[i].color = 85,2,255,255 # uiconfig.color_white
					self.event_list[d-1].pos =  uiconfig.calendar_select_pos[i-1]
					self.event_list[d-1].show()

			elif i % 7 == blue_index and i > 1: 							# Saturday - BLUE
				self.arr_cal[i].text_set('%02d'%d)
				self.arr_cal[i].color = 2, 95, 209, 255#0,94,211,255
				if d == day and month == cur_month and year == cur_year: # TODAY
					self.arr_cal[i].color = 85,2,255,255 #uiconfig.color_white
					self.calendar_today.pos = uiconfig.calendar_select_pos[i-1]
					self.calendar_today.show()
					self.today_focus = i - 1
				elif d in event_days:									# EVENT DAY
					self.arr_cal[i].color = 85,2,255,255  #uiconfig.color_white
					self.event_list[d-1].pos =  uiconfig.calendar_select_pos[i-1]
					self.event_list[d-1].show()
			else: 											# Normal day - BLACK
				self.arr_cal[i].text_set('%02d'%d)
				self.arr_cal[i].color = uiconfig.color_black #uiconfig.color_dark_gray
          			if d == day and month == cur_month and year == cur_year: # TODAY
					self.arr_cal[i].color = 85,2,255,255 # uiconfig.color_white
					self.calendar_today.pos = uiconfig.calendar_select_pos[i-1]
					self.calendar_today.show()
					self.today_focus = i - 1
				elif d in event_days:									# EVENT DAY
					self.arr_cal[i].color = 85,2,255,255  #uiconfig.color_white
					self.event_list[d-1].pos =  uiconfig.calendar_select_pos[i-1]
					self.event_list[d-1].show()
					
			self.arr_cal[i].show()
			
			d += 1
			i += 1
			
		j = 1
		while i <= 42:
			self.arr_cal[i].text_set('%02d'%j)
			if month < 12:
				self.date[i][0] = year
				self.date[i][1] = month + 1
				self.date[i][2] = j
			else:
				self.date[i][0] = year + 1
				self.date[i][1] = 1
				self.date[i][2] = j
			self.arr_cal[i].color = 147,148,149,255
			self.arr_cal[i].show()
			i = i + 1
			j = j + 1		
		
	def set_focus(self, i, show_method=False):
		from calendardb import calendardb
		self.focus = i
		self.calendar_select.pos = uiconfig.calendar_select_pos[self.focus]
		memo_full_text = '%s'%calendardb.get_date(self.date[i + 1][0],self.date[i + 1][1],self.date[i + 1][2])
		memo_text = utils.cut_text(text=memo_full_text, width=250, font=uiconfig.alarm_font)[0]
		self.memo.text_set(memo_text)

	def handle_key(self, key):
		y, x = divmod(self.focus, 7)		 
		if key == 'Left':
			x -= 1
			if x < 0:
				x = 6
				if y == 0:
					y = 5
					self.m -= 1
					if self.m < 1: 
						if self.yy == 1902:
							self.m = 1
							x = 0
							y = 0
						else:
							self.m = 12
							self.yy -= 1						
					
				else:
					y -= 1
		elif key == 'Right':
			x += 1
			if x > 6:
				x = 0
				if y == 5:
					y = 0
					self.m += 1
					if self.m > 12: 
						if self.yy == 2037:
							self.m = 12
							x=6
							y=5
						else:
							self.m = 1
							self.yy += 1	
				else:
					y += 1
		elif key == 'Up':
			y -= 1
			if y < 0:
				y = 5
				self.m -= 1
				if self.m < 1: 
					if self.yy == 1902:
						self.m = 1
						y=0
					else:
						self.m = 12
						self.yy -= 1
		elif key == 'Down':
			y += 1
			if y > 5:
				y = 0
				self.m += 1
				if self.m > 12: 
					if self.yy == 2037:
						self.m = 12
						y=5
					else:
						self.m = 1
						self.yy += 1
		elif key == '1': # to previous year
			if self.yy > 1902:
				self.yy -= 1
		elif key == '3': # to next year
			if self.yy < 2037:	
				self.yy += 1
		elif key == '5' or key == config.Menu3:
			year,month,day,h,m,ss,w = time.localtime(setting.current_time)[:7]
			self.yy = year
			self.m = month
			self.d = day
		elif key == '9': # to next month
			self.m += 1
			if self.m > 12: 
				if self.yy == 2037:
					self.m = 12
				else:
					self.m = 1
					self.yy += 1
		elif key == '7': # to previous month
			self.m -= 1
			if self.m < 1: 
				if self.yy == 1902:
					self.m = 1
				else:
					self.m = 12
					self.yy -= 1	
		else:
			return False
		
		self.update_calendar(self.yy,self.m,self.d,self.h,self.min,self.ss,self.w)
		if key == '5' or key == config.Menu3:
			self.set_focus(self.today_focus)
		else:
			self.set_focus(x + y * 7)
		return True
		
   	def Max_Month(self,month,year):
        	if month in [1,3,5,7,8,10,12]:
            		return 31
        	elif month in [4,6,9,11]:
            		return 30
        	elif (month == 2) and (year % 4 == 0):
            		return 29
        	elif (month == 2) and (year % 4 != 0):
            		return 28
            		
	def show_calendar(self):
		import time,ntptime
		year,month,day,h,m,ss,w = time.localtime(setting.current_time)[:7]	
		self.date = []
		#Thang [20080419 -1 ] ===============
		pos = uiconfig.calendar_month_pos
		name = uiconfig.calendar_month[month-1]
		self.month = utils.put_image(name,pos)
		self.add(self.month)		
		
		self.year1 = utils.put_image(uiconfig.calendar_year[int(year/1000)],uiconfig.calendar_year_pos[0])
		self.add(self.year1)
	
		
		year = year % 1000
		self.year2 = utils.put_image(uiconfig.calendar_year[int(year/100)],uiconfig.calendar_year_pos[1])
		self.add(self.year2)
		
		
		year = year % 100
		self.year3 = utils.put_image(uiconfig.calendar_year[int(year/10)],uiconfig.calendar_year_pos[2])
		self.add(self.year3)
		
		
		year = year % 10
		self.year4 = utils.put_image(uiconfig.calendar_year[int(year)],uiconfig.calendar_year_pos[3])
		self.add(self.year4)		
		
		name, pos = uiconfig.calendar_today,uiconfig.calendar_select_pos[self.focus]
		self.calendar_today = utils.put_image(name,pos)
		self.add(self.calendar_today)
		self.calendar_today.hide()

		index = 0
		while index < 31:
			name, pos = uiconfig.calendar_event,uiconfig.calendar_select_pos[self.focus]
			event_day = utils.put_image(name,pos)
			self.add(event_day)
			self.event_list.append(event_day)
			event_day.hide()
			index += 1

		name, pos = uiconfig.calendar_select,uiconfig.calendar_select_pos[self.focus]
		self.calendar_select = utils.put_image(name,pos)
		self.add(self.calendar_select)
		################################

		if config.monday_first:
			weektext = [_('Mon'),_('Tue'),_('Wed'),_('Thu'),_('Fri'),_('Sat'),_('Sun')]
		else:
			weektext = [_('Sun'), _('Mon'),_('Tue'),_('Wed'),_('Thu'),_('Fri'),_('Sat')]
		d = 0
		x = 42
		while d < 7: 
			blue_index=6
			red_index=0
			if config.monday_first:
				blue_index=5
				red_index=6
			if d == blue_index:
				lcolor = 0,94,211,255
			elif d == red_index:
				lcolor = 255,0,0,255
			else:
				lcolor = uiconfig.list_text_color
            		t =  runtime.evas.text(text=weektext[d],font=uiconfig.alarm_font,pos=(140 + 35 + x * d, 50),color=lcolor)			
			self.add(t)
			d = d + 1	
			
		################################
	
		self.arr_cal = []		
		d = 1
		y = 72			
		x = 42		
		i = 0		
		self.arr_cal.insert(0,'Calendar')
		self.date.insert(0,(year,month,day))
		co = 1

		
		while d <= 42: 
            		t =  runtime.evas.text(text='%02d'%d,font=uiconfig.alarm_font,pos=(133 + x * co, y),color=uiconfig.list_text_color)			
			i = i + 1
			self.arr_cal.insert(i, t)
			self.date.insert(i,[year,month,day])
			self.add(self.arr_cal[i])    
			self.arr_cal[i].hide()			
			if co % 7 == 0:		
            			y = y + 21           			
            			co = 0
            		d = d + 1	
            		co = co + 1	

class CalculatorUI(BaseUI):
	def __init__(self,left,right,menu3,menu4):
		BaseUI.__init__(self,left,right,_('CALCULATOR'),menu3, menu4)
		#CalculatorWindowUI.__init__(self,left,right,menu3,menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
	
		cal_bg_image = utils.put_image(uiconfig.cal_bg_image,(94,38))
		cal_bg_image.hide()
		cal_bg_image.layer = -2
		self.add(cal_bg_image)
 
		pos = uiconfig.entry_info_pos
		font = uiconfig.entry_info_font
		color = uiconfig.entry_info_color

		self.einfo = widget.OutlineLabel('', font, pos, color, align=uiconfig.ALIGN_RIGHT)
		self.add(self.einfo)

		width, height = uiconfig.entry_size_1
		import entry
		self.entry_1= entry.Entry(pos=(115,50), size=(250,25))
		self.entry_1.set_text('')		# for cursor position
		self.add(self.entry_1)		
		self.t9mode = False
		self.automata_icon = None
		self.automata_idx = 0
		self.automata = None, None
		self.def_left = left
		self.menu3 = menu3
		self.fixed_automata = False
	
	def destroy(self):
		BaseUI.destroy(self)

	def show(self):
		BaseUI.show(self)

	def hide(self):
		BaseUI.hide(self)

	def set_automata(self, name, casemode='lower'):
		self.entry_1.set_automata(name, casemode)
		if name == 't9':
			self.t9mode = True
		else:
			self.t9mode = False

		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)

		self.automata = name, casemode

	def get_text(self):
		return self.entry_1.get_text()

	def set_text(self, text):
		self.entry_1.set_text(text)
		self.update_entry_info()

	def insert_text(self, text):
		self.entry_1.insert_unicode_text(unicode(text, 'utf-8'))
		self.entry_1._automata.check_start_of_sentance()
		self.update_entry_info()

	def delete_char(self):
		self.handle_key('\b')
		self.update_entry_info()

	def insert_symbol(self, s):
		before_text = self.get_text()
		self.insert_text(s)
		after_text = self.get_text()
		if before_text == after_text:
			from basemodel import NotifyStage
			runtime.manager.change_stage(NotifyStage(_('Max length exceeded'), uiconfig.baloon_message_icon))
		else:
			runtime.manager.back_stage()
			
	def reset_automata(self):
		self.entry_1._automata.reset()

	def update_entry_info(self):
		if self.entry_1.get_max():
			self.set_entry_info( '%d/%d' % (self.entry_1.length(), self.entry_1.get_max()) )

#		if self.is_t9_add_word_mode():
		#	self.set_left(_('OK'))
		#else:
		#self.set_left(_('OPTION'))

		if self.get_text():
			self.set_menu3(_('CLEAR'))
		else:
			self.set_menu3(self.menu3)
			return
			
	def handle_key(self,key):
		if (key == 'SOFT3' or key == 'CLR') and self.menu3==_('CLEAR'):
			self.delete_char()
			self.update_entry_info()
			return True
		if key == config.CLEAR_LONG and self.menu3==_('CLEAR'):
			self.entry_1.handle_key(key)
			self.update_entry_info()
			return True

		if key == '0':
			if len(self.entry_1.get_text()) == 0:
				return True
		
		ret = self.entry_1.handle_key(key)
		if ret:
			self.update_entry_info()
		return ret
		
#Thang [20080409 - 1] show multiimages
class PhotoGalleryMultiUI(BaseUI):
	def __init__(self,left,right,menu3,menu4):
		BaseUI.__init__(self,left,right,'',menu3, menu4)
		import model
		listmenu_image = uiconfig.menu_bg_image[model.menu_bg_style]
		bg_image = utils.put_image(listmenu_image, (0, 0))
		bg_image.hide()
		self.add(bg_image)		
		#name, pos = uiconfig.title_photogallery
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)
		
		name, pos = uiconfig.image_filename_bg
		filename_bg = utils.put_image(name, pos)
		filename_bg.hide()
		self.add(filename_bg)
		
		self.focus_bg = ('photo_select.png', 'photo_select.png', 'photo_select.png', 'photo_select.png', \
				'photo_select.png', 'photo_select.png','photo_select.png', 'photo_select.png')
		self.focus_bg_image = utils.put_image(self.focus_bg[0], uiconfig.image_photo_select_pos[0])
		self.focus_bg_image.hide()
		self.add(self.focus_bg_image)
		self.set_focus(0)
		
	def set_focus(self, i, show_method=False):
		self.focus = i			
		self.focus_bg_image.file = uiconfig.image_dir  + self.focus_bg[self.focus]
		self.focus_bg_image.pos = uiconfig.image_photo_select_pos[self.focus]		

	def handle_key(self, key):
		y, x = divmod(self.focus, 3)
		if key == 'Left':
			x -= 1
			if x < 0:
				x = 2
				if y == 0:
					y = 1
				else:
					y -= 1
		elif key == 'Right':
			x += 1
			if x > 2:
				x = 0
				if y == 1:
					y = 0
				else:
					y += 1
		elif key == 'Up':
			y -= 1
			if y < 0:
				y = 1
				x -= 1
				if x < 0:
					x = 2
		elif key == 'Down':
			y += 1
			if y > 1:
				y = 0
				x += 1
				if x > 2:
					x = 0
		else:
			return False
		self.set_focus(x + y * 3)
		return True

class PrivacySettingUI(BaseUI):
	def __init__(self,left,right,menu3,menu4):
		BaseUI.__init__(self,left,right,_('SUBSTITUTE SETTING'),menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image,(0,0))
		#bg_image.hide()
		#self.add(bg_image)
		
		#name,pos =uiconfig.setting_privacy_title		
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)
		
	def set_catalog(self,choose):
		self.catalog = controls.ListBox_Control(choose, 1, font=uiconfig.input_font, pos=uiconfig.setting_privacy_box1_pos, color=uiconfig.list_text_color,mode=uiconfig.LIST_MODE_MEDIUM)
		self.add(self.catalog)
		
	def set_files(self,choose):
		self.files = controls.ListBox_Control(choose, 0, font=uiconfig.input_font, pos=uiconfig.setting_privacy_box2_pos, color=uiconfig.list_text_color,mode=uiconfig.LIST_MODE_MEDIUM)
		self.add(self.files)
		
	def set_image(self,filename):
		if filename == '':
			filename = 'images/tde_logo_small.jpg'
		self.image = controls.Image_Control(filename, pos=uiconfig.setting_privacy_img1_pos, size=uiconfig.setting_privacy_img_size)
		self.add(self.image)
		
	def set_imagebg(self,filename,pos):
		self.image = controls.Image_Control(filename,pos)
		self.add(self.image)
		
	def set_icon(self,filename,pos):
		self.icon = controls.Icon_Control(filename,pos)
		self.add(self.icon)
		
	def set_label(self,txt_value,pos):
		self.lbl_image = controls.Label_Control(txt_value, font=uiconfig.input_font, pos=pos, color=uiconfig.list_text_color)	
		self.add(self.lbl_image)
				
#Thang [20080409 - 1] show multiimages
class BackGroundUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, menu3, menu4):

		BaseUI.__init__(self, left, right, _('SELECT BACKGROUND'), menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0,0))
		#bg_image.hide()
		#self.add(bg_image)
		
		#name, pos =uiconfig.setting_bg_title		
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)	
	def set_catalog(self, choose, pos):
		self.catalog = controls.ListBox_Control(choose, 0, font=uiconfig.input_font, pos=pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		self.add(self.catalog)
	def set_files(self, choose, pos):
		self.files = controls.ListBox_Control(choose, 0, font=uiconfig.input_font, pos=pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		self.add(self.files)
	def set_imagebg(self, filename, pos):
		self.image = controls.Image_Control(filename, pos)
		self.add(self.image)
	def set_image(self, filename, pos, size):
		self.image = controls.Image_Control(filename, pos, size)
		self.add(self.image)
	def set_icon(self, filename, pos):
		self.icon = controls.Icon_Control(filename, pos)
		self.add(self.icon)
	def set_label(self, txt_value, pos):
		self.lbl_image = controls.Label_Control(txt_value, font=uiconfig.input_font, pos=pos, color=uiconfig.list_text_color)	
		self.add(self.lbl_image)
		
class WorldTimeUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left,right,menu3,menu4,title=_('WORLD TIME')):
		BaseUI.__init__(self,left,right,title,menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image,(0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#titleimage = uiconfig.worldtime_title
		#name = titleimage
		#pos = uiconfig.worldtime_title_pos
		##size = uiconfig.worldtime_title_size
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)	

		pos = uiconfig.worldtime_background_pos
		size = uiconfig.worldtime_background_size
		worldtime_bg_image = utils.put_image(uiconfig.worldtime_background , pos)
		worldtime_bg_image.hide()
		self.add(worldtime_bg_image)

		
class DSTEnableUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left,right,menu3,menu4):
		BaseUI.__init__(self,left,right,'',menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image,(0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#titleimage = uiconfig.worldtimeset_title
		#name = titleimage
		#pos = uiconfig.worldtime_title_pos
		##size = uiconfig.worldtime_title_size
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)	


class CheckPasswordUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left,right,menu3,menu4):
		BaseUI.__init__(self,left,right,_('PASSWORD'),menu3, menu4)

		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#title_image = utils.put_image(uiconfig.tits_password, uiconfig.menu_tits_pos)
		#title_image.hide()
		#self.add(title_image)	

		icon_image = utils.put_image(uiconfig.img_password, uiconfig.img_password_pos)
		icon_image.hide()
		self.add(icon_image)

		# icon
		ico_password = utils.put_image(uiconfig.icon_password, (uiconfig.pw_entry_pos_x1, uiconfig.pw_entry_pos_y1+4))
		ico_password .hide()
		self.add(ico_password)


class ChangePasswordUI(BaseUI):
	background_color = uiconfig.color_white
	show_bg_depth = True
	def __init__(self, left, right, menu3, menu4, digit_max_len):
		BaseUI.__init__(self, left, right, _('PASSWORD SETTING'), menu3, menu4)
		
		self.list = None
		self.display_idx = 0
		self.digit_max_len = digit_max_len

		self.frame = []
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#title_image = utils.put_image(uiconfig.tits_password_set, uiconfig.menu_tits_pos)
		#title_image.hide()
		#self.add(title_image)	

		icon_image = utils.put_image(uiconfig.img_password, uiconfig.img_password_pos)
		icon_image.hide()
		self.add(icon_image)

		# new password
		pos = (uiconfig.pw_entry_pos_x1, uiconfig.pw_entry_pos_y2[0]+4)
		new_pw_icon = controls.Icon_Control(uiconfig.icon_password_new, pos=pos)
		pos = (uiconfig.pw_entry_pos_x2, uiconfig.pw_entry_pos_y2[0]+16-uiconfig.input_font[1]/2-2)
		new_pw_label = controls.Label_Control(_('New passwd'), font=uiconfig.input_font, pos=pos, color=uiconfig.list_text_color)
		pos = (uiconfig.pw_entry_pos_x3, uiconfig.pw_entry_pos_y2[0])
		new_pw_entry = controls.Input_Control(pos=pos, size=uiconfig.pw_entry_size)
		#new_pw_entry.set_text(digit_max_len)
		new_pw_entry.set_max(digit_max_len)
		self.frame.append((new_pw_icon, new_pw_label, new_pw_entry))
		
		# confirm password
		pos = (uiconfig.pw_entry_pos_x1, uiconfig.pw_entry_pos_y2[1]+4)
		confirm_pw_icon = controls.Icon_Control(uiconfig.icon_confirm, pos=pos)
		pos = (uiconfig.pw_entry_pos_x2, uiconfig.pw_entry_pos_y2[1]+16-uiconfig.input_font[1]/2-2)
		confirm_pw_label = controls.Label_Control(_('Re input'), font=uiconfig.input_font, pos=pos, color=uiconfig.list_text_color)
		pos = (uiconfig.pw_entry_pos_x3, uiconfig.pw_entry_pos_y2[1])
		confirm_pw_entry = controls.Input_Control(pos=pos, size=uiconfig.pw_entry_size)
		#confirm_pw_entry.set_text(digit_max_len)
		confirm_pw_entry.set_max(digit_max_len)
		self.frame.append((confirm_pw_icon, confirm_pw_label, confirm_pw_entry))
		
		unselbarpos = []
		self.set_list(self.frame, unselbarpos)
		
	def set_list(self, frame, unselbarpos=[]):
		self.list = widget.ChangePassword(frame, unselbarpos)
		self.add(self.list)

	def update_lists(self, labels, unselbarpos=[]):
		self.list.free()
		self.widgets.remove(self.list)		
		self.add(self.list)

	def destroy(self):
		BaseUI.destroy(self)

	def show(self):
		BaseUI.show(self)

	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		pass
		
	def set_text(self, n, text):
		self.list.set_text(n, text)

	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)

	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):		
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)
		self.automata = name, casemode

	def update_automata_icon(self,entry):				
		name = entry._automata.name()		
		casemode = entry._automata.case_mode()
		self.automata = name, casemode
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')		# ka...hangul add 2007.01.23
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)

	def get_text(self):
		return self.entry.get_text()

	def handle_key(self, keyname):	
		if keyname == 'Up':
			self.list.focus_up()			
			return True
		elif keyname == 'Down':
			self.list.focus_down()			
			return True			
		return True


class NetworkRegisterUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left,right,menu3,menu4,digit_max_len=255):
		BaseUI.__init__(self,'','','',menu3, menu4)

		#bg_image = utils.put_image(uiconfig.depth_bg_image,(0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#titleimage = uiconfig.tits_password
		#name = titleimage
		#pos = uiconfig.menu_tits_pos
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)	

		icon_image1 = utils.put_image(uiconfig.network_icon_image1,(50,48))
		icon_image1.hide()
		self.add(icon_image1)

		icon_image2 = utils.put_image(uiconfig.network_icon_image2,(60,90))
		icon_image2.hide()
		self.add(icon_image2)

		icon_image3 = utils.put_image(uiconfig.network_icon_image2,(60,123))
		icon_image3.hide()
		self.add(icon_image3)
		
		icon_image4 = utils.put_image(uiconfig.network_icon_image2,(60,156))
		icon_image4.hide()
		self.add(icon_image4)

		icon_image5 = utils.put_image(uiconfig.network_icon_image2,(60,189))
		icon_image5.hide()
		self.add(icon_image5)

		icon_image6 = utils.put_image(uiconfig.network_icon_image2,(60,222))
		self.add(icon_image6)
		
		self.list = None
		self.display_idx = 0
		self.digit_max_len = digit_max_len

		item = None
		self.icon_cols = []
		self.icons = {}
		self.frame = []
		item = ['DHCP','STATIC']
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		choose = ('DHCP','STATIC')
		ind_group = self.find_pos(item[0],choose)
		choice_group = controls.Label_Control(text ='Choice', font=uiconfig.pb_entry_font, pos=(78,57), color=uiconfig.list_text_color)
		group = controls.ListBox_Control(choose,ind_group, font=uiconfig.pb_entry_font, pos=(210,44), color=uiconfig.list_text_color)
		group.size = (228,32)
		self.frame.append((choice_group,group))
		
		ip_address = controls.Label_Control('IP Address', font=uiconfig.pb_entry_font,pos = (78,90), color=uiconfig.list_text_color)
		ip_address_entry = controls.Input_Control(pos=(210,77), size=(228,32))
		ip_address_entry.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((ip_address,ip_address_entry))
		
		sub_address = controls.Label_Control('Subnetmask', font=uiconfig.pb_entry_font,pos = (78,123), color=uiconfig.list_text_color)
		sub_address_entry = controls.Input_Control(pos=(210,110), size=(228,32))
		sub_address_entry.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((sub_address,sub_address_entry))

		gw_address = controls.Label_Control('Default Gateway', font=uiconfig.pb_entry_font,pos = (78,156), color=uiconfig.list_text_color)
		gw_address_entry = controls.Input_Control(pos=(210,143), size=(228,32))
		gw_address_entry.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((gw_address,gw_address_entry))

		DNS1_address = controls.Label_Control('DNS1', font=uiconfig.pb_entry_font,pos = (78,189), color=uiconfig.list_text_color)
		DNS1_address_entry = controls.Input_Control(pos=(210,176), size=(228,32))
		DNS1_address_entry.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((DNS1_address,DNS1_address_entry))

		DNS2_address = controls.Label_Control('DNS2', font=uiconfig.pb_entry_font,pos = (78,222), color=uiconfig.list_text_color)
		DNS2_address_entry = controls.Input_Control(pos=(210,209), size=(228,32))
		DNS2_address_entry.set_max(uiconfig.MAX_INPUT_IP)
		self.frame.append((DNS2_address,DNS2_address_entry))
		
		unselbarpos = []
		self.set_list(self.frame, unselbarpos)

	def find_pos(self,values,list):
		i = 0		
		for chk in list:
			if str(chk).lower() == str(values).lower():
				return i
			else:
				i = i + 1
		return 0	
	def set_list(self, frame, unselbarpos=[]):
		roxia_trace('ListControlUI.set_list(), frame=', frame)
		self.list = widget.NetworkRegister(frame, unselbarpos)
		self.add(self.list)

	def update_lists(self, labels, unselbarpos=[]):
		self.list.free()
		self.widgets.remove(self.list)		
		self.add(self.list)

	def destroy(self):
		BaseUI.destroy(self)

	def show(self):
		BaseUI.show(self)

	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		pass
		
	def set_text(self, n, text):
		self.list.set_text(n, text)

	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)

	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):		
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)
		self.automata = name, casemode

	def update_automata_icon(self,entry):				
		name = entry._automata.name()		
		casemode = entry._automata.case_mode()
		self.automata = name, casemode
		if name == '123':		menu3 = '123'
# ka...hangul add 2007.01.23
		elif name == 'hangul':	menu3 = _('KOR')
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)

	def get_text(self):
		return self.entry.get_text()

	def handle_key(self, keyname):	
		if keyname == 'Up':
			self.list.focus_up()			
			return True
		elif keyname == 'Down':
			self.list.focus_down()			
			return True			
		return True


class PopupWindowUI(BaseUI):
	def __init__(self, left, right, menu3, menu4, title=''):
		BaseUI.__init__(self, left, right, title, menu3, menu4)

		# pop window image
		self.image = utils.put_image(uiconfig.pop_window_image, uiconfig.pop_window_image_pos)
		self.add(self.image)

		# title icon
		self.icon = utils.put_image(uiconfig.pop_window_icon, uiconfig.pop_window_icon_pos)
		self.add(self.icon)

		# title text
		font = uiconfig.pop_window_title_font
		color = uiconfig.pop_window_title_color
		self.label = widget.OutlineLabel(title, font, uiconfig.pop_window_title_pos, color, align=uiconfig.ALIGN_LEFT)
		self.add(self.label)

	def destroy(self):
		BaseUI.destroy(self)
		
	def show(self):
		BaseUI.show(self)
		
	def hide(self):
		BaseUI.hide(self)
		
	def set_info(self, text):
		self.label.set_text(text)


class AutoAnswerSettingUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left,right,menu3,menu4):
		BaseUI.__init__(self,left,right,_('AUTO ANSWER SETTING'),menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image,(0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#titleimage = uiconfig.answering_title
		#name = titleimage
		#pos = uiconfig.answering_title_pos
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)	

		deltay_xxx = uiconfig.worldtime_text_font[1]/2+2

		icon_ans_image = utils.put_image(uiconfig.icon_ans_image,(83,87))
		icon_ans_image.hide()
		self.add(icon_ans_image)

		icon_ansmode_image = utils.put_image(uiconfig.icon_ansmode_image,(83,121))
		icon_ansmode_image.hide()
		self.add(icon_ansmode_image)

		'''
		icon_anstime_image = utils.put_image(uiconfig.icon_anstime_image,(83,121))
		icon_anstime_image.hide()
		self.add(icon_anstime_image)

		icon_ansmode_image = utils.put_image(uiconfig.icon_ansmode_image,(83,155))
		icon_ansmode_image.hide()
		self.add(icon_ansmode_image)
		'''

		ans_text = runtime.evas.text(text=_('Set'),pos=(114,99-deltay_xxx),color=uiconfig.worldtime_text_color,font=uiconfig.worldtime_text_font)
		self.add(ans_text)

		ansmode_text = runtime.evas.text(text=_('Token'),pos=(114,133-deltay_xxx),color=uiconfig.worldtime_text_color,font=uiconfig.worldtime_text_font)
		self.add(ansmode_text)

		'''
		anstime_text = runtime.evas.text(text='Time',pos=(114,133-deltay_xxx),color=uiconfig.worldtime_text_color,font=uiconfig.worldtime_text_font)
		self.add(anstime_text)

		ansmode_text = runtime.evas.text(text='Token',pos=(114,167-deltay_xxx),color=uiconfig.worldtime_text_color,font=uiconfig.worldtime_text_font)
		self.add(ansmode_text)
		'''


class MissCallMessageUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left,right,menu3,menu4):
		BaseUI.__init__(self,left,right,_('MISSED CALL MESSAGE'),menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image,(0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#titleimage = uiconfig.missedcallmsg_title
		#name = titleimage
		#pos = uiconfig.missedcallmsg_title_pos
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		
class ListUI(BaseUI):
	# yylee modified to add new soft key
	# start shchun : add additional argument, x, numcol May-11
	show_bg_depth = True
	def __init__(self, left, right, title=None, menu3='', menu4='', titleimage=None, icon=None, num_col =True, x = uiconfig.list_pos_x):
	#def __init__(self, left, right, title=None, titleimage=None, icon=None):
		self.num_col = num_col
		self.x = x 
		# end shchun
		BaseUI.__init__(self, left, right, title, menu3, menu4)
		#titleimage = None
		self.list = None
		title = None
#		self.top_image = utils.put_image(uiconfig.current_theme.indicator_bar, (0, 0))
#		self.top_image.layer = title_image_layer
#		self.top_image.hide()
#		self.add(self.top_image)
		import model

		#print model.menu_bg_style
		#listmenu_image = uiconfig.menu_bg_image[model.menu_bg_style]
		#bg_image = utils.put_image(listmenu_image, (0, 0)) #24
		#bg_image.hide()
		#self.add(bg_image)
		#if titleimage:
		#	name, pos = titleimage
		#	title_image = utils.put_image(name, pos)
		#	title_image.hide()
		#	self.add(title_image)

		if icon:
			name, pos = icon
			image = utils.put_image(name, pos)
			image.hide()
			self.add(image)

		self.icon_cols = []
		self.icons = {}
		
	#thang [20080315] -2 setup icon image for 2 depth
	def set_list(self, labels, unselbarpos=[]):
		#roxia_trace('ListUI.set_list(), lables=', labels)
		# start shchun : add additional argument, x, numcol May-11
		self.list = widget.List(labels, unselbarpos, num_col = self.num_col, x = self.x)
		# end shchun
		self.add(self.list)		
		if len(uiconfig.list_icon_cnt) >= len(labels) and len(labels) > 0:
			self.icon_cols = uiconfig.list_icon_cnt[0:len(labels)]
			self.list.remove_all_icon_columns()
			self.create_icon_column(241,self.icon_cols)
	
	#thang [20080315] -2 setup icon image for 2 depth
	def create_icon_column(self, x, icons, resize=[0,0]):
		ic = widget.IconColumn(x, icons, resize)
		self.list.attach_icon_column(ic)
		self.icon_cols.append(ic)
		self.add(ic)

	def remove_all_icon_columns(self):
		self.list.remove_all_icon_columns()
		for ic in self.icon_cols:
			# start shchun : add safety code May-11
			try:
				self.widgets.remove(ic)
				ic.free()
			except:
				pass
				#print 'EXCEPT remove_all_icon_columns() ic == ', ic, 'icon_cols == ', self.icon_cols
			# end shchun
		self.icon_cols = []

	def handle_key(self, keyname):		
		if keyname == 'Up':
			self.list.focus_up()			
			return True
		elif keyname == 'Down':
			self.list.focus_down()			
			return True
		return False

	def update_lists(self, labels, unselbarpos=[]):		
		self.list.free()
		self.widgets.remove(self.list)
		self.list = widget.List(labels, unselbarpos)
		self.add(self.list)			
		if len(uiconfig.list_icon_cnt) >= len(labels) and len(labels) > 0:			
			self.icon_cols = uiconfig.list_icon_cnt[0:len(labels)]		
			self.list.remove_all_icon_columns()
			self.create_icon_column(241,self.icon_cols)	  
		
	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		self.list.set_focus(focus)

	def set_text(self, n, text):
		self.list.set_text(n, text)

	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)

#	def change_theme(self):
#		self.top_image.file = uiconfig.image_dir + uiconfig.current_theme.indicator_bar
#		self.list.change_theme()
class PhotoGalleryCheckListUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right,menu3,menu4, titleimage=None):

		BaseUI.__init__(self, left, right,'',menu3,menu4)
		
		self.list = None
		
		import model
		#listmenu_image = uiconfig.menu_bg_image[model.menu_bg_style]
		#bg_image = utils.put_image(listmenu_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		#if titleimage==None:
		#	name, pos = uiconfig.title_photogallery
		#else:
		#	name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		name, pos = uiconfig.image_bg_list
		bg_list = utils.put_image(name,pos)
		bg_list.hide()
		self.add(bg_list)

		self.icon_cols = []
		self.icons = {}
		self.image = None
		self.file_detail = runtime.evas.text(text='',
			font=uiconfig.image_list_text_font,
			pos=uiconfig.image_list_text_pos,
			color=uiconfig.image_list_text_color)
		self.add(self.file_detail)

		self.file_detail_center = 92, uiconfig.image_list_text_pos[1]
		self.align_center(self.file_detail, self.file_detail_center)
		
	def set_list(self, labels, unselbarpos=[]):
		#roxia_trace('ListUI.set_list(), lables=', labels)
		self.list = widget.ChkList(labels, unselbarpos)
		self.add(self.list)

		for ic in self.icon_cols:
			self.list.attach_icon_column(ic)
			
	def set_preview(self, file, pre_flag=0):	
		try:
			file = unicode(file,'utf-8').encode('euc-kr')
		except:
			pass
		import os 
		if not os.access(file, os.R_OK):
			return False
		if not utils.image_isvalid(file):
			file = '/usr/local/lgvp/images/image_big.png'
			tmp_w = 0
			tmp_h = 0
		else:
			tmp_w, tmp_h = utils.get_img_size(file)
			if tmp_w * tmp_h > 640 * 480:
				file = '/usr/local/lgvp/images/image_big.png'
				
		if not self.image:
			self.image = utils.put_image(file, uiconfig.gallery_small_pos)
			self.add(self.image)
		else:
			self.image.file = utils.changefile_gif(file)
		x, y = uiconfig.image_list_small_pos
		w, h = uiconfig.image_list_small_size		
		#utils.image_center_sized(self.image, x + w/2, y + h/2, w, h)
		utils.image_sized(self.image, (x, y), (w, h))
		runtime.evas.render_now()	
		self.file_detail.text_set('%dx%d'%(tmp_w, tmp_h))
		
		self.align_center(self.file_detail, self.file_detail_center)
		
	def align_center(self, l, pos):
		x, y = pos
		width,height = l.size
		l.move(x - width/2, y)
		
	def create_icon_column(self, x, icons, resize=[0,0]):
		ic = widget.IconColumn(x, icons, resize)
		self.list.attach_icon_column(ic)
		self.icon_cols.append(ic)
		self.add(ic)

	def remove_all_icon_columns(self):
		self.list.remove_all_icon_columns()
		for ic in self.icon_cols:
			self.widgets.remove(ic)
			ic.free()
		self.icon_cols = []

	def handle_key(self, keyname):
		if keyname == 'Up':
			self.list.focus_up()
			return True
		elif keyname == 'Down':
			self.list.focus_down()
			return True
		return False

	def update_lists(self, labels, unselbarpos=[]):
		self.list.free()
		self.widgets.remove(self.list)
		self.list = widget.ChkList(labels, unselbarpos)
		self.add(self.list)

		for ic in self.icon_cols:
			self.list.attach_icon_column(ic)

	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		self.list.set_focus(focus)

	def set_text(self, n, text):
		self.list.set_text(n, text)

	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)

	def change_theme(self):
		self.top_image.file = uiconfig.image_dir + uiconfig.current_theme.indicator_bar
		self.list.change_theme()

		
class TimeListUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title=None, titleimage=None, icon=None):
		BaseUI.__init__(self, left, right, title, menu3='', menu4=_('BACK'))
		self.list = None
		title = None
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
		
		#if titleimage:
		#	name, pos = titleimage
		#	title_image = utils.put_image(name, pos)
		#	title_image.hide()
		#	self.add(title_image)
			
		if icon:
			name, pos = icon
			image = utils.put_image(name, pos)
			image.hide()
			self.add(image)
			
		self.icon_cols = []
		self.icon_cols1 = []
		self.icons = {}
		
	def set_list(self, labels, unselbarpos=[]):
		#roxia_trace('ListUI.set_list(), lables=', labels)
		self.list = widget.WorldTimeList(labels, unselbarpos)
		self.add(self.list)
		self.icon_cols = uiconfig.worldtime_icon_flag[0:len(labels)]
		self.list.remove_all_icon_columns()
		self.create_icon_column(15, self.icon_cols)
		'''
		self.icon_cols1 = uiconfig.dst_icon1[0:len(labels)]
		self.create_icon_column(430, self.icon_cols1)
		'''
		
	def create_icon_column(self, x, icons, resize=[0,0]):
		ic = widget.FlagIconColumn(x, 8, icons, resize)
		self.list.attach_icon_column(ic)
		self.icon_cols.append(ic)
		self.add(ic)

	def remove_all_icon_columns(self):
		self.list.remove_all_icon_columns()
		for ic in self.icon_cols:
			self.widgets.remove(ic)
			ic.free()
		self.icon_cols = []
		'''
		for ic in (1,3,6,11,13,14,15,16,18,23,30,31,34):
		for ic in (self.icon_cols1[1],self.icon_cols[3],self.icon_cols[6],self.icon_cols[11],self.icon_cols[13],self.icon_cols[14],\
				self.icon_cols[15],self.icon_cols[16],self.icon_cols[18],self.icon_cols[23],self.icon_cols[30],self.icon_cols[31],self.icon_cols[34]):
			self.widgets.remove(ic)
			ic.free()
		'''

	def handle_key(self, keyname):
		if keyname == 'Up':
			self.list.focus_up()
			return True
		elif keyname == 'Down':
			self.list.focus_down()
			return True
		return False

	def update_lists(self, labels, unselbarpos=[]):
		self.list.free()
		self.widgets.remove(self.list)
		self.list = widget.WorldTimeList(labels, unselbarpos)
		self.add(self.list)

	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		self.list.set_focus(focus)

	def set_text(self, n, text):
		self.list.set_text(n, text)

	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)


class CalendarListUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, menu3, title_image=None, list_icon=None,  x=uiconfig.list2_pos_x, title=None):
		
		BaseUI.__init__(self, left, right, title, menu3, menu4=_('BACK'))
		self.x=x
		self.list = None
		title = None
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		#if title_image == None:
		#	title_image = uiconfig.calendar_title
		#name, pos = title_image
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		if list_icon == None:
			list_icon =  uiconfig.calendar_list_icon
		self.list_icon = list_icon

		self.icon_cols = []		
		self.icons = {}
		
	def set_list(self, labels, unselbarpos=[]):
		#roxia_trace('ListUI.set_list(), lables=', labels)
		self.list = widget.CalendarList(labels, unselbarpos, self.x)
		self.add(self.list)
		#self.icon_cols = [uiconfig.dst_icon] * len(labels)
		self.icon_cols = [self.list_icon] * len(labels)
		self.list.remove_all_icon_columns()
		self.create_icon_column(15, self.icon_cols)
		
	def create_icon_column(self, x, icons, resize=[0,0]):
		ic = widget.FlagIconColumn(x, 4, icons, resize)
		self.list.attach_icon_column(ic)
		self.icon_cols.append(ic)
		self.add(ic)

	def remove_all_icon_columns(self):
		self.list.remove_all_icon_columns()
		for ic in self.icon_cols:
			# start shchun : add safety code Jun-13
			try:		
				self.widgets.remove(ic)
				ic.free()
			except:
				pass

		self.icon_cols = []		

	def handle_key(self, keyname):
		if keyname == 'Up':
			self.list.focus_up()
			return True
		elif keyname == 'Down':
			self.list.focus_down()
			return True
		return False

	def update_lists(self, labels, unselbarpos=[]):
		for ic in self.list.icon_columns:
			self.widgets.remove(ic)
			ic.free()
		self.list.free()
		self.widgets.remove(self.list)
		self.list = widget.WorldTimeList(labels, unselbarpos)
		self.add(self.list)
		#self.icon_cols = [uiconfig.dst_icon] * len(labels)
		self.icon_cols = [self.list_icon] * len(labels)
		
		self.list.remove_all_icon_columns()
		self.create_icon_column(15, self.icon_cols)
		
	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus):
		self.list.set_focus(focus)

	def set_text(self, n, text):
		self.list.set_text(n, text)

	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)


class PhotoGalleryCheckList(PhotoGalleryCheckListUI):
	def set_list(self, labels):
		self.labels = labels
		self.list = widget.CheckList(labels)
		self.add(self.list)

	def toggle(self):
		self.list.toggle()
		self.update_left()
		
	def set_check(self, focus, check):
		self.list.set_check(focus, check)

	def set_slide_check(self, focus, check):
		self.list.set_slide_check(focus, check)
		
	def set_focus(self, focus):
		self.list.set_focus(focus)
		self.update_left()

	def update_lists(self, labels):
		self.remove(self.list)
		self.list = widget.CheckList(labels)
		self.add(self.list)

	def update_left(self):
		focus = self.get_focus()
		checked = self.list.checked[focus]
		if checked:
			self.set_right(_('DESELECT'))
		else:
			self.set_right(_('SELECT'))
	
	def handle_key(self, keyname):
		if keyname == 'Up':
			self.list.focus_up()
			self.update_left()
			return True
		elif keyname == 'Down':
			self.list.focus_down()
			self.update_left()
			return True
		return False


class SystemInformationUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4):
		BaseUI.__init__(self, left, right, _('SYSTEM INFORMATION'), menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image	검색
		#titleimage = uiconfig.Third_title_system_information
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)
		#self.titletext = runtime.evas.text(text=_('System information'),
		#		font=uiconfig.Third_title_system_information_font,
		#		pos=uiconfig.Third_title_system_information_pos,
		#		color=uiconfig.green_color)
		#self.add(self.titletext)

		# version background
		'''
		ver_bg = uiconfig.system_background
		name, pos = ver_bg
		ver_bg_image = utils.put_image(name, pos)
		ver_bg_image.hide()
		self.add(ver_bg_image)
		'''
		
# SETTING>SystemSetting>Phone Information>Version Information by yylee
class VersionInformationUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4):
		BaseUI.__init__(self, left, right, _('VERSION INFO'), menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image	검색
		#titleimage = uiconfig.Third_title_version_information
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		# version background
		ver_bg = uiconfig.version_background
		name, pos = ver_bg
		ver_bg_image = utils.put_image(name, pos)
		ver_bg_image.hide()
		self.add(ver_bg_image)

# SETTING>SystemSetting>Phone Information>Memory Usage by yylee
class MemoryUsageUI(BaseUI):
	show_bg_depth = True	
	def __init__(self, left, right, title, menu3, menu4):
		BaseUI.__init__(self, left, right, _('MEMORY USAGE'), menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image	검색
		#titleimage = uiconfig.Third_title_memory_usage
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		# version background
		mem_bg = uiconfig.mem_info_background
		name, pos = mem_bg
		mem_bg_image = utils.put_image(name, pos)
		mem_bg_image.hide()
		self.add(mem_bg_image)
		

# yylee
class BrightnessSettingUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4):
		BaseUI.__init__(self, left, right, _('SCREEN BRIGHTNESS'), menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image	검색
		#titleimage = uiconfig.Third_title_brightness_setting
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)


# yylee
class NightmodeSettingUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4):
		BaseUI.__init__(self, left, right, _('NIGHT MODE SETTING'), menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image	검색
		#titleimage = uiconfig.Third_title_nightmode_setting
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

class DialNumberSizeUI(BaseUI):
	show_bg_depth = True
	def __init__(self,index,left, right, menu3, menu4):
		BaseUI.__init__(self, left, right, _('DIAL NUMBER SIZE'), menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
	
		#titleimage = uiconfig.dialnumber_title_setting
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		self.number_size = setting.number_size

		name, pos =uiconfig.ico_dial_number_size
		self.dial_number_size_icon = utils.put_image(name, pos)
		self.dial_number_size_icon.hide()
		self.add(self.dial_number_size_icon)
		
		self.dialnumber_text = runtime.evas.text(text=_('Set'),font=uiconfig.input_font,pos=(uiconfig.input3_x2,uiconfig.input3_y2[0]),color=uiconfig.list_text_color)
		self.add(self.dialnumber_text)

		dial_number_size_choose = [_('Small'), _('Medium'), _('Big')]
		self.dial_number_size = controls.ListBox_Control(dial_number_size_choose, self.number_size, font=uiconfig.input_font, pos=(uiconfig.input3_x3,uiconfig.input3_y3[0]), color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		self.add(self.dial_number_size)

		self.dial_bg = utils.put_image('ver_bg.png', (75, 135))
		self.add(self.dial_bg)

		self.small_01 = utils.put_image('small_01.png', (198, 148))
		self.add(self.small_01)
		self.small_02 = utils.put_image('small_02.png', (226, 148))
		self.add(self.small_02)
		self.small_03 = utils.put_image('small_03.png', (254, 148))
		self.add(self.small_03)

		self.medium_01 = utils.put_image('medium_01.png', (186, 142))
		self.add(self.medium_01)
		self.medium_02 = utils.put_image('medium_02.png', (222, 142))
		self.add(self.medium_02)
		self.medium_03 = utils.put_image('medium_03.png', (258, 142))
		self.add(self.medium_03)

		self.big_01 = utils.put_image('big_01.png', (177, 140))
		self.add(self.big_01)
		self.big_02 = utils.put_image('big_02.png', (219, 140))
		self.add(self.big_02)
		self.big_03 = utils.put_image('big_03.png', (261, 140))
		self.add(self.big_03)

	def destroy(self):
		self.dial_number_size_icon.free()
		BaseUI.destroy(self)

	def show_digit(self, digit_size):
		'''
		digit size: 0-small, 1-medium, 2-big
		'''
		if digit_size == 0:
			self.small_01.show()
			self.small_02.show()
			self.small_03.show()
			self.medium_01.hide()
			self.medium_02.hide()
			self.medium_03.hide()
			self.big_01.hide()
			self.big_02.hide()
			self.big_03.hide()
			
		elif digit_size == 1:
			self.small_01.hide()
			self.small_02.hide()
			self.small_03.hide()
			self.medium_01.show()
			self.medium_02.show()
			self.medium_03.show()
			self.big_01.hide()
			self.big_02.hide()
			self.big_03.hide()
			
		elif digit_size == 2:
			self.small_01.hide()
			self.small_02.hide()
			self.small_03.hide()
			self.medium_01.hide()
			self.medium_02.hide()
			self.medium_03.hide()
			self.big_01.show()
			self.big_02.show()
			self.big_03.show()

	def show(self):
		BaseUI.show(self)
		self.dial_number_size.showFocus()
		self.show_digit(self.number_size)
	
	def save(self):
		setting.set_number_size(self.dial_number_size.get_index())
		setting.save()
	
	def handle_key(self, key):		
		if key == 'Up':
			return True
		elif key == 'Down':
			return True
		elif key in ('Right', 'Left'):
			self.dial_number_size.handle_key(key)
			self.show_digit(self.dial_number_size.get_index())
			return True
		return False

class ChangeMenuBgrUI(BaseUI):
	show_bg_depth = True
	def __init__(self,index,left, right, menu3, menu4):
		BaseUI.__init__(self, left, right, _('MENU THEME'), menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image
		#titleimage = uiconfig.Third_title_change_menu_bar
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)	
		
		self.menu_bg_mode = setting.menu_bg_mode
		
		name, pos  = uiconfig.ico_menu_bg
		self.menu_bg_icon = utils.put_image(name, pos)
	
		#self.menu_bg_text = runtime.evas.text(text=_('Set'), font=uiconfig.input_font,pos=(114,63), color=uiconfig.list_text_color)
		self.menu_bg_text = runtime.evas.text(text=_('Set'), font=uiconfig.input_font, pos=uiconfig.setting_bg_label_pos, color=uiconfig.list_text_color)
		self.add(self.menu_bg_text)

		menu_bg_choose = [_('Black'), _('White')]
		#self.menu_bg = controls.ListBox_Control(menu_bg_choose, self.menu_bg_mode, font=uiconfig.input_font, pos=(210, 59), color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		self.menu_bg = controls.ListBox_Control(menu_bg_choose, self.menu_bg_mode, font=uiconfig.input_font, pos=uiconfig.setting_bg_box1_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		self.add(self.menu_bg)

		name, pos = uiconfig.setting_bg_back2
		self.set_imagebg(name, pos)
		
		name = uiconfig.change_bg_blackimg
		pos = uiconfig.setting_bg_img2_pos
		self.change_bg_img = utils.put_image(name, pos, uiconfig.setting_bg_img_size)
		self.add(self.change_bg_img )
		self.change_bg_img.hide()

	def destroy(self):
		self.menu_bg_icon.free()
		BaseUI.destroy(self)

	def show(self):
		BaseUI.show(self)
		self.menu_bg.showFocus()
		self.preview_menu()

	def set_imagebg(self,filename,pos):
		self.image = controls.Image_Control(filename,pos)
		self.add(self.image)

	def preview_menu(self):
		if self.menu_bg_mode == 0:
			self.change_bg_img.file =  uiconfig.image_dir+ uiconfig.change_bg_blackimg
		elif self.menu_bg_mode == 1:
			self.change_bg_img.file =  uiconfig.image_dir + uiconfig.change_bg_whiteimg

	def save(self):
		setting.change_menu_bg(self.menu_bg_mode)
		setting.save()
			
	def handle_key(self, key):
		if key == 'Right' or key =='Left':
			self.menu_bg_mode = 1 - self.menu_bg_mode
			self.menu_bg.handle_key(key)
			self.preview_menu()
		return False
		
class PhoneBookWindowUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4):
		BaseUI.__init__(self, left, right, 'TEST', menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		## title image	검색
		#titleimage = uiconfig.Third_title_PB_detail
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)



		pos = uiconfig.small_window_pos1
		self.window_1 = utils.put_image(uiconfig.multi_window_image, pos)
		self.add(self.window_1)

		pos = uiconfig.small_window_pos2
		self.window_2 = utils.put_image(uiconfig.multi_window_image, pos)
		self.add(self.window_2)

		pos = uiconfig.small_window_pos3
		self.window_3 = utils.put_image(uiconfig.multi_window_image, pos)
		self.add(self.window_3)

#		pos = uiconfig.small_window_title_pos
#		font = uiconfig.small_window_title_font
#		color = uiconfig.small_window_title_color
#		stitle = widget.OutlineLabel(small_title, font, pos, color, align=uiconfig.ALIGN_LEFT)
#		self.add(stitle)
#		self.subtitle = stitle


#	def change_theme(self):
#		self.bar.file = uiconfig.image_dir + uiconfig.current_theme.window_bar

class AlarmUI(BaseUI): # ListUI
	show_bg_depth = True
	def __init__(self, left, right, menu3, menu4):		
		BaseUI.__init__(self, left, right, _('ALARM'), menu3, menu4)
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image	검색
		#titleimage = uiconfig.Third_title_alarm
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)


#thang [20080419 - 1] make calendar additem
class AddCalendarUI(BaseUI): # ListUI
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4, titleimage=None, icon=None):
		BaseUI.__init__(self, left, right, _('CALENDAR'), menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
		
		#titleimage = uiconfig.calendar_title
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)
		
		item = status.calendar_item
		self.frame = []
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		name, pos = uiconfig.cal_date_icon
		self.cal_date_icon = utils.put_image(name, pos)
		self.add(self.cal_date_icon)
		lbl_date = controls.Label_Control(_('Date'), font=uiconfig.pb_entry_font, pos=(uiconfig.input2_x2, uiconfig.input2_y2[0]), color=uiconfig.list_text_color)
		self.add(lbl_date)		
		self.ctl_date = controls.Date_Control(date=(int(item.year), int(item.month), int(item.day)), pos=(uiconfig.input2_x3,uiconfig.input2_y2[0]))
		self.add(self.ctl_date)

		'''
		name, pos = uiconfig.cal_set_icon
		self.cal_set_icon = utils.put_image(name, pos)
		self.add(self.cal_set_icon)
		lbl_set = controls.Label_Control(_('Set'), font=uiconfig.pb_entry_font, pos=(uiconfig.input4_x2, uiconfig.input4_y2[1]), color=uiconfig.list_text_color)
		self.add(lbl_set)		
		self.ctl_yearly = controls.Check_Control(int(item.yearly), _('Yearly'), font=uiconfig.pb_entry_font, pos=(uiconfig.input4_x3, uiconfig.input4_y3[1]), color=uiconfig.list_text_color)		
		self.add(self.ctl_yearly)
		self.ctl_holiday = controls.Check_Control(int(item.holiday), _('Holiday'), font=uiconfig.pb_entry_font, pos=(uiconfig.input4_x3, uiconfig.input4_y3[2]), color=uiconfig.list_text_color)		
		self.add(self.ctl_holiday)
		'''

		name, pos = uiconfig.cal_memo_icon
		self.cal_memo_icon = utils.put_image(name, pos)
		self.add(self.cal_memo_icon)
		lbl_memo = controls.Label_Control(_('Memo'), font=uiconfig.pb_entry_font, pos =(uiconfig.input2_x2, uiconfig.input2_y2[1]), color=uiconfig.list_text_color)
		self.add(lbl_memo)
		self.ctl_memo = controls.Input_Control(pos=(uiconfig.input2_x3,uiconfig.input2_y3[1]), size=(184,28))	
		self.ctl_memo.set_text(item.memo)
		self.ctl_memo.set_max(uiconfig.MAX_INPUT_MEMO)
		self.add(self.ctl_memo)
	
	def destroy(self):
		if self.automata_icon: self.automata_icon.free()		
		BaseUI.destroy(self)

	def show(self):
		if self.automata_icon: self.automata_icon.show()
		BaseUI.show(self)
		
	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):		
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)
		self.automata = name, casemode

	def get_text(self):
		return self.ctl_memo.get_text()

	def insert_text(self, ch):
		return self.ctl_memo.insert_unicode_text(ch)
#thang [20080419 - 1] =================


class AddPhoneBookUI(BaseUI): # ListUI
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, _('PHONEBOOK NEW'), menu3, menu4)
		self.list = None
		self.display_idx = 0

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image: 전화번호등록
		#titleimage = uiconfig.Third_title_PB_detail
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		self.icon_cols = []
		self.icons = {}
		self.frame = []
		item = status.phone_item
		#NAME, GROUP, PRIORITY, HOME, MOBILE, OFFICE, SPEED, EMAIL, MELODY, SNAPSHOT, CDATE, MDATE
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		# name
		icon_name = controls.Icon_Control(uiconfig.pb_name, (0,0))
		lbl_name = controls.Label_Control(_('Name'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)	
		name = controls.Input_Control(pos=(0,0), size=uiconfig.pb_entry_size)	
		name.set_text(item[0])
		name.set_max(uiconfig.MAX_INPUT_NAME)
		self.frame.append((icon_name, lbl_name, name))

		# group
		from groupdb import groupdb
		self.choose_eng = groupdb.get_group_list() # translate on purpose.
		choose = []
		for i in range(len(self.choose_eng)):
			choose.append(runtime.evas.pre_parse(self.choose_eng[i]))
			
		#ind_group = self.find_pos(item[1],choose)
		if  item[1] == '':	
			ind_group = 0
		#elif int(item[1]) > len(choose)-1: #삭제된 경우 /추후에는 그룹 삭제하는 곳에서 처리하도록 해야한다. 
		#	ind_group = 0
		else:
			ind_group = int(item[1])	
		group_bell_icon1 = controls.Icon_Control(uiconfig.pb_group, (0,0))
		lbl_group = controls.Label_Control(_('Group'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		group = controls.ListBox_Control(choose,ind_group, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((group_bell_icon1, lbl_group, group))

		# home
		icon_home = controls.Icon_Control(uiconfig.pb_home, (0,0))
		lbl_home = controls.Label_Control(_('Home'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		home = controls.Input_Control(pos=(0,0), size=uiconfig.pb_entry_size)
		home.set_text(item[3])
		home.set_max(uiconfig.MAX_INPUT_TEL)
		self.frame.append((icon_home, lbl_home,home))

		# mobile
		icon_mobile = controls.Icon_Control(uiconfig.pb_mobile, (0,0))
		lbl_mobile = controls.Label_Control(_('Mobile'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		mobile = controls.Input_Control(pos=(0,0), size=uiconfig.pb_entry_size)
		mobile.set_text(item[4])
		mobile.set_max(uiconfig.MAX_INPUT_TEL)
		self.frame.append((icon_mobile,lbl_mobile,mobile))

		# office
		icon_office = controls.Icon_Control(uiconfig.pb_office, (0,0))
		lbl_office = controls.Label_Control(_('Office'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		office = controls.Input_Control(pos=(0,0), size=uiconfig.pb_entry_size)		
		office.set_text(item[5])
		office.set_max(uiconfig.MAX_INPUT_TEL)
		self.frame.append((icon_office,lbl_office,office))

		# speed
		from speeddb import speeddb
		self.speed_list = [_('None')]
		empty_list = speeddb.get_empty_speed_num_list()
		self.org_speed = item[6]
		if self.org_speed != '':
			speeddb.insert_speed_num_to_list(self.org_speed, empty_list)
			self.speed_list.extend(empty_list)
			speed_index = self.speed_list.index(self.org_speed)
		else:
			self.speed_list.extend(empty_list)
			speed_index = 0
		
		icon_speed = controls.Icon_Control(uiconfig.pb_speed, (0,0))
		lbl_speed = controls.Label_Control(_('Speed'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		speed = controls.ListBox_Control(self.speed_list, speed_index, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((icon_speed,lbl_speed, speed))

		# email
		icon_email = controls.Icon_Control(uiconfig.pb_email, (0,0))
		lbl_email = controls.Label_Control(_('Email'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		email = controls.Input_Control(pos=(0,0), size=uiconfig.pb_entry_size)		
		email.set_text(item[7])
		email.set_max(uiconfig.MAX_INPUT_EMAIL)
		self.frame.append((icon_email,lbl_email,email))

		# bell
		choose = utils.get_ring_dir_list()
		ring_dir_index, ring_list, ring_index = utils.get_ring_dir_index(item[8])

		icon_bell1 = controls.Icon_Control(uiconfig.pb_bell, (0,0))
		lbl_bell1 = controls.Label_Control(_('Bell'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		bell1 = controls.ListBox_Control(choose, ring_dir_index, font = uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((icon_bell1,lbl_bell1,bell1))

		icon_bell2 = controls.Icon_Control(uiconfig.pb_bell, (0,0))
		lbl_bell2 = controls.Label_Control('', font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		bell2 = controls.ListBox_Control(ring_list,ring_index, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((icon_bell2,lbl_bell2,bell2))

		# image
		#choose = ('Avatas','Basic Image','My Album','Received Album')
		choose = utils.get_image_dir_list()
		if config.mmi_debug: print '## item[9]=', item[9]
		dir_index, image_list, image_index  = utils.get_image_dir_index(item[9])

		image_list_no_ext = []
		for item in image_list:
			dot = item.rfind('.')
			if dot >= 0:
				item = item[:dot]
			image_list_no_ext.append(item)
		
		#dir_index, image_list  = utils.get_image_dir_index('photos/avatas/avatar_01.png')
		icon_image1 = controls.Icon_Control(uiconfig.pb_image,(0,0))
		lbl_image1 = controls.Label_Control(_('Image'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		image1 = controls.ListBox_Control(choose, dir_index, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		self.frame.append((icon_image1,lbl_image1,image1))
			
		icon_image2 = controls.Icon_Control(uiconfig.pb_image,(0,0))
		lbl_image2 = controls.Label_Control('', font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		#filenames = self.get_current_names(image_list)
		image2 =controls.ListBox_Control(image_list_no_ext, image_index, font=uiconfig.pb_entry_font, pos=(61,81), color=uiconfig.list_text_color)
		self.frame.append((icon_image2,lbl_image2,image2))		

		icon_image3 = controls.Icon_Control(uiconfig.pb_image,(0,0))
		lbl_image3 = controls.Label_Control('', font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		filename = '/usr/local/lgvp/photos/snapshot/no_photo.png'
		image3 =controls.Image_Control(filename, pos=(0,0), size=(120,80))
		self.frame.append((icon_image3,lbl_image3,image3))		
		
		unselbarpos = []		
		self.set_list(self.frame, unselbarpos)
		self.ring_index = ring_index
		self.ring_list = ring_list
		self.ring_dir_index = ring_dir_index
		self.image_list = image_list

		self.update_priority_icon()

		self.play_audio_timer = None
		
	def find_pos(self,values,list):
		i = 0		
		for chk in list:
			if str(chk).lower() == str(values).lower():
				return i
			else:
				i = i + 1
		return 0
		
	def get_current_names(self,image_list):		
		names = []
		for lst in image_list:
			name = lst
			dot = name.rfind('.')
			if dot >= 0:
				name = name[:dot]
			names.append(name)
		return names	
		
	def set_list(self, frame, unselbarpos=[]):
		roxia_trace('ListControlUI.set_list(), frame=', frame)
		self.list = widget.AddPhoneBook(frame, unselbarpos)
		self.add(self.list)

	def update_priority_icon(self, index=''):
		print 'ka............1 index = ', index
		if index == '':
			index = status.phone_item.prority
		if index == '':
			return
		index = int(index) # 0, 1, 2
		print 'ka............2 index = ', index
		for i in range(3):
			if i == index:
				filename = uiconfig.image_dir + uiconfig.pb_pirority_number_set[i]
				self.list.icons[i+2].changeIcon(filename)
			else:
				filename = uiconfig.image_dir + uiconfig.pb_pirority_number[i]
				self.list.icons[i+2].changeIcon(filename)
		
	def update_ring_list(self, dir_index):
		self.ring_list = utils.get_ring_list(dir_index)
		rings=[]
		for ring in self.ring_list:
			dot = ring.rfind('.')
			if dot >= 0:
				ring = ring[:dot]
				ring = unicode(ring, 'euc-kr').encode('utf-8')
			rings.append(ring)
		self.ring_list = rings
		#names = self.get_current_names(self.ring_list)
		self.list.entrys[8].change_choice(self.ring_list)
		self.ring_index = 0
		self.ring_dir_index = dir_index

	def update_image_list(self, dir_index):
		self.image_list = utils.get_image_dir_index('', dir_index)
		#names = self.get_current_names(self.image_list)
		images = []
		for img in self.image_list:
			dot = img.rfind('.')
			if dot >= 0:
				img = img[:dot]
				img = unicode(img, 'euc-kr').encode('utf-8')
			images.append(img)
		self.list.entrys[10].change_choice(images)
		
	def update_lists(self, frame, unselbarpos=[]):
		self.list.free()
		self.widgets.remove(self.list)		
		self.add(self.list)

	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus, new=False):
		#pass
		return self.list.set_focus(focus, new)

	def set_text(self, n, text):
		self.list.set_text(n, text)

	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)

	def get_current_audio_file(self):
		audio_file = ''
		ring_num = len(self.ring_list)

		if ring_num > 0 and self.ring_dir_index > 0:
			if self.ring_index < ring_num:
				audio_file = self.ring_list[self.ring_index]
				try:
					audio_file = unicode(audio_file, 'utf-8').encode('euc-kr')
				except:
					pass
				dir = utils.get_ring_dir_by_index(self.ring_dir_index)
				audio_file=utils.get_melody_fullname(dir, audio_file)
				audio_file=dir+audio_file
		return audio_file

	def play_audio(self):
		if status.phone_status != status.Disconnected:
			return
			
		audio_file = self.get_current_audio_file()
		if config.mmi_debug: print 'audio filename = ', audio_file
		if audio_file != '':
			utils.player.play_ring(audio_file)

	def stop_audio(self):
		if status.phone_status != status.Disconnected:
			return
		utils.player.stop_ring()

	def handle_key(self, key):		
		if key == 'Up':
			self.play_audio_timer = None
			if self.list.focus == 8:
				self.stop_audio()
			self.list.focus_up()
			if self.list.focus == 8:
				self.play_audio_timer = utils.Timer(uiconfig.play_audio_delay, self.play_audio)
				#self.play_audio()
			return True
		elif key == 'Down':
			self.play_audio_timer = None
			if self.list.focus == 8:
				self.stop_audio()
			self.list.focus_down()
			if self.list.focus == 8:
				self.play_audio_timer = utils.Timer(uiconfig.play_audio_delay, self.play_audio)
				#self.play_audio()
			return True	
		# KA: [20080412] change the ring list by directory path
		elif key in ('Left', 'Right'):
			ret = self.list.entrys[self.list.focus].handle_key(key) # 먼저 dir를 change
			if self.list.focus not in (1, 7, 8, 9, 10):
				return ret
			current_dir_index = self.list.entrys[self.list.focus].index
			if self.list.focus == 7: #melody dir 이 변한 경우 
				self.update_ring_list(current_dir_index)
			if self.list.focus == 8:
				self.stop_audio()
				self.ring_index = self.list.entrys[self.list.focus].index
				self.play_audio_timer = None
				self.play_audio_timer = utils.Timer(uiconfig.play_audio_delay, self.play_audio)			
			if self.list.focus == 9: #image dir 이 변한 경우 
				self.update_image_list(current_dir_index)	
			return ret
		# KA: [20080412] ==
		return False

	def destroy(self):
		if self.automata_icon: self.automata_icon.free()
		status.editing_phone_number_index = -1
		status.phone_item = None
		BaseUI.destroy(self)
		self.play_audio_timer = None

		
	def hide(self):
		BaseUI.hide(self)
		
	def show(self):
		if self.automata_icon: self.automata_icon.show()
		BaseUI.show(self)
	
	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):		
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		self.automata = name, casemode
		self.automata_idx = utils.get_automata_idx(*self.automata)
		
	def get_text(self):
		focus = self.get_focus()
		return self.list.entrys[focus].get_text()
		#return self.entry.get_text()
#Thang [20080326-2] ================


class EditGroupUI(BaseUI):
	show_bg_depth = True
	def __init__(self, item_index, left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, '', menu3, menu4)
		from groupdb import groupdb
		if item_index == -1:
			item = groupdb.new_item()
		else:
			item = groupdb.get_item(item_index)
#		rint 'ka........item=', item
#		audio_dir_index = groupdb.get_melody_dir(item_index)
#		self.audio_dirs = [_('None'), _('Basic bell'), _('Sweet bell'), _('Merry bell'), _('Classic bell'), _('Effect bell'), _('Download bell')]
	
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
		
		# title group set
		#name, pos  = uiconfig.Third_title_PB_group #Third_title_group_bell 
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)
		
		# set small icon
		name, pos = uiconfig.group_bell_icon1
		icon_1 = utils.put_image(name, pos)
		self.add(icon_1)
		name, pos = uiconfig.group_bell_icon2
		icon_2 = utils.put_image(name, pos)
		self.add(icon_2)
		
		# group name title
		pos = uiconfig.group_bell_label1_pos
		group_name = runtime.evas.text(text=_('Group name'),font=uiconfig.alarm_font,pos=pos,color=uiconfig.list_text_color)
		self.add(group_name)
		
		# edit box
		import entry
		self.entry = entry.Entry(pos = uiconfig.pb_entry_group_pos, size=uiconfig.pb_entry_group_size)
		self.entry.add_callback(self.entry.AutomataChanged, self.update_automata_icon)
		self.entry.set_text('')
		self.entry.set_max(uiconfig.MAX_INPUT_NAME)
		self.add(self.entry)

		group_name = item[1]
		self.entry.set_text(group_name)
		
		# group bell title
		pos = uiconfig.group_bell_label2_pos
		group_bell = runtime.evas.text(text=_('Group bell'),font=uiconfig.alarm_font,pos=pos,color=uiconfig.list_text_color)
		self.add(group_bell)
			
		# select box (green)
		name = uiconfig.normal_icon_select_r
		self.sel_box = utils.put_image(name, uiconfig.group_bell_box2_pos)
		self.add(self.sel_box)
		self.sel_box.hide()

		# select box (default)
		name = uiconfig.normal_icon_select
		self.groupbell_image = utils.put_image(name, uiconfig.group_bell_box2_pos)
		self.add(self.groupbell_image)

		# select box (default)
		name = uiconfig.normal_icon_select
		self.bell_image = utils.put_image(name, uiconfig.group_bell_box3_pos)
		self.add(self.bell_image)

		self.audio_dirs = utils.get_ring_dir_list()
		audio_dir_index, ring_list, ring_index = utils.get_ring_dir_index(item[2])

		# group bell dir
		#audio_dir_index = groupdb.get_melody_dir(item_index)
		audio_dir = self.audio_dirs[audio_dir_index]
		self.select_audio_dir= runtime.evas.text(text=audio_dir, font=uiconfig.alarm_font,pos=(0,0),color=uiconfig.list_text_color)
		self.align_center(self.select_audio_dir, uiconfig.group_bell_text2_pos)
		self.add(self.select_audio_dir)

		self.audio_file = ''

		# bell name
		if audio_dir == _('None'):
			ring = audio_dir
			self.select_ring= runtime.evas.text(text=ring, font=uiconfig.alarm_font,pos=(0,0),color=uiconfig.list_text_color)
		else:
			#self.ring = groupdb.get_melody_file(item_index)
			self.audio_file = groupdb.get_melody_file(item_index)
			dot = self.audio_file.rfind('.')
			if dot >= 0:
				self.ring  = self.audio_file[:dot] 
				
			if config.mmi_debug: print 'self.ring =', self.ring
			if self.ring == _('None') or self.ring == '':
				ring = _('None')
				self.audio_file = _('None')				
				self.select_ring= runtime.evas.text(text=ring, font=uiconfig.alarm_font,pos=(0,0),color=uiconfig.list_text_color)
			else:
				ring = unicode(self.ring, 'euc-kr').encode('utf-8')
				#ring = self.ring.split('.')[0]
				#self.audio_file = self.ring+'.mp3' #'.mid'
				self.select_ring= runtime.evas.text(text=utils.cut_text(text=ring, width=uiconfig.bell_width_scroll, font=uiconfig.alarm_font)[0], font=uiconfig.alarm_font,pos=(0,0),color=uiconfig.list_text_color)

		self.ring_name=ring
		self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
		self.add(self.select_ring)

		self.item_index = item_index
		self.item = item
		self.audio_dir_index = audio_dir_index
		self.audio_file_index = 0
		self.index = -1
		self.set_focus(self.index)
		self.path = ''
#	def set_info(self):
#		self.set_name()
#		self.set_melody()

		# for long file name
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None

		self.symbol_stage_timer = None


	def get_text(self):
		return self.entry.get_text()

	def insert_text(self, text):
		self.entry.insert_unicode_text(unicode(text, 'utf-8'))
		self.entry._automata.check_start_of_sentance()
		#self.update_entry_info()

	def get_current_file(self):
		if self.audio_dir_index == 0:
			return ''	
		else:
			if  self.audio_dir_index == 1:		path = config.audio_dir_basic
			elif  self.audio_dir_index == 2:	path = config.audio_dir_sweet
			elif  self.audio_dir_index == 3:	path = config.audio_dir_merry
			elif  self.audio_dir_index == 4:	path = config.audio_dir_classic
			elif  self.audio_dir_index == 5:	path = config.audio_dir_effect
#			elif  self.audio_dir_index == 6:	path = config.audio_dir_download
			elif  self.audio_dir_index == 6:	path = config.audio_dir_recorded
				
		if self.audio_file == _('None'):
			return ''
			
		current_file = path+self.audio_file
		return current_file
			
	def align_center(self, l, pos):
		x, y = pos
		width,height = l.size
		l.move(x - width/2, y)

	def change_melody_dir(self, increase=True):
		self.remove_item_scroll_timer()
		num = len(self.audio_dirs)
		if increase:
			self.audio_dir_index += 1
			if self.audio_dir_index >= num: self.audio_dir_index = 0
		else:
			self.audio_dir_index -= 1
			if self.audio_dir_index < 0: self.audio_dir_index = num - 1
			
		audio_dir = self.audio_dirs[self.audio_dir_index]
		
		self.select_audio_dir.text_set(audio_dir)
		self.align_center(self.select_audio_dir, uiconfig.group_bell_text2_pos)
		self.select_audio_dir.show()

		self.select_ring.hide()
		self.select_ring.text_set(_('None'))
		self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
		self.select_ring.show()
		self.audio_file = _('None')
		self.path = ''
		self.audio_file_index = 0

	def change_melody_file(self, increase=True, dir_changed=False):
		self.remove_item_scroll_timer()
		if self.audio_dir_index == 0:
			self.audio_file = _('None')
			self.path = ''		
		else:
			if  self.audio_dir_index == 1:		self.path = config.audio_dir_basic
			elif self.audio_dir_index == 2:	self.path = config.audio_dir_sweet
			elif self.audio_dir_index == 3:	self.path = config.audio_dir_merry
			elif self.audio_dir_index == 4:	self.path = config.audio_dir_classic
			elif self.audio_dir_index == 5:	self.path = config.audio_dir_effect
#			elif self.audio_dir_index == 6:	self.path = config.audio_dir_download
			elif self.audio_dir_index == 6:	self.path = config.audio_dir_recorded

			import os
			choices =[]
			choices = os.listdir(self.path)
			choices.sort()
			num = len(choices)
			
			if config.mmi_debug: 
				print '## num=', num, 'choices=', choices
				print '##[before] self.audio_file_index=', self.audio_file_index
			if num == 0:
				self.audio_file = _('None')
			else:				
				if dir_changed == True:
					self.audio_file_index = 0
				else:
					if increase:
						self.audio_file_index += 1
						if self.audio_file_index > num-1: self.audio_file_index = 0
					else:
						self.audio_file_index -= 1
						if self.audio_file_index < 0: self.audio_file_index = num-1
				self.audio_file= choices[self.audio_file_index]
			if config.mmi_debug: print '## self.audio_file_index=', self.audio_file_index	
			
		ring = self.audio_file
		dot = ring.rfind('.')
		if dot >= 0:
			ring = ring[:dot]
			# yylee: added for korean file name support
			ring = unicode(ring, 'euc-kr').encode('utf-8')

		self.select_ring.hide()
		
		self.ring_name=ring	
		if config.mmi_debug: print '@@ ring_name =', self.ring_name
		if self.is_scroll_item(self.ring_name) == True:
			if dir_changed:
				self.select_ring.text_set(utils.cut_text(text=self.ring_name, width=uiconfig.bell_width_scroll, font=uiconfig.alarm_font)[0])
			else:
				self.org_label = self.temp_text = self.ring_name
				item_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
				self.select_ring.text_set(item_text)
				self.scroll_text = self.select_ring
				self.item_scroll_timer = utils.Timer(1000, self.scroll_item_timer_cb)
		else:
			self.select_ring.text_set(self.ring_name)
		self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
		self.select_ring.show()
		
	def change_ring(self):
		def searh_files(args, dirname, filenames):
			fnames = filter(lambda fname: fname[-4:] == '.mid', filenames) 
			if len(fnames) > 0:
				files.append(dirname)
				files.append(fnames)
		import os
		files = []
		os.path.walk(config.audio_def_dir, searh_files, [])
		return files

	def set_focus(self,index):
		if index == -1:
			#color = 140,215,56,255
			color = uiconfig.color_select
			self.entry.set_background_color(color)
			self.groupbell_image.show()
			self.bell_image.show()
			self.sel_box.hide()
			self.entry.cursor_show()
		elif index == 0:
			color = uiconfig.color_white
			self.entry.set_background_color(color)
			self.bell_image.show()
			self.groupbell_image.hide()
			self.sel_box.move(uiconfig.group_bell_box2_pos[0], uiconfig.group_bell_box2_pos[1])
			self.sel_box.show()
			self.entry.cursor_hide()
		else:
			if config.mmi_debug: print '@ ring_name =', self.ring_name
			color = uiconfig.color_white
			self.entry.set_background_color(color)
			self.groupbell_image.show()
			self.bell_image.hide()
			self.sel_box.move(uiconfig.group_bell_box3_pos[0], uiconfig.group_bell_box3_pos[1])
			self.sel_box.show()
			self.entry.cursor_hide()

			self.select_ring.show()
			if self.is_scroll_item(self.ring_name) == True:
				self.org_label = self.temp_text = self.ring_name
				item_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
				self.select_ring.text_set(item_text)
				self.scroll_text = self.select_ring
				self.item_scroll_timer = utils.Timer(1000, self.scroll_item_timer_cb)
			else:
				self.select_ring.text_set(self.ring_name)

			self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
			self.select_ring.show()


	# for long file name : copy from NewBell
	def scroll_item_timer_cb(self):
		try:
			# KA: [20070921] this conversion is required for Korean text
			#if ord(self.temp_text[0]) > 127:
			latin_char = True
			
			if type(self.temp_text) == type('abc'):
				self.temp_text = unicode(self.temp_text, 'utf-8')[1:]
			else:
				self.temp_text = self.temp_text[1:]
			self.temp_text = self.temp_text.encode('utf-8')				
		except:
			self.temp_text = ''

		if len(self.temp_text) == 0:
			self.temp_text = self.org_label

		abbr_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
		self.select_ring.text_set(abbr_text)
		runtime.evas.render()
		return True

	def set_scroll_text(self, item_text, abbr_width):
		if abbr_width > 0:
			abbr_text = utils.cut_text(item_text, abbr_width, uiconfig.alarm_font)[0]
			return abbr_text
		else:
			return item_text

	def is_scroll_item(self, item_text):
		etext = runtime.evas.text(text=item_text, font=uiconfig.alarm_font)
		text_width = etext.geometry[2]
		etext.free()

		if text_width > uiconfig.bell_width_scroll:
			return True
		else:
			return False
	
	def remove_item_scroll_timer(self):
		if config.mmi_debug: 
			print 'self.item_scroll_timer=', self.item_scroll_timer
		if self.item_scroll_timer:
			del(self.item_scroll_timer)
			self.item_scroll_timer = None
			self.scroll_text = None
			self.temp_text = None

	def destroy(self):
		BaseUI.destroy(self)
		self.symbol_stage_timer = None

	def show(self):
		BaseUI.show(self)
		#self.sel_box.hide()
		self.index = -1
		self.set_focus(self.index)

	def set_fixed_automata(self, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_automata(name, casemode)
		else:
			self.fixed_automata = False
			self.set_automata(*utils.get_def_automata())

	def set_automata(self, name, casemode='lower'):
		self.automata = name, casemode
		self.entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)

	def insert_symbol(self, s):
		def back_to_symbol():
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
			self.symbol_stage_timer = None
			
		before_text = self.get_text()
		self.insert_text(s)
		after_text = self.get_text()

		if before_text == after_text:
			from basemodel import NotifyStage
			runtime.manager.change_stage(NotifyStage(_('Max length exceeded'), uiconfig.baloon_message_icon))
		else:
			runtime.manager.back_stage()
			#self.symbol_stage_timer = utils.Timer(uiconfig.back_to_symbol_timeout, back_to_symbol)

		

	def update_automata_icon(self):
		name, casemode = self.automata 
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		elif name == 'multitap':
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		elif name == 't9':
			if casemode == 'upper':			menu3 = _('T9ABC')
			elif casemode == 'lower':		menu3 = _('T9abc')
			elif casemode == 'first capital':	menu3 = _('T9Abc')			
		else:				menu3 = _('SYMBOL')
			
		self.set_menu3(menu3)
		
		if name =='symbol':
			# shchun : global automata change
			self.set_automata( 'multitap', 'lower')
			if setting.lang == 'Korean':
				self.set_automata('hangul', False)
			else:
				self.set_automata('multitap', 'lower')	
			
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
			# end shchun
		
	def handle_key(self, key):		
		if key == 'Up':
			self.index -= 1
			if self.index < -1:self.index = 1
			self.set_focus(self.index)
			return True
		elif key == 'Down':
			self.index += 1
			if self.index > 1: self.index = -1
			self.set_focus(self.index)
			return True
		else:
			self.entry.handle_key(key)
		return False


# yylee: [20080429] group bell UI- edit group bell
class EditGroupBellUI(BaseUI):
	show_bg_depth = True
	def __init__(self, item_index, left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, _('GROUP BELL'), menu3, menu4)
		from groupdb import groupdb
		#if item_index == -1:
		#	item = groupdb.new_item()
		#group = groupdb.get_name(item_index)
		#audio_dir_index = groupdb.get_melody_dir(item_index)

		#self.audio_dirs = [_('None'), _('Basic bell'), _('Sweet bell'), _('Merry bell'), _('Classic bell'), _('Effect bell'), _('Download bell'), _('Recorded bell')]
		self.audio_dirs = [_('None'), _('Basic bell'), _('Sweet bell'), _('Merry bell'), _('Classic bell'), _('Effect bell'), _('Recorded bell')]
	
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
		
		# title group set
		#name, pos  = uiconfig.Third_title_group_bell 
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)
		
		# set small icon
		name, pos = uiconfig.group_bell_icon1
		icon_1 = utils.put_image(name, pos)
		self.add(icon_1)
		name, pos = uiconfig.group_bell_icon2
		icon_2 = utils.put_image(name, pos)
		self.add(icon_2)
		
		# group name title
		pos = uiconfig.group_bell_label1_pos
		group_name = runtime.evas.text(text=_('Group name'),font=uiconfig.alarm_font,pos=pos,color=uiconfig.list_text_color)
		self.add(group_name)
		
		# group name bg
		name , pos= uiconfig.group_bell_box1
		self.group_name_bg = utils.put_image(name,pos)
		self.add(self.group_name_bg)

		# group name
		group_name = groupdb.get_name(item_index)
		group_name_cut = utils.cut_text(group_name, 180, uiconfig.alarm_font, with_punc=True)[0]
		self.group_name_text = runtime.evas.text(text=group_name_cut, font=uiconfig.alarm_font,pos=(0,0),color=uiconfig.list_text_color)
		self.align_center(self.group_name_text, uiconfig.group_bell_text1_pos)
		self.add(self.group_name_text)
		
		# group bell title
		pos = uiconfig.group_bell_label2_pos
		group_bell = runtime.evas.text(text=_('Group bell'),font=uiconfig.alarm_font,pos=pos,color=uiconfig.list_text_color)
		self.add(group_bell)
		
		# select box (default)
		name = uiconfig.normal_icon_select
		self.groupbell_image = utils.put_image(name, uiconfig.group_bell_box2_pos)
		self.add(self.groupbell_image)
		
		# select box (green)
		name = uiconfig.normal_icon_select_r
		self.sel_box = utils.put_image(name, uiconfig.group_bell_box2_pos)
		self.add(self.sel_box)
		self.sel_box.hide()

		# select box (default)
		name = uiconfig.normal_icon_select
		self.bell_image = utils.put_image(name, uiconfig.group_bell_box3_pos)
		self.add(self.bell_image)

		# group bell dir
		audio_dir_index = groupdb.get_melody_dir(item_index)
		audio_dir = self.audio_dirs[audio_dir_index]
		self.select_audio_dir= runtime.evas.text(text=audio_dir, font=uiconfig.alarm_font,pos=(0,0),color=uiconfig.list_text_color)
		self.align_center(self.select_audio_dir, uiconfig.group_bell_text2_pos)
		self.add(self.select_audio_dir)

		self.audio_file = ''
		
		if audio_dir_index == 0:
			self.path = ''		
		else:
			if  audio_dir_index == 1:	self.path = config.audio_dir_basic
			elif  audio_dir_index == 2:	self.path = config.audio_dir_sweet
			elif  audio_dir_index == 3:	self.path = config.audio_dir_merry
			elif  audio_dir_index == 4:	self.path = config.audio_dir_classic
			elif  audio_dir_index == 5:	self.path = config.audio_dir_effect
#			elif  audio_dir_index == 6:	self.path = config.audio_dir_download
			elif  audio_dir_index == 6:	self.path = config.audio_dir_recorded
		
		# bell name
		if audio_dir == _('None'):
			ring = audio_dir
			self.select_ring= runtime.evas.text(text=ring, font=uiconfig.alarm_font,pos=(0,0),color=uiconfig.list_text_color)
		else:
			#self.ring = groupdb.get_melody_file(item_index)
			#self.audio_file = self.ring+'.mp3' #'.mid'
			self.audio_file= groupdb.get_melody_file(item_index)
			dot = self.audio_file.rfind('.')
			if dot >= 0:
				ring = self.audio_file[:dot]
			
			ring = unicode(ring, 'euc-kr').encode('utf-8')
			#ring = self.ring.split('.')[0]
			'''
			ring = self.ring
			dot = ring.rfind('.')
			if dot >= 0:
				ring = ring[:dot]
				# yylee: added for korean file name support
				
			'''
			self.select_ring= runtime.evas.text(text=utils.cut_text(text=ring, width=uiconfig.bell_width_scroll, font=uiconfig.alarm_font)[0], font=uiconfig.alarm_font,pos=(0,0),color=uiconfig.list_text_color)
		self.ring_name=ring
		if config.mmi_debug: 
			print '## self.audio_file =', self.audio_file
			print '## self.ring_name=', self.ring_name
			print '## audio_dir_index=', audio_dir_index
			print '## item_index=', item_index
		self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
		self.add(self.select_ring)
		
		self.item_index = item_index
		self.audio_dir_index = audio_dir_index
		self.audio_file_index = 0

		# for long file name
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None

		self.index = 0
		self.set_focus(self.index)

#	def set_info(self):
#		self.set_name()
#		self.set_melody()

	def get_current_file(self):
		if self.audio_dir_index == 0:
			return ''	
		else:
			if  self.audio_dir_index == 1:		path = config.audio_dir_basic
			elif  self.audio_dir_index == 2:	path = config.audio_dir_sweet
			elif  self.audio_dir_index == 3:	path = config.audio_dir_merry
			elif  self.audio_dir_index == 4:	path = config.audio_dir_classic
			elif  self.audio_dir_index == 5:	path = config.audio_dir_effect
#			elif  self.audio_dir_index == 6:	path = config.audio_dir_download
			elif  self.audio_dir_index == 6:	path = config.audio_dir_recorded

		if self.audio_file == _('None'):
			return ''
			
		current_file = path+self.audio_file
		return current_file
		
	def align_center(self, l, pos):
		x, y = pos
		width,height = l.size
		l.move(x - width/2, y)

	def change_melody_dir(self, increase=True):
		self.remove_item_scroll_timer()
		num = len(self.audio_dirs)
		if increase:
			self.audio_dir_index += 1
			if self.audio_dir_index >= num: self.audio_dir_index = 0
		else:
			self.audio_dir_index -= 1
			if self.audio_dir_index < 0: self.audio_dir_index = num - 1
			
		audio_dir = self.audio_dirs[self.audio_dir_index]
		
		self.select_audio_dir.text_set(audio_dir)
		self.align_center(self.select_audio_dir, uiconfig.group_bell_text2_pos)
		self.select_audio_dir.show()

		self.select_ring.hide()
		self.select_ring.text_set(_('None'))
		self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
		self.select_ring.show()
		self.audio_file = _('None')
		self.path = ''

		self.audio_file_index = 0

	def change_melody_file(self, increase=True, dir_changed=False):
		self.remove_item_scroll_timer()
		if self.audio_dir_index == 0:
			self.audio_file = _('None')
			self.path = ''		
		else:
			if  self.audio_dir_index == 1:		self.path = config.audio_dir_basic
			elif  self.audio_dir_index == 2:	self.path = config.audio_dir_sweet
			elif  self.audio_dir_index == 3:	self.path = config.audio_dir_merry
			elif  self.audio_dir_index == 4:	self.path = config.audio_dir_classic
			elif  self.audio_dir_index == 5:	self.path = config.audio_dir_effect
#			elif  self.audio_dir_index == 6:	self.path = config.audio_dir_download
			elif  self.audio_dir_index == 6:	self.path = config.audio_dir_recorded

			import os
			choices =[]
			choices = os.listdir(self.path)
			choices.sort()
			num = len(choices)
			# 현재 설정된 index 얻기 구현 미정

			if num == 0:
				self.ring_name=_('None')
				return
		
			if increase:
				self.audio_file_index += 1
				if self.audio_file_index > num-1: self.audio_file_index = 0
			else:
				self.audio_file_index -= 1
				if self.audio_file_index < 0: self.audio_file_index = num-1
				
			if dir_changed:
				self.audio_file_index = 0
				
			self.audio_file= choices[self.audio_file_index]
			
		ring = self.audio_file
		dot = ring.rfind('.')
		if dot >= 0:
			ring = ring[:dot]
			# yylee: added for korean file name support
			ring = unicode(ring, 'euc-kr').encode('utf-8')

		self.select_ring.hide()

		#스크롤 할지를 결정
		self.ring_name=ring	
		if self.is_scroll_item(self.ring_name) == True:
			if dir_changed:
				self.select_ring.text_set(utils.cut_text(text=self.ring_name, width=uiconfig.bell_width_scroll, font=uiconfig.alarm_font)[0])
			else:
				self.org_label = self.temp_text = self.ring_name
				item_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
				self.select_ring.text_set(item_text)
				self.scroll_text = self.select_ring
				self.item_scroll_timer = utils.Timer(1000, self.scroll_item_timer_cb)
		else:
			self.select_ring.text_set(self.ring_name)
		self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
		self.select_ring.show()
		
	def change_ring(self):
		def searh_files(args, dirname, filenames):
			fnames = filter(lambda fname: fname[-4:] == '.mid', filenames) 
			if len(fnames) > 0:
				files.append(dirname)
				files.append(fnames)
		import os
		files = []
		os.path.walk(config.audio_def_dir, searh_files, [])
		return files

	def set_focus(self,index):
		self.remove_item_scroll_timer()
		if index == 0:
			self.bell_image.show()
			self.groupbell_image.hide()
			self.sel_box.move(uiconfig.group_bell_box2_pos[0], uiconfig.group_bell_box2_pos[1])
			self.sel_box.show()

			# for long file name			
			if self.is_scroll_item(self.ring_name) == True:
				self.select_ring.hide()
				self.select_ring.text_set(utils.cut_text(text=self.ring_name, width=uiconfig.bell_width_scroll, font=uiconfig.alarm_font)[0])
				self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
				self.select_ring.show()
		else:
			self.groupbell_image.show()
			self.bell_image.hide()
			self.sel_box.move(uiconfig.group_bell_box3_pos[0], uiconfig.group_bell_box3_pos[1])
			self.sel_box.show()

			# for long file name
			self.select_ring.hide()
			
			#스크롤 할지를 결정			
			if self.is_scroll_item(self.ring_name) == True:
				self.org_label = self.temp_text = self.ring_name
				item_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
				self.select_ring.text_set(item_text)
				self.scroll_text = self.select_ring
				self.item_scroll_timer = utils.Timer(1000, self.scroll_item_timer_cb)
			else:
				self.select_ring.text_set(self.ring_name)

			self.align_center(self.select_ring, uiconfig.group_bell_text3_pos)
			self.select_ring.show()

	# for long file name : copy from NewBell
	def scroll_item_timer_cb(self):
		try:
			# KA: [20070921] this conversion is required for Korean text
			#if ord(self.temp_text[0]) > 127:
			latin_char = True
			
			if type(self.temp_text) == type('abc'):
				self.temp_text = unicode(self.temp_text, 'utf-8')[1:]
			else:
				self.temp_text = self.temp_text[1:]
			self.temp_text = self.temp_text.encode('utf-8')				
		except:
			self.temp_text = ''

		if len(self.temp_text) == 0:
			self.temp_text = self.org_label

		abbr_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
		self.select_ring.text_set(abbr_text)
		runtime.evas.render()
		return True

	def set_scroll_text(self, item_text, abbr_width):
		if abbr_width > 0:
			abbr_text = utils.cut_text(item_text, abbr_width, uiconfig.alarm_font)[0]
			return abbr_text
		else:
			return item_text

	def is_scroll_item(self, item_text):
		etext = runtime.evas.text(text=item_text, font=uiconfig.alarm_font)
		text_width = etext.geometry[2]
		etext.free()

		if text_width > uiconfig.bell_width_scroll:
			return True
		else:
			return False
	
	def remove_item_scroll_timer(self):
		if config.mmi_debug: 
			print 'self.item_scroll_timer=', self.item_scroll_timer
		if self.item_scroll_timer:
			del(self.item_scroll_timer)
			self.item_scroll_timer = None
			self.scroll_text = None
			self.temp_text = None

	def destroy(self):
		self.remove_item_scroll_timer()
		BaseUI.destroy(self)

	def show(self):
		BaseUI.show(self)
		#self.sel_box.hide()

	def hide(self):
		self.remove_item_scroll_timer()
		BaseUI.hide(self)
		
	def handle_key(self, key):		
		if key == 'Up':
			self.index -= 1
			if self.index <= -1:self.index = 1
			self.set_focus(self.index)
			return True
		elif key == 'Down':
			self.index += 1
			if self.index > 1: self.index = 0
			self.set_focus(self.index)
			return True
		return False
# yylee: [20080429] group bell UI- edit group bell==


class AdminExtraSettingQoSUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, '', menu3, menu4)				
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		#titleimage = uiconfig.title_camera_setting
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		#camera_brightness_choose = [_('Darkest camera'), _('Darker camera'), _('Normal camera'), _('Lighter camera'), _('Lightest camera')]
		#camera_brightness_choose = [_('Disable'), _('Enable')]
		camera_brightness_choose = ['Off', 'On']
		name, pos = uiconfig.icon_camera_brightness
		self.icon_camera_brightness = utils.put_image(name, pos)

		if setting.subscriber !=0 and setting.subscriber != 1:
			print '@@@ setting.subscriber was reset as 0'
			setting.subscriber = 0
		self.label_camera_brightness = controls.Label_Control(_('QoS MARKING'), font=uiconfig.alarm_font, pos=uiconfig.camera_brightness_text_pos, color=uiconfig.list_text_color)
		self.camera_brightness = controls.ListBox_Control(camera_brightness_choose, setting.subscriber, font=uiconfig.alarm_font, pos=uiconfig.select_cam_set_box1_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

	def destroy(self):
		self.icon_camera_brightness.free()
		self.label_camera_brightness.free()
		self.camera_brightness.free()
		BaseUI.destroy(self)
		
	#def set_focus(self,index):
	#	self.camera_brightness.showFocus()
	#	self.camera_wb.lostFocus()
		
	def show(self):		
		BaseUI.show(self)
		self.camera_brightness.showFocus()
		#self.set_focus(self.index)


class AdminExtraSettingDTMFUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, '', menu3, menu4)				
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		camera_brightness_choose = [_('Inband'), _('Out of band')]
		name, pos = uiconfig.icon_camera_brightness
		self.icon_camera_brightness = utils.put_image(name, pos)
		
		self.label_camera_brightness = controls.Label_Control(_('DTMF SETTING'), font=uiconfig.alarm_font, pos=uiconfig.camera_brightness_text_pos, color=uiconfig.list_text_color)
		self.camera_brightness = controls.ListBox_Control(camera_brightness_choose, int(setting.dtmf_set), font=uiconfig.alarm_font, pos=uiconfig.select_cam_set_box1_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

	def destroy(self):
		self.icon_camera_brightness.free()
		self.label_camera_brightness.free()
		self.camera_brightness.free()
		BaseUI.destroy(self)
	
	def show(self):		
		BaseUI.show(self)
		self.camera_brightness.showFocus()


class AdminExtraSettingURIUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, '', menu3, menu4)				
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		camera_brightness_choose = [_('KT URI'), _('Standard URI')]
		name, pos = uiconfig.icon_camera_brightness
		self.icon_camera_brightness = utils.put_image(name, pos)

		if int(setting.urlPolicy) != 1 and int(setting.urlPolicy) != 2:
			setting.urlPolicy = 1	
		self.label_camera_brightness = controls.Label_Control('URI '+_('Settings.'), font=uiconfig.alarm_font, pos=uiconfig.camera_brightness_text_pos, color=uiconfig.list_text_color)
		self.camera_brightness = controls.ListBox_Control(camera_brightness_choose, int(setting.urlPolicy)-1, font=uiconfig.alarm_font, pos=uiconfig.select_cam_set_box1_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

	def destroy(self):
		self.icon_camera_brightness.free()
		self.label_camera_brightness.free()
		self.camera_brightness.free()
		BaseUI.destroy(self)
	
	def show(self):		
		BaseUI.show(self)
		self.camera_brightness.showFocus()


class AdminExtraSettingPremiumIPUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, '', menu3, menu4)				
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		camera_brightness_choose = ['Premium IP', 'Kornet IP'] # out of translation : KT only.
		name, pos = uiconfig.icon_camera_brightness
		self.icon_camera_brightness = utils.put_image(name, pos)
		
		self.label_camera_brightness = controls.Label_Control(_('Premium IP'), font=uiconfig.alarm_font, pos=uiconfig.camera_brightness_text_pos, color=uiconfig.list_text_color)
		if config.mmi_debug: 
			print '## type(vdci_setting.premium_ip)=', type(vdci_setting.premium_ip)
			print '## vdci_setting.premium_ip=', vdci_setting.premium_ip
		if int(vdci_setting.premium_ip) != 0 and int(vdci_setting.premium_ip )!= 1:
			print '@@@ vdci_setting.premiup_ip was reset as 0'
			vdci_setting.premium_ip = 0		
		self.camera_brightness = controls.ListBox_Control(camera_brightness_choose, 1-int(vdci_setting.premium_ip), font=uiconfig.alarm_font, pos=uiconfig.select_cam_set_box1_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

	def destroy(self):
		self.icon_camera_brightness.free()
		self.label_camera_brightness.free()
		self.camera_brightness.free()
		BaseUI.destroy(self)
	
	def show(self):		
		BaseUI.show(self)
		self.camera_brightness.showFocus()


class NewCameraSettingUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, _('CAMERA SETTING'), menu3, menu4)		
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		#titleimage = uiconfig.title_camera_setting
		#name, pos = titleimage
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		# 카메라 밝기
		camera_brightness_choose = [_('Darkest camera'), _('Darker camera'), _('Normal camera'), _('Lighter camera'), _('Lightest camera')]
		name, pos = uiconfig.icon_camera_brightness
		self.icon_camera_brightness = utils.put_image(name, pos)
		self.label_camera_brightness = controls.Label_Control(_('Camera Brightness'), font=uiconfig.alarm_font, pos=uiconfig.camera_brightness_text_pos, color=uiconfig.list_text_color)
		self.camera_brightness = controls.ListBox_Control(camera_brightness_choose, setting.camera_brightness, font=uiconfig.alarm_font, pos=uiconfig.select_cam_set_box1_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

		camera_wb_choose = [_('Auto'), _('Sunny'), _('Cloudy'), _('Tungsten'), _('Fluorescent')]
		name, pos = uiconfig.icon_camera_wb
		self.icon_camera_wb = utils.put_image(name, pos)
		self.label_camera_wb= controls.Label_Control(_('White Balance'), font=uiconfig.alarm_font, pos=uiconfig.camera_wb_text_pos, color=uiconfig.list_text_color)
		self.camera_wb = controls.ListBox_Control(camera_wb_choose, setting.camera_white_balance, font=uiconfig.alarm_font, pos=uiconfig.select_cam_set_box2_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

		self.index = 0

	def destroy(self):
		self.icon_camera_brightness.free()
		self.icon_camera_wb.free()
		self.label_camera_brightness.free()
		self.label_camera_wb.free()
		self.camera_brightness.free()
		self.camera_wb.free()
		BaseUI.destroy(self)
		
	def set_focus(self,index):
		if index == 0:
			self.camera_brightness.showFocus()
			self.camera_wb.lostFocus()
		else:
			self.camera_brightness.lostFocus()
			self.camera_wb.showFocus()
	def show(self):		
		BaseUI.show(self)
		self.set_focus(self.index)

class SRSWOWSettingUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, _('WOW HD SETTING'), menu3, menu4)		
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		#name,pos = uiconfig.title_srs_wow_setting
		#title_image = utils.put_image(name,pos)
		#title_image.hide()
		#self.add(title_image)

		# Get Current SRS WOW Setting
		if utils.is_srswow_enabled():
			print "[yylee debug] srswow_enable"
			setting.srswow_enable = 1
		else:
			print "[yylee debug] srswow_disable"
			setting.srswow_enable = 0
			
		setting.srswow_preset = utils.get_srswow_preset()
		
		srswow_choose = [_('Disable'), _('Enable')]
		name, pos = uiconfig.select_bell_icon1
		self.icon_srs_wow = utils.put_image(name, pos)
		self.label_srs_wow = controls.Label_Control(_('WOW HD'), font=uiconfig.input_font, pos=uiconfig.select_bell_label1_pos, color=uiconfig.list_text_color)
		self.srs_wow_set = controls.ListBox_Control(srswow_choose, setting.srswow_enable, font=uiconfig.input_font, pos=uiconfig.select_bell_box1_pos, color=uiconfig.list_text_color,mode=uiconfig.LIST_MODE_MEDIUM)

		#srswow_preset_choose = [_('Normal'), _('Rock'), _('Pop'), _('Dance'), _('Classic'), _('Bass')]
		srswow_preset_choose = ['Normal', 'Rock', 'POP', 'Dance', 'Classic', 'Bass']
		self.srs_wow_preset = controls.ListBox_Control(srswow_preset_choose, setting.srswow_preset, font=uiconfig.alarm_font, pos=uiconfig.select_bell_box2_pos, color=uiconfig.list_text_color,mode=uiconfig.LIST_MODE_MEDIUM)

		self.index = 0

	def destroy(self):
		self.icon_srs_wow.free()
		self.label_srs_wow.free()
		self.srs_wow_set.free()
		self.srs_wow_preset.free()
		BaseUI.destroy(self)
		
	def set_focus(self,index):
		if index == 0:
			self.srs_wow_set.showFocus()
			self.srs_wow_preset.lostFocus()
		else:
			self.srs_wow_set.lostFocus()
			self.srs_wow_preset.showFocus()
			
	def show(self):		
		BaseUI.show(self)
		self.set_focus(self.index)
		

# Newair7: [20080415] Sound Setting->select bell UI
class NewSelectBellUI(BaseUI):
	show_bg_depth = True
	def __init__(self,left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, _('SELECT BELL'), menu3, menu4)		
		# bg image
#		bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
#		bg_image.hide()
#		self.add(bg_image)

		# title
		#name, pos  = uiconfig.Third_title_select_bell
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)
		
		# select bell icon
		name, pos = uiconfig.select_bell_icon1
		icon_1 = utils.put_image(name, pos)
		self.add(icon_1)

		# select bell text
		pos = uiconfig.select_bell_label1_pos 
		group_bell = runtime.evas.text(text=_('Bell'),font=uiconfig.input_font,pos=pos,color=uiconfig.list_text_color)
		self.add(group_bell)		
		
		# select box 1 (default)
		name = uiconfig.normal_icon_select
		pos = uiconfig.select_bell_box1_pos
		self.sel_box1 = utils.put_image(name, pos)
		self.add(self.sel_box1)
		
		# select box (green)
		name = uiconfig.normal_icon_select_r
		pos = uiconfig.select_bell_box1_pos
		self.sel_box_r = utils.put_image(name, pos)
		self.add(self.sel_box_r)

		# select box 2 (default)
		name = uiconfig.normal_icon_select
		pos = uiconfig.select_bell_box2_pos
		self.sel_box2 = utils.put_image(name, pos)
		self.add(self.sel_box2 )

		# Get audio_dir & file index		
		self.audio_dir_index = 0
		self.audio_file_index = 0
		self.find_audio_dir_index()			

		self.audio_dir = []
		self.lists = []
		self.full_lists = []
		self.update_lists_db()
		self.find_audio_file_index()
		if config.mmi_debug: 
			print '## self.audio_dir_index = ', self.audio_dir_index
			print '## self.audio_file_index =', self.audio_file_index

		#self.audio_dirs = [_('Basic bell'), _('Sweet bell'), _('Merry bell'), _('Classic bell'), _('Effect bell'), _('Download bell'), _('Recorded bell')]
		self.audio_dirs = [_('Basic bell'), _('Sweet bell'), _('Merry bell'), _('Classic bell'), _('Effect bell'),  _('Recorded bell')]
		pos = uiconfig.select_bell_text1_pos
		self.select_audio_dir= runtime.evas.text(text=self.audio_dirs[self.audio_dir_index], font=uiconfig.alarm_font,pos=pos,color=uiconfig.list_text_color)
		self.align_center(self.select_audio_dir, uiconfig.select_bell_text1_pos)
		self.add(self.select_audio_dir)

		#ring_name_ext = self.lists[self.audio_file_index]
		#ring_name = ring_name_ext.split('.')[0]
		ring_name = self.lists[self.audio_file_index]
		pos = uiconfig.select_bell_text2_pos
		# for long file name
		self.select_ring = runtime.evas.text(text=utils.cut_text(text=ring_name, width=uiconfig.bell_width_scroll, font=uiconfig.alarm_font)[0],font=uiconfig.alarm_font,pos=pos,color=uiconfig.list_text_color)
		self.align_center(self.select_ring, uiconfig.select_bell_text2_pos)
		self.add(self.select_ring)
		
		self.index = 0

		# for long file name
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None
		
	def align_center(self, l, pos):
		x, y = pos
		width,height = l.size
		l.move(x - width/2, y)

	def set_focus(self,index):	
		if index == 0:
			self.remove_item_scroll_timer()
			self.sel_box1.hide()
			self.sel_box2.show()
			pos = uiconfig.select_bell_box1_pos
			self.sel_box_r.move(pos[0], pos[1])
			self.sel_box_r.show()			

			# for long file name
			self.select_ring.hide()
			num = len(self.lists)
			if num > 0:
				#self.audio_file_index = 0
				ring_name = self.lists[self.audio_file_index]
				
				# for long file name
				self.select_ring.text_set(utils.cut_text(text=ring_name, width=uiconfig.bell_width_scroll, font=uiconfig.alarm_font)[0])
			else:
				#self.audio_file_index = -1
				self.select_ring.text_set(_('None'))
			self.align_center(self.select_ring, uiconfig.select_bell_text2_pos)
			self.select_ring.show()
			
		else:
			self.sel_box1.show()
			self.sel_box2.hide()
			pos = uiconfig.select_bell_box2_pos
			self.sel_box_r.move(pos[0], pos[1])
			self.sel_box_r.show()

			# for long file name
			num = len(self.lists)
			if num > 0:
				if config.mmi_debug: print 'current self.audio_file_index =', self.audio_file_index
				ring_name_ext = self.lists[self.audio_file_index]
				ring_name = ring_name_ext
					
				self.select_ring.hide()

				#스크롤 할지를 결정
				if self.is_scroll_item(ring_name) == True:
					self.org_label = self.temp_text = ring_name
					item_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
					self.select_ring.text_set(item_text)
					self.scroll_text = self.select_ring
					self.item_scroll_timer = utils.Timer(1000, self.scroll_item_timer_cb)
				else:
					self.select_ring.text_set(ring_name)

				self.align_center(self.select_ring, uiconfig.select_bell_text2_pos)
				self.select_ring.show()
					
				if config.mmi_debug: 
					print 'ring_name =', ring_name

	def update_lists_db(self):
		bell_type = ['basic', 'sweet', 'merry', 'classic', 'effect', 'download', 'recorded']	
		import sounds
		dirname, full_lists = sounds.get_audio_gallery_list(bell_type[self.audio_dir_index])
		self.audio_dir =dirname
		self.full_lists = full_lists
		self.sort()
		self.lists = []
		for item in self.full_lists:
			name = item[0]
			last_dot = name.rfind('.')
			if last_dot > 0:
				name = name[:last_dot]
				# yylee: added for korean file name support
				name = unicode(name, 'euc-kr').encode('utf-8')
				self.lists.append(name)
		if config.mmi_debug: 
			print 'after..final lists =', self.lists 

	def find_audio_dir_index(self):
		#print "[yylee debug] find_audio_dir_index:", setting.external_ring
		if config.mmi_debug: 
			print 'setting.external_ring=', setting.external_ring	

		if setting.external_ring.endswith('.mmf'):
			ring_file = setting.mmf_external_ring
		else:
			ring_file = setting.external_ring
		
		dir_name_index = ring_file.rfind('/')
		dir_name = ring_file[:dir_name_index+1]
		if config.mmi_debug: print 'dir_name=', dir_name

		if dir_name == config.audio_dir_basic:		self.audio_dir_index = 0
		elif	dir_name == config.audio_dir_sweet:	self.audio_dir_index = 1
		elif	dir_name == config.audio_dir_merry:	self.audio_dir_index = 2
		elif	dir_name == config.audio_dir_classic:	self.audio_dir_index = 3
		elif	dir_name == config.audio_dir_effect:	self.audio_dir_index = 4
		#elif	dir_name == config.audio_dir_download:	self.audio_dir_index = 5
		elif	dir_name == config.audio_dir_recorded:	self.audio_dir_index = 5
		else:									self.audio_dir_index = 0
			
	def find_audio_file_index(self):
		#print "[yylee debug] find_audio_file_index:", setting.external_ring
		if setting.external_ring.endswith('.mmf'):
			ring_file = setting.mmf_external_ring
		else:
			ring_file = setting.external_ring
	
		dir_name_index = ring_file.rfind('/')
		file_name = ring_file[dir_name_index+1:]
		if config.mmi_debug: print 'file_name=', file_name

		if len(self.full_lists) == 0:
			self.audio_dir_index = 0
			self.audio_file_index = 0
			self.audio_dir = []
			self.lists = []
			self.full_lists = []
			self.update_lists_db()
			setting.mmf_external_ring = ''
			setting.external_ring = config.def_melody
			
		i = 0
		for item in self.full_lists:
			if config.mmi_debug: 
				print 'i=%s, item[0]=%s' %(i, item[0])
			if item[0] == file_name:
				self.audio_file_index = i
				return 
			i +=1

		self.audio_dir_index = 0
		self.audio_file_index = 0
		self.audio_dir = []
		self.lists = []
		self.full_lists = []
		self.update_lists_db()
		setting.mmf_external_ring = ''
		setting.external_ring = config.def_melody

	def sort(self):
		if setting.audio_sort_rule == 0: # name
			def sort_func(x,y):
				return cmp(x[0].lower(), y[0].lower())
		elif setting.audio_sort_rule == 1: # size
			def sort_func(x,y,sort_col=setting.audio_sort_rule):
				return cmp(x[sort_col], y[sort_col])
		else: # date(new 가 먼저)
			def sort_func(x,y,sort_col=setting.audio_sort_rule):
				return -(cmp(x[sort_col], y[sort_col]))
		self.full_lists.sort(sort_func)

	def change_melody_dir(self, increase=True):
		# for long file name
		self.remove_item_scroll_timer()
		
		num = len(self.audio_dirs)
		if increase:
			self.audio_dir_index += 1
			if self.audio_dir_index >= num: 
				self.audio_dir_index = 0
		else:
			self.audio_dir_index -= 1
			if self.audio_dir_index < 0: 
				self.audio_dir_index = num-1
			
		audio_dir = self.audio_dirs[self.audio_dir_index]
		self.select_audio_dir.hide()
		self.select_audio_dir.text_set(audio_dir)
		self.align_center(self.select_audio_dir, uiconfig.select_bell_text1_pos)
		self.select_audio_dir.show()
		
		self.update_lists_db()

		self.select_ring.hide()
		num = len(self.lists)
		if num > 0:
			self.audio_file_index = 0
			ring_name = self.lists[self.audio_file_index]
			
			# for long file name
			self.select_ring.text_set(utils.cut_text(text=ring_name, width=uiconfig.bell_width_scroll, font=uiconfig.alarm_font)[0])
		else:
			self.audio_file_index = -1
			self.select_ring.text_set(_('None'))
		self.align_center(self.select_ring, uiconfig.select_bell_text2_pos)
		self.select_ring.show()

	def change_melody_file(self, increase=True):
		# for long file name
		self.remove_item_scroll_timer()
		
		if config.mmi_debug: print 'current self.audio_file_index =', self.audio_file_index
		num = len(self.lists)
		if num < 1:
			self.select_ring.hide()
			self.select_ring.text_set(_('None'))
			self.align_center(self.select_ring, uiconfig.select_bell_text2_pos)
			self.select_ring.show()
		else:
			if increase:
				self.audio_file_index += 1
				if self.audio_file_index >= num: 
					self.audio_file_index = 0
			else:
				self.audio_file_index -= 1
				if self.audio_file_index < 0:
					self.audio_file_index = num-1
				
			ring_name_ext = self.lists[self.audio_file_index]
			'''
			dot = ring_name_ext.rfind('.')
			if dot >= 0:
				ring_name = ring_name_ext[:dot]
			'''
			ring_name = ring_name_ext
			
			self.select_ring.hide()

			#스크롤 할지를 결정
			if self.is_scroll_item(ring_name) == True:
				self.org_label = self.temp_text = ring_name
				item_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
				self.select_ring.text_set(item_text)
				self.scroll_text = self.select_ring
				self.item_scroll_timer = utils.Timer(1000, self.scroll_item_timer_cb)
			else:
				self.select_ring.text_set(ring_name)

			self.align_center(self.select_ring, uiconfig.select_bell_text2_pos)
			self.select_ring.show()
			
			if config.mmi_debug: 
				print 'ring_name =', ring_name

	# for long file name
	def scroll_item_timer_cb(self):
		try:
			# KA: [20070921] this conversion is required for Korean text
			#if ord(self.temp_text[0]) > 127:
			latin_char = True
			
			if type(self.temp_text) == type('abc'):
				self.temp_text = unicode(self.temp_text, 'utf-8')[1:]
			else:
				self.temp_text = self.temp_text[1:]
			self.temp_text = self.temp_text.encode('utf-8')				
		except:
			self.temp_text = ''

		if len(self.temp_text) == 0:
			self.temp_text = self.org_label

		abbr_text = self.set_scroll_text(self.temp_text, uiconfig.bell_width_scroll)
		self.select_ring.text_set(abbr_text)
		runtime.evas.render()
		return True

	def set_scroll_text(self, item_text, abbr_width):
		if abbr_width > 0:
			abbr_text = utils.cut_text(item_text, abbr_width, uiconfig.alarm_font)[0]
			return abbr_text
		else:
			return item_text

	def is_scroll_item(self, item_text):
		etext = runtime.evas.text(text=item_text, font=uiconfig.alarm_font)
		text_width = etext.geometry[2]
		etext.free()

		if text_width > uiconfig.bell_width_scroll:
			return True
		else:
			return False
	
	def remove_item_scroll_timer(self):
		if self.item_scroll_timer:
			del(self.item_scroll_timer)
			self.item_scroll_timer = None
			self.scroll_text = None
			self.temp_text = None

	def show(self):		
		BaseUI.show(self)
		self.set_focus(self.index)
		if config.mmi_debug: print 'self.index=', self.index

	def hide(self):
		self.remove_item_scroll_timer()
		BaseUI.hide(self)

	def destroy(self):
		self.remove_item_scroll_timer()
		BaseUI.destroy(self)
		
	#def destroy(self):
	#	BaseUI.destroy(self)

	
# Newair7: [20080415] Sound setting --> select bell


# Newair7: [20080416] Sound Setting->select effect
class NewSelectEffectUI(BaseUI):
	show_bg_depth = True
	def __init__(self, item_index, left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, _('SELECT EFFECT'), menu3, menu4)		
		# bg image
#		bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
#		bg_image.hide()
#		self.add(bg_image)

		# title group set
		#name, pos  = uiconfig.Third_title_select_effect  #CHANGEME
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)

		# keytone effect
		name, pos = uiconfig.select_effect_icon1
		icon_keytone = utils.put_image(name, pos)
		self.add(icon_keytone)
		font = uiconfig.alarm_font
		color = uiconfig.list_text_color
		pos = uiconfig.select_effect_label1_pos
		keytone_text = runtime.evas.text(text=_('Key tone select'), font=font, pos=pos, color=color)
		self.add(keytone_text)
		self.keytone_sel = utils.put_image(uiconfig.normal_icon_select, uiconfig.select_effect_box1_pos)
		self.add(self.keytone_sel)

		# setting effect
		name, pos = uiconfig.select_effect_icon2
		icon_set = utils.put_image(name, pos)
		self.add(icon_set)
		pos = uiconfig.select_effect_label2_pos
		setting_text = runtime.evas.text(text=_('Effect tone select'), font=font, pos=pos, color=color)
		self.add(setting_text)
		self.set_sel = utils.put_image(uiconfig.normal_icon_select, uiconfig.select_effect_box2_pos)
		self.add(self.set_sel)

		# message effect
		'''
		name, pos = uiconfig.select_effect_icon3
		icon_msg = utils.put_image(name, pos)
		self.add(icon_msg)
		pos = uiconfig.select_effect_label3_pos
		message_text = runtime.evas.text(text=_('Message effect'), font=font, pos=pos, color=color)
		self.add(message_text)
		self.msg_sel = utils.put_image(uiconfig.normal_icon_select, uiconfig.select_effect_box3_pos)
		self.add(self.msg_sel)
		'''

		# weather effect
		'''
		name, pos = uiconfig.select_effect_icon4
		icon_weather = utils.put_image(name, pos)
		self.add(icon_weather)
		pos = uiconfig.select_effect_label4_pos
		weather_text = runtime.evas.text(text=_('Weather effect'), font=font, pos=pos, color=color)
		self.add(weather_text)
		self.weather_sel = utils.put_image(uiconfig.normal_icon_select, uiconfig.select_effect_box4_pos)
		self.add(self.weather_sel)
		'''
		
		# select box (green)
		self.sel_box = utils.put_image(uiconfig.normal_icon_select_r, uiconfig.select_effect_box1_pos)
		self.add(self.sel_box)

		#self.button_lists = [_('None'), _('Musical Scale'), _('Human Voice'), _('Xylophone'), _('Waterdrop') ]
		self.button_lists = [_('None'), _('Musical Scale'), _('Xylophone'), _('Waterdrop') ]
		self.setting_lists = [_('None'), _('Setting 1'), _('Setting 2'), _('Setting 3')]

		
		self.button_effect_index = setting.button_effect_index
		if setting.button_effect_index == 4:
			self.button_effect_index = 3
		elif setting.button_effect_index == 3:
			self.button_effect_index = 2
		self.setting_effect_index = setting.setting_effect_index
		#self.msg_effect_index = setting.message_effect_index
		#self.weather_effect_index = setting.weather_effect_index
		
		if config.mmi_debug: 
			print 'button_effect_index=%s, setting_effect_index=%s' %(self.button_effect_index, self.setting_effect_index)
			#print 'message_effiect_index=%s, weather_effect_index=%s' % (self.msg_effect_index, self.weather_effect_index)
			
		if self.button_effect_index < 0 and self.button_effect_index >= len(self.button_effect_lists):
			setting.button_effect_index = 0
			self.button_effect_index = 0
		if self.setting_effect_index < 0 and self.setting_effect_index >= len(self.setting_effect_lists):
			setting.button_effect_index = 0
			self.button_effect_index = 0
		'''
		if self.msg_effect_index < 0 and self.msg_effect_index >= len(self.message_effect_lists):
			setting.message_effect_index = 0
			self.msg_effect_index = 0
		'''
		'''
		if self.weather_effect_index < 0 and self.weather_effect_index >= len(self.weather_lists):
			setting.weather_effect_index = 0
			self.weather_effect_index= 0
		'''
		
		button_effect_text= self.button_lists[self.button_effect_index ]
		setting_effect_text = self.setting_lists[self.setting_effect_index]
		#msg_effect_text = self.message_lists[self.msg_effect_index]
		#weather_effect_text = self.weather_lists[self.weather_effect_index]
		
		self.button_text= runtime.evas.text(text=button_effect_text, font=uiconfig.alarm_font,pos=(250,104),color=uiconfig.list_text_color)
		self.align_center(self.button_text, uiconfig.select_effect_text1_pos)
		self.add(self.button_text)
		
		self.setting_text = runtime.evas.text(text=setting_effect_text, font=uiconfig.alarm_font,pos=(250,104),color=uiconfig.list_text_color)
		self.align_center(self.setting_text, uiconfig.select_effect_text2_pos)
		self.add(self.setting_text)

		'''
		self.msg_text = runtime.evas.text(text=msg_effect_text , font=uiconfig.alarm_font,pos=(250,104),color=uiconfig.list_text_color)
		self.align_center(self.msg_text, uiconfig.select_effect_text3_pos)
		self.add(self.msg_text)
		'''

		'''
		self.weather_text = runtime.evas.text(text=weather_effect_text, font=uiconfig.alarm_font,pos=(250,104),color=uiconfig.list_text_color)
		self.align_center(self.weather_text, uiconfig.select_effect_text4_pos)
		self.add(self.weather_text)
		'''

		self.index = 0
		self.set_focus(self.index, True)
		
	def align_center(self, l, pos):
		x, y = pos
		width,height = l.size
		l.move(x - width/2, y)
		
	def set_focus(self,index, in_init=False):
		if index == 0:
			self.sel_box.move(uiconfig.select_effect_box1_pos[0],uiconfig.select_effect_box1_pos[1])
			self.sel_box.show()
			# Up/Down 시에 다른 소리가 나는 문제 수정
			keytone_index = self.button_effect_index
			if self.button_effect_index == 2:
				keytone_index = 3
			elif self.button_effect_index == 3:
				keytone_index = 4
			if not in_init:
				utils.player.play_keytone('OK', keytone_index)
		elif 	index == 1:
			self.sel_box.move(uiconfig.select_effect_box2_pos[0],uiconfig.select_effect_box2_pos[1])
			self.sel_box.show()	
			if not in_init:
				utils.player.play_effect(config.SETTING_SUCCEEDED, effect_index=self.setting_effect_index)

	def change_button(self, increase=True):
		num = len(self.button_lists)
		if increase:
			self.button_effect_index += 1
			if self.button_effect_index >= num: 
				self.button_effect_index = 0
		else:
			self.button_effect_index -= 1
			if self.button_effect_index < 0: 
				self.button_effect_index = num-1

		button_text = self.button_lists[self.button_effect_index]		
		self.button_text.hide()
		self.button_text.text_set(button_text)
		self.align_center(self.button_text, uiconfig.select_effect_text1_pos)
		self.button_text.show()

		keytone_index = self.button_effect_index
		if self.button_effect_index == 2:
			keytone_index = 3
		elif self.button_effect_index == 3:
			keytone_index = 4
		
		utils.player.play_keytone('OK', keytone_index=keytone_index)

	def change_setting(self, increase=True):
		num = len(self.setting_lists)
		if increase:
			self.setting_effect_index += 1
			if self.setting_effect_index >= num: 
				self.setting_effect_index = 0
		else:
			self.setting_effect_index -= 1
			if self.setting_effect_index < 0: 
				self.setting_effect_index = num-1
			
		setting_text = self.setting_lists[self.setting_effect_index]
		self.setting_text.hide()
		self.setting_text.text_set(setting_text)
		self.align_center(self.setting_text, uiconfig.select_effect_text2_pos)
		self.setting_text.show()
		utils.player.play_effect(config.SETTING_SUCCEEDED, effect_index=self.setting_effect_index)

	def change_message(self, increase=True):
		num = len(self.message_lists)
		if increase:
			self.msg_effect_index += 1
			if self.msg_effect_index >= num: 
				self.msg_effect_index = 0
		else:
			self.msg_effect_index -= 1
			if self.msg_effect_index < 0: 
				self.msg_effect_index = num-1

		msg_text = self.message_lists[self.msg_effect_index]
		self.msg_text.hide()
		self.msg_text.text_set(msg_text )
		self.align_center(self.msg_text, uiconfig.select_effect_text3_pos)
		self.msg_text.show()
		utils.player.play_message_effect(message_effect_index=self.msg_effect_index)

	def change_weather(self, increase=True):
		num = len(self.weather_lists)
		if increase:
			self.weather_effect_index += 1
			if self.weather_effect_index >= num: 
				self.weather_effect_index = 0
		else:
			self.weather_effect_index -= 1
			if self.weather_effect_index < 0: 
				self.weather_effect_index = num-1

		weather_text = self.weather_lists[self.weather_effect_index]
		self.weather_text.hide()
		self.weather_text.text_set(weather_text)
		self.align_center(self.weather_text, uiconfig.select_effect_text4_pos)
		self.weather_text.show()
	
	#def destroy(self):
	#	BaseUI.destroy(self)
	
	#def show(self):
	#	BaseUI.show(self)

# Newair7: [20080416] Sound Setting->select bell UI


# KA: [20080311] phonebook UI
class SearchUI(BaseUI): # ListUI
	show_bg_depth = True
	def __init__(self, left, right, menu3, menu4):		
		BaseUI.__init__(self, left, right, _('SEARCH CONTACTS'), menu3, menu4)
		self.list = None
		self.item = None
		self.display_idx = 0
		
		# label: 검색
		titletext = _('Search')
		self.titletext = runtime.evas.text(text=titletext,font=uiconfig.pb_font)
		self.titletext.color = uiconfig.color_dark_gray
		self.titletext.pos = 84, 59-(uiconfig.pb_font[1]/2+2)
		self.add(self.titletext)

		# text input
		import entry
		self.entry = entry.Entry(pos=uiconfig.pb_search_entry_pos, size=uiconfig.pb_search_entry_size)
		self.entry.add_callback(self.entry.AutomataChanged, self.update_automata_icon)
		self.entry.set_text('') # this is just for initial cursor position
		self.entry.set_max(uiconfig.MAX_INPUT_NAME)
		self.add(self.entry)
		#self.window_rect = utils.put_image(uiconfig.multi_window_image, uiconfig.pb_entry_pos,uiconfig.pb_entry_size)
		#self.add(self.window_rect)

#		lbl_name = controls.Label_Control('Name', font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)	
#		name = controls.Input_Control(pos = (0,0), size=uiconfig.pb_entry_size)	
#		name.set_text('')
#		self.frame.append((lbl_name,name))

		# image box
		self.image_box = utils.put_image(uiconfig.PB_image_box, uiconfig.PB_image_box_pos)
		self.image_box.hide()
		self.add(self.image_box)
		
		# phonebook image
		#self.snapshot = utils.put_image(uiconfig.PB_image_file, uiconfig.PB_image_pos, img_dir = config.image_phonebook_dir)
		self.snapshot = utils.put_image(uiconfig.PB_image_file, uiconfig.PB_image_pos)
		self.snapshot.hide()
		self.add(self.snapshot)

		self.search_icon = utils.put_image(uiconfig.PB_search_icon_file, uiconfig.PB_search_icon_pos)
		self.add(self.search_icon)
		
		'''
		# number select icon
		self.sel_number = utils.put_image(uiconfig.PB_sel_number_file[0], uiconfig.PB_sel_number_pos)
		self.sel_number.hide()
		self.add(self.sel_number)
		
		# number icon
		self.sel_number_icon = utils.put_image(uiconfig.PB_number_icon_file[0], uiconfig.PB_number_icon_pos)
		self.sel_number_icon.hide()
		self.add(self.sel_number_icon)

		# number
		self.number = runtime.evas.text(text='',
				font=uiconfig.PB_number_pos_font,
				pos=uiconfig.PB_number_pos,
				color=uiconfig.color_dark_gray)
		self.add(self.number)
		'''
		# 3 numbers
		self.numbers=['', '', '']
		self.number_icons=['', '', '']
		for i in range(3):
			number_box = utils.put_image(uiconfig.PB_number_box, uiconfig.PB_number_box_pos[i])
			number_box.hide()
			self.add(number_box)

			#self.number_icon = utils.put_image(uiconfig.PB_number_icon_file[i], uiconfig.PB_number_icon_pos[i])
			#self.number_icon.hide()
			#self.add(self.number_icon)
			self.number_icons[i] =  utils.put_image(uiconfig.PB_number_icon_file[i], uiconfig.PB_number_icon_pos[i])
			self.number_icons[i].hide()
			self.add(self.number_icons[i])
			
			self.numbers[i] = runtime.evas.text(text='',
				font=uiconfig.PB_number_pos_font,
				pos=uiconfig.PB_number_pos[i],
				color=uiconfig.color_dark_gray)
			self.add(self.numbers[i])
		# 3number ==

		# for check box
		self.check = None
		self.icon_cols = []
		self.icons = {}
		self.checked = None
		self.return_number = ''
		self.return_numbers = []

######## Entry UI
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0
######## Entry UI ==
		self.newChoice = None

	def set_focus(self, focus):
		self.list.set_focus(focus)

	def update_info(self, init = False, no_result=False):
		if config.mmi_debug: print '## init=', init, 'no_result=', no_result
		from phonedb import phonedb
		if init:
			self.item = phonedb.new_item()
			self.update_snapshot()
			self.update_numbers()
			return
		# KA: 2008.06.17		
		#focus = self.get_focus() #new list의 focus
		#name = self.newChoice[focus]
		
		#self.phonedb_indexes = range(phonedb.count())
		#focus = phonedb.find_by_char(name, self.phonedb_indexes)# 실제 phonedb에서의 focus
		#self.item = phonedb.get_item(focus)
		
		if no_result == True:			
			self.set_preview('photos/snapshot/no_photo.png')
			for i in range(3):
		 		self.number_icons[i].file = uiconfig.image_dir + uiconfig.PB_number_icon_file[i]
		 		self.numbers[i].text_set('')
		else:
			index = self.get_focus()
			if len(status.real_phonedb_index) != 0:
				try:
					index = status.real_phonedb_index[index]
				except:
					pass
			if phonedb.count()<= index:
				print '&&& critical error'
				index = 0
			self.item=phonedb.get_item(index)
			if config.mmi_debug: 
				print 'index=', index
				print 'self.item=',self.item		
			self.update_snapshot()
			self.update_numbers()
		
	# KA: [20080329] init number by priority
	def get_priority_number(self):
		from phonedb import phonedb
		self.display_idx, number = phonedb.get_priority_number(self.item)
		return number
		'''
		from phonedb import phonedb
		self.display_idx, number = phonedb.get_priority_number(self.item)
		self.sel_number_icon.file = uiconfig.image_dir + uiconfig.PB_number_icon_file[self.display_idx]
		self.number.text_set(number)
		self.return_number = number
		'''
	# KA: [20080329] init number by priority ==
	
	def update_priority_icon(self):
		if not self.item[2]:
			index = 0
		else:
			index = int(self.item[2]) # 0, 1, 2
		
		for i in range(3):
		 	num = self.item[i+3]
		 	if i == index:
		 		self.number_icons[i].file = uiconfig.image_dir + uiconfig.pb_pirority_number_set[i]
		 	else:
		 		self.number_icons[i].file = uiconfig.image_dir + uiconfig.PB_number_icon_file[i]
	
	def update_numbers(self):
		 for i in range(3):
		 	num = self.item[i+3]
			'''
		 	if len(num) > 11:
		 		display_num = num[:11]
		 	else:
		 		display_num = num

		 	self.numbers[i].text_set(utils.conv_telnum(display_num))
		 	'''
		 	display_num = utils.conv_telnum(num)

		 	if len(display_num) > 13:
		 		display_num = display_num[:13]

		 	self.numbers[i].text_set(display_num)
		 	
		 self.update_priority_icon()
		
	def update_snapshot(self):
		item = self.item
		number = item[3] or item[4] or item[5]
		from phonedb import phonedb
		snapshot = phonedb.get_snapshot(number)
		if snapshot:
			import os
			if not os.access(snapshot, os.R_OK):
				if config.mmi_debug: print '@@@@ snapshot is not available'
				snapshot = 'photos/snapshot/no_photo.png'
			self.set_preview(snapshot)
		else:
			snapshot = 'photos/snapshot/no_photo.png'
#			self.snapshot.show()
			self.set_preview(snapshot)
	
			# 알 수 없는 이유로 인해 파일이 존재 하지 않을때
			#if not os.access(snapshot, os.R_OK):

			#	snapshot = None

	def get_item(self):
		from phonedb import phonedb
		focus = self.get_focus()
		item = phonedb.get_item(focus)
		return item

	def set_find(self):
		self.entry.set_text(self.item[0])
		
	def set_preview(self, file):
		filesize = utils.get_size_kb(file)
		tmp_w, tmp_h = utils.get_img_size(file)
		if tmp_w * tmp_h > 640 * 480:
			file = '/usr/local/lgvp/images/image_big.png'
		
		self.snapshot.file = file
		#self.snapshot.file = utils.changefile_gif(file)

	def update_number(self):
		self.sel_number_icon.file = uiconfig.image_dir + uiconfig.PB_number_icon_file[self.display_idx]
#		if self.display_idx == 0:
#			self.number.text_set(self.item[int(self.item.prority)+3])
#			self.return_number = self.item[int(self.item.prority)+3]
#		else:
		self.number.text_set(self.item[self.display_idx + 3])
		self.return_number = self.item[self.display_idx + 3]
		# KA: [20080406] phonebook multiselect icon -- return_number added

	def set_list(self, labels, unselbarpos=[]):
		#roxia_trace('ListUI.set_list(), lables=', labels)
		self.list = widget.PhoneBookList(labels, unselbarpos)
		self.add(self.list)
		# 2008.06.17
		self.newChoice = labels

	def EA_set_list(self, labels, unselbarpos=[]):
		#roxia_trace('ListUI.set_list(), lables=', labels)
		self.list = widget.PhoneBookList(labels, unselbarpos)
		self.add(self.list)

		for ic in self.icon_cols:
			self.list.attach_icon_column(ic)

# KA: [20080406] phonebook multiselect icon
		self.icon_cols = [uiconfig.check_icon_unselected ] * len(labels)
		self.list.remove_all_icon_columns()
		self.create_icon_column(self.icon_cols)
		self.checked = [False] * len(labels)

	def create_icon_column(self,icons, resize=[0,0]):
		self.check = widget.PhonebookIconColumn(icons, resize)
		self.list.attach_icon_column(self.check)
		self.icon_cols.append(self.check)
		self.add(self.check)

	def remove_all_icon_columns(self):
		self.list.remove_all_icon_columns()
		for ic in self.icon_cols:
			self.widgets.remove(ic)
			ic.free()
		self.icon_cols = []

	def set_check(self, focus, check):
		if self.checked[focus] == check:
			return
		self.checked[focus] = check
		if check:
			self.check.set_icon(focus, uiconfig.check_icon_selected)
			self.update_return_number(focus, True)
		else:
			self.check.set_icon(focus, uiconfig.check_icon_unselected)
			self.update_return_number(focus, False)

	def toggle(self, focus=None):
		if focus == None:
			focus = self.focus
		self.set_check(focus, not self.checked[focus])

	def update_return_number(self, focus, add=True):
		if add:
			self.return_numbers.append(self.return_number)
		else:
			self.return_numbers.remove(self.return_number)
		#print 'ka.....####### return number = ', self.return_numbers
	
# KA: [20080406] phonebook multiselect icon ==

	def update_lists(self, labels, unselbarpos=[]):
		prev_pos = self.get_focus()
		self.list.free()
		self.widgets.remove(self.list)
		self.list = widget.PhoneBookList(labels, unselbarpos)
		self.add(self.list)
		if prev_pos >= len(self.list.labels):
			prev_pos = len(self.list.labels)-1
		self.set_focus(prev_pos)
		# 2008.06.17
		self.newChoice = labels

	def get_focus(self):
		return self.list.focus

#	def set_focus(self, focus):
#		self.list.set_focus(focus)

	def set_text(self, n, text):
		self.list.set_text(n, text)

	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)

	def handle_key(self, keyname):		
		if keyname == 'Up':
			self.list.focus_up()
			#self.display_idx = 0
			self.update_info()
			#self.sel_number.file = uiconfig.image_dir  + uiconfig.PB_sel_number_file[0]
			#self.sel_number.show()
			#self.set_find()
			return True
		elif keyname == 'Down':
			self.list.focus_down()
			#self.display_idx = 0
			self.update_info()
			#self.sel_number.file = uiconfig.image_dir  + uiconfig.PB_sel_number_file[0]
			#self.sel_number.show()
			#self.set_find()
			return True
		elif keyname == 'Right':
			self.display_idx = self.display_idx + 1
			if self.display_idx > 2:
				self.display_idx = 0	
			self.sel_number.file = uiconfig.image_dir  + uiconfig.PB_sel_number_file[1]
			self.sel_number.show()
			self.update_number()
			return True
		elif keyname == 'Left':
			self.display_idx = self.display_idx - 1
			if self.display_idx < 0:
				self.display_idx = 2
			self.sel_number.file = uiconfig.image_dir  + uiconfig.PB_sel_number_file[1]
			self.sel_number.show()
			self.update_number()
			return True
		return False

############# EntryUI

	def destroy(self):
		if self.automata_icon: self.automata_icon.free()
		BaseUI.destroy(self)

	def hide(self):
		if self.automata_icon: self.automata_icon.hide()
		BaseUI.hide(self)

	def show(self):
		if self.automata_icon: self.automata_icon.show()
		BaseUI.show(self)

	# 최초 init시에 
	def set_fixed_automata(self, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_automata(name, casemode)
		else:
			self.fixed_automata = False
			self.set_automata(*utils.get_def_automata())

# KA: [20080426] soft3 - symbol
	def set_automata(self, name, casemode='lower'):
		self.automata = name, casemode
		self.entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)

	def update_automata_icon(self):
		#name = self.entry._automata.name()
		#casemode = self.entry._automata.case_mode()
		#self.automata = name, casemode
		name, casemode = self.automata 
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		elif name == 'multitap':
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		elif name == 't9':
			if casemode == 'upper':			menu3 = _('T9ABC')
			elif casemode == 'lower':		menu3 = _('T9abc')
			elif casemode == 'first capital':	menu3 = _('T9Abc')	
		else:				menu3 = _('SYMBOL')
			
		self.set_menu3(menu3)
		
		if name =='symbol':
			# shchun : global automata change
			#self.ui.set_fixed_automata(self.ui.list.entrys[0], None, False)
			self.set_automata( 'multitap', 'lower')
			if setting.lang == 'Korean':
				self.set_automata('hangul', False)
			else:
				self.set_automata('multitap', 'lower')	
			
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
			# end shchun
		
			#self.set_automata('hangul', False)	
			#from basemodel import SymbolSelectionStage
			#runtime.manager.stack_stage(SymbolSelectionStage(self, True))
			#return self.entry.handle_key(key) # Automata.handle_key에서 한글 입력후에 Editing mode를 0 으로 만든다. 

	def insert_text(self, text):
		self.entry.insert_unicode_text(unicode(text, 'utf-8'))
		self.entry._automata.check_start_of_sentance()
		#self.update_entry_info()

	def delete_char(self):
		self.handle_key('\b')
		#self.update_entry_info()

	def insert_symbol(self, s):
		before_text = self.get_text()
		self.insert_text(s)
		after_text = self.get_text()
		runtime.manager.back_stage()
		#if before_text == after_text:
		#	from basemodel import NotifyStage
		#	runtime.manager.change_stage(NotifyStage(_('Max length exceeded'), uiconfig.baloon_message_icon))
		#else:
		#	runtime.manager.back_stage()
		
# KA: [20080426] soft3 - symbol ==

	def get_text(self):
		return self.entry.get_text()
# KA: [20080311] phonebook UI ==

class WhiteUI(BaseUI):
	def __init__(self, left, right, title, small_title='', menu3='', menu4=''):
		BaseUI.__init__(self, left, right, title, menu3, menu4)
		t = runtime.evas.text()
		t.font=uiconfig.def_font, 14
		t.color=uiconfig.color_dark_gray
		t.text= title
		t.pos =(15, 10)
		self.add(t)



class SmallWindowUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, small_title='', menu3='', menu4=''):
		BaseUI.__init__(self, left, right, title, menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		
		pos = uiconfig.small_window_bar_pos
		self.bar = utils.put_image(uiconfig.current_theme.window_bar, pos)
		self.posx = pos[0]
		self.posy = pos[1]
		self.add(self.bar)

		pos = uiconfig.small_window_pos
		self.window = utils.put_image(uiconfig.small_window_image, pos)
		self.add(self.window)

		pos = uiconfig.small_window_title_pos
		font = uiconfig.small_window_title_font
		color = uiconfig.small_window_title_color
		stitle = widget.OutlineLabel(small_title, font, pos, color, align=uiconfig.ALIGN_LEFT)
		self.add(stitle)
		self.subtitle = stitle

#	def change_theme(self):
#		self.bar.file = uiconfig.image_dir + uiconfig.current_theme.window_bar


class LargeWindowUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left='', right='', title='', small_title='', menu3='', menu4=''):
		BaseUI.__init__(self, left, right, title, menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
		
		top = pos = uiconfig.large_window_bar_pos

		# shchun --  need new layout (rollbacked..)
		self.bar = utils.put_image(uiconfig.current_theme.window_bar, pos)
		self.posx = pos[0]
		self.posy = pos[1]
		self.add(self.bar)

		pos = uiconfig.large_window_pos
		self.window = utils.put_image(uiconfig.large_window_image, pos)
		self.add(self.window)

		self._show_arrow = False

		dpos = uiconfig.large_window_up_arrow_pos
		self.up_arrow = utils.put_image(uiconfig.up_arrow, (top[0] + dpos[0], top[1] + dpos[1]))
		self.up_arrow.hide()

		dpos = uiconfig.large_window_down_arrow_pos
		self.down_arrow = utils.put_image(uiconfig.down_arrow, (top[0] + dpos[0], top[1] + dpos[1]))
		self.down_arrow.hide()

		pos = uiconfig.large_window_title_pos
		font = uiconfig.large_window_title_font
		color = uiconfig.large_window_title_color
		stitle = widget.OutlineLabel(small_title,font,pos,color,align=uiconfig.ALIGN_LEFT)
		self.add(stitle)
		self.window_title = stitle

		pos = uiconfig.large_window_info_pos
		font = uiconfig.large_window_info_font
		color = uiconfig.large_window_info_color
		self.einfo = widget.OutlineLabel('', font, pos, color, align=uiconfig.ALIGN_RIGHT)
		self.add(self.einfo)

	def destroy(self):
		BaseUI.destroy(self)
		self.up_arrow.free()
		self.down_arrow.free()

	def show(self):
		BaseUI.show(self)
		if self._show_arrow:
			self.up_arrow.show()
			self.down_arrow.show()

	def hide(self):
		BaseUI.hide(self)
		self.up_arrow.hide()
		self.down_arrow.hide()

	def show_arrow(self, show):
		if self._show_arrow != show:
			self._show_arrow = show
			self.hide()
			self.show()

	def set_info(self, text):
		self.einfo.set_text(text)

#	def change_theme(self):
#		self.bar.file = uiconfig.image_dir + uiconfig.current_theme.window_bar


#ka...3800 wizard 2007.04.16
class LargeWindowMessageUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, message='', small_title=''):
		BaseUI.__init__(self, left, right, title)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)
		
		top = pos = uiconfig.large_window_bar_pos
		self.bar = utils.put_image(uiconfig.current_theme.window_bar, pos)
		self.posx = pos[0]
		self.posy = pos[1]
		self.add(self.bar)

		pos = uiconfig.large_window_pos
		self.window = utils.put_image(uiconfig.large_window_image, pos)
		self.add(self.window)

		self._show_arrow = False

		dpos = uiconfig.large_window_up_arrow_pos
		self.up_arrow = utils.put_image(uiconfig.up_arrow, (top[0] + dpos[0], top[1] + dpos[1]))
		self.up_arrow.hide()

		dpos = uiconfig.large_window_down_arrow_pos
		self.down_arrow = utils.put_image(uiconfig.down_arrow, (top[0] + dpos[0], top[1] + dpos[1]))
		self.down_arrow.hide()

		pos = uiconfig.large_window_title_pos
		font = uiconfig.large_window_title_font
		color = uiconfig.large_window_title_color
		stitle = widget.OutlineLabel(small_title,font,pos,color,align=uiconfig.ALIGN_LEFT)
		self.add(stitle)
		self.window_title = stitle

		pos = uiconfig.large_window_info_pos
		font = uiconfig.large_window_info_font
		color = uiconfig.large_window_info_color
		self.einfo = widget.OutlineLabel('', font, pos, color, align=uiconfig.ALIGN_RIGHT)
		self.add(self.einfo)

		text_lines = message
		tmp_l = runtime.evas.text(text=text_lines)
		text_lines = tmp_l.text_get()
		lines = text_lines.split('\n')
		tmp_l.free()
		if not lines:
			lines = ['']
		if len(lines) > 4:
			lines = lines[:4]
		nlines = len(lines)
		pos_y = uiconfig.Large_text_pos_y[nlines - 1]
		x = uiconfig.baloon_text_pos_x
		font=uiconfig.Large_text_font
		new_font = font
		new_line = []
		for i, line in enumerate(lines):
			text1, text2, new_font = utils.baloon_resize_text(line, 310, new_font)
			if not text1:
				text1, text2, new_font = utils.baloon_resize_text2(line, 310, new_font)
			new_line.append(text1)
			if text2:
				while text2:
					text1, text2, new_font = utils.baloon_resize_text(text2, 310, new_font)
					if not text1:
						new_line.pop()
						text1, text2, new_font = utils.baloon_resize_text2(line, 310, new_font)
					new_line.append(text1)

		nlines = len(new_line)
		pos_y = uiconfig.Large_text_pos_y[nlines - 1]
#Roxia Begin smyook 06.02.07
		#x = uiconfig.baloon_text_pos_x

		for i, line in enumerate(new_line):
			y = pos_y[i]
			line, new_font = utils.resize_text(line, 310, new_font)
			message = runtime.evas.text(text=line)
			message.font=new_font
			message.pos=((320 - message.geometry[2])/2, y)
			message.color=uiconfig.baloon_text_color
#Roxia End smyook
			self.add(message)

	def destroy(self):
		BaseUI.destroy(self)
		self.up_arrow.free()
		self.down_arrow.free()

	def show(self):
		BaseUI.show(self)
		if self._show_arrow:
			self.up_arrow.show()
			self.down_arrow.show()

	def hide(self):
		BaseUI.hide(self)
		self.up_arrow.hide()
		self.down_arrow.hide()

	def show_arrow(self, show):
		if self._show_arrow != show:
			self._show_arrow = show
			self.hide()
			self.show()

	def set_info(self, text):
		self.einfo.set_text(text)

#	def change_theme(self):
#		self.bar.file = uiconfig.image_dir + uiconfig.current_theme.window_bar


class GaugeUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, menu3, menu4, titleimage, title=''):
		BaseUI.__init__(self, left, right, title, menu3, menu4)

		#bg_image = utils.put_image(uiconfig.depth_bg_image,(0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#self.titleimage  = titleimage 
		#name = titleimage
		#pos = uiconfig.menu_tits_pos
		#title_image = utils.put_image(name, pos)
		#title_image.hide()
		#self.add(title_image)	

		bg_icon_image = utils.put_image(uiconfig.volume_setting_bgicon_image,(93,73))
		bg_icon_image.hide()
		self.add(bg_icon_image)
		
		self.gauge = widget.Gauge()
		if title==_('RINGING VOLUME'):
			self.gauge.min = 0
		self.add(self.gauge)

	def set_value(self, value):
		self.gauge.set_value(value)

	def get_value(self):
		return self.gauge.get_value()

	def handle_key(self, keyname):
		if keyname == 'Up' or keyname == 'Right':
			self.gauge.value_up()
			return True
		elif keyname == 'Down' or keyname == 'Left':
			self.gauge.value_down()
			return True
		return False
		
	def show(self):
		BaseUI.show(self)
		self.gauge.update_arrow()


class BaloonUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, icon, isline=False, menu3='', menu4=''):
		BaseUI.__init__(self, left, right, '', menu3, menu4)

		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		if icon != -1:
			if icon:
				pass
				'''
				icon_name, pos = icon
				self.icon = utils.put_image(icon_name, pos)
				self.add(self.icon)
				'''
		name, pos = uiconfig.baloon_icon
		image = utils.put_image(name, pos)
		self.add(image)


class BaloonMessageUI(BaloonUI):
	# add shchun (May-18): add change_message, add self.msg_widget
	def __init__(self, left, right, title, icon, message, menu3='', menu4=''):
		BaloonUI.__init__(self, left, right, title, icon, '', menu3, menu4 )
		self.msg_wigdet = []
		text_lines = message
		tmp_l = runtime.evas.text(text=text_lines)
		text_lines = tmp_l.text_get()
		lines = text_lines.split('\n')
		tmp_l.free()
		if not lines:
			lines = ['']
		if len(lines) > 4:
			lines = lines[:4]
		nlines = len(lines)
		pos_y = uiconfig.baloon_text_pos_y[nlines - 1]
		x = uiconfig.baloon_text_pos_x
		font = uiconfig.baloon_text_font[nlines - 1]
		new_font = font
		new_line = []
		for i, line in enumerate(lines):
			text1, text2, new_font = utils.baloon_resize_text(line, 310, new_font)
			if not text1:
				text1, text2, new_font = utils.baloon_resize_text2(line, 310, new_font)
			new_line.append(text1)
			if text2:
				while text2:
					text1, text2, new_font = utils.baloon_resize_text(text2, 310, new_font)
					if not text1:
						new_line.pop()
						text1, text2, new_font = utils.baloon_resize_text2(line, 310, new_font)
					new_line.append(text1)

		nlines = len(new_line)
		pos_y = uiconfig.baloon_text_pos_y[nlines - 1]
		x = uiconfig.baloon_text_pos_x

		for i, line in enumerate(new_line):
			y = pos_y[i]
			line, new_font = utils.resize_text(line, 310, new_font)
			message = runtime.evas.text(text=line,
				font=new_font,
				pos=(x, y),
				color=uiconfig.baloon_text_color)
			self.align_center(message, (240,y))
			#self.add(message)
			self.msg_wigdet.append(message)

	def align_center(self, l, pos):
		x, y = pos
		width,height = l.size
		l.move(x - width/2, y)

	def change_language(self):
		pass

	# shchun : add change_message()
	def change_message(self, new_message):
		for w in self.msg_wigdet:
			w.hide()
			w.free()
		
		text_lines = new_message
		tmp_l = runtime.evas.text(text=text_lines)
		text_lines = tmp_l.text_get()
		lines = text_lines.split('\n')
		tmp_l.free()
		if not lines:
			lines = ['']
		if len(lines) > 4:
			lines = lines[:4]
		nlines = len(lines)
		pos_y = uiconfig.baloon_text_pos_y[nlines - 1]
		x = uiconfig.baloon_text_pos_x
		font=uiconfig.baloon_text_font[nlines - 1]
		new_font = font
		new_line = []
		for i, line in enumerate(lines):
			text1, text2, new_font = utils.baloon_resize_text(line, 310, new_font)
			if not text1:
				text1, text2, new_font = utils.baloon_resize_text2(line, 310, new_font)
			new_line.append(text1)
			if text2:
				while text2:
					text1, text2, new_font = utils.baloon_resize_text(text2, 310, new_font)
					if not text1:
						new_line.pop()
						text1, text2, new_font = utils.baloon_resize_text2(line, 310, new_font)
					new_line.append(text1)

		nlines = len(new_line)
		pos_y = uiconfig.baloon_text_pos_y[nlines - 1]
		x = uiconfig.baloon_text_pos_x

		for w in self.msg_wigdet:
			w.hide()
			w.free()

		self.msg_wigdet = []
		for i, line in enumerate(new_line):
			y = pos_y[i]
			line, new_font = utils.resize_text(line, 310, new_font)
			message = runtime.evas.text(text=line, 
				font=new_font,
				pos=(x, y),
				color=uiconfig.baloon_text_color)
			self.align_center(message, (240,y))
			self.msg_wigdet.append(message)
			
		for w in self.msg_wigdet:
			w.show()
			
	def hide(self):
		for w in self.msg_wigdet:
			w.hide()
		BaseUI.hide(self)	
		
	def show(self):
		for w in self.msg_wigdet:
			w.show()
		BaseUI.show(self)	
		
	def destroy(self):
		for w in self.msg_wigdet:
			w.hide()
			w.free()	
		BaloonUI.destroy(self)

		
# KA: [20080403] SNMP UI
class FullBaloonUI(BaseUI):
	def __init__(self, left, right, title, icon, isline=False):
		BaseUI.__init__(self, left, right, title)
		#if icon != -1:
		#	if icon:
		#		icon_name, pos = icon
		#		self.icon = utils.put_image(icon_name, pos)
		#		self.add(self.icon)
		#name, pos = uiconfig.notify_bg_image
		#image = utils.put_image(name, pos)
		#self.add(image)


class FullBaloonDownloadUI(FullBaloonUI):
	def __init__(self, left='', right='', title='', icon='', message='', auto_duration = False):
		FullBaloonUI.__init__(self, left, right, title, icon)
		# background box
		name, pos = uiconfig.downloading_box
		self.background_box = utils.put_image(name, pos)
		self.add(self.background_box)
		
		# Download msg
		text_lines = message
		tmp_l = runtime.evas.text(text=text_lines)
		text_lines = tmp_l.text_get()
		lines = text_lines.split('\n')
		tmp_l.free()
		if not lines:
			lines = ['']
		if len(lines) > 4:
			lines = lines[:4]
		nlines = len(lines)
		pos_y = uiconfig.full_download_msg_pos_y[nlines - 1]
		x = uiconfig.full_baloon_text_pos_x
		font=uiconfig.download_progress_text_font[nlines - 1]
		new_font = font
		new_line = []
		for i, line in enumerate(lines):
			text1, text2, new_font = utils.baloon_resize_text(line, 310, new_font)
			if not text1:
				text1, text2, new_font = utils.baloon_resize_text2(line, 310, new_font)
			new_line.append(text1)
			if text2:
				while text2:
					text1, text2, new_font = utils.baloon_resize_text(text2, 310, new_font)
					if not text1:
						new_line.pop()
						text1, text2, new_font = utils.baloon_resize_text2(line, 310, new_font)
					new_line.append(text1)

		nlines = len(new_line)
		pos_y = uiconfig.full_download_msg_pos_y[nlines - 1]
		x = uiconfig.full_baloon_text_pos_x

		for i, line in enumerate(new_line):
			y = pos_y[i]
			line, new_font = utils.resize_text(line, 310, new_font)
			message = runtime.evas.text(text=line,
				font=new_font,
				pos=(x, y),
				color=uiconfig.color_dark_gray)
			self.add(message)
		# Download msg ==

		# Donwload status image
		#self.progress = widget.Progress(pos = uiconfig.download_progress_image_pos, \
		#			size = uiconfig.download_progress_bar_size, \
		#			out_icon = uiconfig.download_progress_image, \
		#			in_icon=uiconfig.audio_record_progress_in_icon_new)
		self.progress = widget.SNMPProgress()
		self.add(self.progress)
		self.progress.hide()

		# Donwload status text
		if not auto_duration:
			info =  '%d/%d' % (0, 0)
			self.duration = runtime.evas.text(text=info, 
					font=uiconfig.download_progress_text_font[5],
					pos=uiconfig.download_progress_text_pos,
					color=uiconfig.color_dark_gray) #baloon_text_color
			self.add(self.duration)

		self.progress_timer = None

	# 최초 값 세팅
	def set_state(self, current, total):
		self.total = total
		#self.progress.set_max_value(100)
		status =  '%d/%d' % (int(current), int(total))
		self.duration.text_set(status)
		
	# change progress bar
	def set_value(self, value):
		self.progress.set_value(value)
		
	# change current file
	def set_current_file(self, value):
		status =  '%d/%d' % (int(value), int(self.total))
		self.duration.text_set(status)

	def update_image(self):
		self.progress.set_max_value(100)
		for i in range(41):
			self.progress.set_value(i)
		return True	

	def update_status(self):
		self.progress_timer = utils.Timer(1000, self.update_image)
# KA: [20080403] SNMP UI ==




class EntryUI(SmallWindowUI):
	def __init__(self, left, right, title, subtitle, ismms=False, menu3='', menu4='', need_hangul=True):
		self.ismms = ismms
		self.need_hangul = need_hangul

		print 'NEED HANGUL', self.need_hangul
		SmallWindowUI.__init__(self, left, right, title, subtitle, menu3, menu4)
		width, height = uiconfig.entry_size
		import entry
		self.entry = entry.Entry(pos = uiconfig.entry_pos, size=uiconfig.entry_size)
		self.entry.add_callback(self.entry.AutomataChanged, self.update_automata_icon)

		# shchun: Korean version doesn't need euro alphabet.
		#		in order to prevent euc-kr encodings...
		self.entry.ascii_mode_case0 = True	
		self.add(self.entry)

		pos = uiconfig.entry_info_pos
		font = uiconfig.entry_info_font
		color = uiconfig.entry_info_color
		self.einfo = widget.OutlineLabel('', font, pos, color, align=uiconfig.ALIGN_RIGHT)
		self.add(self.einfo)

		self.t9mode = False
		self.automata_icon = None
		self.automata_idx = 0
		if setting.lang == 'Korean':	
			self.automata = config.automata_list_hangul[self.automata_idx]		
		else:	
			self.automata = config.automata_list[self.automata_idx]	

		self.def_left = left
		self.def_right = right
		self.fixed_automata = False

		self.symbol_stage_timer = None

	def destroy(self):
		if self.automata_icon: self.automata_icon.free()
		SmallWindowUI.destroy(self)
		self.symbol_stage_timer = None

	def show(self):	
		if self.automata_icon: self.automata_icon.show()
		SmallWindowUI.show(self)

		self.automata_idx = 0
		if setting.lang == 'Korean':	
			self.automata = config.automata_list_hangul[self.automata_idx]		
		else:	
			self.automata = config.automata_list[self.automata_idx]	

		if self.entry.length() == 0:
			self.set_right('')
		else:
			self.set_right(_('CLEAR'))

	def hide(self):
		if self.automata_icon: self.automata_icon.hide()
		SmallWindowUI.hide(self)

	def set_subtitle(self, text):
		self.subtitle.text = text

	def set_max(self, max=-1):
		self.entry.set_max(max)
		self.update_entry_info()

	def set_fixed_automata(self, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			#self.set_right(_(right_field))
			self.set_automata(name, casemode)
		else:
			self.fixed_automata = False
			self.set_automata(*utils.get_def_automata())

	def set_automata(self, name, casemode='lower'):
		self.automata = name, casemode
		self.entry.set_automata(name, casemode)
		if name == 't9':
			self.t9mode = True
		else:
			self.t9mode = False
			
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)

	def update_automata_icon(self):
		#name = self.entry._automata.name()
		#casemode = self.entry._automata.case_mode()
		#self.automata = name, casemode
		name, casemode = self.automata 
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		elif name == 'symbol':	menu3 = _('SYMBOL')
		elif name == 't9':
			if casemode == 'upper':			menu3 = _('T9ABC')
			elif casemode == 'lower':		menu3 = _('T9abc')
			elif casemode == 'first capital':	menu3 = _('T9Abc')		
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
			
				
		self.set_menu3(menu3)
		if name == 'symbol':
			if setting.lang == 'Korean':
				if self.need_hangul:
					self.set_automata('hangul', False)
				else:
					self.set_automata('multitap', 'upper')
			else:
				self.set_automata('multitap', 'lower')	

			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
			#return self.entry.handle_key(key) # Automata.handle_key에서 한글 입력후에 Editing mode를 0 으로 만든다. 
		
		
	def get_text(self):
		return self.entry.get_text()

	def set_text(self, text):
		self.entry.set_text(text)
		self.update_entry_info()

	def insert_text(self, text):
	
		self.entry.insert_unicode_text(unicode(text, 'utf-8'))
		self.entry._automata.check_start_of_sentance()
		self.update_entry_info()

	def delete_char(self):
		self.handle_key('\b')
		self.update_entry_info()

	def set_entry_info(self, text):
		self.einfo.set_text(text)

#ka...hangul TEST 2007.01.22 add
	def insert_symbol(self, s):
		
		def back_to_symbol():
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
			self.symbol_stage_timer = None
			
		before_text = self.get_text()
		self.insert_text(s)
		after_text = self.get_text()

		if before_text == after_text:
			from basemodel import NotifyStage
			runtime.manager.change_stage(NotifyStage(_('Max length exceeded'), uiconfig.baloon_message_icon))
		else:
			runtime.manager.back_stage()
			#self.symbol_stage_timer = utils.Timer(uiconfig.back_to_symbol_timeout, back_to_symbol)
			

# ---End of Adding

	def handle_key(self, keyname):
		#if keyname == config.Menu4 and self.right == _('DELETE'):
		#	self.delete_char()
		#	self.update_entry_info()
		#	return True
		if config.mmi_debug: 
			print '## keyname =', keyname
			print '## self.fixed_automata=', self.fixed_automata
		if keyname == 'CLR' or (keyname == config.Menu2 and self.right == _('CLEAR')):
			if self.get_text() == '':
				runtime.manager.back_stage()
				return True
			self.delete_char()
			self.update_entry_info()
			return True
		elif keyname == config.Menu2:
			self.delete_char()
			self.update_entry_info()
			return True
		# KA: [20070831] hangul lvp-2000		
		elif keyname == config.Menu3 and not self.fixed_automata:
			if self.is_t9_add_word_mode():
				if config.mmi_debug: print 'is_t9_add_word_mode is True'
				return True
			if config.mmi_debug: 
				print '## org_idx=', self.automata_idx
			if setting.lang == 'Korean':	
				self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_hangul)	
				self.automata = config.automata_list_hangul[self.automata_idx]		
			else:		
				self.automata_idx = (self.automata_idx + 1) % len(config.automata_list)		
				self.automata = config.automata_list[self.automata_idx]	
			if config.mmi_debug: 
				print '## new idx=', self.automata_idx			
			self.automata_idx = utils.get_automata_idx(*self.automata)			
			if config.mmi_debug: 
				print '## self.automata=', self.automata, 'idx=', self.automata_idx
			self.set_automata(*self.automata)		
			return True
		# KA: [20070831] hangul lvp-2000	==	
	
		elif keyname == config.Menu2:
			self.reset_automata()
			from basemodel import Stage, SymbolSelectionStage
			if self.entry.ascii_mode_case0:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=0))
			elif self.entry.ascii_mode_case1:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=1))
			elif self.entry.ascii_mode_case2:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=2))
			elif self.entry.ascii_mode_case3:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=3))
			else:
				runtime.manager.stack_stage(SymbolSelectionStage(self, True))
				
			return self.entry.handle_key(keyname)
			
		elif keyname == config.Menu4:
			runtime.manager.back_stage()
			return True
# --- End of Adding

		if self.entry._automata.name() == 't9':
			if keyname == config.Menu2 and self.right == _('PREVIOUS'):
				automata = self.entry._automata
				automata.handle_previous()
				if automata.get_t9_objnum() == 1:
					self.set_right(_('CLEAR'))
				else:
					self.set_right(_('PREVIOUS'))

				if self.is_t9_add_word_mode():
					self.set_left(_('OK'))
				else:
					self.set_left(self.def_left)
				return True

			elif keyname == '*':
				self.entry._automata.handle_next()
				if self.entry._automata.get_t9_objnum() == 0:
					self.set_left(_('OK'))
				else:
					self.set_left(self.def_left)

				if self.entry._automata.get_t9_objnum() == 1:
					self.set_right(_('CLEAR'))
#ka...hangul 2007.01.25 
				elif self.entry._automata.get_t9_objnum() == 0:
					pass
# --- End of Adding
				else:
					self.set_right(_('PREVIOUS'))

				return True
		ret = self.entry.handle_key(keyname)
		if ret:
			self.update_entry_info()
		return ret

	def change_language(self):
		self.subtitle.text = self.subtitle.text

	def reset_automata(self):
		self.entry._automata.reset()

	def update_entry_info(self):
		if self.entry.get_max():
			#self.set_entry_info( '%d/%d' % (self.entry.length(), self.entry.get_max()) )
			self.set_entry_info( '%d/%d' % (self.entry.message_length_KT(), self.entry.get_max()) )

		if self.is_t9_add_word_mode():
			self.set_left(_('OK'))
		else:
			self.set_left(self.def_left)

		if self.entry.length() == 0:
			self.set_right('')
		else:
			self.set_right(_('CLEAR'))
		#if self.get_text():
		#	self.set_right(_('CLEAR'))
		#else:
		#	self.set_right(self.def_right)
		#	return

	def is_t9_add_word_mode(self):
		if self.entry._automata.name() == 't9':
			return self.entry._automata.is_add_word_mode()
		return False

	def is_t9_editing_mode(self):
		if self.entry._automata.name() == 't9':
			if not self.entry._automata.is_edit_buffer_empty():
				return True
		return False

class EntryNoHangulUI(EntryUI):
	def set_fixed_automata(self, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			#self.set_right(_(right_field))
			self.set_automata(name, casemode)
		else:
			self.fixed_automata = False
			self.set_automata(*utils.get_def_automata_no_hangul())

	def handle_key(self, keyname):
		print 'HANDLE_KEY'
		if keyname == config.Menu3 and not self.fixed_automata:
			# vpark 2006.08.28 automata	
			self.automata_idx = utils.get_automata_idx(*self.automata)

			self.automata_idx = (self.automata_idx + 1) % len(config.automata_list)		
			self.automata = config.automata_list_mult_num_symbol[self.automata_idx]		
			self.set_automata(*self.automata)		
			print 'AUTOMATA IDX', self.automata_idx, 'AUTOMATA', self.automata
			return True
		else:			
			return EntryUI.handle_key(self, keyname)
			
# KA: [20070121] phonebook UI
class PhoneBookUI(PhoneBookWindowUI):
	def __init__(self, left, right, title, menu3, menu4):
		PhoneBookWindowUI.__init__(self, left, right, title, menu3, menu4)
		width, height = uiconfig.entry_size_1
		import entry
		self.entry_total = []
		
		self.entry_1= entry.Entry(pos = uiconfig.entry_pos_1, size=uiconfig.entry_size_1)
		self.entry_1.add_callback(self.entry_1.AutomataChanged, self.update_automata_icon)
		self.entry_1.set_text('') # this is just for initial cursor position
		self.entry_1.set_max(uiconfig.MAX_INPUT_NAME)
		self.add(self.entry_1)

		self.entry_total.append(self.entry_1)

		self.entry_2 = entry.Entry(pos = uiconfig.entry_pos_2, size=uiconfig.entry_size_1)
		self.entry_2.add_callback(self.entry_1.AutomataChanged, self.update_automata_icon)
		self.entry_2.set_text('') # this is just for initial cursor position
		self.entry_2.set_max(uiconfig.MAX_INPUT_NAME)
		self.add(self.entry_2)

		self.entry_total.append(self.entry_2)

		self.entry_3 = entry.Entry(pos = uiconfig.entry_pos_3, size=uiconfig.entry_size_1)
		self.entry_3.add_callback(self.entry_1.AutomataChanged, self.update_automata_icon)
		self.entry_3.set_text('') # this is just for initial cursor position
		self.entry_3.set_max(uiconfig.MAX_INPUT_NAME)
		self.add(self.entry_3)

		self.entry_total.append(self.entry_3)

		self.entry = self.entry_total[0]

		pos = uiconfig.entry_info_pos
		font = uiconfig.entry_info_font
		color = uiconfig.entry_info_color
		self.einfo = widget.OutlineLabel('', font, pos, color, align=uiconfig.ALIGN_RIGHT)
		self.add(self.einfo)

		self.t9mode = False
		self.automata_icon = None
		self.automata_idx = 0
		self.automata = None, None

		self.def_left = left
		self.def_right = right
		self.fixed_automata = False

	def destroy(self):
		if self.automata_icon: self.automata_icon.free()
		PhoneBookWindowUI.destroy(self)

	def show(self):
		if self.automata_icon: self.automata_icon.show()
		PhoneBookWindowUI.show(self)

	def hide(self):
		if self.automata_icon: self.automata_icon.hide()
		PhoneBookWindowUI.hide(self)

	def set_subtitle(self, text):
		self.subtitle.text = text

	def set_max(self, max=-1):
		self.entry.set_max(max)
		self.update_entry_info()

	def set_fixed_automata(self, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_right(_(right_field))
			self.set_automata(name, casemode)
		else:
			self.fixed_automata = False
			self.set_automata(*utils.get_def_automata())

	def set_automata(self, name, casemode='lower'):
		self.entry.set_automata(name, casemode)
		if name == 't9':
			self.t9mode = True
		else:
			self.t9mode = False

		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)

		self.automata = name, casemode

	def update_automata_icon(self):
		name = self.entry._automata.name()
		casemode = self.entry._automata.case_mode()

		self.automata = name, casemode

		if self.automata_icon:
			self.automata_icon.free()

		self.automata_icon = utils.put_image(uiconfig.edit_automata_info_icon(name,casemode), uiconfig.entry_automata_info_pos)
		self.automata_icon.show()

	def get_text(self):
		return self.entry.get_text()

	def set_text(self, text):
		self.entry.set_text(text)
		self.update_entry_info()

	def insert_text(self, text):
		self.entry.insert_unicode_text(unicode(text, 'utf-8'))
		self.entry._automata.check_start_of_sentance()
		self.update_entry_info()

	def delete_char(self):
		self.handle_key('\b')
		self.update_entry_info()

	def set_entry_info(self, text):
		self.einfo.set_text(text)

#ka...hangul TEST 2007.01.22 add
	def insert_symbol(self, s):
		before_text = self.get_text()
		self.insert_text(s)
		after_text = self.get_text()
		if before_text == after_text:
			from basemodel import NotifyStage
			runtime.manager.change_stage(NotifyStage(_('Max length exceeded'), uiconfig.baloon_message_icon))
		else:
			runtime.manager.back_stage()
# ---End of Adding

	def handle_key(self, keyname):
		if keyname == config.Menu2 and self.right == _('CLEAR'):
			self.delete_char()
			self.update_entry_info()
			return True

		# KA: [20070831] hangul lvp-2000		
		elif keyname == 'SOFT4' and not self.fixed_automata:
			if self.is_t9_add_word_mode():
				return True
			# vpark 2006.08.28 automata	
			self.automata_idx = utils.get_automata_idx(*self.automata)
			if setting.lang == 'Korean':	
				self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_hangul)	
				self.automata = config.automata_list_hangul[self.automata_idx]		
			else:		
				self.automata_idx = (self.automata_idx + 1) % len(config.automata_list)		
				self.automata = config.automata_list[self.automata_idx]		
			self.set_automata(*self.automata)		
			return True
		# KA: [20070831] hangul lvp-2000	==	
	
		elif keyname == 'SOFT3':
			self.reset_automata()
			from basemodel import Stage, SymbolSelectionStage
			if self.entry.ascii_mode_case0:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=0))
			elif self.entry.ascii_mode_case1:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=1))
			elif self.entry.ascii_mode_case2:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=2))
			elif self.entry.ascii_mode_case3:
				runtime.manager.stack_stage(SymbolSelectionStage(self, case=3))
			else:
				runtime.manager.stack_stage(SymbolSelectionStage(self, True))
				
			return self.entry.handle_key(keyname)
			
		ret = self.entry.handle_key(keyname)
		if ret:
			self.update_entry_info()
		return ret

	def change_language(self):
		self.subtitle.text = self.subtitle.text

	def reset_automata(self):
		self.entry._automata.reset()

	def update_entry_info(self):
		return
#		if self.entry.get_max():
#			self.set_entry_info( '%d/%d' % (self.entry.length(), self.entry.get_max()) )

#		if self.is_t9_add_word_mode():
#			self.set_left(_('OK'))
#		else:
#			self.set_left(self.def_left)
#		if self.get_text():
#			self.set_right(_('CLEAR'))
#		else:
#			self.set_right(self.def_right)
#			return

	def is_t9_add_word_mode(self):
		if self.entry._automata.name() == 't9':
			return self.entry._automata.is_add_word_mode()
		return False

	def is_t9_editing_mode(self):
		if self.entry._automata.name() == 't9':
			if not self.entry._automata.is_edit_buffer_empty():
				return True
		return False
# KA: [20070121] phonebook UI ==		


class YesNoUI(BaloonMessageUI):
	def __init__(self, title, message,icon):
		BaloonMessageUI.__init__(self, '' ,_('YES'), title, icon, message, _('NO'), '')

class OkNoUI(BaloonMessageUI):
	def __init__(self, title, message,icon):
		BaloonMessageUI.__init__(self, _('OK'), _('NO'), title, icon, message)


class NotifyUI(BaloonMessageUI):
	def __init__(self, message, icon=None, title = '', left = '', right = '', menu3='', menu4=''):
		BaloonMessageUI.__init__(self, left, right, title, icon, message, menu3, menu4)


class AgendaActiveUI(NotifyUI):
	#display wallpaper
	show_bg = True
	def __init__(self, message):
		# KA: [20070917] Alarm message cut off
		message = message.replace('\n', ' ') # from rich text.
		#NotifyUI.__init__(self, message, '', '', _('SNOOZE'), '', '',_('STOP'))
		

		BaloonUI.__init__(self, _('SNOOZE'), '', '', -1, menu4=_('STOP')) # icon -> -1
		from richtextview import RichTextScrollView
		'''
		from mmsutils import MMS_Unicode_len
		if MMS_Unicode_len(message) <= 24:
			_pos = uiconfig.agenda_active_label_pos[1][0], uiconfig.agenda_active_label_pos[1][1]
		else:
			_pos = uiconfig.agenda_active_label_pos[1][0], uiconfig.agenda_active_label_pos[1][1]
		'''
		#_pos = uiconfig.baloon_text_pos_x, uiconfig.baloon_text_pos_y[0][0]
		_center_pos = 240, uiconfig.baloon_text_pos_y[0][0]
		'''
		self.label = RichTextScrollView(pos=_pos, size=uiconfig.agenda_active_label_size, text_font=uiconfig.baloon_large_font, text_color=uiconfig.baloon_text_color)
		message = message.replace('\n', ' ')
		self.add(self.label)
		self.set_text(message)
		'''
		self.agenda_text = runtime.evas.text(text=message,font=uiconfig.baloon_medium_font,pos=(0,0),color=uiconfig.baloon_text_color)
		self.add(self.agenda_text)
		self.align_center(self.agenda_text, _center_pos)
		
		runtime.evas.alarm_temp_ani = None
		self.alarm_ani = []
		self.index = 0
		for w in uiconfig.alarm_icon_ani:
			runtime.evas.alarm_temp_ani = utils.put_image(w, uiconfig.alarm_icon_ani_pos)
			self.alarm_ani.append(runtime.evas.alarm_temp_ani)
			self.alarm_ani[self.index].hide()
			self.index += 1
		self.ani_count = -1
		
	def align_center(self, l, pos):
		x, y = pos
		width,height = l.size
		l.move(x - width/2, y)

	def show(self):
		BaloonUI.show(self)
		global alarm_timer
		if not alarm_timer:
			self.ani_count = 0
		self.alarm_ani[self.ani_count].show()
		alarm_timer = runtime.evas.timeout_add(500, self.ani_timer_cb)

	def ani_timer_cb(self):
		global alarm_timer
		if not alarm_timer:
			return
		if self.ani_count == -1:
			self.ani_count += 1
		else:
			self.alarm_ani[self.ani_count].hide()
			self.ani_count += 1
			if self.ani_count > 3:
				self.ani_count = 0
		self.alarm_ani[self.ani_count].show()
		runtime.evas.timeout_remove(alarm_timer)
		alarm_timer = runtime.evas.timeout_add(500, self.ani_timer_cb)

	def destroy(self):
		global alarm_timer
		if alarm_timer:
			runtime.evas.timeout_remove(alarm_timer)
		alarm_timer = None
		BaloonUI.destroy(self)
		for w in self.alarm_ani:
			w.free()

	def get_text(self):
		self.label.get_text()

	def set_text(self, text):
		self.label.set_text(text)

	def change_language(self):
		pass


class EnblockEditUI(BaseUI):
	bigDialNumberPosition_x = [8, 55, 102, 149, 196, 243, 290, 337, 384, 431]
	bigDialNumberPosition_y = [23, 94, 164]
	
	mediumDialNumberPosition_x = [12, 54, 96, 138, 180, 222, 264, 306, 348, 390, 432]
	mediumDialNumberPosition_y = [14, 69, 124, 179]

	smallDialNumberPosition_x = [9, 40, 71, 102, 133, 164, 195, 226, 257, 288, 319, 350, 381, 412, 443]
	smallDialNumberPosition_y = [14, 58, 102, 146, 190]

	LARGE_KEY = 2
	MEDIUM_KEY = 1
	SMALL_KEY = 0

	LARGE_MAX_LOW = 3
	LARGE_MAX_COLUMN = 10
	MEDIUM_MAX_LOW = 4
	MEDIUM_MAX_COLUMN = 11
	SMALL_MAX_LOW = 5
	SMALL_MAX_COLUMN = 15

	def __init__(self):
		BaseUI.__init__(self, _('PHONEBOOK'),_('AUDIO REDIAL'), '', _('VIDEO REDIAL'), _('CALL LOG') )

		self.currentKeySize = setting.number_size
		self.currentKeyPositionIndex_x = 0
		self.currentKeyPositionIndex_y = 0

		self.keyBuffer = []
		
		self.KEY_FULL = False
		self.KEY_EMPTY = True

		# Pre-dial background (tempoarary)
		#icon, pos = uiconfig.dial_ready_back
		#self.dial_back = utils.put_image(icon, pos)
		#self.add(self.dial_back)

		icon, pos = uiconfig.dial_ready
		self.number_empty = utils.put_image(icon, pos)
		self.add(self.number_empty)

		self.number_empty_text= runtime.evas.text(text=_('Please, input numbers'), font=uiconfig.enblock_dial_font, pos=(200,120), color=uiconfig.enblock_dial_font_color)
		self.add(self.number_empty_text)
		
	def isKeyEmpty(self):
		return self.KEY_EMPTY
		
	def isKeyFull(self):
		return self.KEY_FULL
		
	def show(self):
		BaseUI.show(self)
		'''
		for keyImage in self.keyBuffer:
			keyImage.show()
		'''
		if self.keyBuffer:
			self.showKey('')	# this routine is added for conv_telnum() instead of keyImage.show()
			
		if self.keyBuffer:
			self.number_empty.hide()
			self.number_empty_text.hide()
			
		runtime.dialBg.show()

	def showKey(self, key=''):
		if key == '':	# this routine is added for conv_telnum() 
			self.hideAllKey()
			
			telnum = utils.conv_telnum(status.dial_number)
			#print '>>>>>>>telnum=' + telnum
			for i in range(len(telnum)):
				key = telnum[i]
				icon = self.getNumberImage(key)
				self.changeCursorPosition(index=i+1)
				pos = self.getNumberPosition()
				keyImage = utils.put_image(icon, pos)
				self.keyBuffer.append(keyImage)
				keyImage.show()

			self.changeCursorPosition()
		else:
			self.number_empty.hide()
			self.number_empty_text.hide()
			
			icon = self.getNumberImage(key)
			pos = self.getNumberPosition()
			keyImage = utils.put_image(icon, pos)
			self.keyBuffer.append(keyImage)
			keyImage.show()
			
			self.changeCursorPosition()

	def hideKey(self):
		deletedKey = self.keyBuffer.pop()
		deletedKey.hide()
		deletedKey.free()
		
		self.changeCursorPosition(back=True)

	def getNumberPosition(self):
		if self.currentKeySize == self.LARGE_KEY:
			x = self.bigDialNumberPosition_x[self.currentKeyPositionIndex_x]
			y = self.bigDialNumberPosition_y[self.currentKeyPositionIndex_y]
		elif self.currentKeySize == self.MEDIUM_KEY:
			x = self.mediumDialNumberPosition_x[self.currentKeyPositionIndex_x]
			y = self.mediumDialNumberPosition_y[self.currentKeyPositionIndex_y]
		elif self.currentKeySize == self.SMALL_KEY:
			x = self.smallDialNumberPosition_x[self.currentKeyPositionIndex_x]
			y = self.smallDialNumberPosition_y[self.currentKeyPositionIndex_y]
		return x, y
		
	def changeCursorPosition(self, back=False, index=0):
		if self.currentKeySize == self.LARGE_KEY:
			maxLowSize = self.LARGE_MAX_LOW
			maxColumnSize = self.LARGE_MAX_COLUMN
		elif self.currentKeySize == self.MEDIUM_KEY:
			maxLowSize = self.MEDIUM_MAX_LOW
			maxColumnSize = self.MEDIUM_MAX_COLUMN
		elif self.currentKeySize == self.SMALL_KEY:
			maxLowSize = self.SMALL_MAX_LOW
			maxColumnSize = self.SMALL_MAX_COLUMN

		if index > 0:	# this routine is added for conv_telnum()
			index -= 1
			self.currentKeyPositionIndex_x = int(index %maxColumnSize)
			#print '>>>>>>>self.currentKeyPositionIndex_x=', self.currentKeyPositionIndex_x 
			self.currentKeyPositionIndex_y = int(index / maxColumnSize)
			#print '>>>>>>>self.currentKeyPositionIndex_y=', self.currentKeyPositionIndex_y 
			if self.currentKeyPositionIndex_x == maxColumnSize-1 and \
				self.currentKeyPositionIndex_y >= maxLowSize-1:
				self.KEY_FULL = True
				#print '>>>>>>>KEY_FULL'
			if self.currentKeyPositionIndex_x == 0 and \
				self.currentKeyPositionIndex_y == 0:
				self.KEY_EMPTY = True
				#print '>>>>>>>KEY_EMPTY'
			else:
				self.KEY_FULL = False
				self.KEY_EMPTY = False
			return

		if back:
			if self.currentKeyPositionIndex_x == 0:
				if self.currentKeyPositionIndex_y == 0:
					self.KEY_EMPTY = True
					#print '>>>>>>>KEY_EMPTY'
				else:
					self.currentKeyPositionIndex_x = maxColumnSize - 1
					#print '>>>>>>>self.currentKeyPositionIndex_x=', self.currentKeyPositionIndex_x 
					self.currentKeyPositionIndex_y = self.currentKeyPositionIndex_y - 1
					#print '>>>>>>>self.currentKeyPositionIndex_y=', self.currentKeyPositionIndex_y 
			else:
				self.currentKeyPositionIndex_x = self.currentKeyPositionIndex_x - 1
				#print '>>>>>>>self.currentKeyPositionIndex_x=', self.currentKeyPositionIndex_x 
				if self.KEY_FULL:
					self.KEY_FULL = False
		else:
			if self.currentKeyPositionIndex_x == maxColumnSize-1:
				if self.currentKeyPositionIndex_y+1 == maxLowSize:
					self.currentKeyPositionIndex_x = self.currentKeyPositionIndex_x+1
					#print '>>>>>>>self.currentKeyPositionIndex_x=', self.currentKeyPositionIndex_x 
					self.KEY_FULL = True
					#print '>>>>>>>KEY_FULL'
				else:
					self.currentKeyPositionIndex_x = 0
					#print '>>>>>>>self.currentKeyPositionIndex_x=', self.currentKeyPositionIndex_x 
					self.currentKeyPositionIndex_y = self.currentKeyPositionIndex_y + 1
					#print '>>>>>>>self.currentKeyPositionIndex_y=', self.currentKeyPositionIndex_y 
			else:
				self.currentKeyPositionIndex_x = self.currentKeyPositionIndex_x + 1
				#print '>>>>>>>self.currentKeyPositionIndex_x=', self.currentKeyPositionIndex_x 
				if self.KEY_EMPTY:
					self.KEY_EMPTY = False

	def getNumberImage(self, keyNumber):
		if self.currentKeySize == self.LARGE_KEY:
			if keyNumber == '0':	return 'big_00.png'
			elif keyNumber == '1':	return 'big_01.png'
			elif keyNumber == '2':	return 'big_02.png'
			elif keyNumber == '3':	return 'big_03.png'
			elif keyNumber == '4':	return 'big_04.png'
			elif keyNumber == '5':	return 'big_05.png'
			elif keyNumber == '6':	return 'big_06.png'
			elif keyNumber == '7':	return 'big_07.png'
			elif keyNumber == '8':	return 'big_08.png'
			elif keyNumber == '9':	return 'big_09.png'
			elif keyNumber == '-':	return 'big_hyphen.png'
			elif keyNumber == '#':	return 'big_sharp.png'
			elif keyNumber == '*':	return 'big_star.png'
			elif keyNumber == '+':	return 'big_plus.png'
			else:				return None
		elif self.currentKeySize == self.MEDIUM_KEY:
			if keyNumber == '0':	return 'medium_00.png'
			elif keyNumber == '1':	return 'medium_01.png'
			elif keyNumber == '2':	return 'medium_02.png'
			elif keyNumber == '3':	return 'medium_03.png'
			elif keyNumber == '4':	return 'medium_04.png'
			elif keyNumber == '5':	return 'medium_05.png'
			elif keyNumber == '6':	return 'medium_06.png'
			elif keyNumber == '7':	return 'medium_07.png'
			elif keyNumber == '8':	return 'medium_08.png'
			elif keyNumber == '9':	return 'medium_09.png'
			elif keyNumber == '-':	return 'medium_hyphen.png'
			elif keyNumber == '#':	return 'medium_sharp.png'
			elif keyNumber == '*':	return 'medium_star.png'
			elif keyNumber == '+':	return 'medium_plus.png'
			else:				return None
		elif self.currentKeySize == self.SMALL_KEY:
			if keyNumber == '0':	return 'small_00.png'
			elif keyNumber == '1':	return 'small_01.png'
			elif keyNumber == '2':	return 'small_02.png'
			elif keyNumber == '3':	return 'small_03.png'
			elif keyNumber == '4':	return 'small_04.png'
			elif keyNumber == '5':	return 'small_05.png'
			elif keyNumber == '6':	return 'small_06.png'
			elif keyNumber == '7':	return 'small_07.png'
			elif keyNumber == '8':	return 'small_08.png'
			elif keyNumber == '9':	return 'small_09.png'
			elif keyNumber == '-':	return 'small_hyphen.png'
			elif keyNumber == '#':	return 'small_sharp.png'
			elif keyNumber == '*':	return 'small_star.png'
			elif keyNumber == '+':	return 'small_plus.png'
			else:				return None

	def hide(self):
		BaseUI.hide(self)
		runtime.dialBg.hide()
		for keyImage in self.keyBuffer:
			keyImage.hide()

	def hideAllKey(self):	# this routine is added for conv_telnum()
		for keyImage in self.keyBuffer:
			keyImage.hide()
		
	def destroy(self):
		BaseUI.destroy(self)
		runtime.dialBg.hide()
		for keyImage in self.keyBuffer:
			keyImage.free()
		
class NotifyCallUI(BaloonUI):
	def __init__(self, left, right, title, message1, message2, icon = -1, message4=''):
		BaloonUI.__init__(self, left, right, title,icon,True)
		self.cursor = None
		self.two_lines = False
### answer delay
		self.msg1 = message1
		self.msg4 = message4
		
		self.message1 = runtime.evas.text(text=message1,
			font=uiconfig.baloon_font,
			pos=uiconfig.baloon_text_pos,
			color=uiconfig.baloon_text_color)
		self.add(self.message1)

		message2_clip = runtime.evas.rectangle()
		message2_clip.pos = uiconfig.baloon_text2_clip_pos
		message2_clip.size=uiconfig.baloon_text2_size
		self.add(message2_clip)

		self.message2 = runtime.evas.text(text='',
			font=uiconfig.baloon_font,
			pos=uiconfig.baloon_text2_pos,
			color=uiconfig.baloon_text2_color)
		self.message2.clip_set(message2_clip)
		self.add(self.message2)

		self.message3 = runtime.evas.text(text='',
				font=uiconfig.baloon_small_font,
				pos=uiconfig.baloon_small_text2_pos2,
				color=uiconfig.baloon_text2_color)
		self.add(self.message3)

		self.message4 = None
				
		self.change_caller_number(message2)

	# hcryoo : [20070515_1]			
	def change_message1(self):
		if self.message4 != None:
			self.remove(self.message4)
			self.message4 = None
			
		self.message4 = runtime.evas.text(text=self.msg4,
				font=uiconfig.baloon_font,
				pos=uiconfig.baloon_text_pos,
				color=uiconfig.baloon_text_color)
		if self.message1 != None:
			self.message1.hide()
			self.remove(self.message1)
			self.message1= None
		
				
		self.add(self.message4)
		self.message4.show()
		BaloonUI.show(self)
		
	def change_message4(self):
		if self.message1 != None:
			self.remove(self.message1)
			self.message1 = None

		self.message1 = runtime.evas.text(text=self.msg1,
				font=uiconfig.baloon_font,
				pos=uiconfig.baloon_text_pos,
				color=uiconfig.baloon_text_color)
				
		if self.message4 != None:
			self.remove(self.message4)
			self.message4 = None
			runtime.evas.render_now()

		self.add(self.message1)
		self.message1.show()
		BaloonUI.show(self)
	# hcryoo : [20070515_1]==

### answer delay

	def change_caller_number(self, number):
		if number.find('\n') != -1:
			self.two_lines = True
			msg1, msg2 = number.split('\n')
			self.change_font_size
			#self.message2.font = uiconfig.baloon_small_font
			self.message2.pos = uiconfig.baloon_small_text2_pos1
			self.message2.text_set(msg1)
			self.message3.text_set(msg2)
			x,y = uiconfig.baloon_small_text2_pos1
			width,height = self.message2.geometry_get()[2:]
			self.message2.pos = x - width, y
			x,y = uiconfig.baloon_small_text2_pos2
			width,height = self.message3.geometry_get()[2:]
			self.message3.pos = x - width, y
		else:
			self.two_lines = False
			self.change_font_size()
			#self.message2.font=uiconfig.baloon_font
			self.message2.pos=uiconfig.baloon_text2_pos
			self.message2.color=uiconfig.baloon_text2_color
			txt = number.replace('R','').replace('P','').replace('*','')
			txt = txt.replace('#','')
			if txt.isdigit():
				pass
			else:
				number, self.message2.font = utils.resize_text(number, uiconfig.baloon_text_size[0], uiconfig.baloon_font)
				self.change_font_size()
			self.message2.text_set(number)
			x,y = uiconfig.baloon_text2_pos
			width,height = self.message2.geometry_get()[2:]
			self.message2.pos = x - width, y

			if self.cursor:
				self.cursor.queue_update()

		if not self.two_lines:
			self.message3.hide()

	def show(self):
		BaloonUI.show(self)
		if not self.two_lines:
			self.message3.hide()
		self.change_font_size()

	def destroy(self):
		BaseUI.destroy(self)

	def hide(self):
		BaseUI.hide(self)

	def show_cursor(self, show):
		if show:
			if not self.cursor:
				import cursor
				self.cursor = cursor.Cursor(self)
				self.add(self.cursor)
		else:
			if self.cursor:
				self.remove(self.cursor)
				self.cursor.free()
				self.cursor = None

	def cursor_pos_height(self):
		x,y,width,height = self.message2.geometry_get()
		return (x + width, y, height)

	def change_language(self):
		self.message1.change_language()

	def change_font_size(self):
		if setting.number_size == 0:
			self.message2.font = uiconfig.baloon_small_font
			#self.message1.font = uiconfig.baloon_small_font
			
		elif setting.number_size == 1:
			self.message2.font = uiconfig.baloon_medium_font
			#self.message1.font = uiconfig.baloon_medium_font
			
		elif setting.number_size == 2:
			self.message2.font = uiconfig.baloon_large_font
			#self.message1.font = uiconfig.baloon_large_font
			


class NotifyConfCallUI(BaloonUI):
	def __init__(self, left, right, title, message1, message2, message3, icon):
		BaloonUI.__init__(self, left, right, title,icon)
		self.cursor = None
		self.two_lines = False

		self.message1 = runtime.evas.text(text=message1,
			font=uiconfig.conference_font,
			pos=uiconfig.conference_text_pos,
			color=uiconfig.conference_text_color)
		self.add(self.message1)

		message2_clip = runtime.evas.rectangle()
		message2_clip.pos = uiconfig.conference_text2_clip_pos
		message2_clip.size=uiconfig.conference_text2_size
		self.add(message2_clip)

		self.message2 = runtime.evas.text(text='',
			font=uiconfig.conference_font,
			pos=uiconfig.conference_text2_pos,
			color=uiconfig.conference_text2_color)
		self.message2.clip_set(message2_clip)
		self.add(self.message2)

		message3_clip = runtime.evas.rectangle()
		message3_clip.pos = uiconfig.conference_text3_clip_pos
		message3_clip.size=uiconfig.conference_text3_size
		self.add(message3_clip)

		self.message3 = runtime.evas.text(text='',
				font=uiconfig.conference_font,
				pos=uiconfig.conference_text3_pos,
				color=uiconfig.conference_text3_color)
		self.message3.clip_set(message3_clip)
		self.add(self.message3)

		self.change_caller_number(message2)
		self.change_hold_number(message3)

	def change_caller_number(self, number):
		self.message2.font=uiconfig.conference_font
		self.message2.pos=uiconfig.conference_text2_pos
		self.message2.color=uiconfig.conference_text2_color
		txt = number.replace('R','').replace('P','').replace('*','')
		txt = txt.replace('#','')
		
		if txt.isdigit():
			pass
		else:
			number, self.message2.font = utils.resize_text(number, uiconfig.conference_text2_size[0], uiconfig.conference_font)
		self.message2.text_set(number)
		x,y = uiconfig.conference_text2_pos
		width,height = self.message2.geometry_get()[2:]
		self.message2.pos = x - width, y

		if self.cursor:
			self.cursor.queue_update()

	def change_hold_number(self, number):
		self.message3.font=uiconfig.conference_font
		self.message3.pos=uiconfig.conference_text3_pos
		self.message3.color=uiconfig.conference_text3_color
		txt = number.replace('R','').replace('P','').replace('*','')
		txt = txt.replace('#','')
		if txt.isdigit():
			pass
		else:
			number, self.message3.font = utils.resize_text(number, uiconfig.conference_text3_size[0], uiconfig.conference_font)
		self.message3.text_set(number)
		x,y = uiconfig.conference_text3_pos
		width,height = self.message3.geometry_get()[2:]
		self.message3.pos = x - width, y

	def show(self):
		BaloonUI.show(self)

	def show_cursor(self, show):
		if show:
			if not self.cursor:
				import cursor
				self.cursor = cursor.Cursor(self)
				self.add(self.cursor)
		else:
			if self.cursor:
				self.remove(self.cursor)
				self.cursor.free()
				self.cursor = None

	def cursor_pos_height(self):
		x,y,width,height = self.message2.geometry_get()
		return (x + width, y, height)

	def change_language(self):
		self.message1.change_language()

class Baloon2UI(BaseUI):
	def __init__(self, left, right, title, icon1, icon2):
		BaseUI.__init__(self, left, right, title)

		name, pos = uiconfig.back_baloon_icon
		image = utils.put_image(name, pos)
		self.add(image)

		name, pos = uiconfig.front_baloon_icon
		image = utils.put_image(name, pos)
		self.add(image)

		if icon1:
			icon_name, pos = icon1
			self.icon1 = utils.put_image(icon_name, pos)
			self.add(self.icon1)
		if icon2:
			icon_name, pos = icon2
			self.icon2 = utils.put_image(icon_name, pos)
			self.add(self.icon2)

	def icon1_hide(self):
		self.icon1.hide()

	def icon2_hide(self):
		self.icon2.hide()

class NotifyCall2UI(Baloon2UI):
	def __init__(self, left, right, title, msg11, msg12, msg21, msg22, icon1, icon2):
		Baloon2UI.__init__(self, left, right, title, icon1, icon2)
		self.cursor = None

		self.message1 = runtime.evas.text(text=msg11,
			font=uiconfig.front_baloon_font,
			pos=uiconfig.front_baloon_text_pos,
			color=uiconfig.front_baloon_text_color)
		self.add(self.message1)

		message2_clip = runtime.evas.rectangle()
		message2_clip.pos = uiconfig.front_baloon_text2_clip_pos
		message2_clip.size=uiconfig.front_baloon_text2_size
		self.add(message2_clip)


		self.message2 = runtime.evas.text(text='',
			font=uiconfig.front_baloon_font,
			pos=uiconfig.front_baloon_text2_pos,
			color=uiconfig.front_baloon_text2_color)
		self.message2.clip_set(message2_clip)
		self.add(self.message2)

		self.change_caller_number(msg12)

		self.message3 = runtime.evas.text(text=msg21,
			font=uiconfig.back_baloon_font,
			pos=uiconfig.back_baloon_text_pos,
			color=uiconfig.back_baloon_text_color)
		self.add(self.message3)

		message4_clip = runtime.evas.rectangle()
		message4_clip.pos = uiconfig.back_baloon_text2_clip_pos
		message4_clip.size=uiconfig.back_baloon_text2_size
		self.add(message4_clip)


		self.message4 = runtime.evas.text(text='',
			font=uiconfig.back_baloon_font,
			pos=uiconfig.back_baloon_text2_pos,
			color=uiconfig.back_baloon_text2_color)
		self.message4.clip_set(message4_clip)
		self.add(self.message4)
		self.change_hold_number(msg22)

		# hcryoo : [20070522_1]
		self.message_held = None
		# hcryoo : [20070522_1]==
		
	def call_icon_hide(self):
		self.icon1_hide()

	def hold_icon_hide(self):
		self.icon2_hide()

	# hcryoo : [20070522_1]
	def change_message1_to_held(self):
		if self.message_held != None:
			self.remove(self.message_held)
			self.message_held = None
			
		msg_held = _('Call connected') + '(' + _('Held') + ')' + ':'
		self.message_held = runtime.evas.text(text=msg_held,
			font=uiconfig.front_baloon_font,
			pos=uiconfig.front_baloon_text_pos,
			color=uiconfig.front_baloon_text_color)

		if self.message1 != None:
			self.message1.hide()
			self.remove(self.message1)
			self.message1= None
		
				
		self.add(self.message_held)
		self.message_held.show()
		#Baloon2UI.show(self)
		
	def change_message1_to_normal(self):
		if self.message1 != None:
			self.remove(self.message1)
			self.message1 = None

		msg_normal = _('Call connected')  + ':'
		self.message1 = runtime.evas.text(text=msg_normal,
			font=uiconfig.front_baloon_font,
			pos=uiconfig.front_baloon_text_pos,
			color=uiconfig.front_baloon_text_color)
				
		if self.message_held != None:
			self.remove(self.message_held)
			self.message_held = None
			runtime.evas.render_now()

		self.add(self.message1)
		self.message1.show()
		#Baloon2UI.show(self)
	# hcryoo : [20070522_1]==
	
	def change_caller_number(self, number):
		self.message2.font=uiconfig.front_baloon_font
		self.message2.pos=uiconfig.front_baloon_text2_pos
		self.message2.color=uiconfig.front_baloon_text2_color

		# hcryoo : [20070413_2]
		if number.isdigit():
			pass
		else:
			number, self.message2.font = utils.resize_text(number, uiconfig.front_baloon_text2_size[0], uiconfig.front_baloon_font)
		# hcryoo : [20070413_2]==
		self.message2.text_set(number)
		x,y = uiconfig.front_baloon_text2_pos
		width,height = self.message2.geometry_get()[2:]
		self.message2.pos = x - width, y

		if self.cursor:
			self.cursor.queue_update()

	def change_hold_number(self, number):
		self.message4.font=uiconfig.back_baloon_font
		self.message4.pos=uiconfig.back_baloon_text2_pos
		self.message4.color=uiconfig.back_baloon_text2_color
			
		hold_font = uiconfig.back_baloon_font[0], 11
		
		# hcryoo : [20070413_2]
		if number.isdigit():
			pass
		else:
			number, self.message4.font = utils.resize_text(number, uiconfig.back_baloon_text2_size[0], hold_font)
		# hcryoo : [20070413_2]==
		
		self.message4.text_set(number)
		x,y = uiconfig.back_baloon_text2_pos
		width,height = self.message4.geometry_get()[2:]
		self.message4.pos = x - width, y

	def change_caller_title(self, name):
		self.message1.text=name

	def change_hold_title(self, name):
		self.message3.text=name

	def show(self):
		Baloon2UI.show(self)

	def show_cursor(self, show):
		if show:
			if not self.cursor:
				import cursor
				self.cursor = cursor.Cursor(self)
				self.add(self.cursor)
		else:
			if self.cursor:
				self.remove(self.cursor)
				self.cursor.free()
				self.cursor = None

	def cursor_pos_height(self):
		x,y,width,height = self.message2.geometry_get()
		return (x + width, y, height)

	def change_language(self):
		self.message1.change_language()


class GalleryUI(BaseUI):
	def __init__(self, left='', right='', menu3='',menu4=''):
		BaseUI.__init__(self, left, right,'', menu3,menu4)
		name,pos = uiconfig.image_bg
		self.bg = utils.put_image(name,pos)		
		self.add(self.bg)
		
		name,pos = uiconfig.image_small_arrow_left		
		self.small_arrow_left = utils.put_image(name,pos)
		self.add(self.small_arrow_left)
		self.small_arrow_left.hide()

		name,pos = uiconfig.image_small_arrow_right		
		self.small_arrow_right = utils.put_image(name,pos)
		self.add(self.small_arrow_right)
		self.small_arrow_right.hide()

		name,pos = uiconfig.image_large_arrow_left		
		self.large_arrow_left = utils.put_image(name,pos)
		self.add(self.large_arrow_left)
		self.large_arrow_left.hide()
		
		name,pos = uiconfig.image_large_arrow_right		
		self.large_arrow_right = utils.put_image(name,pos)
		self.add(self.large_arrow_right)
		self.large_arrow_right.hide()

		self.image = None
		self.video = None
		self.tag_cb = []
		self.video_image = ''
		self.video_file = ''
		self.video_png_timer = None
		self.video_yuv_timer = None		
		self.file_detail = runtime.evas.text(text='',
			font=uiconfig.image_text_font,
			pos=uiconfig.image_text_pos,
			color=uiconfig.image_text_color)
		self.add(self.file_detail)

		self.list = None
	
	def set_preview(self, file, pre_flag=0):
		try:
			file = unicode(file,'utf-8').encode('euc-kr')
		except:
			pass

		import os 
		if not os.access(file, os.R_OK):
			return False
			
		filesize = utils.get_size_kb(file)
		fname = file.split('/')[-1]

		tmp_w, tmp_h = utils.get_img_size(file)
		if tmp_w * tmp_h > 640 * 480:
			file = '/usr/local/lgvp/images/image_big.png'
			
		if not self.image:
			self.image = utils.put_image(file, uiconfig.gallery_small_pos)
			self.add(self.image)
		else:
			self.image.file = utils.changefile_gif(file)
			
		if pre_flag==0:
			x, y = uiconfig.gallery_small_pos
			w, h = uiconfig.gallery_small_size
		else:
			x, y = uiconfig.gallery_large_pos
			w, h = uiconfig.gallery_large_size
		#utils.image_center_sized(self.image, x + w/2, y + h/2, w, h)
		utils.image_sized(self.image, (x, y), (w, h))
		runtime.evas.render_now()
		dot = fname.rfind('.')
		if dot >=0:
			fname = fname[:dot]		
			image_width = 210;		
			if filesize >= 10:
				image_width -= 30
			else:
				image_width -= 10
			#refame , font = utils.resize_text( fname, image_width, uiconfig.large_window_title_font)
			#refame , font = utils.cut_text( fname, image_width, uiconfig.image_text_font)
			#refame , font = utils.cut_text( fname, image_width, uiconfig.image_text_font)
			refame  = utils.cut_text( fname, image_width, uiconfig.image_text_font ,with_punc=True)[0]
		
		
		title = "%s %dKB" % (refame, filesize)	
		try:
			title = unicode(title,'euc-kr').encode('utf-8')
		except:
			pass
		self.file_detail.text_set(title)
		self.file_detail.hide()
		x,y = uiconfig.image_text_pos
		self.file_detail.pos = x -(self.file_detail.horiz_advance_get()/2),y
		self.file_detail.show()
		
	def set_video_preview(self, file, image=True, isshow=False):
		import os
		try:
			file = unicode(file,'utf-8').encode('euc-kr')
		except:
			pass
			
		if not os.access(file, os.R_OK):
			return False
			
		isthumb = False
		self.delete_thumb()
		self.video_file = file
		if image:
			import os.path
			path = os.path.split(file)
			if path[0] == config.video_recorded_dir[:-1]:
				image_path = config.video_recorded_thumnail_dir
			else:
				image_path = config.video_received_thumnail_dir
			self.video_image = path[-1]
			dot = self.video_image.rfind('.')
			# KA: [20070724] change path of the video thumbnail file
			if dot >=0:
				self.video_image = image_path+self.video_image[:dot]+'.png'
			else:
				self.video_image = image_path+self.video_image+'.png'
			if not self.video:
				if os.access(self.video_image, os.R_OK):
					self.video = utils.put_image(self.video_image, uiconfig.gallery_small_pos)
				else:
					self.video = utils.put_image(uiconfig.image_dir+'icon_image_sound_video.png', uiconfig.gallery_small_pos)
					isthumb = True
				self.add(self.video)
			else:
				if os.access(self.video_image, os.R_OK):
					self.video.file = self.video_image
				else:
					self.video.file = uiconfig.image_dir + 'icon_image_sound_video.png'
					isthumb = True
			'''
			x, y = uiconfig.gallery_pos
			w, h = uiconfig.gallery_size
			utils.image_center_sized(self.video, x + w/2, y + h/2, w, h)
			'''
			utils.image_sized(self.video, uiconfig.gallery_pos, uiconfig.gallery_size)

		filesize = utils.get_size_kb(file)
		fname = file.split('/')[-1]
		dot = fname.rfind('.')
		if dot >=0:
			fname = fname[:dot]
			video_width = uiconfig.large_window_title_width;
			if filesize >= 10:
				video_width -= 30
			else:
				video_width -= 10
			refame , font = utils.resize_text( fname, video_width, uiconfig.large_window_title_font)
		title = "%s [%dKB]" % (refame, filesize)
		try:
			title = unicode(title,'euc-kr').encode('utf-8')
		except:
			pass
		'''
		self.file_detail.text = title
		'''
		self.file_detail.text_set(title)
		self.file_detail.hide()
		x,y = uiconfig.image_text_pos
		self.file_detail.pos = x -(self.file_detail.horiz_advance_get()/2),y
		self.file_detail.show()
		
		if not isshow:
			runtime.evas.render_now()
		if image and isthumb:
			if utils.player.create_thumb_yuv(self.video_file):
				self.video_yuv_timer = utils.Timer(config.video_thumnail_time_1, self.create_image_file)

	def create_image_file(self):
		ret = utils.player.create_thumb_png(self.video_file)
		if ret == 0:
			utils.remove(self.video_image)
			return True
		elif ret == 1:
			self.video_yuv_timer = None
			self.video_png_timer = utils.Timer(config.video_thumnail_time_2, self.change_image_file)
			return False
		elif ret == 2:
			self.delete_thumb()
			self.video_yuv_timer = None
			if utils.player.create_thumb_yuv(self.video_file):
				self.video_yuv_timer = utils.Timer(config.video_thumnail_time_1, self.create_image_file)
			return False

	def change_image_file(self):
		import os
		if os.access(self.video_image, os.R_OK):
			if os.stat(self.video_image)[6] == 0:
				return True
			self.video_png_timer = None
			utils.player.delete_thumb()
			self.video.file = self.video_image
			x, y = uiconfig.gallery_pos
			w, h = uiconfig.gallery_size
			utils.image_center_sized(self.video, x + w/2, y + h/2, w, h)
			runtime.evas.render_now()
			return False
		else:
			return True

	def delete_thumb(self):
		ret = False
		if self.video_png_timer or self.video_yuv_timer:
			self.video_png_timer = None
			self.video_yuv_timer = None
			utils.remove(self.video_image)
			utils.remove_cmd('/tmp/*.yuv420')
			ret = True
		utils.player.delete_thumb()
		return ret

	def thumb_end(self):
		utils.player.delete_thumb()
		for i in range(2):
			self.video.file = self.video_image
			x, y = uiconfig.gallery_pos
			w, h = uiconfig.gallery_size
			utils.image_center_sized(self.video, x + w/2, y + h/2, w, h)
		runtime.evas.render()

	def hide(self):
		self.delete_thumb()
		BaseUI.hide(self)
		
	def destroy(self):
		self.delete_thumb()
		BaseUI.destroy(self)


class InfoUI(LargeWindowUI):
	def __init__(self, lists, mode = 0):
		self.lists = lists
		if mode == 0:
			LargeWindowUI.__init__(self, _('OK'), '', _('SELECT'), '', '', _('CANCEL'))
		else:
			LargeWindowUI.__init__(self, '', _('BACK'), _('DETAILS'), _('DETAILS'))

		lt = runtime.evas.text(text=_('ESSID:')+ ' ' + self.lists[1], font=uiconfig.details_font,
				pos=(20,60),
				color=uiconfig.list_text_color)
		self.add(lt)
		lt = runtime.evas.text(text=_('AP MAC:')+ ' ' + self.lists[0], font=uiconfig.details_font,
				pos=(20,80),
				color=uiconfig.list_text_color)
		self.add(lt)
		lt = runtime.evas.text(text=_('Channel ID:')+ ' ' + self.lists[2], font=uiconfig.details_font,
				pos=(20,100),
				color=uiconfig.list_text_color)
		self.add(lt)
		lt = runtime.evas.text(text=_('Security:')+ ' ' + self.lists[4], font=uiconfig.details_font,
				pos=(20,120),
				color=uiconfig.list_text_color)
		self.add(lt)
		lt = runtime.evas.text(text=_('Signal level:')+ ' ' + self.lists[3], font=uiconfig.details_font,
				pos=(20,140),
				color=uiconfig.list_text_color)
		self.add(lt)
		lt = runtime.evas.text(text=_('Bit rate:')+ ' ' + self.lists[5], font=uiconfig.details_font,
				pos=(20,160),
				color=uiconfig.list_text_color)
		self.add(lt)

class RichTextUI(LargeWindowUI):
	def __init__(self, left='', right='', title='', small_title='', text_font=uiconfig.richtext_font, text_color=uiconfig.richtext_color, menu3='', menu4=''):
		LargeWindowUI.__init__(self, left, right, title, small_title, menu3, menu4)
		from richtextview import RichTextScrollView
		self.label = RichTextScrollView(uiconfig.edit_pos, uiconfig.edit_size, 5, text_font, text_color)
		self.add(self.label)

	def get_text(self):
		self.label.get_text()

	def set_text(self, text):
		self.label.set_text(text)
		self.check_arrow()

	def change_language(self):
		self.subtitle.text = self.subtitle.text

	def handle_key(self, keyname):
		self.label.handle_key(keyname)
		self.check_arrow()

	def check_arrow(self):
		if not self.label.need_scroll():
			return False
		if self.label.show_up_arrow:
			self.up_arrow.show()
		else:
			self.up_arrow.hide()
		if self.label.show_down_arrow:
			self.down_arrow.show()
		else:
			self.down_arrow.hide()
		return False

class RichTextEditUI(LargeWindowUI):
	def __init__(self, left, right, title, small_title=''):
		LargeWindowUI.__init__(self, left, right, title, small_title)
		import richtextedit
		self.edit = richtextedit.RichTextEdit(pos=uiconfig.edit_pos, size=uiconfig.edit_size)
		self.add(self.edit)
		self.automata = None, None	#automata의 name(t9, multitap, 123), 문자 입력 방식(LOWERCASE, FIRSTCAPITAL, UPPERCASE)
		self.automata_icon = None	#윗변수 automata에 대한 설명 아이콘
		self.edit.add_callback(self.edit.AutomataChanged, self.update_automata_icon)	#Automata가 변화 될때 현재 설정 변경된 값으로 automata와 automata_icon의 값을 변경 시키고 아이콘은 그려줌

		self.def_left = left
		self.def_right = right

	def show(self):
		LargeWindowUI.show(self)
		if self.automata_icon:
			self.automata_icon.show()

		self.set_left(self.def_left)
		self.update_edit_info()
		self.show_arrow(self.edit.need_scroll())

	def hide(self):
		LargeWindowUI.hide(self)
		if self.automata_icon:
			self.automata_icon.hide()

	def destroy(self):
		if self.automata_icon: self.automata_icon.free()
		LargeWindowUI.destroy(self)

	def set_automata(self, name, casemode):
		self.edit.set_automata(name, casemode)
		self.update_edit_info()

	def update_automata_icon(self):		#현재 설정 변경된 값으로 automata와 automata_icon의 값을 변경 시키고 아이콘은 그려줌
		name = self.edit._automata.name()
		casemode = self.edit._automata.case_mode()

		self.automata = name, casemode

		if self.automata_icon:
			self.automata_icon.free()

		self.automata_icon = utils.put_image(uiconfig.edit_automata_info_icon(name,casemode), uiconfig.edit_automata_info_pos)
		self.automata_icon.show()

	def set_max(self, max=-1):
		self.edit.set_max(max)
		self.update_edit_info()

	def get_max(self):
		return self.edit.get_max()

	def get_text(self):
		return self.edit.get_text()

	def set_text(self, text):
		self.edit.set_text(text)
		self.show_arrow(self.edit.need_scroll())
		self.update_edit_info()

	def delete_char(self):
		self.edit.handle_key('\b')
		self.show_arrow(self.edit.need_scroll())
		self.update_edit_info()

	def insert_text(self, text):
		self.edit.insert_unicode_text(unicode(text, 'utf-8'))
		self.edit._automata.check_start_of_sentance()
		self.update_edit_info()
		self.show_arrow(self.edit.need_scroll())

	def insert_image(self, path, data = None):
		self.edit.insert_image(path, data)

	def insert_audio(self, path, data = None):
		self.edit.insert_audio(path, data)

	def handle_key(self, keyname):
		if keyname == config.Menu2 and self.right == _('CLEAR'):
			self.delete_char()
			if not self.get_text():
				self.set_right(_('BACK'))

			self.show_arrow(self.edit.need_scroll())
			self.update_edit_info()
			return True

		if self.edit._automata.name() == 't9':
			if keyname == config.Menu2 and self.right == _('PREVIOUS'):
				automata = self.edit._automata
				automata.handle_previous()
				if automata.get_t9_objnum() == 1:
					self.set_right(_('CLEAR'))
				else:
					self.set_right(_('PREVIOUS'))

				if self.is_t9_add_word_mode():
					self.set_left(_('OK'))
				else:
					self.set_left(self.def_left)

				return True

			elif keyname == '*':
				self.edit._automata.handle_next()
				if self.edit._automata.get_t9_objnum() == 0:
					self.set_left(_('OK'))
				else:
					self.set_left(self.def_left)

				if self.edit._automata.get_t9_objnum() == 1:
					self.set_right(_('CLEAR'))
				else:
					self.set_right(_('PREVIOUS'))

				# the 'cur/max' text doesn't updated in the right/top
				# coner, because we don't call self.update_edit_info()
				# in usual case, '*' doens't change message's length.
				return True

		ret = self.edit.handle_key(keyname)
		if ret:
			self.update_edit_info()
			self.show_arrow(self.edit.need_scroll())
		return ret

	def update_edit_info(self):		#에디트 화면을 업데이트 시켜줌(소프트키와 입력된 바이트 수)
		if self.is_t9_add_word_mode():
			self.set_left(_('OK'))
			return
		else:
			self.set_left(self.def_left)

		if self.edit.get_max() > 0:
			self.set_info( '%d/%d' % (self.edit.message_length_KT(), self.edit.get_max()) )
		if self.right in (_('PREVIOUS'),_('BACK')) and self.get_text():
			self.set_right(_('CLEAR'))
		elif not self.get_text():
			self.set_right(self.def_right)

	def change_language(self):
		self.subtitle.text = self.subtitle.text

	def reset_automata(self):
		self.edit._automata.reset()

	def is_t9_add_word_mode(self):
		if self.edit._automata.name() == 't9':
			return self.edit._automata.is_add_word_mode()
		return False

	def is_t9_editing_mode(self):
		if self.edit._automata.name() == 't9':
			if not self.edit._automata.is_edit_buffer_empty():
				return True
		return False


class SymbolSelectionUI(LargeWindowUI):
	def __init__(self, isentry=False, case=-1):
		self.isentry = isentry
		LargeWindowUI.__init__(self, _('OK'), '', '', _('SYMBOL'), _('SYMBOL'), _('BACK'))

		self.cursor_x = 0
		self.cursor_y = 0

		if case == 0:
			self.symbols = (('.', ',', '?', '!', '$', '\'', '~'),
						('*', ';', '(', ')', '/', '&', '_'),
						('-', '+', '='))
			symbol = utils.put_image(uiconfig.symbol_sel_case0, uiconfig.symbol_sel_pos)
			self.add(symbol)
		elif case == 1:
			self.symbols = (('.', ',', '?', '!', '$', '\'', '@'),
						(':', ';', '(', ')', '/', '|', '&'),
						('*', '#', '[', ']', '{', '}', '%'),
						('-', '+', '=', '>', '<', '~', '^'),
						('_', '`', ' '))
			symbol = utils.put_image(uiconfig.symbol_sel_case1, uiconfig.symbol_sel_pos)
			self.add(symbol)
		elif case == 2:
			self.symbols = (('.', ',', '!', '$', '\'', '~', '*'),
						('(', ')', '&', '_', '-', '+', '='))
			symbol = utils.put_image(uiconfig.symbol_sel_case2, uiconfig.symbol_sel_pos)
			self.add(symbol)
		elif case == 3:
			self.symbols = (('.', ',', '!', '\'', '~', '(', ')'),
						('&', '_', '-', '+', '=', ' '))
			symbol = utils.put_image(uiconfig.symbol_sel_case3, uiconfig.symbol_sel_pos)
			self.add(symbol)
		elif case == 4:
			# RHC / [20061102_1]
			#self.symbols = (('.', ',', '?', '!', '"', '\'', '@'),
			#self.symbols = (('.', ',', '\xC2\xBF', '?', '\xC2\xA1', '!', '"'),
			self.symbols = (('.', ',', '쩔', '?', '징', '!', '"'),
						(':', ';', '(', ')', '/', '\\', '&'),
						('*', '#', '[', ']', '{', '}', '%'),
						('-', '+', '=', '>', '<', '~', '^'),
						#('_', '??, '짙', '$', '짜', ' ', '\n'))
						#('_', '??, '짙', '$', '\'', '@', '\n'))
						('_', '\xE2\x82\xAC', '\xC2\xA3', '$', '\'', '@', '\n'))
						
			#symbol = utils.put_image(uiconfig.symbol_sel, uiconfig.symbol_sel_pos)
			symbol = utils.put_image(uiconfig.symbol_sel_email, uiconfig.symbol_sel_pos)
			# RHC / [20061102_1]--
			self.add(symbol)
		else:
			self.symbols = (('.', ',', '?', '!', '"', '\'', '@'),
						(':', ';', '(', ')', '/', '\\', '&'),
						('*', '#', '[', ']', '{', '}', '%'),
						('-', '+', '=', '>', '<', '~', '^'),
						#('_',  '\xE2\x82\xAC', '짙', '$', '\xc2\xa5', ' ', '\n'))
						#('_', '$', ' ', ' ', ' ', ' ', ' '))
						('_', '$', ' '))
						#('_', '??, '짙', '$', '짜', ' ', '\n'))
			symbol = utils.put_image(uiconfig.symbol_sel, uiconfig.symbol_sel_pos)
			self.add(symbol)

		self.focus = utils.put_image(uiconfig.symbol_sel_focus,
			(uiconfig.symbol_sel_focus_pos_x[self.cursor_x],
			uiconfig.symbol_sel_focus_pos_y[self.cursor_y]) )
		self.add(self.focus)

		if self.isentry:
			self.empty_rect = runtime.evas.rectangle(pos=(uiconfig.symbol_sel_pos[0]+245-35, uiconfig.symbol_sel_pos[1]+148-28),\
					size=(35,28))
			self.empty_rect.color = (255,255,255,255)#(uiconfig.color_white)
			self.add(self.empty_rect)

	def show(self):
		LargeWindowUI.show(self)
		#self.set_left(_('OK'))
		#self.set_right(_('BACK'))

	def get_symbol(self):
		return self.symbols[self.cursor_y][self.cursor_x]

	def update_cursor(self):
		self.focus.move(uiconfig.symbol_sel_focus_pos_x[self.cursor_x],
			uiconfig.symbol_sel_focus_pos_y[self.cursor_y])

	def right_key(self):
		x_max = len(self.symbols[self.cursor_y]) - 1
		y_max = len(self.symbols) - 1
		self.cursor_x += 1
		if self.cursor_x > x_max:
			self.cursor_x = 0
			self.cursor_y += 1
			if self.cursor_y > y_max:
				self.cursor_y = 0

	def left_key(self):
		x_max = len(self.symbols[self.cursor_y]) - 1
		y_max = len(self.symbols) - 1
		self.cursor_x -= 1
		if self.cursor_x < 0:
			self.cursor_x = x_max
			self.cursor_y -= 1
			if self.cursor_y < 0:
				self.cursor_y = y_max
			self.cursor_x = len(self.symbols[self.cursor_y]) - 1

	def up_key(self):
		x_max = len(self.symbols[self.cursor_y]) - 1
		y_max = len(self.symbols) - 1
		self.cursor_y -= 1
		if self.cursor_y < 0:
			self.cursor_y = y_max
			try:
				self.symbols[self.cursor_y][self.cursor_x]
			except:
				self.cursor_y -= 1

	def down_key(self):
		x_max = len(self.symbols[self.cursor_y]) - 1
		y_max = len(self.symbols) - 1
		self.cursor_y += 1
		try:
			self.symbols[self.cursor_y][self.cursor_x]
		except:
			self.cursor_y = 0
		if self.cursor_y > y_max:
			self.cursor_y = 0

	def handle_key(self, key):
		if key == 'Right':
			self.right_key()
			if self.isentry and self.symbols[self.cursor_y][self.cursor_x] == '\n':
				self.right_key()
			self.update_cursor()
			return True
		elif key == 'Left':
			self.left_key()
			if self.isentry and self.symbols[self.cursor_y][self.cursor_x] == '\n':
				self.left_key()
			self.update_cursor()
			return True
		elif key == 'Up':
			self.up_key()
			if self.isentry and self.symbols[self.cursor_y][self.cursor_x] == '\n':
				self.up_key()
			self.update_cursor()
			return True
		elif key == 'Down':
			self.down_key()
			if self.isentry and self.symbols[self.cursor_y][self.cursor_x] == '\n':
				self.down_key()
			self.update_cursor()
			return True
			
def _preloading_images():
	icon, pos = uiconfig.dial_ready_back
	runtime.dialBg = utils.put_image(icon, pos)
	runtime.dialBg.layer = videocall_bg_layer
	runtime.dialBg.hide()

	icon, pos = uiconfig.depth_bg_image, (0,0)
	runtime.depthBg = utils.put_image(icon, pos)
	runtime.depthBg.layer = videocall_bg_layer
	runtime.depthBg.hide()

	icon, pos = uiconfig.change_bg_blackimg, (0,0)
	runtime.TopMenuBg = utils.put_image(icon, pos)
	runtime.TopMenuBg.layer = menu_layer
	runtime.TopMenuBg.hide()


	
#Thang: [20080314 -1] hide time, date
def _make_fixed_widget():
	runtime.lb = widget.Label('',font=uiconfig.button_font,pos=uiconfig.left_button_pos,color=uiconfig.button_color,align=uiconfig.ALIGN_CENTER)
	runtime.rb= widget.Label('',font=uiconfig.button_font,pos=uiconfig.right_button_pos,color=uiconfig.button_color,align=uiconfig.ALIGN_CENTER)

	runtime.menu3 = widget.Label('',font=uiconfig.button_font,pos=uiconfig.left_2_button_pos,color=uiconfig.button_color,align=uiconfig.ALIGN_CENTER)
	runtime.menu4 = widget.Label('',font=uiconfig.button_font,pos=uiconfig.right_2_button_pos,color=uiconfig.button_color,align=uiconfig.ALIGN_CENTER)



	runtime.title = widget.TitleLabel(text='', font=uiconfig.title_font, pos=uiconfig.title_pos, \
				color=uiconfig.title_color, outline_color=uiconfig.title_outline_color, abbr_width=uiconfig.title_width)
	runtime.timer = widget.Label(text='', font=uiconfig.timer_font, pos=uiconfig.timer_pos, color=uiconfig.timer_color, align=uiconfig.ALIGN_LEFT)
	runtime.day = widget.OutlineLabel(text='',
								font = uiconfig.timer_font,
								pos = uiconfig.idle_date_pos,
								color = uiconfig.timer_color,
								outline_color = uiconfig.idle_outline_color,
								align=uiconfig.ALIGN_RIGHT)
	runtime.timer.hidden = False	
	def update_timer():
#Roxia Begin jhbang 06.04.06 <ntp>
		# summer time 기간을 넘어설때 다시 시간을 가져온다
		import status
		if profile.ip_mode == 1 and setting.ntp_enable and setting.ntp_summertime and status.ntp_running == False:
			current_time = ntptime.ntime()
			today = time.localtime(current_time)

			if setting.ntp_timezone == 'Canarias (GMT)':
				gmt = 0
			else:
				gmt = 1

			begin_time = ntptime.get_summertime_begin_date(today[0], gmt)
			end_time = ntptime.get_summertime_end_date(today[0], gmt)

			# 3월 마지막주 일요일 02시에 03시로 돌림(Madrid, GMT+1)
			# 10월 마지막주 일요일 03시(summer time)에 02시로 돌림(Madrid, GMT+1)
			# 3월 마지막주 일요일 01시에 02시로 돌림(Canarias, GMT+0)
			# 10월 마지막주 일요일 02시(summer time)에 01시로 돌림(Canarias, GMT+0)
#Roxia Begin jhbang 06.04.26
			if begin_time > 0 and end_time > 0:
				if 0 < begin_time - current_time < 1:
					if runtime.manager.dst_timer == None: # summer time start
						runtime.manager.dst_timer = utils.Timer(1500, runtime.manager.dst_update, 1)
				elif 0 < end_time + 3600 - current_time < 1:
					if runtime.manager.dst_timer == None: # summer time end
						runtime.manager.dst_timer = utils.Timer(1500, runtime.manager.dst_update, -1)
#Roxia End jhbang
#Roxia End jhbang

		#Video call 연결시 시간/날짜 안나오게
		import status
		if status.videocall_mode == status.VideoCallConnected and status.supervision_idle == 0:
# eicho DEBUG
			#print '####### BASEUI :: status.supervision_call_on = ', status.supervision_call_on
			if status.supervision_call_on == 1:
				pass
			else:
# end.
				runtime.timer.hide()
				runtime.day.hide()
				runtime.evas.render()
				return True

		#web 실행시 시간/날짜 안나오게
		if runtime.manager:
			if runtime.manager.stage.get_name() == 'webloading':
				runtime.timer.hide()
				runtime.day.hide()
				runtime.evas.render()
				return True
		lt = time.localtime(ntptime.ntime())
#Roxia Begin jhbang 06.04.25
		if runtime.manager:
			if not runtime.manager.dst_timer:
				pass
				#runtime.timer.set_text("%02d:%02d" % (lt[3], lt[4]))
#Roxia End jhbang
		#runtime.day.set_text('%02d/%02d/%04d' % (lt[2], lt[1], lt[0]))
		#for w in runtime.timer.children:
		#	w.layer = 0
		import status
		if not status.date_time_ready:
			if lt[5] % 3:
				if runtime.timer.hidden:
					#runtime.timer.show()
 					if runtime.manager and (runtime.manager.stage.get_name() == 'idle' or \
 									status.supervision_idle == 1):
						pass
						#runtime.day.show()
					else:
						runtime.day.hide()
					runtime.timer.hidden = False
			else:
				if not runtime.timer.hidden:
					runtime.timer.hide()
					if runtime.manager and (runtime.manager.stage.get_name() == 'idle' or \
									status.supervision_idle == 1):
						runtime.day.hide()
					runtime.timer.hidden = True
		else:
			if runtime.timer.hidden:
				#runtime.timer.show()
				if runtime.manager and (runtime.manager.stage.get_name() == 'idle' or \
								status.supervision_idle == 1):
					pass
					#runtime.day.show()
				else:
					runtime.day.hide()
				runtime.timer.hidden = False
			# eicho add 06.11.13
			elif runtime.manager and runtime.manager.stage.get_name() == 'idle' and status.supervision_idle == 1:
				#print '### date_time is ready ... '
				runtime.day.show()
			
		runtime.evas.render()
		return True

#Roxia Begin jhbang 06.03.16 <ntp>
	#print '### Baseui.py : call update_timer and runtime.evas.render()'
	# eicho remove for DEMO LVP-3800 (06.11.09)
	runtime.evas.timeout_add(1000, update_timer)
#Roxia End jhbang
	update_timer()
#	for w in runtime.lb, runtime.rb, runtime.title, runtime.timer:
#		w.show()
#Thang: [20080314 -1] hide time, date


def load_theme(canvas, theme):

	print '### LOAD_THEME:', canvas.bg
	if not canvas.bg:
		canvas.bg = utils.put_image(theme.bg_file, (0,0))
		canvas.bg.layer = -90

		#canvas.soft = utils.put_image(uiconfig.image_dir + uiconfig.soft_bar, uiconfig.soft_pos)
		canvas.soft = utils.put_image(uiconfig.image_dir + uiconfig.soft_bar, uiconfig.soft_pos)
		canvas.soft.layer = menu_layer

		print '### CANVAS_BG:', canvas.bg, canvas.soft
	else:
		canvas.bg.file = uiconfig.image_dir + uiconfig.current_theme.bg_file		
		canvas.bg.layer = -90

		canvas.soft.file = uiconfig.image_dir + uiconfig.current_theme.soft_bar
		canvas.soft.layer = menu_layer
		
def change_bg(canvas, file, copy=True):
	if canvas.bg_image:
		canvas.bg_image.free()
	import os
	dir, fname = utils.split_image_name(file)

	#if utils.get_ext(fname) == 'gif':
	#	fname = fname.split('.')[0] + '.png'
	#	file = '/tmp/tmp_gif/'+ fname.split('.')[0] + '.png'

	new_bg_file = config.image_background_dir + fname
	# bgfile을 copy 한다.
	# copy:False 일때(처음 ui_init)는 copy를 하지 않는다.

	if copy:
		utils.remove_dir(config.image_background_dir)
		utils.file_copy(file, new_bg_file)
		time.sleep(1)	# this is needed for os.access function of next line

	# 혹시 file copy 가 안되었거나 error 발생시에는 default bg 로...
	if not os.access(new_bg_file, os.R_OK):
		new_bg_file = config.def_bg
	#new_bg_file = config.lgvp + new_bg_file
	image = runtime.evas.image(file=new_bg_file)
	utils.image_center_sized(image, 240, 136, 480, 272)
	canvas.bg_image = image
	canvas.bg_image.hide()
	canvas.bg_image.layer = -80


def ui_init(exit_cb):
	debugLogN("ui_init start")
	import evas
	runtime.evas = canvas = evas.Evas(config.x, config.y, config.width, config.height, config.rotation)
	canvas.image_cache_set(2*1024*1024)
	canvas.font_cache_set(10*1024)
	canvas.bg = None
	canvas.bg_image = None
	dir_lists = '/usr/local/share/evas/data'

	import os
	if os.access(dir_lists, os.R_OK):
		canvas.font_path_prepend(dir_lists)

	base = canvas.rectangle(0, 0, 1, 1)
	base.layer = -100
	canvas.base = base

	canvas.clip = canvas.rectangle()
	canvas.clip.geometry = 0,0,1,1
	canvas.clip.layer = clip_layer
	canvas.clip.color = 255, 255, 254, 255 # magic colorkey
	'''
	def set_clip(*geo):
		if geo:
			if config.rotation == 180:
				x,y,w,h = geo
				geo = 320 - (x + w), y, w, h
			canvas.clip.geometry = geo
			canvas.clip.color = 128, 128, 128, 255
			canvas.clip.show()
			canvas.render_now()
			canvas.clip.color = 255, 255, 254, 255 # magic colorkey
			canvas.use_transparency(True)
			canvas.clip.hide()
			canvas.clip.show()
		else:
			canvas.use_transparency(False)
			canvas.clip.hide()
		canvas.render()
	'''
	def set_clip(*geo):
		if geo:
			if config.rotation == 180:
				x,y,w,h = geo
				geo = 320 - (x + w), y, w, h
			canvas.clip.geometry = geo
			canvas.clip.color = 255, 255, 254, 255 # magic colorkey
			#canvas.clip.color = 0, 0, 8, 0 # magic colorkey
			canvas.use_transparency(True)
			canvas.clip.show()
		else:
			canvas.use_transparency(False)
			canvas.clip.hide()
		canvas.render()

	canvas.set_clip = set_clip

	load_theme(canvas, uiconfig.current_theme)

	bg_image_file = setting.bg_image_file
	canvas.bg_image = None
	change_bg(canvas, bg_image_file, copy=False)

	if 0:
		def key_down_cb(ev):
			if config.key_debug:
				print 'key press', ev.keyname
			if ev.keyname == 'q':
				exit_cb()
			canvas.handle_key(True, ev.keyname)

		def key_up_cb(ev):
			if config.key_debug:
				print 'key release', ev.keyname
			canvas.handle_key(False, ev.keyname)

		base.event_callback_add(evas.CALLBACK_KEY_DOWN, key_down_cb)
		base.event_callback_add(evas.CALLBACK_KEY_UP, key_up_cb)
		base.focus_set(True)
		base.show()
	else:
		canvas.event_set_mask(evas.CALLBACK_KEY_DOWN|evas.CALLBACK_KEY_UP)
		def event_cb(type, *args):
			if config.key_debug:
				print type
			if type == evas.CALLBACK_KEY_DOWN:
				if args[0] == 'q':
					exit_cb()
				canvas.handle_key(True, args[0])
			elif type == evas.CALLBACK_KEY_UP:
				canvas.handle_key(False, args[0])
		canvas.event_set_callback(event_cb)
	_make_fixed_widget()
	_preloading_images()

	
	debugLogN("ui_init end")
	return
	def text(*va, **kw):
		import traceback
		traceback.print_stack()
		return canvas._text(*va, **kw)
	canvas._text, canvas.text = canvas.text, text
	def rect(*va, **kw):
		import traceback
		traceback.print_stack()
		return canvas._rectangle(*va, **kw)
	canvas._rectangle, canvas.rectangle = canvas.rectangle, rect

	
#Thang: widget --------------
class WidgetBackgroundUI(BaseUI):
	show_bg_depth = True
	def __init__(self, item_index, left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, _('WIDGET SETTING'), menu3, menu4)
		
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0,0))
		#bg_image.hide()
		#self.add(bg_image)

		#Title Image
		#name, pos  = uiconfig.Third_title_widget_setting
		#title_image = utils.put_image(name, pos)		
		#self.add(title_image)

		#if setting.idle_style == 3:
		#	self.widget_enable = 0
		#else:
		#	self.widget_enable = 1

		self.idle_style = setting.idle_style
		
		#lbl_set = controls.Label_Control(_('Set'), font=uiconfig.input_font, pos=(uiconfig.input2_x2, uiconfig.input2_y2[0]), color=uiconfig.list_text_color)
		#self.add(lbl_set)

		#name, pos  = uiconfig.ico_widget_enable
		#self.widget_enable_icon = utils.put_image(name, pos)
		#widget_enable_choose = [_('Disable'), _('Enable')]
		#self.widget_enable = controls.ListBox_Control(widget_enable_choose, self.widget_enable, font=uiconfig.input_font, pos=(uiconfig.input2_x3, uiconfig.input2_y3[0]), color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		#self.add(self.widget_enable)
		
		#lbl_mode = controls.Label_Control(_('Mode'), font=uiconfig.input_font, pos=(uiconfig.input2_x2, uiconfig.input2_y2[1]), color=uiconfig.list_text_color)
		lbl_mode = controls.Label_Control(_('Set'), font=uiconfig.input_font, pos=(uiconfig.input2_x2, uiconfig.input2_y2[0]), color=uiconfig.list_text_color)
		self.add(lbl_mode)

		#name, pos  = uiconfig.ico_widget_mode
		name, pos  = uiconfig.ico_widget_enable
		self.widget_mode_icon = utils.put_image(name, pos)
		widget_style_choose = [_('Small clock'), _('Big clock'), _('Calendar'), _('None')]
		#self.widget_style= controls.ListBox_Control(widget_style_choose, self.idle_style, font=uiconfig.input_font, pos=(uiconfig.input2_x3, uiconfig.input2_y3[1]), color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		self.widget_style= controls.ListBox_Control(widget_style_choose, self.idle_style, font=uiconfig.input_font, pos=(uiconfig.input2_x3, uiconfig.input2_y3[0]), color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		self.add(self.widget_style)
		
		self.focus = 0
		
	def destroy(self):
		#self.widget_enable_icon.free()
		self.widget_mode_icon.free()
		
		BaseUI.destroy(self)

	def show(self):		
		BaseUI.show(self)		
		#self.set_focus(self.focus)
		self.widget_style.showFocus()
		
	def set_right(self, right):
		self.right = right
		runtime.rb.set_text(right)
		
	def save(self):
		#if self.widget_enable.get_index() == 0:
		#	setting.idle_style = 3
		#else:
		#	setting.idle_style = self.widget_style.get_index()
		setting.idle_style = self.widget_style.get_index()
		setting.save()

	#def set_focus(self,focus):
	#	if focus == 0:
	#		self.widget_enable.showFocus()
	#		self.widget_style.lostFocus()
	#	elif focus == 1:
	#		self.widget_enable.lostFocus()
	#		self.widget_style.showFocus()
	def handle_key(self,key):
		#if key == 'Down' or  key == 'Up':
		#	self.focus = 1 - self.focus
		#	self.set_focus(self.focus)
		#	return True
		#elif key in ('Left','Right'):
		if key in ('Left','Right'):
			#if self.focus == 0:
			#	self.widget_enable.handle_key(key)
			#else:
			self.widget_style.handle_key(key)
			return True
		return False

# KA: [20081107] common UI - setting
class OneSelectBoxUI(BaseUI):
	def __init__(self, index, left, right, menu3, menu4, choices=None,):		
		BaseUI.__init__(self, left, right, '', menu3, menu4)
		self.index = index
		#Title Image
		#name, pos  = uiconfig.Third_title_networkEV
		#title_image = utils.put_image(name, pos)		
		#self.add(title_image)	
		# setting icon
		set_icon = controls.Label_Control(_('Set'), font=uiconfig.input_font, pos=(uiconfig.input2_x2, uiconfig.input2_y2[0]), color=uiconfig.list_text_color)
		self.add(set_icon)
		# select box
		name, pos  = uiconfig.ico_widget_enable
		select_box = utils.put_image(name, pos)
		self.add(select_box)
		# select list
		self.list = controls.ListBox_Control(choices, self.index, font=uiconfig.input_font, pos=(uiconfig.input2_x3, uiconfig.input2_y3[0]), color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		self.add(self.list)
		self.list.showFocus()

	def handle_key(self,key):
		if key in ('Left','Right'):
			self.list.handle_key(key)
			return True
		return False

		
#Thang: widget --------------
#Jongwook:Screen Text------------------
class EditBackgroundTextUI(BaseUI):
	show_bg_depth = True
	def __init__(self, item_index, left, right, menu3, menu4, titleimage=None, icon=None):		
		BaseUI.__init__(self, left, right, _('SCREEN TEXT'), menu3, menu4)
		
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title image
		#name, pos  = uiconfig.Third_title_screen_text
		#title_image = utils.put_image(name, pos)
		##title_image.hide()
		#self.add(title_image)

		# setting
		bg_text_set_choose = [_('Disable'), _('Enable'), _('My number')]
		name, pos = uiconfig.screen_text_icon1
		self.icon_bg_text_set = utils.put_image(name, pos)
		self.label_bg_text_set = controls.Label_Control(_('Set'), font=uiconfig.input_font, pos=uiconfig.screen_text_label1_pos, color=uiconfig.list_text_color)
		self.bg_text_set = controls.ListBox_Control(bg_text_set_choose, setting.ScreenTextEnable, font=uiconfig.input_font, pos=uiconfig.screen_text_box1_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

		# text position
		bg_text_pos_choose = [_('Upper'), _('Middle'), _('Lower')]
		name, pos = uiconfig.screen_text_icon2
		self.icon_bg_text_pos = utils.put_image(name, pos)
		self.label_bg_text_pos = controls.Label_Control(_('Position'), font=uiconfig.input_font, pos=uiconfig.screen_text_label2_pos, color=uiconfig.list_text_color)
		self.bg_text_pos = controls.ListBox_Control(bg_text_pos_choose, setting.ScreenTextAlign, font=uiconfig.input_font, pos=uiconfig.screen_text_box2_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

		# text input
		self.ScreenTextText = setting.ScreenTextText
		name, pos = uiconfig.screen_text_icon3
		icon_2 = utils.put_image(name, pos)
		self.add(icon_2)
		ScreenText_input_name = runtime.evas.text(text=_('Input'), font=uiconfig.input_font, pos=uiconfig.screen_text_label3_pos, color=uiconfig.list_text_color)
		self.add(ScreenText_input_name)
		import entry
		self.entry = entry.Entry(pos=uiconfig.screen_text_box3_pos, size=uiconfig.screen_text_box3_size, bgcolor=uiconfig.color_gray)
		#self.entry.add_callback(self.entry.AutomataChanged, self.update_automata_icon)
		if self.bg_text_set.get_index()==2:
			self.entry.set_text(utils.conv_telnum(vdci_setting.tel_num))
			self.entry.cursor_start()
		else:
			self.entry.set_text(self.ScreenTextText)
		self.entry.set_max(26)   # 한글 13자, 영문 26자 글자수 제한
		self.entry.cursor_start()
		self.add(self.entry)
	
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		# text size
		bg_text_size_choose = ['12', '13', '14', '15', '16', '17', '18']
		name, pos = uiconfig.screen_text_icon4
		self.icon_bg_text_size = utils.put_image(name, pos)
		self.label_bg_text_size = controls.Label_Control(_('Size'), font=uiconfig.input_font, pos=uiconfig.screen_text_label4_pos, color=uiconfig.list_text_color)
		self.bg_text_size = controls.ListBox_Control(bg_text_size_choose, setting.ScreenTextSizeIndex, font=uiconfig.input_font, pos=uiconfig.screen_text_box4_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)

		# text color
		bg_text_color_choose = [_('Black'), _('Red'), _('Orange'), _('Yellow'), _('Yellowish green'), _('Green'), _('Sky blue'), _('Blue'), _('Violet'), _('Purple')]
		name, pos = uiconfig.screen_text_icon5
		self.icon_bg_text_color = utils.put_image(name, pos)
		self.label_bg_text_color = controls.Label_Control(_('Color'), font=uiconfig.input_font, pos=uiconfig.screen_text_label5_pos, color=uiconfig.list_text_color)
		self.bg_text_color = controls.ListBox_Control(bg_text_color_choose, setting.ScreenTextColorIndex, font=uiconfig.input_font, pos=uiconfig.screen_text_box5_pos, color=uiconfig.list_text_color, mode=uiconfig.LIST_MODE_MEDIUM)
		
		self.index = 0
		#elf.set_focus(self.index)

		self.symbol_stage_timer = None

	def align_center(self, l, pos):
		x, y = pos
		width,height = l.size
		l.move(x - width/2, y)
		
	def destroy(self):
		if self.automata_icon: self.automata_icon.free()
		self.icon_bg_text_set.free()
		self.icon_bg_text_pos.free()
		self.icon_bg_text_size.free()
		self.icon_bg_text_color.free()
		self.label_bg_text_set.free()
		self.label_bg_text_pos.free()
		self.label_bg_text_size.free()
		self.label_bg_text_color.free()
		self.bg_text_set.free()
		self.bg_text_pos.free()
		self.bg_text_size.free()
		self.bg_text_color.free()
		BaseUI.destroy(self)
		self.symbol_stage_timer = None

	def show(self):
		if self.automata_icon: self.automata_icon.show()
		BaseUI.show(self)
		self.refresh_show()
		self.entry.cursor_hide()
		if self.index == 2:
			self.bg_text_set.lostFocus()
			self.bg_text_pos.lostFocus()
			color = uiconfig.color_select
			self.entry.set_background_color(color)
			self.entry.cursor_show()
			self.bg_text_size.lostFocus()
			self.bg_text_color.lostFocus()
			self.update_menu3()
		else:
			self.set_menu3('')
			self.set_focus(self.index)
		self.set_right('')		
		
	def set_focus(self,index):
		if index == 0:
			self.bg_text_set.showFocus()
			self.bg_text_pos.lostFocus()
			self.entry.cursor_hide()
			color = uiconfig.color_white
			self.entry.set_background_color(color)
			self.bg_text_size.lostFocus()
			self.bg_text_color.lostFocus()		
			self.set_menu3('')
			
		elif index == 1:
			self.bg_text_set.lostFocus()
			self.bg_text_pos.showFocus()
			self.entry.cursor_hide()
			color = uiconfig.color_white
			self.entry.set_background_color(color)
			self.bg_text_size.lostFocus()
			self.bg_text_color.lostFocus()
			self.set_menu3('')
			
		elif index == 2:
			self.bg_text_set.lostFocus()
			self.bg_text_pos.lostFocus()
			color = uiconfig.color_select
			self.entry.set_background_color(color)
			self.entry.cursor_end()
			self.entry.cursor_show()
			self.bg_text_size.lostFocus()
			self.bg_text_color.lostFocus()

			if setting.lang == 'Korean':
				self.set_automata('hangul', False)
				self.set_menu3(_('KOR'))
			
			else:
				self.set_automata('multitap', 'lower')	
				self.set_menu3(_('abc'))
			
		elif index == 3:
			self.bg_text_set.lostFocus()
			self.bg_text_pos.lostFocus()
			self.entry.cursor_hide()
			color = uiconfig.color_white
			self.entry.set_background_color(color)
			self.bg_text_size.showFocus()
			self.bg_text_color.lostFocus()
			self.set_menu3('')
			
		elif index == 4:
			self.bg_text_set.lostFocus()
			self.bg_text_pos.lostFocus()
			self.entry.cursor_hide()
			color = uiconfig.color_white
			self.entry.set_background_color(color)
			self.bg_text_size.lostFocus()
			self.bg_text_color.showFocus()			
			self.set_menu3('')

	def refresh_show(self):
		self.bg_text_set.show()
		self.bg_text_pos.show()
		self.entry.show()
		self.bg_text_size.show()
		self.bg_text_color.show()		

	def hide(self):
		BaseUI.hide(self)
		self.bg_text_set.hide()
		self.bg_text_pos.hide()
		self.entry.hide()
		self.bg_text_size.hide()
		self.bg_text_color.hide()

	def save(self):
		setting.ScreenTextEnable = self.bg_text_set.get_index()
		setting.ScreenTextAlign = self.bg_text_pos.get_index()
		if self.bg_text_set.get_index() != 2:
			setting.ScreenTextText = self.entry.get_text()
		setting.ScreenTextSizeIndex = self.bg_text_size.get_index()
		setting.ScreenTextColorIndex = self.bg_text_color.get_index()

	def get_text(self):
		return self.entry.get_text()

	def insert_text(self, text):
		self.entry.insert_unicode_text(unicode(text, 'utf-8'))
		self.entry._automata.check_start_of_sentance()
		#self.update_entry_info()

	def insert_symbol(self, s):
		def back_to_symbol():
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
			self.symbol_stage_timer = None
			
		before_text = self.get_text()
		self.insert_text(s)
		after_text = self.get_text()

		if before_text == after_text:
			from basemodel import NotifyStage
			runtime.manager.change_stage(NotifyStage(_('Max length exceeded'), uiconfig.baloon_message_icon))
		else:
			runtime.manager.back_stage()
			#self.symbol_stage_timer = utils.Timer(uiconfig.back_to_symbol_timeout, back_to_symbol)
	
	def handle_key(self, key):
		if key == 'Up':
			self.index -= 1
			if self.bg_text_set.get_index()==2 and self.index==2: self.index -= 1
			if self.index < 0:self.index = 4
			self.set_focus(self.index)
			return True
		elif key == 'Down':
			self.index += 1
			if self.bg_text_set.get_index()==2 and self.index==2: self.index += 1
			if self.index > 4: self.index = 0
			self.set_focus(self.index)
			return True
		elif key == 'Left':
			if self.index == 0:
				self.bg_text_set.handle_key(key)
				if self.bg_text_set.get_index()==2:
					self.entry.set_text(utils.conv_telnum(vdci_setting.tel_num));
					self.entry.cursor_start()
				else:
					self.entry.set_text(setting.ScreenTextText);
				self.entry.cursor_hide()
			elif self.index == 1:	self.bg_text_pos.handle_key(key)
			elif self.index == 2:	self.entry.cursor_backward()
			elif self.index == 3:	self.bg_text_size.handle_key(key)
			elif self.index == 4:	self.bg_text_color.handle_key(key)
			return True
		elif key == 'Right':
			if self.index == 0:
				self.bg_text_set.handle_key(key)
				if self.bg_text_set.get_index()==2:
					self.entry.set_text(utils.conv_telnum(vdci_setting.tel_num));
					self.entry.cursor_start()
				else:
					self.entry.set_text(setting.ScreenTextText);
				self.entry.cursor_hide()
			elif self.index == 1:	self.bg_text_pos.handle_key(key)
			elif self.index == 2:
				self.entry.handle_key(key)
				'''
				if self.entry.is_cursor_end():
					self.entry.handle_key(key)
					self.entry.cursor_forward()
					self.entry.insert_unicode_text(unicode(' ', 'utf-8'), ul=False)
				else:
					self.entry.cursor_forward()
				'''
			elif self.index == 3:	self.bg_text_size.handle_key(key)
			elif self.index == 4:	self.bg_text_color.handle_key(key)
			return True
		elif key == config.Menu3:	
			if self.index == 2:

				# shchun: global input change
				if setting.lang == 'Korean':
					self.automata_idx = utils.get_automata_idx(*self.automata)	
					self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_hangul)
					
					self.automata = config.automata_list_hangul[self.automata_idx]		
				else:	
					self.automata_idx = utils.get_automata_idx(*self.automata)	
					self.automata_idx = (self.automata_idx + 1) % len(config.automata_list)
					
					self.automata = config.automata_list[self.automata_idx]			
				self.set_automata(*self.automata)
				# end shchun
				self.update_menu3()
			return True
		elif key == 'CLR':	
			if self.index == 2:
				if len(self.entry.get_text()) > 0:
					#self.entry.backspace(1)
					self.entry.handle_key('\b')
				else:
					runtime.manager.back_stage()
			else:
				runtime.manager.back_stage()
			return True
		else:
			if self.index == 2:
				self.entry.handle_key(key)
				return True
		return False
		
	def set_fixed_automata(self, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_automata(name, casemode)
		else:
			self.fixed_automata = False
			self.set_automata(*utils.get_def_automata())

	def set_automata(self, name, casemode='lower'):
		self.entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)
		self.automata = name, casemode

	'''
	def update_automata_icon(self):
		name = self.entry._automata.name()
		casemode = self.entry._automata.case_mode()
		self.automata = name, casemode
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)
	'''

	def update_menu3(self):
		name = self.entry._automata.name()
		casemode = self.entry._automata.case_mode()
		self.automata = name, casemode

		if self.automata[0] == '123':			menu3 = '123'
		elif self.automata[0] == 'hangul':		menu3 = _('KOR')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'lower':			menu3 = _('abc')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'upper':			menu3 = _('ABC')
		elif self.automata[0] == 'multitap' and self.automata[1] == 'first capital':	menu3 = _('Abc')
		elif self.automata[0] == 't9' and self.automata[1] == 'lower':			menu3 = _('T9abc')
		elif self.automata[0] == 't9' and self.automata[1] == 'upper':			menu3 = _('T9ABC')
		elif self.automata[0] == 't9' and self.automata[1] == 'first capital':	menu3 = _('T9Abc')		
		else:							menu3 = _('SYMBOL')
		#runtime.menu3.set_text(menu3)	
		self.set_menu3(menu3)
		
		if menu3 ==_('SYMBOL'):
			# shchun : global automata change
			self.set_automata( 'multitap', 'lower')
			if setting.lang == 'Korean':
				self.set_automata('hangul', False)
			else:
				self.set_automata('multitap', 'lower')	
			
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))
			# end shchun
			#self.set_fixed_automata(None, False)	
#Jongwook:Screen Text------------------


class CallHistoryUI(ListUI):
	def __init__(self, left=_('MENU'), right=_('AUDIO CALL'), menu3=_('VIDEO CALL'), menu4=_('BACK'), subtitle=''):		
		ListUI.__init__(self, left, right, _('CALL HISTORY'), menu3, menu4, num_col=False)
		self.list = None
		self.item = None
		self.display_idx = 0

		# bg image
		leftbgimage = uiconfig.call_history_bg_left
		name, pos = leftbgimage
		left_bg_image = utils.put_image(name, pos)
		left_bg_image.hide()
		self.add(left_bg_image)

		call_history_type_text = [_('All'), _('Recv'), _('Send'), _('Missed')]
		call_history_type_text_color = []
		# call type image
		if subtitle == _('RECENT CALL'):
			title_sel_recent = utils.put_image(uiconfig.call_history_type_ico_select, uiconfig.call_history_type_ico_pos[0])
			self.add(title_sel_recent)
			call_history_type_text_color.append(uiconfig.color_dark_telio)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			
		elif subtitle == _('RECEIVED CALL'):
			title_sel_received = utils.put_image(uiconfig.call_history_type_ico_select, uiconfig.call_history_type_ico_pos[1])
			self.add(title_sel_received)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_telio)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			
		elif subtitle == _('DIALED CALL'):			
				
			title_sel_dialed = utils.put_image(uiconfig.call_history_type_ico_select, uiconfig.call_history_type_ico_pos[2])
			self.add(title_sel_dialed)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_telio)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			
		elif subtitle == _('MISSED CALL'):

			title_sel_missed = utils.put_image(uiconfig.call_history_type_ico_select, uiconfig.call_history_type_ico_pos[3])
			self.add(title_sel_missed)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_gray)
			call_history_type_text_color.append(uiconfig.color_dark_telio)

		titletext = []
		for i in range(4):
			titletext.append(runtime.evas.text(text=call_history_type_text[i],
					font=uiconfig.call_history_type_font,
					pos=uiconfig.call_history_type_pos[i],
					color=call_history_type_text_color[i]))
			self.add(titletext[i])
		
		# phonebook image
		self.snapshot = utils.put_image(uiconfig.PB_image_file, uiconfig.call_history_PB_image_pos)
		self.snapshot.hide()
		self.add(self.snapshot)

		# call time
		#ctime_box = utils.put_image(uiconfig.call_history_info_box, uiconfig.call_history_info_box_pos[0])
		#ctime_box.hide()
		#self.add(ctime_box)
			
		self.ctime = runtime.evas.text(text='',
				font=uiconfig.call_history_font,
				pos=uiconfig.call_history_info_pos[0],
				color=uiconfig.color_dark_gray)
		self.add(self.ctime)

		# duration
		#duration_box = utils.put_image(uiconfig.call_history_info_box, uiconfig.call_history_info_box_pos[1])
		#duration_box.hide()
		#self.add(duration_box)
		
		self.duration = runtime.evas.text(text='',
				font=uiconfig.call_history_font,
				pos=uiconfig.call_history_info_pos[1],
				color=uiconfig.color_dark_gray)
		self.add(self.duration)

	def set_list(self, labels, icons, call_duration, calling_time, number, unselbarpos=[]):
		roxia_trace('CallHistoryUI.set_list(), lables=', labels)
		self.call_duration = call_duration
		self.calling_time = calling_time
		self.number = number
		self.list = widget.List(labels, unselbarpos, num_col = self.num_col, x = self.x+15)
		self.add(self.list)		
		#if len(uiconfig.list_icon_cnt) >= len(labels) and len(labels) > 0:
		if len(labels):
			#self.icon_cols = uiconfig.list_icon_cnt[0:len(labels)]
			self.remove_all_icon_columns()
			self.create_icon_column(uiconfig.call_history_ico_callhistory_pos+15, icons)
			self.update_info(0)
		else:
			self.set_left('')

	def create_icon_column(self, x, icons, resize=[0,0]):
		ic = widget.IconColumn(x, icons, resize)
		self.list.attach_icon_column(ic)
		self.icon_cols.append(ic)
		self.add(ic)

	def remove_all_icon_columns(self):
		self.list.remove_all_icon_columns()
		for ic in self.icon_cols:
			try:
				self.widgets.remove(ic)
				ic.free()
			except:
				pass
				#print 'EXCEPT remove_all_icon_columns() ic == ', ic, 'icon_cols == ', self.icon_cols
		self.icon_cols = []

	def update_lists(self, labels, icons, call_duration, calling_time, number, unselbarpos=[]):		
		self.list.free()
		self.widgets.remove(self.list)
		self.call_duration = call_duration
		self.calling_time = calling_time
		self.number = number
		self.list = widget.List(labels, unselbarpos, num_col = self.num_col, x = self.x)
		self.add(self.list)			
		self.remove_all_icon_columns()
		if len(labels):
			self.create_icon_column(uiconfig.call_history_ico_callhistory_pos, icons)
			self.update_info(0)

	def set_preview(self, file):
		filesize = utils.get_size_kb(file)
		tmp_w, tmp_h = utils.get_img_size(file)
		if tmp_w * tmp_h > 640 * 480:
			file = '/usr/local/lgvp/images/image_big.png'
		self.snapshot.file = file

	def update_info(self, idx):
		self.duration.text_set(self.call_duration[idx])
		self.ctime.text_set(self.calling_time[idx])
		number = self.number[idx]
		if config.mmi_debug: print '## update_info:number=', number
	
		from phonedb import phonedb
		snapshot = phonedb.get_snapshot(number)
		
		import os		
		if snapshot and os.access(snapshot, os.R_OK):
			self.set_preview(snapshot)
		else:
			#snapshot = 'photos/snapshot/no_photo.png'
			snapshot = 'images/no_photo.png'
			self.set_preview(snapshot)

	def handle_key(self, keyname):
		if keyname == 'Up':
			if self.get_focus() >= 0:			
				self.list.focus_up()
				self.update_info(self.get_focus())
			return True
		elif keyname == 'Down':
			if self.get_focus() >= 0:	
				self.list.focus_down()
				self.update_info(self.get_focus())
			return True
		return False


class TransferUI(BaloonMessageUI):
	show_bg_depth = True
	def __init__(self,left,right,menu3,menu4, message):
		#BaseUI.__init__(self,left,right,'',menu3, menu4)
		#BaloonMessageUI.__init__(self, left, right, title,icon, message, menu3, menu4)
		BaloonMessageUI.__init__(self, left, right, '', '', message, menu3, menu4)
		#bg_image = utils.put_image(uiconfig.depth_bg_image,(0,0))
		#bg_image.hide()
		#self.add(bg_image)
		
import widget
class UserInfomationWidget(widget.Widget):
	def __init__(self, frame, unselbarpos=[]):
		self.unselbarpos = unselbarpos
		import status
		widget.Widget.__init__(self)
		self.icon_columns = []
		self.scroll_bg = None
		self.scroll_ball = None
		edit_entry_n=13
		self.first_column_offset = -80
		#self.choose = ( _('Set'), _('Number') + '1', _('Number') + '2')
		self.choose = []
		#self.choose.append(_('Registration'))
		#LabelText = [_('Phone number'), _('Auth ID'),  _('Password.'), _('SIP URI'), _('Domain name'),\
		#_('Proxy address')+'1', _('Proxy port')+'1', _('Proxy address')+'2', _('Proxy port')+'2',\
		#_('SBC address')+'1', _('SBC port')+'1', _('SBC address')+'2',  _('SBC port')+'2']
		LabelText = [_('Phone number'), _('Auth ID'), _('Password.'), _('SIP URI'), 'SIP Domain',\
			'CSCF Domain 1', _('CSCF Port 1'), 'CSCF Domain 2', _('CSCF Port 2'),\
			'SBC Domain 1', _('SBC Port 1'), 'SBC Domain 2',  _('SBC Port 2')] #	_('CSCF/SBC')]
		for i in range(edit_entry_n):
			self.choose.append(LabelText[i])
		self.icons = []
		self.labels = []
		self.entrys = []
		for lst in frame:
			#self.icons.append(lst[0])
			self.labels.append(lst[1])
			self.entrys.append(lst[2])
		
		self.org_label = None
		self.scroll_text = None
		self.temp_text = None
		self.item_scroll_timer = None
		self.top_index = 0		
		self.focus = -1
		x = uiconfig.pb_entry_pos_x

		self.nrow = nrow = len(self.labels)
		if nrow == 0:		pos_y = []
		elif nrow == 1:	pos_y = uiconfig.pb_entry_pos_y1
		elif nrow == 2:	pos_y = uiconfig.pb_entry_pos_y2
		elif nrow == 3:	pos_y = uiconfig.pb_entry_pos_y3
		elif nrow == 4:	pos_y = uiconfig.pb_entry_pos_y4
		elif nrow == 5:	pos_y = uiconfig.pb_entry_pos_y5
		else:			pos_y = uiconfig.pb_entry_pos_y6
			
#		x = uiconfig.list_pos_x
		self.pos_y = pos_y
		
		i = 0
		while i < len(self.labels):			
			#self.children.append(self.icons[i])			
			self.children.append(self.labels[i])	
			self.children.append(self.entrys[i])			
			i += 1
			
		for i, y in enumerate(pos_y):	
			#self.icons[i].setPosition(uiconfig.input6p_x1, y+4)
			self.labels[i].set_position(uiconfig.input6p_x2+self.first_column_offset, y+16-uiconfig.input_font[1]/2-2)
			self.labels[i].set_text(self.choose[i])			
			self.labels[i].show()
			self.entrys[i].setPosition(uiconfig.input6p_x3, y)
			self.entrys[i].set_text(self.entrys[i].get_text()) # this is for text align refreshing
			self.entrys[i].show()
			
		if nrow > 6: # draw scroll arrow
			self.scroll_bg = utils.put_image('scroll_bg.png',(444,45),(4, 192))			
			self.scroll_bg.hide()
			self.scroll_ball = utils.put_image('scroll_ball.png',(444,47),(4,int(192/len(self.labels))))
			self.scroll_bg.hide()
			self.children.append(self.scroll_bg)
			self.children.append(self.scroll_ball)
		
		self.set_focus(0)
		
	def set_focus(self, focus, new=False):
		import status
		if self.nrow == 0:
			return

		if self.focus == -1:
			selected_olditem = False
		else:
			selected_olditem = True

		if focus < 0:
			focus = self.nrow + focus
		hi_index = focus - self.top_index

		if config.mmi_debug: print '### hi_index(%s) = self.nrow(%s) - self.top_index(%s)' %(hi_index, focus, self.top_index)
		if hi_index < 0 or len(self.pos_y) <= hi_index or (new == True and self.top_index > 0):
			if config.mmi_debug: print 'before self.top_index=', self.top_index
			if new == False:
				if hi_index < 0:
					self.top_index += hi_index
				else:
					self.top_index += hi_index - len(uiconfig.list_pos_y6) + 1	
			if config.mmi_debug: print 'After self.top_index=', self.top_index
			i =0
			while i < len(self.labels):			
				#self.icons[i].hide()
				self.labels[i].hide()
				self.entrys[i].hide()
				i += 1
			x = uiconfig.pb_entry_pos_x
			for i, y in enumerate(self.pos_y):	
				#self.icons[i+self.top_index].setPosition(uiconfig.input6p_x1, y+4)
				#self.icons[i+self.top_index].show()
				self.labels[i+self.top_index].set_position(uiconfig.input6p_x2+self.first_column_offset, y+16-uiconfig.input_font[1]/2-2)
				self.labels[i+self.top_index].set_text(self.choose[i+self.top_index])
				self.labels[i+self.top_index].show()				
				self.entrys[i+self.top_index].setPosition(uiconfig.input6p_x3, y)
				self.entrys[i+self.top_index].set_text(self.entrys[i+self.top_index].get_text()) # this is for text align refreshing
				self.entrys[i+self.top_index].show()
				if config.mmi_debug: print 'jun.............. i=%s, y=%s, self.top_index=%s' %(i, y, self.top_index)

		self.focus = focus
		if len(self.labels) > 6:
			self.scroll_ball.move(444, int(192/len(self.labels)) + self.focus * int(192/len(self.labels)) + 47 - int(192/len(self.labels)) )	
		
	def focus_up(self):
		if self.focus > 0:
			self.set_focus(self.focus - 1)
		else:
			self.set_focus(self.nrow - 1)
	
	def focus_down(self):
		if self.focus < len(self.labels) - 1:
			self.set_focus(self.focus + 1)
		else:
			self.set_focus(0)
			
	def show(self):
		#self.set_focus(self.focus)
		widget.Widget.show(self)
		i=6
		while i < len(self.labels):
			#self.icons[i].hide()
			self.labels[i].hide()
			self.entrys[i].hide()
			i += 1
			
	def hide(self):
		#self.remove_item_scroll_timer()
		widget.Widget.hide(self)

	def free(self):
		#self.remove_item_scroll_timer()
		widget.Widget.free(self)
	#---------------------------------
	# List Item 이 선택되었음		

import controls
class UserInfomationUI(BaseUI):
	show_bg_depth = True
	def __init__(self, left, right, title, menu3, menu4, titleimage=None, icon=None, arg_enabled=False):		
		BaseUI.__init__(self, left, right, title, menu3, menu4)
		self.list = None
		self.display_idx = 0
		edit_entry_n = 13
		# bg image
		#bg_image = utils.put_image(uiconfig.depth_bg_image, (0, 0))
		#bg_image.hide()
		#self.add(bg_image)

		# title text
		#t = runtime.evas.text()
		#t.font=uiconfig.def_font, 14
		#t.color=uiconfig.color_dark_gray
		#t.text= title
		#t.pos =(13, 10)
		#self.add(t)

		
		listidx = 1
		if arg_enabled:
			listidx = 0

		self.icon_cols = []
		self.icons = {}
		self.frame = []
		self.fixed_automata = False
		self.automata_icon = None
		self.automata_idx = 0

		#icon_name = controls.Icon_Control(uiconfig.ico_in_restrict_set, (0,0))
		#choose = [_('Register'), _('Expires')]
		#lbl_group = controls.Label_Control( _('Registration'), font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		#group = controls.ListBox_Control(choose, listidx, font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color)
		#self.frame.append((icon_name, lbl_group, group))

		# number 1-10
		self.ico_nums = []
		self.lbl_nums = []
		self.txt_nums = []
		input_box_size = uiconfig.pb_entry_size #246, 26
		#LabelText = [_('Phone number'), _('Auth ID'), _('Password.'), _('SIP URI'), _('Domain name'),\
		#_('Proxy address')+'1', _('Proxy port')+'1', _('Proxy address')+'2', _('Proxy port')+'2',\
		#_('SBC address')+'1', _('SBC port')+'1', _('SBC address')+'2',  _('SBC port')+'2'] #	_('CSCF/SBC')]
		LabelText = [_('Phone number'), _('Auth ID'), _('Password.'), _('SIP URI'), 'SIP Domain',\
			'CSCF Domain 1', _('CSCF Port 1'), 'CSCF Domain 2', _('CSCF Port 2'),\
			'SBC Domain 1', _('SBC Port 1'), 'SBC Domain 2',  _('SBC Port 2')] #	_('CSCF/SBC')]
		for i in range(edit_entry_n):
			#self.ico_nums.append(controls.Icon_Control(uiconfig.ico_in_restrict_tel[i], (0,0)))
			self.lbl_nums.append(controls.Label_Control(LabelText[i], font=uiconfig.pb_entry_font, pos=(0,0), color=uiconfig.list_text_color))
			if LabelText[i] == _('Password.'):
				#self.txt_nums.append(controls.Input_Control(pos=(0,0), size=input_box_size, hiddenset=1))
				inputs = controls.Input_Control(pos=(0,0), size=input_box_size, hiddenset=1)
			else:
				#self.txt_nums.append(controls.Input_Control(pos=(0,0), size=input_box_size))
				inputs = controls.Input_Control(pos=(0,0), size=input_box_size)
				inputs.set_max(40)
			self.txt_nums.append(inputs)
			self.frame.append(('', self.lbl_nums[-1], self.txt_nums[-1]))

		unselbarpos = []		
		#print '## self.lbl_nums =', self.lbl_nums
		#print '## self.txt_nums=', self.txt_nums
		#print '## self.frame =', self.frame
		self.set_list(self.frame, unselbarpos)

		self.set_fixed_automata(self.list.entrys[0], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[1], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[2], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[3], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[4], 'multitap','lower')
		self.set_fixed_automata(self.list.entrys[5], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[6], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[7], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[8], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[9], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[10], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[11], '123', 'lower')
		self.set_fixed_automata(self.list.entrys[12], '123', 'lower')
		self.update_automata_icon(self.list.entrys[self.list.focus])
		
	def set_list(self, frame, unselbarpos=[]):
		roxia_trace('ListControlUI.set_list(), frame=', frame)
		self.list = UserInfomationWidget(frame, unselbarpos)
		self.add(self.list)
		
	def update_lists(self, labels, unselbarpos=[]):
		self.list.free()
		self.widgets.remove(self.list)		
		self.add(self.list)

	def get_focus(self):
		return self.list.focus

	def set_focus(self, focus, new=False):
		return self.list.set_focus(focus, new)

	def set_text(self, n, text):
		self.list.set_text(n, text)
	
	def change_language(self):
		self.list.change_language()
		BaseUI.change_language(self)

	def update_softkey_right(self):
		if self.list.focus == 2:			
			if status.voip_auth_pwd_type == 0:
				self.set_right(_('Plain text'))
			else:
				self.set_right(_('Hexa'))	
		else:
			self.set_right('')

	def handle_key(self, key):	
		if key == 'Up':
			self.list.focus_up()			
			self.update_automata_icon(self.list.entrys[self.list.focus])
			#self.update_softkey_right()
			return True
		elif key == 'Down':
			self.list.focus_down()			
			self.update_automata_icon(self.list.entrys[self.list.focus])
			#self.update_softkey_right()
			return True	
		# KA: [20080412] change the ring list by directory path
		elif key in ('Left', 'Right'):
			ret = self.list.entrys[self.list.focus].handle_key(key) # 먼저 dir를 change
			if self.list.focus == 7: #dir 이 변한 경우 
				self.update_ring_list()
			return ret
		# KA: [20080412] ==

		if key == 'CLR':
			self.delete_char()
			return True

		return False

	def destroy(self):
		if self.automata_icon: self.automata_icon.free()		
		BaseUI.destroy(self)

	def show(self):
		if self.automata_icon: self.automata_icon.show()
		BaseUI.show(self)
		self.update_automata_icon(self.list.entrys[self.list.focus])
		if config.mmi_debug: print '[UserInfomationUI.show] self.list.focus =', self.list.focus		
	
	def set_fixed_automata(self,entry, name, casemode, right_field='BACK'):
		if name:
			self.fixed_automata = True
			self.set_automata(entry,name, casemode)
		else:
			self.fixed_automata = False			
			self.set_automata(entry,*utils.get_def_automata())

	def set_automata(self,entry, name, casemode='lower'):
		entry.set_automata(name, casemode)
		if name != 'multitap_addword':
			self.automata_idx = utils.get_automata_idx(name,casemode)
		self.automata = name, casemode

	def update_automata_icon(self,entry):
		name = entry._automata.name()		
		casemode = entry._automata.case_mode()
		self.automata = name, casemode
		if config.mmi_debug: 
			print 'UserInfo:name=',name,',casemode=',casemode
		if name == '123':		menu3 = '123'
		elif name == 'hangul':	menu3 = _('KOR')
		elif name == 'symbol':	menu3 = _('SYMBOL')
		elif name == 't9':
			if casemode == 'upper':			menu3 = _('T9ABC')
			elif casemode == 'lower':		menu3 = _('T9abc')
			elif casemode == 'first capital':	menu3 = _('T9Abc')		
		else:
			if casemode == 'upper':			menu3 = _('ABC')
			elif casemode == 'lower':		menu3 = _('abc')
			elif casemode == 'first capital':	menu3 = _('Abc')
		self.set_menu3(menu3)
		if name =='symbol': # 'CHECKME:  when it runs
			from basemodel import SymbolSelectionStage
			runtime.manager.stack_stage(SymbolSelectionStage(self, True))

	def update_automata_icon_symbol(self):
		self.set_menu3(_('SYMBOL'))		
		self.automata_idx = self.get_automata_idx(*self.automata)
		self.automata_idx = (self.automata_idx + 1) % len(config.automata_list_mult_num_symbol)	
		self.automata = config.automata_list_mult_num_symbol[self.automata_idx]					
		self.set_automata(self.list.entrys[self.list.focus], *self.automata)	
		from basemodel import SymbolSelectionStage
		runtime.manager.stack_stage(SymbolSelectionStage(self, True))

	def delete_char(self):
		self.handle_key('\b')

	def get_text(self):
		return self.list.entrys[self.list.focus].get_text()

	def insert_text(self, entry, text):
		entry.insert_unicode_text(unicode(text, 'utf-8'))
		entry._automata.check_start_of_sentance()

	def insert_symbol(self, s):
		before_text = self.list.entrys[self.list.focus].get_text()
		self.insert_text(self.list.entrys[self.list.focus], s)
		after_text = self.list.entrys[self.list.focus].get_text()
		runtime.manager.back_stage()

	def get_automata_idx(self, name, casemode):
		print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode
		for i, a in enumerate(config.automata_list_mult_num_symbol):
			n,c = a
			if n == name and (not c or c == casemode):
				print 'UserInfo:get_automata_idx:name=',name,',casemode=',casemode,':i=',i
				return i