import kivy
from kivy.utils import platform

from appPublic.registerfunction import RegisterFunction

from .baseWidget import *
from .tree import Tree, TextTree, PopupMenu
from .toolbar import ToolPage, Toolbar
from .dg import DataGrid
from .vplayer import VPlayer
from .aplayer import APlayer
from .form import Form, StrSearchForm
from .boxViewer import BoxViewer
from .pagescontainer import PageContainer
from .hostimage import HostImage
from .toggleitems import PressableBox, ToggleItems
from .twosides import TwoSides
from .tab import TabsPanel
from .qrdata import QRCodeWidget
# from .kivycamera import KivyCamera
from .filebrowser import FileLoaderBrowser
from .graph import Graph, MeshLinePlot, MeshStemPlot, LinePlot, \
	SmoothLinePlot, ContourPlot, BarPlot, HBar, VBar, ScatterPlot, \
	PointPlot
from .mapview import MapView
from .chart2d import Chart2d
from .message import Conform
from .pagepanel import PagePanel
from .markdown import Markdown
from .custom_camera import CustomCamera, QrReader
if kivy.platform in ['win','linux', 'macosx']:
	from .camerawithmic import ScreenWithMic
from .camerawithmic import CameraWithMic

r = Factory.register
if kivy.platform in ['win','linux', 'macosx']:
	r('ScreenWithMic', ScreenWithMic)
r('CameraWithMic', CameraWithMic)
r('CustomCamera', CustomCamera)
r('QrReader', QrReader)
r('Markdown', Markdown)
r('PagePanel', PagePanel)
r('Conform', Conform)
r('Chart2d', Chart2d)
r('Popup', Popup)
r('Graph', Graph)
r('MeshLinePlot', MeshLinePlot)
r('MeshStemPlot', MeshStemPlot)
r('LinePlot', LinePlot)
r('SmoothLinePlot', SmoothLinePlot)
r('ContourPlot', ContourPlot)
r('BarPlot', BarPlot)
r('HBar', HBar)
r('VBar', VBar)
r('ScatterPlot', ScatterPlot)
r('PointPlot', PointPlot)
r('MapView', MapView)
r('DataGrid',DataGrid)
r('FileLoaderBrowser',FileLoaderBrowser)
# r('KivyCamera',KivyCamera)
r('QRCodeWidget',QRCodeWidget)
r('TabsPanel',TabsPanel)
r('TwoSides',TwoSides)
r('PageContainer', PageContainer)
r('BoxViewer', BoxViewer)
r('Form', Form)
r('StrSearchForm', StrSearchForm)
r('VPlayer', VPlayer)
r('DataGrid', DataGrid)
r('Toolbar', Toolbar)
r('ToolPage',ToolPage)
r('HTTPDataHandler',HTTPDataHandler)
r('Text',Text)
r('ScrollWidget',ScrollWidget)
r('BinStateImage',BinStateImage)
r('JsonCodeInput',JsonCodeInput)
r('FloatInput',FloatInput)
r('IntegerInput',IntegerInput)
r('StrInput',StrInput)
r('SelectInput',SelectInput)
r('BoolInput',BoolInput)
r('AmountInput',AmountInput)
r('Messager',Messager)
r('Bar',Bar)
r('LoginForm',LoginForm)
r('PressableImage', PressableImage)
r('PressableLabel', PressableLabel)
r('Tree',Tree)
r('TextTree',TextTree)
r('PopupMenu',PopupMenu)
r('HostImage',HostImage)
r('APlayer',APlayer)
r('WrapText',WrapText)
r('PressableBox',PressableBox)
r('Title1',Title1)
r('Title2',Title2)
r('Title3',Title3)
r('Title4',Title4)
r('Title5',Title5)
r('Title6',Title6)
r('Modal',Modal)
r('TimedModal',TimedModal)
r('HBox',HBox)
r('VBox',VBox)
r('ToggleItems',ToggleItems)
if platform == 'android':
	r('PhoneButton',PhoneButton)
	r('AWebView',AWebView)


def register_widget(name, klass):
	try:
		Factory.regiter(name, klass)
	except:
		Logger.info(f'Plugin : register_widget():{name} register error')

def register_registerfunction(name, func):
	rf = RegisterFunction()
	try:
		rf.register(name, func)
	except Exception as e:
		Logger.info(f'Plugin : register_registerfunction():{name} register error({e})')
		print_exc()

def register_blocks(name, value):
	b = Factory.Blocks()
	try:
		b.register_widget(name, value)
	except:
		Logger.info(f'plugin : register_blocks():{name} register error')


