def plugin_main(image, __unused_drawable, name_pattern): gprint("ADD NEW LAYER...") #save previous layer layer = image.layers[0] directory = "C:\\3d-Model\\bin\\segmentation_files" filename = join(directory, name_pattern) print type(name_pattern) raw_filename = name_pattern text_file = raw_filename[:raw_filename.find(".")] + ".txt" with open("C:\\3d-Model\\bin\\segmentation_files\\seg_text.txt", 'w') as myFile: myFile.write(str(text_file)) pdb.gimp_file_save(image, layer, filename, raw_filename) #upgrade database os.chdir('C:\\3d-Model\\bin\\segmentation_files') os.system('"C:\\3d-Model\\bin\\segmentation_files\\GUI.py"') #add new layer image = gimp.image_list()[0] layer = image.layers[0] layer = pdb.gimp_layer_new(image, image.width, image.height, 1, "segmented contours", 100, 0) image.add_layer(layer, -1)
def __init__(self, *args): #message, image = args gimp.message(args[0]) dlg = gtk.MessageDialog(type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_CLOSE, message_format=args[0]) dlg.set_position(gtk.WIN_POS_CENTER) dlg.run() dlg.destroy() # house keeping try: gimp.pdb.gimp_context_pop() except RuntimeError: pass # no previous context push try: image = gimp.image_list()[0] gimp.pdb.gimp_image_undo_group_end(image) except RuntimeError: pass # no previous group start try: gimp.pdb.gimp_progress_end() except RuntimeError: pass # NOTE: this only in case, as unlike context & group, this seemingly doesn't get thrown if progress init wasn't called first gimp.pdb.gimp_displays_flush()
def add_layer(opacity=100, mode=0): image = gimp.image_list()[0] new_layer = gimp.Layer(image, "worms", image.width, image.height, 0, opacity, mode) pdb.gimp_image_add_layer(image, new_layer, 0) pdb.gimp_image_set_active_layer(image, new_layer) drawable = pdb.gimp_image_active_drawable(image)
def _update_image_ids(image_ids_dict_setting, image_filenames_dict_setting): current_images = gimp.image_list() for image in current_images: if image.ID not in image_ids_dict_setting.value and image.filename in image_filenames_dict_setting.value: _second_first_assign_func( image.ID, os.path.abspath(image.filename), image_ids_dict_setting, image_filenames_dict_setting, *convert_value_second_first_func_args)
def _set_image_ids_and_folders(self): setting = self._image_ids_and_folders_setting current_image_ids = set([image.ID for image in gimp.image_list()]) setting.value = { image_id : setting.value[image_id] for image_id in setting.value.keys() if image_id in current_image_ids } for image_id in current_image_ids: if image_id not in setting.value.keys(): setting.value[image_id] = None
def _set_image_ids_and_folders(self): setting = self._image_ids_and_folders_setting current_image_ids = set([image.ID for image in gimp.image_list()]) setting.value = { image_id: setting.value[image_id] for image_id in setting.value.keys() if image_id in current_image_ids } for image_id in current_image_ids: if image_id not in setting.value.keys(): setting.value[image_id] = None
def _update_image_ids(image_ids_dict_setting, image_filepaths_dict_setting, assign_filepath_to_image_id_func, assign_filepath_to_image_id_func_args): current_images = gimp.image_list() for image in current_images: if (image.ID not in image_ids_dict_setting.value and image.filename in image_filepaths_dict_setting.value): assign_filepath_to_image_id_func( image.ID, os.path.abspath(image.filename), image_ids_dict_setting, image_filepaths_dict_setting, *assign_filepath_to_image_id_func_args)
def ImageMenu(constraint=None, callback=None, data=None): items = [] for img in gimp.image_list(): if constraint and not constraint(img): continue if not img.filename: filename = img.name else: filename = img.filename items.append((filename, img)) items.sort() return _createMenu(items, callback, data)
def ChannelMenu(constraint=None, callback=None, data=None): items = [] for img in gimp.image_list(): filename = img.filename if not filename: filename = img.name for channel in img.channels: if constraint and not constraint(img, channel): continue name = filename + "/" + channel.name items.append((name, channel)) items.sort() return _createMenu(items, callback, data)
def DrawableMenu(constraint=None, callback=None, data=None): items = [] for img in gimp.image_list(): filename = img.filename if not filename: filename = img.name for drawable in img.layers + img.channels: if constraint and not constraint(img, drawable): continue name = filename + "/" + drawable.name items.append((name, drawable)) items.sort() return _createMenu(items, callback, data)
def LayerMenu(constraint=None, callback=None, data=None): items = [] for img in gimp.image_list(): filename = img.filename if not filename: filename = img.name for layer in img.layers: if constraint and not constraint(img, layer): continue name = filename + "/" + layer.name items.append((name, layer)) items.sort() return _createMenu(items, callback, data)
def VectorsMenu(constraint=None, callback=None, data=None): items = [] for img in gimp.image_list(): filename = img.filename if not filename: filename = img.name for vectors in img.vectors: if constraint and not constraint(img, vectors): continue name = filename + "/" + vectors.name items.append((name, vectors)) items.sort() return _createMenu(items, callback, data)
def _update_image_filepaths( image_filepaths_dict_setting, image_ids_dict_setting, assign_image_id_to_filepath_func, assign_image_id_to_filepath_func_args): current_images = gimp.image_list() for image in current_images: if image.ID in image_ids_dict_setting.value and image.filename: assign_image_id_to_filepath_func( image.ID, os.path.abspath(image.filename), image_ids_dict_setting, image_filepaths_dict_setting, *assign_image_id_to_filepath_func_args)
def update_image_ids_and_directories(self): """ Remove all (image ID, import directory) pairs for images no longer opened in GIMP. Add (image ID, import directory) pairs for new images opened in GIMP. """ # Get the list of images currently opened in GIMP current_images = gimp.image_list() current_image_ids = set([image.ID for image in current_images]) # Remove images no longer opened in GIMP self._value = { image_id: self._value[image_id] for image_id in self._value.keys() if image_id in current_image_ids } # Add new images opened in GIMP for image in current_images: if image.ID not in self._value.keys(): self._value[image.ID] = self._get_imported_image_path(image)
def initData(self): global previewSize,imgPreview,localDir,xcfEdits,isHaveBack curFilename = localDir+"/default.jpg" imgBuf = gtk.gdk.pixbuf_new_from_file(curFilename) gprint(curFilename) imgBuf = imgBuf.scale_simple(previewSize[0],previewSize[1],gtk.gdk.INTERP_NEAREST) imgPreview.set_from_pixbuf(imgBuf) gprint('a') #获取当前打开的所有图像 xcfEdits = gimp.image_list() isHaveBack = None ## fileName = gimp.pdb.gimp_image_get_filename(xcfEdits[0]) ## name = os.path.basename(fileName) ## gprint(name) ## layers = xcfEdits[1].layers return
def update_image_ids_and_dirpaths(self): """ Remove all (image ID, import directory path) pairs for images no longer opened in GIMP. Add (image ID, import directory path) pairs for new images opened in GIMP. """ # Get the list of images currently opened in GIMP current_images = gimp.image_list() current_image_ids = set([image.ID for image in current_images]) # Remove images no longer opened in GIMP self._value = { image_id: self._value[image_id] for image_id in self._value.keys() if image_id in current_image_ids} # Add new images opened in GIMP for image in current_images: if image.ID not in self._value: self._value[image.ID] = self._get_image_import_dirpath(image)
def move_ant(ant_in, distance=45): ctrlpoints = [] image = gimp.image_list()[0] ctrlpoints.append(ant_in['x']) ctrlpoints.append(ant_in['y']) ant_in['x'] += int(round(sin(radians(ant_in['heading'])) * distance)) if ant_in['x'] < 0: ant_in['x'] = image.width if ant_in['x'] > image.width: ant_in['x'] = 0 ant_in['y'] += int(round(cos(radians(ant_in['heading'])) * distance)) if ant_in['y'] < 0: ant_in['y'] = image.height if ant_in['y'] > image.height: ant_in['y'] = 0 ctrlpoints.append(ant_in['x']) ctrlpoints.append(ant_in['y']) if abs(ctrlpoints[0] - ctrlpoints[2]) > image.width / 2 or abs( ctrlpoints[1] - ctrlpoints[3]) > image.height / 2: draw_line(ctrlpoints[0], ctrlpoints[1], ctrlpoints[0], ctrlpoints[1]) else: draw_line(*ctrlpoints) return (ant_in, ctrlpoints)
def plugin_main(image, __unused_drawable, name_pattern): gprint("ADD NEW LAYER...") #save previous layer layer=image.layers[0] directory="C:\\3d-Model\\bin\\segmentation_files" filename = join(directory, name_pattern) print type(name_pattern) raw_filename = name_pattern text_file=raw_filename[:raw_filename.find(".")]+".txt" with open("C:\\3d-Model\\bin\\segmentation_files\\seg_text.txt", 'w') as myFile: myFile.write(str(text_file)) pdb.gimp_file_save(image, layer, filename, raw_filename) #upgrade database os.chdir( 'C:\\3d-Model\\bin\\segmentation_files' ) os.system( '"C:\\3d-Model\\bin\\segmentation_files\\GUI.py"') #add new layer image = gimp.image_list()[0] layer=image.layers[0] layer = pdb.gimp_layer_new(image, image.width, image.height, 1, "segmented contours", 100, 0) image.add_layer(layer, -1)
def py_edit_libgdx_debug(self): return edit_libgdx_atlas(-1, gimp.image_list()[0], None)
def py_select_move_layers_debug(self): return select_move_layers(-1, gimp.image_list()[0], None, 0, 0)
def brush_size(size=-1): image = gimp.image_list()[0] drawable = pdb.gimp_image_active_drawable(image) if size < 1: size = randrange(2, ((image.height + image.width) / 8)) pdb.gimp_context_set_brush_size(size)
def draw_line(x1, y1, x2, y2): image = gimp.image_list()[0] drawable = pdb.gimp_image_active_drawable(image) ctrlPoints = (x1, y1, x2, y2) pdb.gimp_paintbrush_default(drawable, len(ctrlPoints), ctrlPoints) return ctrlPoints
def arrows_creator(image, layer) : """ This is the procedure that is registered with GIMP """ global AC_argmenu, GIMP_version # GIMP version from the PDB, but tuple as from pygimp pdb_version = pdb.gimp_version().split('.') # here version is a string pdb_version = tuple([int(item) for item in pdb_version]) if pdb_version != GIMP_version and (pdb_version < (2, 8, 14) or pdb_version > (2, 11)) : gimp.message(_("WARNING: your PDB version is '%s', so different from the pygimp one '%s'")\ % (str(pdb_version), str(GIMP_version)) + _(" and a miss-match!")) # officially GIMP_version = pdb_version ## next was for the case of a size change by explanation of the label? #wdth = image.width #hght = image.height # with gimpshelf avoid duplicate launch (comment out 'shelf' for dev.) if shelf.has_key(whoiamName) and shelf[whoiamName] : gimp.message(_("ERROR: an 'arrows creator' instance is already running!")) return ##1) Preparations # ******************************************** shelf[whoiamName] = True # the context antialias is set by default in GIMP! # instability of GIMP-2.6 core with 'image.undo_group' here but work in 2.8 image.disable_undo() # initial paths? vectors_new = [] init_paths = image.vectors if init_paths : for p in init_paths : # if "AC_vectors" there keep it visible if p.name == _("AC_vectors") : p.visible = True pdb.gimp_image_lower_item_to_bottom(image, p) pdb.gimp_image_set_active_vectors(image, p) else : p.visible = False # configure pattern for the head previous_pattern = pdb.gimp_context_get_pattern() pdb.gimp_context_set_pattern(pdb.gimp_patterns_get_list('')[1][AC_argmenu[4]]) # set brush for the shaft explanation of the label previous_brush = pdb.gimp_context_get_brush() pdb.gimp_context_set_brush("2. Hardness 100") pdb.gimp_context_set_dynamics("Dynamics Off") ##2) Main event: GUI in 'ArrowsModule.py' # ******************************************** objct = ArrowWindow(image, AC_argmenu[3], AC_argmenu[4], GIMP_version) gtk.main() ##3) Closing # ******************************************** # restore some context pdb.gimp_context_set_brush(previous_brush) pdb.gimp_context_set_pattern(previous_pattern) if image in gimp.image_list() : # cleanup buffer path if len(image.vectors)>2 : buf_name = pdb.gimp_item_get_name(image.vectors[1]) if buf_name == _("AC buffer") : pdb.gimp_image_remove_vectors(image, vectors_new) Lgroup = pdb.gimp_image_get_layer_by_name(image, _("AC_group")) if Lgroup : image.active_layer = Lgroup # quitting go here also layer = pdb.gimp_image_get_layer_by_name(image, _("AC_element")) if objct.arrow_done and layer : position = pdb.gimp_image_get_item_position(image, layer) if position == 0 : image.merge_down(layer, 1) elif not (objct.arrow_done) and not (objct.layer_miss) : # cleanup layer, if close before the arrow is drawn image.remove_layer(Lgroup.children[0]) # remove empty AC group layer empty_group = Lgroup and Lgroup.children == [] # empty group if empty_group : image.remove_layer(Lgroup) image.enable_undo() # permitting the user to keep tab on measuring arrow(s), not if last before quitting if objct.measurements : cur_name = image.name mess_txt = _("MEASURING ARROW in %s: \n\n Nr Size") % cur_name\ + _(" Direction (clockwise +)\n") for arrow in objct.measurements : mess_txt += " %s %.1f px \t %.1f°\n" % (str(arrow[0]) + '.' +\ str(arrow[1]), arrow[2], arrow[3]) gimp.message(mess_txt) shelf[whoiamName] = False