def loadUiType(uiFile):
    import plugin.Qt as Qt
    if Qt.__binding__.startswith('PyQt'):
        from Qt import _uic as uic
        return uic.loadUiType(uiFile)
    elif Qt.__binding__ == 'PySide':
        import pysideuic as uic
    else:
        import pyside2uic as uic

    import xml.etree.ElementTree as xml
    from cStringIO import StringIO

    parsed = xml.parse(uiFile)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    with open(uiFile, 'r') as f:
        o = StringIO()
        frame = {}

        uic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')
        exec pyc in frame

        # Fetch the base_class and form class based on their type
        # in the xml from designer
        form_class = frame['Ui_%s' % form_class]
        base_class = eval('%s' % widget_class)

    return form_class, base_class
def loadUiType(uiFile):
    """
    Pyside "loadUiType" command like PyQt4 has one, so we have to convert the 
    ui file to py code in-memory first and then execute it in a special frame
    to retrieve the form_class.
    """
    import plugin.Qt as Qt
    if Qt.__binding__.startswith('PyQt'):
        from Qt import _uic as uic
        return uic.loadUiType(uiFile)
    elif Qt.__binding__ == 'PySide':
        import pysideuic as uic
    else:
        import pyside2uic as uic

    import xml.etree.ElementTree as xml
    from cStringIO import StringIO

    parsed = xml.parse(uiFile)
    widget_class = parsed.find('widget').get('class')
    form_class = parsed.find('class').text

    with open(uiFile, 'r') as f:
        o = StringIO()
        frame = {}

        uic.compileUi(f, o, indent=0)
        pyc = compile(o.getvalue(), '<string>', 'exec')
        exec pyc in frame

        # Fetch the base_class and form class based on their type
        # in the xml from designer
        form_class = frame['Ui_%s' % form_class]
        base_class = eval('%s' % widget_class)

    return form_class, base_class
UI_PATH = os.path.join(DIR_PATH,"ui",'UI2CG.ui')

sys.path.append(PLUGIN_PATH)

from Qt.QtCore import *
from Qt.QtGui import *
from Qt.QtWidgets import *
from Qt import _uic as uic
import re
import traceback
import json
import shutil
import subprocess
from functools import partial

form_class , base_class = uic.loadUiType(UI_PATH)
from ModuleName import ModuleName
class PreviewDialog(QDialog):
    def __init__(self, parent=None , text=""):
        super(PreviewDialog, self).__init__(parent)

        self.textBrowser = QPlainTextEdit(self)
        self.textBrowser.appendPlainText(text)

        def Copy():
            self.textBrowser.selectAll()
            self.textBrowser.copy()

        self.CopyBTN = QPushButton()
        self.CopyBTN.setStyleSheet("height:20px")
        self.CopyBTN.setText("复制全部")