예제 #1
0
def generateProject(rectViews, projectFolder, templateFolder, canvas_width,  projectName="SketchToUI"):
    CANVAS_WIDTH = canvas_width
    dipCalulator = SketchDipCalculator(CANVAS_WIDTH, CANVAS_HEIGHT)
    
    mOutProjectFolder =  os.path.join(projectFolder,projectName )
    
    rawRects = jsonToRect(rectViews,dipCalulator)
    
#    return 
    rootView = createHierachy(rawRects, CANVAS_WIDTH,CANVAS_HEIGHT)
    
    mProjectName = generateProjectName(projectName)


    
    SketchProjectGenerator.setup(projectFolder, templateFolder)
   
    
#    mDrawableWriter = DrawableWriter(file_extension, mOutProjectFolder)
    creator = SketchLayoutCreator(rootView, mProjectName, mOutProjectFolder,dipCalulator)

# create layout
    layoutDocument = creator.createDocument()
    layoutFilter = SketchLayoutFilter()
#
    anotateMap = layoutFilter.anotate(layoutDocument)

    layoutFilter = SketchRelativeLayoutFilter()
    layoutFilter.doFilter(layoutDocument, anotateMap)
    layoutFilter = SketchLayoutFilter()
    layoutFilter.doFilter(layoutDocument, anotateMap)
    mainXmlPath = os.path.join(mOutProjectFolder,"app", "src","main", "res", "layout", "activity_main.xml")

# write to xml
    XmlUtil.writeDocumentxml(layoutDocument,mainXmlPath)

# write style
#    styleWriter = creator.mStyleWriter
#    styleDocument = styleWriter.mRoot
#    styleDocumentPath = os.path.join(mOutProjectFolder, "app", "src","main","res","values","styles.xml")
#    XmlUtil.writeDocumentxml(styleDocument, styleDocumentPath)
#
#write to color file    
    colorWriter = creator.mColorWriter
    colorDocument = colorWriter.mRoot
    colorDocumentPath = os.path.join(mOutProjectFolder, "app", "src","main","res","values","colors.xml")
    XmlUtil.writeDocumentxml(colorDocument, colorDocumentPath)

# write to string file
    stringWriter = creator.mWriter
    resourceDocument = stringWriter.mRoot
    stringDocumentPath = os.path.join(mOutProjectFolder, "app", "src","main","res","values","strings.xml")
    XmlUtil.writeDocumentxml(resourceDocument, stringDocumentPath)
    SketchProjectGenerator.prepareProject(projectFolder, projectName)

    return 
 def write(self):
     XmlUtil.writeDocumentxml(self.mDocument, self.mAndroidManifestPath)
예제 #3
0
def generateProject(imageLocation):

    fileExitst = os.path.isfile(imageLocation)
    if (not fileExitst):
        return "Can't access the file"
    img_color = cv2.imread(imageLocation)

    img_gray = copy.deepcopy(img_color)
    if (len(img_color.shape) == 3):
        img_gray = cv2.cvtColor(img_color, cv2.COLOR_BGR2GRAY)

    profile = Profile(Resolution.XXHDPI, img_gray.shape[1], img_gray.shape[0])

    dipCalculator = DipCalculator(img_color, profile)

    width = 0
    height = 0
    if len(img_color.shape) == 2:
        height, width = img_color.shape
    else:
        height, width, channels = img_color.shape

    #create a valid project name and package name

    mProjectName = generateProjectName(imageLocation)
    mOutProjectFolder = PROJECT_FOLDER + mProjectName

    #create project info

    mProjectInfo = ProjectInfo(mProjectName, mOutProjectFolder)

    filename, file_extension = os.path.splitext(imageLocation)
    mDrawableWriter = DrawableWriter(file_extension, mOutProjectFolder)

    #generate project from project template
    ProjectGenerator.setup(mProjectInfo)

    # dilate and find edges in the provided screenshot
    dst_denoised = cv2.fastNlMeansDenoising(img_gray)
    canny = Canny()
    dst_edge = canny.findEdge(img_gray)
    #    project = Project("sample")
    dst_edge_dilate = canny.addDilate(dst_edge)
    contourAnalysis = ContourAnalysis()
    contours = contourAnalysis.findContoursWithCanny(dst_edge_dilate)
    contoursOutput = contourAnalysis.analyze(dst_edge_dilate, contours)

    #do the hierarchy processing
    hierarchyProcessor = ViewHierarchyProcessor(contoursOutput.rootView,
                                                img_color, canny)
    hierarchyInfo = hierarchyProcessor.process()

    # use tesseract to detect the text
    tesseractOCR = TesseractOCR(dst_denoised, dipCalculator, "English")
    textProcessor = TextProcessor(img_color, dst_denoised,
                                  hierarchyInfo.biMapViewRect, tesseractOCR,
                                  dipCalculator)
    # process text to remove invalid texts
    textInfo = textProcessor.processText(CColor.Red)
    # Add text boxes to hierarchy
    hierarchyProcessor.addTextToHierarchy(textInfo)

    # List support right now not implemented
    #        creator = LayoutCreatorForList(contoursOutput.rootView, mProjectName, tesseractOCR, mDrawableWriter, img_color, mFileName,
    #                           mOutLogFolder, mOutProjectFolder, dipCalculator)
    #   else:
    creator = DefaultLayoutCreator(contoursOutput.rootView, mProjectName,
                                   tesseractOCR, mDrawableWriter, img_color,
                                   mOutProjectFolder, dipCalculator)

    # create layout
    layoutDocument = creator.createDocument()
    layoutFilter = LayoutFilter()
    #
    anotateMap = layoutFilter.anotate(layoutDocument)

    layoutFilter = RelativeLayoutFilter()
    layoutFilter.doFilter(layoutDocument, anotateMap)
    layoutFilter = RootAlignmentLayoutFilter()
    layoutFilter.doFilter(layoutDocument, anotateMap)

    # write to xml
    XmlUtil.writeDocumentxml(
        layoutDocument, mOutProjectFolder + Constants.DEFAULT_LAYOUT_PATH +
        "activity_main.xml")

    # write style
    styleWriter = creator.mStyleWriter
    styleDocument = styleWriter.mRoot
    XmlUtil.writeDocumentxml(
        styleDocument,
        mOutProjectFolder + "\\app\\src\\main\\res\\values\\styles.xml")
    #
    #write to color file
    colorWriter = creator.mColorWriter
    colorDocument = colorWriter.mRoot
    XmlUtil.writeDocumentxml(
        colorDocument,
        mOutProjectFolder + "\\app\\src\\main\\res\\values\\colors.xml")

    # write to string file
    stringWriter = creator.mWriter
    resourceDocument = stringWriter.mRoot
    XmlUtil.writeDocumentxml(
        resourceDocument,
        mOutProjectFolder + "\\app\\src\\main\\res\\values\\strings.xml")

    # save drawable files
    mDrawableWriter.save()

    # compile and create a zip of the project
    ProjectGenerator.prepareProject(mProjectInfo)
    #    ProjectGenerator.unInstallAPK(mOutProjectFolder,mPackageName)
    #    ProjectGenerator.installAPK(mOutProjectFolder,mProjectName)
    return