def run(): if gimp_shelf.has_key('socket_server') and gimp_shelf['socket_server']: gimp.message( "WARNING: '%s' is already running!" % SocketService.titleServer) return SocketService().run()
def hue_map_plugin_main(self, run_mode, image, drawable, gradient_name=None, flatten=1): #set default gradient name if gradient_name is None: gradient_name = self.default_gradient self.image = image self.drawable = drawable #create settings storage if not shelf.has_key(self.shelfkey): self.shelf_store(gradient_name, flatten) #initialize dialog self.create_dialog() #create default hue gradient if not self.gradient_exists(self.default_gradient): self.reset_gradient() pdb.gimp_image_undo_group_start(self.image) if run_mode == RUN_INTERACTIVE: #show and run the dialog self.dialog.run() #this code runs after the dialog is closed -> cleanup time! #destroy preview self.layer_destroy() else: #non-interactive or use last values self.ok_clicked(None) pdb.gimp_image_undo_group_end(self.image) #refresh gimp.displays_flush()
def python_fu_sendosc_headless( inImage, inDrawable): addr = "127.0.0.1" port = 57120 bFlatten = False # just call sendosc with the saved parameters # if there are any if shelf.has_key('oscnetaddr'): addr = shelf['oscnetaddr'][0] if shelf.has_key('oscport'): port = shelf['oscport'][0] if shelf.has_key('oscbflatten'): bFlatten = shelf['oscbflatten'][0] pdb.python_fu_sendosc(inImage,inDrawable,bFlatten,addr,port) gimp.delete(inImage)
def run(image, drawable): #startPyDevClient() if gimp_shelf.has_key('socket_server') and gimp_shelf['socket_server']: gimp.message("WARNING: '%s' is already running!" % SocketService.titleServer) return SocketService().run(image)
def run(): if gimp_shelf.has_key('socket_server') and gimp_shelf['socket_server']: msg = "WARNING: '{}' is already running!".format(Service.titleServer) Service.printMessage(msg) return serv = Service() serv.run() del serv
def btn4ws(self, runmode, filename = None, outdir = None, font = None, strcolor = None, transparency = False, bgcolor = None, glow = False, glowcolor = None, usepattern = False, pattern = None, buttoncolor = None, roundradius = None, padding = None, glowsize = None, bevelwidth = None, nova = False, novasparkles = None, novaradius = None, novacolor = None, writexcf = False, makeinactive = True, makeactive = True, makepressed = True, makejscript = True): """ This function controls the creation of the buttons and is registered as gimp plugin. """ self.inputdata = { "filename" : filename, "outdir" : outdir, "font" : font, "strcolor" : strcolor, "transparency" : transparency, "bgcolor" : bgcolor, "glow" : glow, "glowcolor" : glowcolor, "usepattern" : usepattern, "pattern" : pattern, "buttoncolor" : buttoncolor, "roundradius" : roundradius, "padding" : padding, "glowsize" : glowsize, "bevelwidth" : bevelwidth, "nova" : nova, "novasparkles" : novasparkles, "novaradius" : novaradius, "novacolor" : novacolor, "writexcf" : writexcf, "makeinactive" : makeinactive, "makeactive" : makeactive, "makepressed" : makepressed, "makejscript" : makejscript } if runmode in (RUN_INTERACTIVE, RUN_WITH_LAST_VALS): if shelf.has_key("btn4ws"): self.inputdata = shelf["btn4ws"] else: self.inputdata = self._loaddata(self.inputdata) dialog = Btn4wsDialog(self.inputdata) dialog.connect("close", self._cb_destroy) dialog.connect("cancel", self._cb_destroy) dialog.connect("destroy", self._cb_destroy) dialog.connect("apply", self._cb_apply) gtk.main() elif runmode == RUN_NONINTERACTIVE: logging.debug("runmode noninteractive") if self.checkdata(self.inputdata): self.makebuttons(**self.inputdata) else: logging.error("checking data failed") else: logging.error("unknown runmode %d" % runmode) return
def info_layers(img, drw): img.undo_group_start() # avoid duplicate launch if shelf.has_key('info_layers') and shelf['info_layers']: gimp.message( _("WARNING: an 'info_layers' instance is already running!")) else: shelf['info_layers'] = True r = LayerViewer(img, drw) gtk.main() shelf['info_layers'] = False if (img in gimp.image_list()): layers_aft = get_all_layers(img) if layers_aft == layers: for i in range(len(layers)): layers[i].visible = layer_view[i] img.undo_group_end()
def arrows_creator(image, layer): global arrow_done, init_paths, ID_path, inter_val, brush_name if message: gimp.message(message) wdth = image.width hght = image.height # with gimpshelf avoid duplicate launch if shelf.has_key('arrows_creator') and shelf['arrows_creator']: gimp.message(_("ERROR: an 'arrows creator' instance is already running!")) else: #1) Preparations # ******************************************** shelf['arrows_creator'] = True # instability of GIMP-2.6 core with 'image.undo_group' here but work in 2.8 if version[1] > 7 : image.disable_undo() # initial paths? init_paths = image.vectors if init_paths: for p in init_paths : p.visible = False # before putting two anchors, case when called from tracing a path vectors_new = pdb.gimp_vectors_new(image, _("AC buffer")) pdb.gimp_image_add_vectors(image, vectors_new, -1) # configure time interval in timeout_add(), probably depends on image size & # sluggishness? Greater interval: more time for GIMP? Approximation. slug = 1.0 # Linux 64 bits, 4 cores at 2.83 GHz, GIMP 2.6.11 (64 b) #slug = 1.4 # Win_7 64 bits, 8 cores at 2 GHz, GIMP 2.6.11 (32 b) inter_val = int((0.26*math.sqrt(wdth*hght) + 100)*slug) # generated brush previous_brush = pdb.gimp_context_get_brush() #brush_name = pdb.gimp_brush_duplicate(bru_con_nam) #next line gives less surprise brush_name = pdb.gimp_brush_new('AC_brush') pdb.gimp_brush_set_shape(brush_name, 0) pdb.gimp_brush_set_hardness(brush_name, 1.0) pdb.gimp_context_set_brush(brush_name) if version[1] > start_minver: pdb.gimp_context_set_dynamics("Dynamics Off") #2) Main event # ******************************************** r = ArrowWindow(image) gtk.main() #3) Closing # ******************************************** # cleanup brush pdb.gimp_context_set_brush(previous_brush) pdb.gimp_brush_delete(brush_name) if image in gimp.image_list(): # cleanup path if ID_path: pdb.gimp_image_remove_vectors(image, ID_path) if init_paths and ID_path != vectors_new : pdb.gimp_image_remove_vectors(image, vectors_new) #pdb.gimp_item_set_tattoo(item, tattoo) # cleanup layer, if close before the arrow is drawn if not arrow_done and not layer_miss : # and no missing top layer #item = pdb.gimp_image_get_active_layer(image) image.remove_layer(image.layers[0]) if version[1] > 7 : image.enable_undo() # permitting the user to keep tab on measuring arrow if measurements : if gimp.version >= (2, 8, 0): temp_name = str(image.filename) if temp_name: start_tmp = temp_name.rfind(os.sep)+1 end_tmp = temp_name.find('.', start_tmp) if end_tmp > 0: cur_name = temp_name[start_tmp:end_tmp] else: cur_name = temp_name[start_tmp:] else: cur_name = curImages[id].name[:curImages[id].name.find('.')] # this was working in 2.6 else: cur_name = image.name mess_txt = _("MEASURING ARROW in %s: \n\n Nr Size")%cur_name\ +_(" Direction (clockwise +)\n") for arrow in measurements : mess_txt += " %s %.1f px \t %.1f°\n"%(str(arrow[0])+'.'+\ str(arrow[1]), arrow[2], arrow[3]) gimp.message(mess_txt) shelf['arrows_creator'] = False
def arrows_creator(image, layer): global arrow_done, init_paths, ID_path, inter_val, brush_name if message: gimp.message(message) wdth = image.width hght = image.height # with gimpshelf avoid duplicate launch if shelf.has_key('arrows_creator') and shelf['arrows_creator']: gimp.message( _("ERROR: an 'arrows creator' instance is already running!")) else: #1) Preparations # ******************************************** shelf['arrows_creator'] = True # instability of GIMP-2.6 core with 'image.undo_group' here but work in 2.8 if version[1] > 7: image.disable_undo() # initial paths? init_paths = image.vectors if init_paths: for p in init_paths: p.visible = False # before putting two anchors, case when called from tracing a path vectors_new = pdb.gimp_vectors_new(image, _("AC buffer")) pdb.gimp_image_add_vectors(image, vectors_new, -1) # configure time interval in timeout_add(), probably depends on image size & # sluggishness? Greater interval: more time for GIMP? Approximation. slug = 1.0 # Linux 64 bits, 4 cores at 2.83 GHz, GIMP 2.6.11 (64 b) #slug = 1.4 # Win_7 64 bits, 8 cores at 2 GHz, GIMP 2.6.11 (32 b) inter_val = int((0.26 * math.sqrt(wdth * hght) + 100) * slug) # generated brush previous_brush = pdb.gimp_context_get_brush() #brush_name = pdb.gimp_brush_duplicate(bru_con_nam) #next line gives less surprise brush_name = pdb.gimp_brush_new('AC_brush') pdb.gimp_brush_set_shape(brush_name, 0) pdb.gimp_brush_set_hardness(brush_name, 1.0) pdb.gimp_context_set_brush(brush_name) if version[1] > start_minver: pdb.gimp_context_set_dynamics("Dynamics Off") #2) Main event # ******************************************** r = ArrowWindow(image) gtk.main() #3) Closing # ******************************************** # cleanup brush pdb.gimp_context_set_brush(previous_brush) pdb.gimp_brush_delete(brush_name) if image in gimp.image_list(): # cleanup path if ID_path: pdb.gimp_image_remove_vectors(image, ID_path) if init_paths and ID_path != vectors_new: pdb.gimp_image_remove_vectors(image, vectors_new) #pdb.gimp_item_set_tattoo(item, tattoo) # cleanup layer, if close before the arrow is drawn if not arrow_done and not layer_miss: # and no missing top layer #item = pdb.gimp_image_get_active_layer(image) image.remove_layer(image.layers[0]) if version[1] > 7: image.enable_undo() # permitting the user to keep tab on measuring arrow if measurements: if gimp.version >= (2, 8, 0): temp_name = str(image.filename) if temp_name: start_tmp = temp_name.rfind(os.sep) + 1 end_tmp = temp_name.find('.', start_tmp) if end_tmp > 0: cur_name = temp_name[start_tmp:end_tmp] else: cur_name = temp_name[start_tmp:] else: cur_name = curImages[id].name[:curImages[id].name. find('.')] # this was working in 2.6 else: cur_name = image.name mess_txt = _("MEASURING ARROW in %s: \n\n Nr Size")%cur_name\ +_(" Direction (clockwise +)\n") for arrow in measurements: mess_txt += " %s %.1f px \t %.1f°\n"%(str(arrow[0])+'.'+\ str(arrow[1]), arrow[2], arrow[3]) gimp.message(mess_txt) shelf['arrows_creator'] = False
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
def btn4ws(self, runmode, filename=None, outdir=None, font=None, strcolor=None, transparency=False, bgcolor=None, glow=False, glowcolor=None, usepattern=False, pattern=None, buttoncolor=None, roundradius=None, padding=None, glowsize=None, bevelwidth=None, nova=False, novasparkles=None, novaradius=None, novacolor=None, writexcf=False, makeinactive=True, makeactive=True, makepressed=True, makejscript=True): """ This function controls the creation of the buttons and is registered as gimp plugin. """ self.inputdata = { "filename": filename, "outdir": outdir, "font": font, "strcolor": strcolor, "transparency": transparency, "bgcolor": bgcolor, "glow": glow, "glowcolor": glowcolor, "usepattern": usepattern, "pattern": pattern, "buttoncolor": buttoncolor, "roundradius": roundradius, "padding": padding, "glowsize": glowsize, "bevelwidth": bevelwidth, "nova": nova, "novasparkles": novasparkles, "novaradius": novaradius, "novacolor": novacolor, "writexcf": writexcf, "makeinactive": makeinactive, "makeactive": makeactive, "makepressed": makepressed, "makejscript": makejscript } if runmode in (RUN_INTERACTIVE, RUN_WITH_LAST_VALS): if shelf.has_key("btn4ws"): self.inputdata = shelf["btn4ws"] else: self.inputdata = self._loaddata(self.inputdata) dialog = Btn4wsDialog(self.inputdata) dialog.connect("close", self._cb_destroy) dialog.connect("cancel", self._cb_destroy) dialog.connect("destroy", self._cb_destroy) dialog.connect("apply", self._cb_apply) gtk.main() elif runmode == RUN_NONINTERACTIVE: logging.debug("runmode noninteractive") if self.checkdata(self.inputdata): self.makebuttons(**self.inputdata) else: logging.error("checking data failed") else: logging.error("unknown runmode %d" % runmode) return
def python_fu_receiveosc( inImage, inDrawable, netAddr="127.0.0.1", port=57130): global receiving,newSpecs,pic inImage.disable_undo() gimp.progress_init("receiving...") receiving = 1 startingTime = time.time() # get right port for sc if shelf.has_key('oscnetaddr'): sendAddr = shelf['oscnetaddr'][0] else: sendAddr = "127.0.0.1" if shelf.has_key('oscport'): sendPort = shelf['oscport'][0] else: sendPort = 57120 ## init osc listeners osc.init() osc.listen(netAddr, port) osc.bind(python_fu_receiveosc_storeSpecs, "/gimp/spec") osc.bind(python_fu_receiveosc_receiveImage, "/gimp/pic") osc.bind(python_fu_receiveosc_displayImage, "/gimp/end") ## ping sc to send image osc.sendMsg("/gimp/ping", [-1], sendAddr, sendPort) ## loop until done while receiving: #print("ping", len(pic)) if receiving == 3: time.sleep(1) gimp.progress_update(96) newPic = [] newLayer = gimp.Layer(inImage, "fromOSC", newSpecs[0], newSpecs[1], RGB_IMAGE, 100, NORMAL_MODE) inImage.add_layer(newLayer, 0) pdb.gimp_edit_fill(newLayer, BACKGROUND_FILL) newPic = newLayer.get_pixel_rgn(0,0, newSpecs[0],newSpecs[1], True) #newPic = pic print(len(pic)) ## remove all brightness values ## convert from int to chr-values ## if newSpecs[2] == 4: ## for index in range(len(pic)): ## if index%4 == 3: ## pic[index] = 255 ## elif index == 0: ## picAsStr = chr(pic[index]) ## else: ## picAsStr = picAsStr + chr(pic[index]) ## set the pixel region to pic #print(pic) newPic[0:newSpecs[0],0:newSpecs[1]] = pic newLayer.flush() newLayer.update(0,0,newSpecs[0],newSpecs[1]) print("flushed & updated") receiving = 0 elif time.time() - startingTime > 20: print("time's up") receiving = 0 else: gimp.progress_update(int(18 * (time.time() - startingTime))) #time.sleep(0.2) osc.dontListen() inImage.enable_undo() gimp.displays_flush() gimp.extension_ack()