Git Product home page Git Product logo

gtk4pythontutorial's Introduction

🌌

Hi there friend. I hope you're having a good evening.

Mmm whats what? Software? I might have some around here somewhere.

gtk4pythontutorial's People

Contributors

bor-real avatar julius-gu avatar jummit avatar lunarmagpie avatar markochk avatar mijorus avatar sigmasd avatar taiko2k avatar vikdevelop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gtk4pythontutorial's Issues

Serious Warning

WARNING: Before people spend too much effort on this, please read this: https://www.bassi.io/articles/2022/12/02/on-pygobject/

I appreciate your efforts, but be warned.

A few years back when pygtk was the shit, I started writing a few modules to make my work with the gnome desktop more comfortable. Most of the modules are written with PyGObject/GTK 3. This week I came back to maintain it; After some hours of work I stopped. If I find the software really useful I wont write it in Python anymore. Good for prototyping, bad for LTS.

Click in Entry

Thank you for this tutorial. Until today I haven't found one for gtk4, so this is a blessing.

Currently I'm struggling with a simple question: how to detect a mouse button click in an Entry?

(I want to open a popup when left-click inside an Entry).

In GTK3, I did (in my entry class):

        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.connect("button-press-event", self.onClick)

but GTK4 doesn't have "button-press-event", right?

After some search, I managed to do something like this:

        self.leftClick = Gtk.GestureClick()
        self.leftClick.set_button(1)
        self.leftClick.connect("pressed", self.onClick)
        self.add_controller(self.leftClick)

but the callback works only when I click on the entry's border, but not in the text field.

It would be nice to know how it works.

Non-functioning code in the "Open with" and single instancing section.

I have been following this tutorial to make my side project and it has been very helpful. But the code
if not self.win: in the "Open with" and single instancing section gave me an error AttributeError: 'App' object has no attribute 'win'.. My understanding is i should use hasattr() instead?

indicate some in python

"I need help learning how to use icons, titles, background images, and search bars in a Python GTK application. Can you help me find some tutorials on this topic?"

UI from XML

This seems a very important point. This tutorial has been extremely helpful to me thus far!

I'd love to see UI from XML implemented soon.

[Documentation / Example] Could a specific example for events be added?

Hey there,

Would it be possible to add a specific example for events?

That includes buttons - this is easy.

But it would be nice if more events could be showcased, such as
how to respond to mouse-click events in different widgets,
including a gtk entry and a gtk label.

And perhaps a few more examples.

This would be helpful for people who port older code from e. g. gtk3 to see
how things changed in regards to events. The new event model still
confuses me and is one reason I failed to transition into gtk4 so far.

[Documentation] How to install python-gtk4?

Could your guide briefly show how to install it e. g. the pip command?

I only had it for python gtk3 I think. I am so lazy, I could google but
I prefer it in the guide if that is possible.

Adding an application icon

Has anyone had success with adding an application icon for Wayland sessions? I'm posting this issue both to ask for help and to show what I've done so far.

The "right" way to do it

GTK4 applications are expected to follow the Freedesktop Icon Theme Specification. Icons should be installed to the icon directory, typically /usr/share/icons or ~/.local/share/icons. The icon is supposed to be named according to the application ID, such as com.example.myapp.svg

Then the application icon can be set for a window by using the set_icon_name method.

my_window = Gtk.Window()
my_window.set_icon_name("com.example.myapp")

However, this doesn't work for all use cases, such as AppImages. When using an AppImage intergration program like AppImageLauncher, icons are saved to the desktop with a hash, using a format similar to appimagekit_3e227aae859f2298ca6d5802f48f6f5b_com.example.myapp.svg so these icons won't be found using the above code. There is, however, a workaround.

The workaround

By adapting some code found in this StackExchange question, we can get an icon to show for our application.

icon_theme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default())
icon_theme.add_search_path("/path/to/resource/directory")

This, in addition to the earlier code block for our window, will allow us to add an icon for our application. There's one problem, though. Adding an application icon only seems to work for Xorg sessions. I've been unsuccessful at getting this method to work for Wayland.

I'm honestly a bit stumped with this one. Anyone have a clue as to how to get this working?

Extending the 'Adding a button into the header bar' section

I have some tips / information based on trial and error that I think could help extend this section a little bit.

Firstly, in this part, you say:

'If you were adding a new action icon it would go in /usr/share/icons/hicolor/scalable/actions'

However, this is only good if you're using default icons, and is no good if you have a theme set that's not hicolor.

A better way (to the best of my knowledge) to explain using symbolic icons would be that it will look for an svg matching the
specified svg name, in the currently set theme, so if you have for example a custon svg you want for a button, and your theme is Yaru, you would copy your svg to /usr/share/icons/Yaru/scalable/actions, than reference its name.

You can also replace a button other than a header bar one with an image with set_icon_name.
Adwaita has 'Adw.ButtonContent for adding an icon next to a label, which may also be worth looking into adding if interested.
I hope this was helpful.

'gi.repository.Gtk' object has no attribute 'FileDialog' error

Things are going along hunky-dory in this rather nice tutorial until I hit the 'Adding a file chooser' section. I then see the error mentioned in the title. Below is the snippet with the pre and post couple of lines. What am I missing other than the "FileDialog attribiute"? Thanks.

        self.open_button.connect('clicked', self.hello)
        self.open_button.set_icon_name("document-open-symbolic")

        self.open_dialog = Gtk.FileDialog.new()
        self.open_dialog.set_title("Select a File")

    def show_open_dialog(self, button):
        self.open_dialog(self, None, self.open_dialog_open_callback)

how to set app icon

image
i need app icon indicate in gtk4.0 in python all the whole version is completed can you help me

Adw.AboutWindow codeblock explaination

in the 'Better About Window' tab, you showcase some code for an adwaita AboutWindow, but (unless I missed it, and I checked code examples) I can't find a complete usage example of that, and the documentation isn't too much help since it's all for C....

Would you be willing to show an Adw.AboutWindow example that shows where the:     
dialog = Adw.AboutWindow(transient_for=app.get_active_window())
and following line(s) are defined?

I was able to make an about window with the section for Gtk.AboutDialouge, but I don't understand the small 'dialog' snippets for the Adw.AboutWindow

A couple of minor points

Apologies for not providing a patch, but a few points.

  1. For rects I have to do it differently to make it work. For some reason your method just does not work for me, although it is seemingly the same thing.
Graphene.Rect().init(x1, y1, x2, y2)
  1. In the RoundedRect section you mention that a radius of 360 makes a circle, as this is per one corner a radius of 90 makes for a circle.
  2. See https://gitlab.gnome.org/GNOME/pygobject/-/merge_requests/196 for the Gdk.RGBA override being restored for GDK4. This allows for Gdk.RGBA(r, g, b, a) to work again. Also, for some more of these newer types overrides need to be added to make it cleaner to access them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.