Example #1
0
    def ChangeOcrDataFolder(self, fileName):
        #the code goes here!
        #print fileName
        dataPath = ""
        f = open(fileName)
        for line in f:
            #print line
            if "Ocr.Data =" in line or "Ocr.Data=" in line:
                try:
                    if line.index('#') < line.index('Ocr.Data'):
                        continue
                except:
                    pass
                dataPath = line.split('=')[1]
                dataPath = dataPath.strip()
                #print dataPath

        f.close()

        if dataPath != "":
            try:
                jsfile = json_manager.read_json(fileName.replace(
                    ".py", ".nja"))
                jsfile['ocrdatafolder'] = dataPath.replace("\\\\", "\\")
                jsfile['ocrdatafolder'] = jsfile['ocrdatafolder'].replace(
                    "\"", "")
                #print jsfile
                fileNameWithExtension = os.path.split(fileName)[1]
                fileNameWithOutExtension = os.path.splitext(
                    fileNameWithExtension)[0]
                json_manager.create_ninja_project(
                    os.path.split(fileName)[0], fileNameWithOutExtension,
                    jsfile)
            except:
                pass
Example #2
0
    def ChangeOcrDataFolder(self, fileName):
        #the code goes here!
        #print fileName
        dataPath = ""
        f = open(fileName)
        for line in f:
            #print line
            if "Ocr.Data =" in line or "Ocr.Data=" in line:
                try:
                    if line.index('#') < line.index('Ocr.Data'):
                        continue
                except:
                    pass
                dataPath = line.split('=')[1]
                dataPath = dataPath.strip()
                #print dataPath

        f.close()

        if dataPath != "":
            try:
                jsfile = json_manager.read_json(fileName.replace(".py", ".nja"))
                jsfile['ocrdatafolder'] = dataPath.replace("\\\\", "\\")
                jsfile['ocrdatafolder'] = jsfile['ocrdatafolder'].replace("\"", "")
                #print jsfile
                fileNameWithExtension = os.path.split(fileName)[1]
                fileNameWithOutExtension = os.path.splitext(fileNameWithExtension)[0]
                json_manager.create_ninja_project(os.path.split(fileName)[0], fileNameWithOutExtension, jsfile)
            except:
                pass
Example #3
0
 def load(self, plugin_name, dir_name):
     global PLUGIN_EXTENSION
     if plugin_name in self._active_plugins:
         return
     for dir_name, plugin_list in list(self._plugins_by_dir.items()):
         if plugin_name in plugin_list:
             ext = PLUGIN_EXTENSION
             plugin_filename = os.path.join(dir_name, plugin_name)
             plugin_structure = json_manager.read_json(plugin_filename)
             plugin_structure['name'] = plugin_name.replace(ext, '')
             module = plugin_structure.get('module', None)
             klassname = plugin_structure.get('class', None)
             if module is not None and klassname is not None:
                 try:
                     plugin_instance = self._load_module(
                         module, klassname, plugin_structure, dir_name)
                     # set a get_plugin method to get the reference to other
                     # call a special method *initialize* in the plugin!
                     plugin_instance.metadata = plugin_structure
                     logger.info("Calling initialize (%s)", plugin_name)
                     plugin_instance.initialize()
                     plugin_metadata = (plugin_instance, plugin_structure)
                     self._active_plugins[plugin_name] = plugin_metadata
                 except (PluginManagerException, Exception) as reason:
                     logger.error("Not instanciated (%s): %s", plugin_name,
                                  reason)
                     # remove the plugin because has errors
                     self._found_plugins.remove(plugin_name)
                     traceback_msg = traceback.format_exc()
                     plugin_name = plugin_name.replace(ext, '')
                     # add the traceback to errors
                     self._add_error(plugin_name, traceback_msg)
                 else:
                     logger.info("Successfuly initialized (%s)",
                                 plugin_name)
Example #4
0
def local_plugins():
    '''
    Returns the local plugins
    '''
    if not os.path.isfile(resources.PLUGINS_DESCRIPTOR):
        return []
    plugins = json_manager.read_json(resources.PLUGINS_DESCRIPTOR)
    return plugins
Example #5
0
    def getKeyMap(self, path):
        ''' Gets the key map from the given json file

        @arg filePath path Path to keyMap.json

        '''

        return self.convertCollection(json_manager.read_json(path))
Example #6
0
def local_plugins():
    '''
    Returns the local plugins
    '''
    if not os.path.isfile(resources.PLUGINS_DESCRIPTOR):
        return []
    plugins = json_manager.read_json(resources.PLUGINS_DESCRIPTOR)
    return plugins
Example #7
0
def has_dependencies(plug):
    global REQUIREMENTS, COMMAND_FOR_PIP_INSTALL

    plugin_name = plug[0]
    structure = []
    if os.path.isfile(resources.PLUGINS_DESCRIPTOR):
        structure = json_manager.read_json(resources.PLUGINS_DESCRIPTOR)
    PLUGINS = resources.PLUGINS
    for p in structure:
        if p['name'] == plugin_name:
            pd_file = os.path.join(PLUGINS, p['plugin-descriptor'])
            p_json = json_manager.read_json(pd_file)
            module = p_json.get('module')
            #plugin_module/requirements.txt
            req_file = os.path.join(os.path.join(PLUGINS, module),
                                    REQUIREMENTS)
            if os.path.isfile(req_file):
                return (True, COMMAND_FOR_PIP_INSTALL % req_file)
            #the plugin was found but no requirement then break!
            break
    return (False, None)
Example #8
0
def has_dependencies(plug):
    global REQUIREMENTS, COMMAND_FOR_PIP_INSTALL

    plugin_name = plug[0]
    structure = []
    if os.path.isfile(resources.PLUGINS_DESCRIPTOR):
        structure = json_manager.read_json(resources.PLUGINS_DESCRIPTOR)
    PLUGINS = resources.PLUGINS
    for p in structure:
        if p['name'] == plugin_name:
            pd_file = os.path.join(PLUGINS, p['plugin-descriptor'])
            p_json = json_manager.read_json(pd_file)
            module = p_json.get('module')
            #plugin_module/requirements.txt
            req_file = os.path.join(os.path.join(PLUGINS, module),
                                    REQUIREMENTS)
            if os.path.isfile(req_file):
                return (True, COMMAND_FOR_PIP_INSTALL % req_file)
            #the plugin was found but no requirement then break!
            break
    return (False, None)
Example #9
0
def uninstall_plugin(plug):
    """
    Uninstall the given plugin
    """
    plugin_name = plug[0]
    structure = []
    if os.path.isfile(resources.PLUGINS_DESCRIPTOR):
        structure = json_manager.read_json(resources.PLUGINS_DESCRIPTOR)
    #copy the strcuture we iterate and remove at the same time
    structure_aux = copy.copy(structure)
    for plugin in structure_aux:
        if plugin["name"] == plugin_name:
            fileName = plugin["plugin-descriptor"]
            structure.remove(plugin)
            break
    #open <plugin>.plugin file and get the module to remove
    fileName = os.path.join(resources.PLUGINS, fileName)
    plugin = json_manager.read_json(fileName)
    module = plugin.get('module')
    if module:
        pluginDir = os.path.join(resources.PLUGINS, module)
        folders = [pluginDir]
        for root, dirs, files in os.walk(pluginDir):
            pluginFiles = [os.path.join(root, f) for f in files]
            #remove all files
            list(map(os.remove, pluginFiles))
            #collect subfolders
            folders += [os.path.join(root, d) for d in dirs]
        folders.reverse()
        for f in folders:
            if os.path.isdir(f):
                os.removedirs(f)
        #remove ths plugin_name.plugin file
        os.remove(fileName)
    #write the new info
    json_manager.write_json(structure, resources.PLUGINS_DESCRIPTOR)
Example #10
0
def uninstall_plugin(plug):
    """
    Uninstall the given plugin
    """
    plugin_name = plug[0]
    structure = []
    if os.path.isfile(resources.PLUGINS_DESCRIPTOR):
        structure = json_manager.read_json(resources.PLUGINS_DESCRIPTOR)
    #copy the strcuture we iterate and remove at the same time
    structure_aux = copy.copy(structure)
    for plugin in structure_aux:
        if plugin["name"] == plugin_name:
            fileName = plugin["plugin-descriptor"]
            structure.remove(plugin)
            break
    #open <plugin>.plugin file and get the module to remove
    fileName = os.path.join(resources.PLUGINS, fileName)
    plugin = json_manager.read_json(fileName)
    module = plugin.get('module')
    if module:
        pluginDir = os.path.join(resources.PLUGINS, module)
        folders = [pluginDir]
        for root, dirs, files in os.walk(pluginDir):
            pluginFiles = [os.path.join(root, f) for f in files]
            #remove all files
            list(map(os.remove, pluginFiles))
            #collect subfolders
            folders += [os.path.join(root, d) for d in dirs]
        folders.reverse()
        for f in folders:
            if os.path.isdir(f):
                os.removedirs(f)
        #remove ths plugin_name.plugin file
        os.remove(fileName)
    #write the new info
    json_manager.write_json(structure, resources.PLUGINS_DESCRIPTOR)
Example #11
0
    def OpenMouseAndKeyboard(self):
        SERVICE_NAME = "editor"
        self.editor_service = self.locator.get_service(SERVICE_NAME)
        fullFileName = self.editor_service.get_editor_path()

        try:  # check if .nja file exists
            filePath = os.path.split(fullFileName)[0]
            fileName = os.path.split(fullFileName)[1]
            #print os.path.splitext(fileName)[1]
            self.jsonfile = json_manager.read_json(filePath + os.sep + fileName.replace(os.path.splitext(fileName)[1], ".nja"))
            #filetoparse = filePath + os.sep + fileName.replace("py", "nja")
            self.ocrdata = self.jsonfile["ocrdatafolder"]
        except:
            self.message = QMessageBox.critical(self.editor_service.get_editor(), 'Error', "You can use this button only on an Al'exa Project!", QMessageBox.Ok)
            return
        self.mouseAndKey = MouseKeyboard(self)
        self.mouseAndKey.show()
Example #12
0
    def OpenMouseAndKeyboard(self):
        SERVICE_NAME = "editor"
        self.editor_service = self.locator.get_service(SERVICE_NAME)
        fullFileName = self.editor_service.get_editor_path()

        try:  # check if .nja file exists
            filePath = os.path.split(fullFileName)[0]
            fileName = os.path.split(fullFileName)[1]
            #print os.path.splitext(fileName)[1]
            self.jsonfile = json_manager.read_json(
                filePath + os.sep +
                fileName.replace(os.path.splitext(fileName)[1], ".nja"))
            #filetoparse = filePath + os.sep + fileName.replace("py", "nja")
            self.ocrdata = self.jsonfile["ocrdatafolder"]
        except:
            self.message = QMessageBox.critical(
                self.editor_service.get_editor(), 'Error',
                "You can use this button only on an Al'exa Project!",
                QMessageBox.Ok)
            return
        self.mouseAndKey = MouseKeyboard(self)
        self.mouseAndKey.show()
Example #13
0
 def load(self, plugin_name, dir_name):
     global PLUGIN_EXTENSION
     if plugin_name in self._active_plugins:
         return
     for dir_name, plugin_list in list(self._plugins_by_dir.items()):
         if plugin_name in plugin_list:
             ext = PLUGIN_EXTENSION
             plugin_filename = os.path.join(dir_name, plugin_name)
             plugin_structure = json_manager.read_json(plugin_filename)
             plugin_structure['name'] = plugin_name.replace(ext, '')
             module = plugin_structure.get('module', None)
             klassname = plugin_structure.get('class', None)
             if module is not None and klassname is not None:
                 try:
                     plugin_instance = self._load_module(module,
                                                         klassname,
                                                         plugin_structure,
                                                         dir_name)
                     #set a get_plugin method to get the reference to other
                     #setattr(plugin_instance,'get_plugin',self.__getitem__)
                     #call a special method *initialize* in the plugin!
                     plugin_instance.metadata = plugin_structure
                     logger.info("Calling initialize (%s)", plugin_name)
                     plugin_instance.initialize()
                     #tuple (instance, metadata)
                     plugin_metadata = (plugin_instance, plugin_structure)
                     self._active_plugins[plugin_name] = plugin_metadata
                 except (PluginManagerException, Exception) as reason:
                     logger.error("Not instanciated (%s): %s", plugin_name,
                                  reason)
                     #remove the plugin because has errors
                     self._found_plugins.remove(plugin_name)
                     traceback_msg = traceback.format_exc()
                     plugin_name = plugin_name.replace(ext, '')
                     #add the traceback to errors
                     self._add_error(plugin_name, traceback_msg)
                 else:
                     logger.info("Successfuly initialized (%s)",
                                 plugin_name)
Example #14
0
def update_local_plugin_descriptor(plugins):
    '''
    updates the local plugin description
    The description.json file holds the information about the plugins
    downloaded with NINJA-IDE
    This is a way to track the versions of the plugins
    '''
    structure = []
    if os.path.isfile(resources.PLUGINS_DESCRIPTOR):
        structure = json_manager.read_json(resources.PLUGINS_DESCRIPTOR)
    for plug_list in plugins:
        #create the plugin data
        plug = {}
        plug['name'] = plug_list[0]
        plug['version'] = plug_list[1]
        plug['description'] = plug_list[2]
        plug['authors'] = plug_list[3]
        plug['home'] = plug_list[4]
        plug['download'] = plug_list[5]
        plug['plugin-descriptor'] = plug_list[6]
        #append the plugin data
        structure.append(plug)
    json_manager.write_json(structure, resources.PLUGINS_DESCRIPTOR)
Example #15
0
def update_local_plugin_descriptor(plugins):
    '''
    updates the local plugin description
    The description.json file holds the information about the plugins
    downloaded with NINJA-IDE
    This is a way to track the versions of the plugins
    '''
    structure = []
    if os.path.isfile(resources.PLUGINS_DESCRIPTOR):
        structure = json_manager.read_json(resources.PLUGINS_DESCRIPTOR)
    for plug_list in plugins:
        #create the plugin data
        plug = {}
        plug['name'] = plug_list[0]
        plug['version'] = plug_list[1]
        plug['description'] = plug_list[2]
        plug['authors'] = plug_list[3]
        plug['home'] = plug_list[4]
        plug['download'] = plug_list[5]
        plug['plugin-descriptor'] = plug_list[6]
        #append the plugin data
        structure.append(plug)
    json_manager.write_json(structure, resources.PLUGINS_DESCRIPTOR)
Example #16
0
    def __init__(self, plugin):
        QWidget.__init__(self)

        self.plugin = plugin
        self.plug_path = plugin.path

        SERVICE_NAME = "editor"
        self.editor_service = self.plugin.locator.get_service(SERVICE_NAME)
        fullFileName = self.editor_service.get_editor_path()
        #from os.path import basename

        filePath = os.path.split(fullFileName)[0]
        fileName = os.path.split(fullFileName)[1]
        #print os.path.splitext(fileName)[1]
        self.jsonfile = json_manager.read_json(filePath + os.sep + fileName.replace(os.path.splitext(fileName)[1], ".nja"))
        #filetoparse = filePath + os.sep + fileName.replace("py", "nja")
        self.jsonfile["ocrdatafolder"]

        self.isCanny = False

        self.MovingAppObject = False

        self.TollerancePreview = False

        #self.binarizeImagePreviewFlag = False
        #self.Brightness = 0.0
        #self.Contrast = 0.0

        #self.binarizeLabelPreviewFlag = False

        #set pixmap for the background
        self.pixmap = QPixmap()
        self.pixmap.load(self.plug_path + os.sep + 'tmp' + os.sep + 'screenshot.png')
        self.OriginalScreenshot = Image.open(self.plug_path + os.sep + 'tmp' + os.sep + 'screenshot.png')

        #store if mouse is pressed
        self.pressed = False
        self.released = False
        self.printLabelBorder = False

        self.InsideRect = False
        self.InsideRegion = False
        self.AdjustOnlyHeightTollerance = False
        self.AdjustOnlyWidthTollerance = False

        #store mouse position
        self.mouseOldX = 0
        self.mouseOldY = 0
        self.mouseNewX = 0
        self.mouseNewY = 0

        self.rectLabelCollection = []
        self.rectLabelCollectionDeleted = []

        #Al'exa AppObject
        self.AlexaAppImagesBackup = []
        self.AlexaAppImagesBackupDeleted = []
        self.AlexaAppImages = []
        self.AlexaAppImagesDeleted = []

        self.AlexaAppObjectsBackup = []
        self.AlexaAppObjects = []

        self.LabelOfInterest = []

        self.LastRectHover = 0

        self.Dialog = None
        self.DialogOpened = False
        self.DialogHwnd = None

        self.CropLabel = False
        self.CropRegion = False
        self.AppObjectFeedbackIndex = None
        self.indexFound = None
        self.indexFoundAppText = None
Example #17
0
    def HideEditor(self):

        self.plugin = plugin

        SERVICE_NAME = "editor"
        self.editor_service = self.locator.get_service(SERVICE_NAME)
        fullFileName = self.editor_service.get_editor_path()

        try:  # check if .nja file exists
            filePath = os.path.split(fullFileName)[0]
            fileName = os.path.split(fullFileName)[1]
            #print os.path.splitext(fileName)[1]
            self.jsonfile = json_manager.read_json(
                filePath + os.sep +
                fileName.replace(os.path.splitext(fileName)[1], ".nja"))
            #filetoparse = filePath + os.sep + fileName.replace("py", "nja")
            self.ocrdata = self.jsonfile["ocrdatafolder"]
        except:
            self.message = QMessageBox.critical(
                self.editor_service.get_editor(), 'Error',
                "You can use this button only on an Al'exa Project!",
                QMessageBox.Ok)
            return

        #if self.undockWindowOpened is True:
        #self.undockWindow.close()

        closewindow.CloseHideAllWindow(True)

        if self.undockWindowOpened is True:
            self.undockWindow.setVisible(False)
        elif sys.platform == 'win32':
            hwnd = win32gui.GetForegroundWindow()
            win32gui.ShowWindow(hwnd, 0)

            toplist = []
            winlist = []

            def enum_callback(hwnd, results):
                winlist.append((hwnd, win32gui.GetWindowText(hwnd)))

            win32gui.EnumWindows(enum_callback, toplist)
            #if self.undocked is False:
            firefox = [(hwnd, title) for hwnd, title in winlist
                       if 'exa-ide' in title.lower()
                       or 'exa tool' in title.lower() and 'about' not in
                       title.lower() and 'command prompt' not in title.lower()]

            # just grab the first window that matches
            #firefox = firefox[0]
            for ninja in firefox:
                #print str(ninja[0]) + " " + ninja[1]
                win32gui.ShowWindow(ninja[0], 0)
            #else:
            #self.undockWindow.hide()

        time.sleep(0.5)

        if self.undockWindowOpened is True:
            time.sleep(self.screenshotDelay)

        app = wx.App(False)
        screen = wx.ScreenDC()
        size = screen.GetSize()
        bmp = wx.EmptyBitmap(size[0], size[1])
        mem = wx.MemoryDC(bmp)
        mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
        del mem  # Release bitmap
        bmp.SaveFile(
            self.plug_path + os.sep + 'alexatools' + os.sep + 'tmp' + os.sep +
            'screenshot.png', wx.BITMAP_TYPE_PNG)
Example #18
0
    def HideEditor(self):

        self.plugin = plugin

        SERVICE_NAME = "editor"
        self.editor_service = self.locator.get_service(SERVICE_NAME)
        fullFileName = self.editor_service.get_editor_path()

        try:  # check if .nja file exists
            filePath = os.path.split(fullFileName)[0]
            fileName = os.path.split(fullFileName)[1]
            #print os.path.splitext(fileName)[1]
            self.jsonfile = json_manager.read_json(filePath + os.sep + fileName.replace(os.path.splitext(fileName)[1], ".nja"))
            #filetoparse = filePath + os.sep + fileName.replace("py", "nja")
            self.ocrdata = self.jsonfile["ocrdatafolder"]
        except:
            self.message = QMessageBox.critical(self.editor_service.get_editor(), 'Error', "You can use this button only on an Al'exa Project!", QMessageBox.Ok)
            return


        #if self.undockWindowOpened is True:
            #self.undockWindow.close()

        closewindow.CloseHideAllWindow(True)

        if self.undockWindowOpened is True:
            self.undockWindow.setVisible(False)
        elif sys.platform == 'win32':
            hwnd = win32gui.GetForegroundWindow()
            win32gui.ShowWindow(hwnd, 0)

            toplist = []
            winlist = []

            def enum_callback(hwnd, results):
                winlist.append((hwnd, win32gui.GetWindowText(hwnd)))
            win32gui.EnumWindows(enum_callback, toplist)
            #if self.undocked is False:
            firefox = [(hwnd, title) for hwnd, title in
                winlist if 'exa-ide' in title.lower() or 'exa tool' in title.lower() and 'about' not in title.lower() and 'command prompt' not in title.lower()]

            # just grab the first window that matches
            #firefox = firefox[0]
            for ninja in firefox:
                #print str(ninja[0]) + " " + ninja[1]
                win32gui.ShowWindow(ninja[0], 0)
            #else:
                #self.undockWindow.hide()

        time.sleep(0.5)

        if self.undockWindowOpened is True:
            time.sleep(self.screenshotDelay)

        app = wx.App(False)
        screen = wx.ScreenDC()
        size = screen.GetSize()
        bmp = wx.EmptyBitmap(size[0], size[1])
        mem = wx.MemoryDC(bmp)
        mem.Blit(0, 0, size[0], size[1], screen, 0, 0)
        del mem  # Release bitmap
        bmp.SaveFile(self.plug_path + os.sep +'alexatools' + os.sep + 'tmp' + os.sep + 'screenshot.png', wx.BITMAP_TYPE_PNG)