How to change style of symbol in layer ? Categorized type Pyqgis - styles

i would like to know how to change style (opacity, color etc) of shape in Pyqgis
For ex. I have got 1 poligon layer, in this layer 2 shapes.
I want to change style one of them, using categorized ( first shape Has got value '1' next '2', name of attribute - 'NO'

Related

How to print conditional fields in PPFA code

How do I print a conditional field using PPFA code. When a value is an 'X' then I'd like to print it. However, if the 'X' is not present then I'd like to print an image. Here is my code:
LAYOUT C'mylayout' BODY
POSITION .25 in ABSOLUTE .25 in
FONT TIMES
OVERLAY MYTEMPOVER 8.5 in 11.0 in;
FIELD START 1 LENGTH 60
POSITION 2.0 in 1.6 in;
Where it has FIELD START 1 LENGTH 60 that will print the given text at that location. But based on the value I want to print either the given text or an image. How would I do that?
Here is an answer from the AFP-L list:
I would create two PAGEFORMATS, one with LAYOUT for TEXT and one with LAYOUT for IMAGE. With CONDITION you can jump between the Pageformats (where Copygroup is always 'NULL')
If you work in a z/OS environment, be careful of 'JES Blanc Truncation'.
That means in one sentence:
if there is a X in the data, condition is true
if there is nothing in the data, condition doesn't work and is always wrong (nothing happens)
In this case you must create a Condition which is always true. I call it a Dummy-Condition.
PPFA sample syntax:
CONDITION TEST start 1 length 1
when eq 'X' NULL PAGEFORMAT PRTTXT
when ge x'00' NULL PAGEFORMAT PRTIMAGE;
You must copy this CONDITION into both PAGEFORMATS after LAYOUT command.
Blanc truncation is a difficult problem on z/OS.
In this sample, the PAGEFORMAT named PRTTXT contains all the formatting and printing directives when the condition is true, and the other called PRTIMAGE contains every directive needed to print the image.
HTH

Is there a way to emmit a signal when a cell is edited with same value?

I need to change the font of a cell in a QTableWidget if the user change the text in it, EVEN if the text is the same as the default one.
I used to use itemChanged signal from the table for that kind of things, but here I'm stuck because the signal won't raise if the user type the exact same text.
item = QtWidgets.QTableWidgetItem("42")
self.my_table.setItem(0, 0, item)
self.my_table.itemChanged.connect(self.update)
def update(self, cell):
print("update")
self.my_table.itemChanged.disconnect(self.update)
font = cell.font()
if cell.text() == "":
cell.setText("42")
font.setUnderline(False)
else:
font.setUnderline(True)
cell.setFont(font)
self.my_table.itemChanged.connect(self.update)
knowing :
default text in the cell is "42"
default font is not underline, other one is
Case 1:
User type "3" -> text become underlined
User type "42" -> text stay underlined
Case 2:
User type "42" -> text should become underlined
Why it doesn't ? :
Because the ItemChanged signal won't raise if the user type exactly the same thing.
Should I use another Signal ? (didn't find any which could match my need)
Is there another way to do so ?
Why does it make sens to try to do so ? :
The user want to make the difference between a value that is the default value and a value that is FIXED to a value (and doesn't care if that fixed value is the default one or not, because the default value may change).
Also if the user want to set back the value to the default one, he can empty the cell.

Python tkinter, label has no attribute 'count'

I have an error message saying:
sentences = text.count(".") + text.count("!") + text.count("?")
AttributeError: 'Label' object has no attribute 'count'
What can I use instead of .count to count items?
Accessing the Label object directly will not get the text of it. You'll need to do text["text"].count or text.cget("text").count. Either will extract the actual text from the label. Tkinter objects can be treated as dictionaries, where the lookup keys are their attributes. cget stands for "configuration get" and allows you to more safely retrieve the attributes.
This occurs because the object text does not implement the function count().
Assuming that the text object you are referring to is a tkinter Label, you need to call count() like this:
text["text"].count(string)
So the line you posted would look like this instead:
sentences = text["text"].count(".") + text["text"].count("!") + text["text"].count("?")
Also, I would recommend you change the variable name text to something else that is more descriptive to avoid confusion in the future.

Why doesn't my RangeEditor work, when I use mode='spinner'?

In a HasTraits subclass, I have the following Trait defined:
tx_lane_sel = Range(0, 12)
If I display it in my View, using:
Item('tx_lane_sel')
it works as expected, displaying a slider bar, which ranges from 0 to 12.
However, if I try to display it, using:
Item('tx_lane_sel', editor=RangeEditor(mode='spinner'))
the resultant spinner only offers me choices '0' and '1'!
How do I get the spinner working correctly? That is, how do I get it to offer me the full range [0, 12]?
The RangeEditor is not especially ment for Range traits. Thus, as for integers or floats, you need to specify the range by using the low=0, high=12 or the low_name or high_name editor factory attributes:
Item("tx_lane_sel", editor=RangeEditor(low=0, high=12, mode='spinner'))

JqGrid - losing ability to sort and perform multipleSearch when column header text is changed programmatically on gridComplete

This is my jqgrid - $("#list1")
When it loads, i.e. on the gridComplete event, I need to rename the column header texts.
Original column header texts are in this format - Colomn1, Column2 ...
On gridComplete, I change these header texts like this:
$("#list1_Column" + someNumber).text(someText);
However on doing this, I lose the ability to sort columns. Column headers are no longer clickable and hence I cannot sort the grid after this custom programmatic editing.
Similar thing happens when I try changing the texts in the search dropdown list (search modal - using multipleSearch: true)
When, on gridComplete, I change text values in the select list as per the grid column headers, like this -
var select = $('#grid_wrapper #fbox_list1 .ui-widget-content .sf .fields select');
$('#grid_wrapper #fbox_list1 .ui-widget-content .sf .fields select option').remove();
$.each(data, function (i, item) {
select.append('<option value="Column' + item.id + '">' + item.ColumnName + '</option>')
});
...I lose the ability to perform multiple search, i.e. the + and - buttons in the search modal disappear.
How do I get around these two issues? Retaining ability to sort and perform multiple search after having changed column header and search list text values on load.
Please guide.
The column header <th> element has two child elements: one <span> with the text of the column header and another with the sort icons which are hidden the most time. So if you want to change the text manually you should use another selector
$("#list1_Column" + someNumber+ " > span").text(someText);
If you do so you will change the text on the page, but not change the text in the colNames or in the colModel (if you use label property instead of colNames). The text will be used for example to create Multisearch dialog. You can make changes in the colModel with respect of setColProp method or use getGridParam to get reference to any internal parameter of jqGrid (which are objects like inclusive colNames and colModel) and then make any changes which you need.
The best way in my opinion to solve the described problems is to use setLabel method to change the text in the column header:
$("#list1").jqGrid('setLabel','ColumnName','My new Name');
this will solve both problems.

Resources