tkinter: revoke clickthrough - python-3.x

when you want to make a window and its elements clickthrough-able one will probably use code like that:
label = Label(root)
hwnd = label.winfo_id()
styles = win32gui.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
styles = win32con.WS_EX_LAYERED | win32con.WS_EX_TRANSPARENT
win32gui.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, styles)
win32gui.SetLayeredWindowAttributes(hwnd, 0, 255, win32con.LWA_ALPHA)
Note: you need to use the handle of the elements (here: label) and not the handle of the window (here: root)
assuming background of Window is alredy transparent:
root.config(bg='#000000')
root.attributes('-transparentcolor', '#000000')
Now the Question: how do I revoke the clickthrough? I assume its something like:
def revoke_click_through(hwnd):
... #maybe work with new styles?
win32gui.SetWindowLong(hwnd, ... )
win32gui.SetLayeredWindowAttributes(hwnd, ... )

Related

navigation tilemaps without placing walkable tiles manually

I have a tilemap in godot, but all tiles are obstacles and provide collision. Only cells without any tile are walkable. I'm now trying to add navigation via Navigation2D node. As far as I see there is no way to tell it "everything is walkable, but not where these tiles are" (all one can say is "this part of the tile is walkable", but in my current setup there is no tile at the walkable space).
As a workaround I tried to set every cell with no tile to a "dummy tile" which is fully walkable with the following code:
func _ready():
for x in size.x:
for y in size.y:
var cell = get_cell(x, y)
if cell == -1:
set_cell(x, y, WALKABLE)
But the Navigation2D node does not recognize these tiles. If I place the WALKABLE tile manually, everything works as expected.
I think I might be hitting this issue, and need to call update_dirty_quadrants() but this does not fix the problem.
I tried this with the versions 3.0.6stable, 3.1Alpha2 and a recent commit 9a8569d (provided by godotwild), and the result was always the same.
Is there anyway to get navigation with tilemaps working, without placing every tile beforehand manually?
For anyone coming across this in the future, the 'dummy navigation tile' solution works now (using Godot 3.2.3). Put this script on the tilemap in question:
extends TileMap
# Empty/invisible tile marked as completely walkable. The ID of the tile should correspond
# to the order in which it was created in the tileset editor.
export(int) var _nav_tile_id := 0
func _ready() -> void:
# Find the bounds of the tilemap (there is no 'size' property available)
var bounds_min := Vector2.ZERO
var bounds_max := Vector2.ZERO
for pos in get_used_cells():
if pos.x < bounds_min.x:
bounds_min.x = int(pos.x)
elif pos.x > bounds_max.x:
bounds_max.x = int(pos.x)
if pos.y < bounds_min.y:
bounds_min.y = int(pos.y)
elif pos.y > bounds_max.y:
bounds_max.y = int(pos.y)
# Replace all empty tiles with the provided navigation tile
for x in range(bounds_min.x, bounds_max.x):
for y in range(bounds_min.y, bounds_max.y):
if get_cell(x, y) == -1:
set_cell(x, y, _nav_tile_id)
# Force the navigation mesh to update immediately
update_dirty_quadrants()
I couldn't find the ID from my tile in the autotiler (when checking in the editor, having the tilemap selected, these all show the same imagename.png 0). So instead of using the ID, I used the coordinates of the walkable blank tile in the Tileset. The code remains the same as LukeZaz', but with set_cell replaced by:
set_cell(x, y, 0, false, false, false, Vector2(7,4)); where Vector2(7,4) is the coordinate of the blank tile in my tileset that has the navigationpolygon on it. (Remember that coördinates start at 0)
(Godot 3.2.3.stable)

Implementing conditionals and loops in Tkinter GUI

I need to add an IF statement, FOR and WHILE loop in my form, can someone add some kind of IF statment, FOR and WHILE loop in my code?
from tkinter import * # Ingress all components from Tkinter
mGui = Tk()
mGui.geometry('400x400') # The size of the form window
mGui.title('Registration Form',)
def response():
label3 = Label(text='Thank You!',fg='White', bg='Purple',font='none 16 bold').place(x=140,y=300) # The colours and font style and size used for the response
mlabel = Label(text='Registration Form',fg='White', bg='Purple',font='none 18 bold underline') # The colours and font style and size used for the form title
mlabel.pack()
mlabel2 = Label(text='Forename',fg='White', bg='Purple',font='times 14 bold').place(x=0,y=100) # The colours and font style and size used for the label
mlabel3 = Label(text='Surname',fg='White', bg='Purple',font='times 14 bold').place(x=0,y=150) # The colours and font style and size used for the label
mbutton = Button(text = 'Submit',command = response).place(x=150,y=250) # Location of the the button 'submit' using the x and y axis
mGui.configure(background='Green') # Background colour of the form
mEntry = Entry(bg='White').place(x=100,y=100)
mEntry = Entry(bg='White').place(x=100,y=150)
mGui.mainloop() # The code iterates
Tkinter programs are event-driven, like all GUIs that I know of.
The only place where you can execute your own code is in callbacks or timeouts.
If you want to check the contents of the entry windows, you could do that in at least two ways:
Write a callback function for the Submit button that retrieves the contents of the entry windows and validates them. You could e.g. use a messagebox telling the user that the entries are not valid.
You could also set up the entry windows to validate themselves when a key is pressed. I've used this to e.g. make the text or background of an entry window red if it contains invalid text. You could also put a tip in a Label below the entry windows, like "Both Forename and Surname must at least contain one character."

Fl_Scroll initial scroll values

I'm using FLTK for a project (the version distributed with Debian/sid 1.3.2-6+b1) and I'm having some trouble initializing Fl_Scroll's content scroll values.
I create a Fl_Double_Window and on the right side a vertical panel using Fl_Scroll, it is positioned at left x 600 and top y 24.
Then I set Fl_Scroll's type to Fl_Scroll::VERTICAL and place a Fl_Button inside, everything works fine.
The problem? Fl_Scroll initialize already scrolled with xposition() = 600 and yposition() = 24 (X and Y of the Fl_Scroll's constructor?? Is supposed to work so?), instead I want it to initialize with content scrolled at left and top 0, 0, so I tried scroll_to() in different places, before and after window's show(), on FL_SHOW of the subclassed Fl_Scroll (I didn't really need to subclass Fl_Scroll, just trying to get scroll_to() working), also on overridden draw() after
the parent draw(), even creating Fl_Scroll at 0, 0 then position() at 600, 24, but nothing.
The only way I got scroll_to() working is if I call it from an async event after the application initialize (FL_KEYUP).
Here's the overridden Fl_Double_Window window constructor:
group = new Fl_Group(0, 0, WIN_W, WIN_H);
{
menu = new Fl_Menu_Bar(0, 0, WIN_W, MENU_H);
menu->add("File/Quit", FL_CTRL+'q', cbMenuQuit_i);
glview = new CGLView(0, MENU_H, WIN_W-PROPS_W+1, WIN_H-MENU_H);
group->resizable(glview);
scroll = new CScroll(WIN_W-PROPS_W, MENU_H, PROPS_W-1, WIN_H-MENU_H);
scroll->type(Fl_Scroll::VERTICAL);
{
Fl_Pack *pack = new Fl_Pack(0, 0, PROPS_W-1, WIN_H-1);
{
btnAddLayer = new Fl_Button(0, 0, PROPS_W, 32, "##+ Add Layer");
btnAddLayer->callback(btnAddLayerCb_i, (void *)this);
}
pack->end();
}
scroll->end();
}
group->end();
end();
size_range(WIN_MIN_W, WIN_MIN_H); /* Make the window resizable */
show();
Never mind, got it, two altenative:
create Fl_Scroll at 0, 0 then position() it after scroll->end()
create Fl_Scroll at the wanted position then after scroll->end() use negative values scroll_to(-X, -Y)
In both cases is important that the widgets contained are already added (scroll_to() alter cotained widgets coords)
Isn't clear to me why X and Y of Fl_Scroll's constructor are used.

Xamarin.Forms get standard color of TextCell's label

I have a custom ViewCell with a StackLayout like this:
var viewLayout = new StackLayout () {
Padding = new Thickness (10, 0, 10, 0),
Orientation = StackOrientation.Horizontal,
Children = { nameLabel, button1, button2 }
};
When I use Xamarin.Forms standard ViewCells, i.e "TextCell", the label will get a blueish color on Android. My questions is: Where can I find this property? I want to set it to my custom nameLabel like this:
nameLabel.TextColor = TextCell.StandardTextColorForCurrentPlatform;
For TextCells:-
On Android you can get this value via Color.Accent.
On WindowsPhone use the system-defined PhoneForegroundBrush.
iOS appears to be hard coded to black.
You can write a simple DependencyService to return the appropriate color per the platform your executing on.

Manipulate pixels in QGraphcisPixmapItem

I am using PyQt to build a small application for viewing images. When I click on the image I would like to alter the color of the pixels I have clicked:
Schematically my current code looks like this:
scene = QtGui.QGraphicsScene()
view = QtGui.QGraphicsView( scene )
image = QtGui.QImage( "image.png" )
pixmap = QtGui.QGraphicsPixmapItem( QtGui.QPixMap.fromImage( image ))
scene.addItem( pixmap )
...
...
def mousePressEvent(self , event):
print "Click on pixmap recorded - setting Pixel to red"
image.setPixel( event.pos() , RED.rgb())
The code 'works' in the sense that the mousePressEvent() method is called, and the image.setPixel() method does not give any errors, but nothing happens on the screen. Any tips on how to get the updated pixels to be displayed?
Joakim
To make changes appear, you need to reload image
self.image.setPixel(event.pos(), RED.rgb())
self.pixmap.setPixmap(QtGui.QPixmap.fromImage(self.image))
But I'm not sure that it's a good way. If you don't need to save modified image, I'd add some circles (e.g. addEllipse) instead modifying pixels.
Also, don't forget to map window coordinates to image.

Resources