def call_copy_image(self, event): img_name=var_name.get(self.label + "_image",\ self._shell.locals) if img_name is not None: self._shell.run("%s = %s.image.image_copy()"\ % (img_name, self.label))
def OnDropFiles(self, x, y, filenames): for filename in filenames: if os.path.exists(filename): filename = os.path.normpath(os.path.abspath(filename)) if filename.endswith('.xml') or filename.endswith('.xml.gz'): if open(filename, 'r').read(4) == "<xml": name = var_name.get("glyphs", self.display.shell.locals) if name: self.display.shell.run('from gamera import gamera_xml') self.display.shell.run( '%s = gamera_xml.glyphs_from_xml(r"%s")' % (name, filename)) else: name = var_name.get('image', self.display.shell.locals) if name: self.display.shell.run( '%s = load_image(r"%s")' % (name, filename))
def get_result_name(self, function, dict): if function.return_type not in ('', None): if function.return_type.name is not None: name = function.return_type.name else: name = function.__name__ return var_name.get(name, dict) return ''
def get_result_name(self, function, dict): if function.return_type not in ('', None): if function.return_type.name != None: name = function.return_type.name else: name = function.__name__ return var_name.get(name, dict) return ''
def openTifFile(self, event): tiffilename = "" foldir = "" global swap2 alist = [] dialog = Args([FileOpen("Send a .tif or .png file to Aruspix", tiffilename, "*.tif;*.png"), # #FileOpen("or a .png file", tiffilename, "*.tif;*.png"), Directory("or all .tif and .png files in folder", foldir)], name = "Open") params = dialog.show() #print; print "params"; print params; print if not params: return if params[0]: # print 'it is a single file: ' # print params[0] alist.append(params[0]) else: ## It is a folder # print "yes! a folder"; print alist = Tools.dirEntries(params[1], True, 'tif', 'png') #app_path = '/Users/gabriel/Documents/code/aruspix/Debug/Aruspix.app/Contents/MacOS/Aruspix' app_path = '/Applications/Aruspix.app/Contents/MacOS/Aruspix' #print; print 'alist: '; print alist; print for i_file in alist: print 'Processing '; print i_file; print o_file = os.path.splitext(i_file); #print 'o_file'; print o_file; print if o_file[1] == '.png': # print; print "PNG" f = 'convert ' + i_file + ' -compress None ' + o_file[0] + '.tif' subprocess.Popen(f, shell = True) f = app_path + ' -q -e Rec -p ' + o_file[0] + '.tif ' + o_file[0] + '.axz' p = subprocess.Popen(f, shell = True) p.wait() subprocess.Popen("rm " + o_file[0] + '.tif' , shell=True) # erasing the created TIF else: # print; print "TIF" f = app_path + ' -q -e Rec -p ' + i_file + ' ' + o_file[0] + '.axz' p = subprocess.Popen(f, shell = True) p.wait() if params[0]: axfilename = o_file[0] + '.axz' #; print "axfilename: "; print axfilename; print axfile = AxFile(axfilename, "") swap2 = axfile.get_img0() #; print"swap: "; print swap2; print name = var_name.get("aruspix_img",\ self._shell.locals) self._shell.run("%s = %s.swap2.visualize()"\ % (name, self.label )) print 'Done!' print
def double_click(self): from gamera.gui import matplotlib_support if matplotlib_support.matplotlib_installed: name = var_name.get("figure") if name != None: return "%s = plot(%s)" % (name, self.label) else: gui_util.message("Plotting is not supported because the optional matplotlib library\n" "could not be found.\n\n" "Download and install matplotlib from matplotlib.sourceforge.net,\n" "then restart Gamera to have plotting support.")
def _OnFileOpen(self, event): filename = gui_util.open_file_dialog( self, util.get_file_extensions("load")) if filename: name = var_name.get("image", self.shell.locals) if name: try: wx.BeginBusyCursor() self.shell.run('%s = load_image(r"%s")' % (name, filename)) finally: wx.EndBusyCursor()
def OnCreateCopy(self, event): sh = self.get_shell() name = var_name.get("copy", sh.locals) if name: if len(self.images) == 1: sh.locals[name] = self.images[0].image_copy() else: sh.locals[name] = [] for i in range(len(self.images)): sh.locals[name].append(self.images[i].image_copy()) sh.Update() sh.update()
def _OnLoadXML(self, event): from gamera import gamera_xml filename = gui_util.open_file_dialog(self, gamera_xml.extensions) if filename: name = var_name.get("glyphs", self.shell.locals) if name: wx.BeginBusyCursor() try: self.shell.run("from gamera import gamera_xml") self.shell.run('%s = gamera_xml.glyphs_from_xml(r"%s")' % (name, filename)) finally: wx.EndBusyCursor()
def OnIntoGameraGUI(self, event): #--------------------------------------------------------------------------- from gamera import knn from gamera.gui import gui from gamera.gui import var_name name = var_name.get("classifier", gui.main_win.shell.locals) if name is None: gui_util.message("No valid variable name for classifier entered") return copiedClassifier = self.CopyClassifier(self.classifier) gui.main_win.shell.locals[name] = copiedClassifier gui.main_win.shell.run('\n')
def OnIntoGameraGUI(self, event): # --------------------------------------------------------------------------- from gamera import knn from gamera.gui import gui from gamera.gui import var_name name = var_name.get("classifier", gui.main_win.shell.locals) if name == None: gui_util.message("No valid variable name for classifier entered") return copiedClassifier = self.CopyClassifier(self.classifier) gui.main_win.shell.locals[name] = copiedClassifier gui.main_win.shell.run("\n")
def OnCreateReference(self, event): sh = self.get_shell() name = var_name.get("ref", sh.locals) if name: if len(self.images) == 1: if isinstance(self.images[0], weakref.ProxyTypes): sh.locals[name] = self.images[0].image_copy() else: sh.locals[name] = self.images[0] else: sh.locals[name] = [] for image in self.images: if isinstance(image, weakref.ProxyTypes): sh.locals[name].append(image.image_copy()) else: sh.locals[name].append(image) sh.Update() sh.update()
def call_copy_image(self, event): img_name=var_name.get(self.label + "_image",\ self._shell.locals)
def _OnClassifier(self, event): name = var_name.get("classifier", self.shell.locals) if name: self.shell.run("from gamera import knn") self.shell.run("%s = knn.kNNInteractive()" % name) self.shell.run("%s.display()" % name)
def openAxFile(self, event): # # let the user choose the parameters # #pp_module="PsaltikiPage" axfilename = "" tmpdir = "" imgdir = "" imgvisual = True imgmusic = True imglyrics = False imgborder = False imgornate = False imgtext = False imgtitle = False imgflat = False imggrey = False #opt = c_opt() # start options dialog dialog = Args([FileOpen("Aruspix file", axfilename, "*.axz"), #Directory("or all Aruspix Files in folder", imgdir), Directory("Temporary directory (optional)", tmpdir), Check("Visualize image","",True), Check("Extract music staves","",True), Check("Extract lyrics"), Check("Extract title elements"), Check("Extract ornate letters"), Check("Extract text in staff"), Check("Extract borders"), Check("Flatten as BW"), Check("Original greyscale image")], name = "Select options") params = dialog.show() if not params: return i = 0 axfilename = params[i]; i+=1 if axfilename == "": return tmpdir = params[i]; i+=1 if tmpdir == None: tmpdir = "" imgvisual = params[i]; i+=1 imgmusic = params[i]; i+=1 imglyrics = params[i]; i+=1 imgborders = params[i]; i+=1 imgornate = params[i]; i+=1 imgtext = params[i]; i+=1 imgtitle = params[i]; i+=1 imgflat = params[i]; i+=1 imggrey = params[i]; i+=1 axfile = AxFile(axfilename, tmpdir) global swap swap = axfile.get_img0() if imgvisual == True: name = var_name.get("aruspix_img",\ self._shell.locals) self._shell.run("%s = %s.swap.visualize()"\ % (name, self.label )) if imgmusic == True: name = var_name.get("staves",\ self._shell.locals) self._shell.run("%s = %s.swap.extract(0)"\ % (name, self.label )) if imglyrics == True: name = var_name.get("lyrics",\ self._shell.locals) self._shell.run("%s = %s.swap.extract(4)"\ % (name, self.label )) if imgborders == True: name = var_name.get("borders",\ self._shell.locals) self._shell.run("%s = %s.swap.extract(1)"\ % (name, self.label )) if imgornate == True: name=var_name.get("ornate_letters",\ self._shell.locals) self._shell.run("%s = %s.swap.extract(2)"\ % (name, self.label )) if imgtext == True: name=var_name.get("text_in_staff",\ self._shell.locals) self._shell.run("%s = %s.swap.extract(3)"\ % (name, self.label )) if imgtitle == True: name=var_name.get("titles",\ self._shell.locals) self._shell.run("%s = %s.swap.extract(5)"\ % (name, self.label )) if imgflat == True: name=var_name.get("all",\ self._shell.locals) self._shell.run("%s = %s.swap.flatten()"\ % (name, self.label )) if imggrey == True: swap = axfile.get_img1() name=var_name.get("original",\ self._shell.locals) self._shell.run("%s = %s.swap.image_copy()"\ % (name, self.label ))
def createMusicStavesObj(self, event): # find class belonging to menu entry index = -1 for i, m in enumerate(self._menuids): if m == event.GetId(): index = i break if index < 0: return ms_module=self.classes[index] # ask for parameters dialog=Args([FileOpen("Image file", "", "*.*"),\ Int("Staffline height"),\ Int("Staffspace height")],\ "Create a %s object" % ms_module) params=dialog.show() if params != None: if params[0] != None: # # load the image here and load it # into the gamera shell, too. this is # done because for checking whether # it is a onebit image or not. # filename=params[0] imagename = path.basename(params[0]) imagename=imagename.split('.')[0] # substitute special characters imagename=re.sub('[^a-zA-Z0-9]', '_',\ imagename) imagename=re.sub('^[0-9]', '_',\ imagename) test = r"test\t" test2 = "test\t" image=load_image(filename) #self._shell.run(imagename + ' = load_image(r"' + filename + '") ') self._shell.run('%s = load_image(r"%s")'\ % (imagename, filename)) if image.data.pixel_type != ONEBIT: self._shell.run("%s = %s.to_onebit()"\ % (imagename,\ imagename)) # still exists in the gamera shell del image # choose a name for the variable in # the GUI if ms_module.startswith("StaffFinder"): name=var_name.get("stafffinder",\ self._shell.locals) else: name=var_name.get("musicstaves",\ self._shell.locals) if name is "" or name is None: return # create an instance of the specified # MusicStaves_XXX class self._shell.run("%s = %s.%s(%s, %d, %d)"\ % (name,\ self.label,\ ms_module,\ imagename,\ params[1], params[2]))
def createMusicStavesObj(self, event): # find class belonging to menu entry index = -1 for i, m in enumerate(self._menuids): if m == event.GetId(): index = i break if index < 0: return ms_module = self.classes[index] # ask for parameters dialog=Args([FileOpen("Image file", "", "*.*"),\ Int("Staffline height"),\ Int("Staffspace height")],\ "Create a %s object" % ms_module) params = dialog.show() if params != None: if params[0] != None: # # load the image here and load it # into the gamera shell, too. this is # done because for checking whether # it is a onebit image or not. # filename = params[0] imagename = path.basename(params[0]) imagename = imagename.split('.')[0] # substitute special characters imagename=re.sub('[^a-zA-Z0-9]', '_',\ imagename) imagename=re.sub('^[0-9]', '_',\ imagename) test = r"test\t" test2 = "test\t" image = load_image(filename) #self._shell.run(imagename + ' = load_image(r"' + filename + '") ') self._shell.run('%s = load_image(r"%s")'\ % (imagename, filename)) if image.data.pixel_type != ONEBIT: self._shell.run("%s = %s.to_onebit()"\ % (imagename,\ imagename)) # still exists in the gamera shell del image # choose a name for the variable in # the GUI if ms_module.startswith("StaffFinder"): name=var_name.get("stafffinder",\ self._shell.locals) else: name=var_name.get("musicstaves",\ self._shell.locals) if name is "" or name is None: return # create an instance of the specified # MusicStaves_XXX class self._shell.run("%s = %s.%s(%s, %d, %d)"\ % (name,\ self.label,\ ms_module,\ imagename,\ params[1], params[2]))