Create a Qgis Icon based on an existing Icon - python

I am in need to create a Qgis icon similar to the existing Selection Qgis icon Select features by are or single click. I will create a new Icon to do exactly what the existing Qgis icon does and add some more script to it.
1 - I need to get the code for this existing Icon Select features by are or single click.
2 - Add the following code to it:
layer = iface.activeLayer()
selection = layer.selectedFeatures()
print len(selection)
for f in layer.selectedFeatures():
layer_xml = iface.addRasterLayer(f['tms'], f['name'])
Any help on that will be very appreciated.

Related

How to show ahp_calculator using webEngineView.setHtml in PyQt5

I'm trying to show the following code results on webEngineView.setHtml:
from ahp_calculator import ahp_calculator
AC = ahp_calculator()
AC.open_calculator()
So it will be displayed in the right box (instead of folium map) after clicking a button on the left as shown in the figure below:
I found ways to display maps, Tables and Plotes using SetHtml. But how to render and display ahp_calculator?

turi create and label studio, error join annotation with photo

I'm trying to implement a model of Object Detecting using Turi Create.
For simplicity I just use 1 photo which is locate in my Desktop, inside a folder CondaMLProject.
Using the software Label Studio I place the label on this photo and export the csv file annotation
I notice that the csv file is like:
as you can see the image column report a wrong link to the photo, is not my desktop link.
when I run the python script of turi create to join the the image to the annotation I'm getting error
import turicreate as tc
path = "Spikosmall"
pathAnnotation = "Spikosmall/annotation.csv"
images = tc.load_images(path, with_path=True)
annotation = tc.SFrame(pathAnnotation)
data = images.join(annotation)
Error:
Columns image and image do not have the same type in both SFrames
How can I solve this issue?
Not so smart in python .. looking for some code to iterate inside the column image and change the link to match the photo folder..
Is there any other solution?

Resizing of QMessageBox

I have created a QMessageBox as follows:
msg_box = QtGui.QMessageBox()
msg_box.setSizeGripEnabled(True)
msg_box.setIcon( QtGui.QMessageBox.Information )
msg_box.setText('The following files are not .jpg ')
msg_box.setInformativeText('No. of Items : {0}'.format(len(contents)))
msg_box.setDetailedText('{0}'.format('\n'.join([str(sel) for sel in img_sels])))
msg_box.setStandardButtons(QtGui.QMessageBox.Cancel)
msg_exec = msg_box.exec_()
User will select a handful of images, and if within the selections, if it consists of items that are not of jpeg/ .jpg format, these items' file path will be collated and be displayed in QMessageBox
One issue that I had is that, I am having difficulties in getting the QMessageBox to be resize or have the UI width conform according the the length or the text etc. As I am unable to do that, the popup ui displays the filepath almost like in a wrapped text format, somewhat unsightly.
Is there any other ways that I can do to improve the code and have it accommodate to the width etc?
If not, is there another QtGui command that I can consider to use it?

Python PPTX workaround function for rotating chart data labels

I intend to create the following chart using Python PPTX.
Below code achieve the color setting, font size and number format. However, I am not yet able to rotate the data label, as I believe this API is not yet available in python-pptx 0.6.5
lbl = plot.data_labels
lbl.font.size = config["DATA_LABEL_FONT_SIZE"]
lbl.font.color.rgb = config["DATA_LABEL_FONT_COLOR"]
lbl.number_format = config["DATA_LABEL_NUMBER_FORMAT"]
lbl.position = config["DATA_LABEL_POSITION"]
To get started, I have created two minimal slides before and after rotating, and use opc-diag tool to find the diff.
<a:bodyPr rot="-5400000" spcFirstLastPara="1" vertOverflow="ellipsis"
vert="horz" wrap="square" lIns="38100" tIns="19050" rIns="38100"
bIns="19050" anchor="ctr" anchorCtr="1">\n
<a:spAutoFit/>\n </a:bodyPr>\n
I believe I need to add rot="-5400000" XML element to lbl (plot.data_labels), but not clear on how to achieve this. I have used dir(), ._element and .xml on the chart and its children but not able to find <a:bodyPr> tag.
I tried below and it works.
if config["DATA_LABEL_VERTICAL"]:
txPr = lbl._element.get_or_add_txPr()
txPr.bodyPr.set('rot','-5400000')

Python images display

How can I create a python script that runs through the images (1.jpeg-n.jpeg) in a directory on a mac and displays them in a browser OR via another python program?
Do I import a file to python and than display in browser?
Do I extract the file names 1,2,3,4,5 and add that to a list, which I give to another function that calls a browser and displays?
Any help would be great.
Thanks!
Using Tkinter and PIL for this purpose is pretty trivial. Add muskies example to the information from this thread that contains this example:
# use a Tkinter label as a panel/frame with a background image
# note that Tkinter only reads gif and ppm images
# use the Python Image Library (PIL) for other image formats
# free from [url]http://www.pythonware.com/products/pil/index.htm[/url]
# give Tkinter a namespace to avoid conflicts with PIL
# (they both have a class named Image)
import Tkinter as tk
from PIL import Image, ImageTk
root = tk.Tk()
root.title('background image')
# pick an image file you have .bmp .jpg .gif. .png
# load the file and covert it to a Tkinter image object
imageFile = "Flowers.jpg"
image1 = ImageTk.PhotoImage(Image.open(imageFile))
# get the image size
w = image1.width()
h = image1.height()
# position coordinates of root 'upper left corner'
x = 0
y = 0
# make the root window the size of the image
root.geometry("%dx%d+%d+%d" % (w, h, x, y))
# root has no image argument, so use a label as a panel
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')
# put a button on the image panel to test it
button2 = tk.Button(panel1, text='button2')
button2.pack(side='top')
# save the panel's image from 'garbage collection'
panel1.image = image1
# start the event loop
root.mainloop()
Of course if you're more familiar with another GUI, go ahead and adapt the example, it shouldn't take much.
You first have to find all image filenames. You can use os.listdir(...) to get all files in a certain directory, or glob.glob(...) to find all files matching a certain pattern.
Showing the images is the second and more challenging part of this. The first option is to open the images in an external program, this can be a web browser. On (most) platforms a command firefox 1.jpeg will open the image 1.jpeg in the Firefox browser. You can use the subprocess module to execute such commands. If you want to show them using a nice GUI, you have to create a GUI using some framework and use this. But if you are a beginner this might be a little bit too difficult for you.
For example:
import glob
import subprocess
files = glob.glob('dir/*.jpeg')
for file in files:
subprocess.call(['firefox', file])
muksie's answer already contains very useful advice. If don't want to write the HTML file yourself or want something a little fancier you could use a small script I wrote for the MDP library. This basically allows you to just do:
import slideshow
slideshow.show_image_slideshow(filenames, image_size=(80,60))
This will create an HTML slideshow and open it in your browser. You can grab just the needed files here (only templet.py and the two slideshow files are needed), which might be better for you than getting the full library.
It might be a lot easier to just generate a static web page with pictures than building a GUI for displaying pictures.
You can just generate a hmtl page, put the images on it and start your web browser with the newly created html file. this gives you some possibilities for layout as well.
If you just want a picture in the browser then muksie gave a working example.

Categories

Resources