Setting Selected property of Row in TreeView dynamically in Gtk3 (python) - python-3.x

This is the same problem as in my previous question, but I moved to python3/gtk3 to be able to use a css for setting the basic properties.
From the python file:
self.w = Gtk.Window()
self.w.set_name("App")
I can use a css:
#App GtkTreeView row:selected {
border-color: #000000;
border-top-width: 1px;
border-bottom-width: 1px;
color: #000;
}
And easily permanently change the style of the selection. To me this means that I should be able to dynamically get access to the row-object and its style where I could set the bg for the Gtk.StateFlags.SELECTED.
I've tried a bunch of weird ways, e.g (where bg_color is a Gdk.Color that works fine for e.g. changing the style of a Label outside the TreeView).
style=self.treeview.get_style_context()
col = style.get_background_color(Gtk.StateFlags.SELECTED)
col.alpha = 1.0
col.blue = bg_color.blue
col.red = bg_color.red
col.green = bg_color.green
Or:
style = self.treeview.get_style().copy()
style.bg[Gtk.StateFlags.SELECTED] = bg_color
self.treeview.set_style(style)
(produces error: style.bg[Gtk.StateFlags.SELECTED] = bg_color
IndexError: list assignment index out of range)
etcetera...
So please, how do I find the way to dynamically change the selection effect depending on the normal-color of the row? Or in other words, how do I find my way to the object that actually holds the style-setting for the selection?

I had one last idea about how it could be done after posting which actually ended up working:
Reloading the css dynamically:
In the css I added a row leaving the value for the background open to dynamic substitution:
#App GtkTreeView row:selected {
border-color: #400;
border-top-width: 2px;
border-bottom-width: 2px;
background: {0};
color: #000;
}
Then I loaded the css in python:
screen = Gdk.Screen.get_default()
self._css_provider = Gtk.CssProvider()
css = open("notify_stack.css", 'rb')
self._css = css.read()
css.close()
self._css_from = bytes("{0}".encode("utf8"))
self._css_provider.load_from_data(self._css.replace(
self._css_from,
bytes("#fff".encode("utf8"))))
context = Gtk.StyleContext()
context.add_provider_for_screen(screen, self._css_provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
Later in the callback for when a row is selected I put this row (data is my ListStore):
self._css_provider.load_from_data(
self._css.replace(self._css_from,
bytes(data[rows[0]][self.BG_COLOR].encode("utf8"))))
It feels really brute, there must be a nicer way, but hey it actually worked.

Related

method to draw circular buttons in pyqt5

i would like to try to create a row of circular buttons with a method different with the one that uses setStyleSheets to define the color, the thickness and so on. The code that I managed to get with that method is the following:
self.button_list = []
for i in range(10):
button = QPushButton("{}".format(i+1), self)
button.setFixedSize(QSize(50, 50))
button.setStyleSheet("border : 1px solid black;background-color : green; color: yellow; border-radius : 25px")
self.button_list.append(button)
mainlayout.addWidget(button, i)
With what other method can I achieve the same results of circular buttons?

How to make label text in jointjs elements not selectable?

i'm trying to find a solution for the following. When I drag a link between elements the label text inside the elements get selected for some reason.
Lets say I have an element A with the property A.attr("body/magnet", "active"); set and A.attr("label/text", "some text"); When I create a link from that element by clicking and dragging the label text gets selected on elements the link goes through.
This seems a little bit random though as sometimes all the labels in the graph gets selected when dragging the link.
Is there a way to make the label text not to be selectable?
We solved it by adding the following label style to the shapes.
let element = new joint.shapes.standard.Rectangle();
element.attr(
"label/style",
"-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;"
);
From the answer above the links will still be selected, so you can put css on you #paper is or canvas like so
#paper {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}

How to control line height between non block level elements with different font sizes?

I have a layout where I need to control the line height between wrapped non block level elements:
<p class="payments"><small class="light">You Pay</small><abbr title="GBP">£</abbr>121.50<br><small>per month</small></p>
What I want to achieve is something like:
I don't want to rely on absolute positioning as there will be elements beneath which need to clear this and simply setting a low line-height on he paragraph results in an object which breaks out of its box, see the Fiddle below:
http://jsfiddle.net/mdHKy/2/
Any ideas?
You can first give the p a height then set its line-height to half that amount (being 2 lines).
p.payments {
line-height: 1em;
height:2em;
}
Then set the line-height of small to 1em and give that a vertical-align:
p.payments small {
line-height:1em;
vertical-align:top;
}
Then set the vertical-align of your .light:
p.payments small.light {
vertical-align:baseline;
}
JSFiddle example.

Dojo and heights of widgets

I am trying to figure out how "heights" are worked out when instancing a widget.
I am not going very far...
At the moment, I have a simple HTML page that goes like this:
</head>
<body class="claro"><div id="appContainer"></div></body>
</html>
The CSS is like this:
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
#appContainer {
height: 100%;
}
When my app starts, this happens (this is a simplification):
// Create the "application" object, and places them in the right spot.
appContainer = new BorderContainer( {} , 'appContainer');
Left as it is, the app has the right size and everything.
** Q1: why do I need to specify the height for html, body and #appContainer?
Then, I have:
// Create the new BookingDojo application
bookingDojo = new BookingDojo( { id: 'bookingDojo', region: 'center' } );
appContainer.addChild( bookingDojo );
and finally:
appContainer.startup();
BookingDojo has this CSS:
#bookingDojo {
height: 100%;
}
.bookingDojo {
height: 100%;
}
And uses this template:
templateString: '' +
'<div>' +
' <div class="bookingDojo" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design: \'headline\'">' +
' <div data-dojo-type="dijit.layout.TabContainer" data-dojo-props="region: \'center\', tabPosition: \'left-h\'">' +
' <div data-dojo-type="hotplate.bd.Settings" data-dojo-props="title: \'Settings\'">Settings</div>' +
' <div data-dojo-type="dijit.layout.TabContainer" data-dojo-props="title: \'attempt\', tabPosition: \'top\'" data-dojo-attach-point="settingsTab">' +
' <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:\'One\'">ONE</div>' +
' <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title:\'Two\'">TWO</div>' +
' </div>' +
' <div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="title: \'Two\'">Section Two</div>' +
' <div data-dojo-type="hotplate.bd.Dashboard" data-dojo-props="title: \'Dashboard\'">Section One</div>' +
' </div>'+
' </div>' +
'</div>',
Note that
class="bookingDojo"
within the widget:
** Q2: If I take out wither #bookingDojo or .bookingDojo from the CSS, the app isn't rendered properly.
I mean, I also have a problem where I cannot get the Dashboard to render properly, because it comes out with height 0, but that's a different (probably related) story for which I have added a different post.
** Q3: Can somebody please explain to me the whole "heights of widgets" issue? I am aware that widgets need startup(), and I am aware that if you create an inner-widget and it's invisible, it will need a resize(). But that's obviously not all I need to know, since I find myself struggling over and over to get a widget to appear (and I go trying CSS, doLayout, resize, etc.) so... well, I must be missing something!
Thanks a million,
Merc.
For Q1, the documentation says :
The outer size must be specified on the BorderContainer node. Width must be specified for the sides and height for the top and bottom, respectively. No dimensions should be specified on the center; it will fill the remaining space.
In your CSS, you are setting the appContainer to take the full screen, because a height of 100% means 100% of the parent element... and your structure is
<html><body><div id="appContainer">...etc
Therefore, you have to set both body and html to 100% if you want your appContainer to take 100% of the screen height...
By default, block elements are already 100% wide, so no need to set the width there...
For Q2, I suggest you have a look at your html in firebug. You will notice a div with id="bookingDojo", which will be the outmost div of your template. The first inner div has a class="bookingDojo". Again, these 2 divs are nested, and for that reason, they both need to be set to a height of 100% if you want them to fill-in the full height of their parent container div (which is your BorderContainer, which you already set to be 100% high). I made a little example here http://jsfiddle.net/psoares/7JQWC/
You will see something like your bookingDojo where I set #bookingDojo to 100% height, but didn't specify a height for the .bookingDojo class. Try to set it and you will see the red border expand...
For Q3, well, I think the whole issue here is understanding how nested boxes get their sizes, so for that you can refer to Q1 and Q2...
I hope this helps...

Keep Checkbox group items from wrapping?

I have a check box group with multiple items that may contain a space. It is a horizontal check box. What is happening is the items are wrapping where there is a space in the item.
How could I get them to not wrap?
Also how do I control the width? I tried setting the width of the control and even placed it in a panel with the width set but nothing seems to work.
Try something like this in your stylesheet for the application:
.xspCheckBox { width: 500px; /* change to your preferred width */ }
.xspCheckBox td { white-space: nowrap; }

Resources