While walking through my GSOC proposal idea, one question that i have find out on multiple platform is “How can I create xfce-panel-plugin in python, javascript or vala”.
so, Now time have come around to give you basic idea or overview about xfce-panel-plugin development in programming language other than C.
With the release of Xfce-panel 4.4, support have been added to create plugin in two ways: Internal and External Plugin.
Internal Plugins are loadable plugins that are developed using GModule Interface.
External Plugins are individuals program which are embedded into Xfce-Panel through GtkSocket and GtkPlug concept.
Here is list of Internal and External plugins.
Xfce4-Panel Internal Plugin
- Workspace Switcher – Switch between virtual desktops
- Launcher – Program launcher with optional menu
- Notification Area – Area where notification icons appear.
- Clock – a clock for the panel.
- Application Menu – Adds a menu containing categories of installed applications
Xfce4-Panel External Plugin
- Calculator – a calculator plugin for the Xfce4 panel.
- Clipman – A clipboard manager for Xfce
- Eyes – Eyes that spy on you.
- Notes – provides sticky notes for your desktop.
- Weather – Shows the current temperature and weather condition, using weather data provided by xoap.weather.com
If you are working with C or Vala programming language, You can go out for plugin development using both of methods, it just a matter of your choice.
But, If you are trying to develop Xfce-panel-plugin through Python or JavaScript then Using GtkPlug and GtkSocket approach is more feasbile for developers.
There is small logic behind it, you can develop most of the part of the plugin through Python or Javascript but while registering down developed plugin, you will face one biggest problem that is registration through Macros, i.e You can’t access macros inside Python and Javascript, so this was the reason i was suggesting you to prefer GtkSocket and GtkPlug method with these two programming language.
Example for Gtk Socket and Gtk Plug using python
#!/usr/bin/python """ General flow of program Entry widget -> GtkPlug -> GtkSocket -> Window """ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk import sys def perform_embed_event(widget): print("This will get called when plug will emit embedded signal") # initialize GtkSocket window = Gtk.Window() window.show() # initialize GtkSocket socket = Gtk.Socket() socket.show() window.add(socket) # store socket id in socket_id variable socket_id = socket.get_id() print("socket", socket_id) # initialize GtkPlug plug = Gtk.Plug.new(socket_id) # Different Plug signals plug.connect("embedded", perform_embed_event) plug.connect("destroy", Gtk.main_quit) print("Plug ID:", plug.get_id()) # Entry Widget entry = Gtk.Entry() entry.set_text("Xfce GSoC 2021") # Add entry widget into plug plug.add(entry) plug.show_all() Gtk.main()
Above mentioned example contain four different things i.e GtkPlug, GtkSocket, Entry Widget and window.
Program Output:
In general term, Entry widget is added to GtkPlug. Through GtkSocket ID, GtkPlug have been added to it. And GtkSocket have been added to the window.
One tryout If you want to.
GtkSocket is dependent on window, If you don’t add socket to window, you would not be able to generate socket id through ‘get_id’, logic is very simple behind this thing, I want to you think about the logic behind it :).
Through this program, I have tried to give you an idea how does GtkPlug and GtkSocket works inside a single window. This program is totally based on single programming language that is python, In the next blog post we will try out GtkSocket in one programming language and GtkPlug in other programming. It will be a combination of GtkSocket in C and GtkPlug in Python and After That, Dbus concept is coming up next.
Update: Special Thanks to @dmytrokyrychuk for making me notice some bug inside a attached code snippet.
Pingback:Final blog during GSOC 2021 with XFCE – FreshlyBuilt.com
I am getting the following error message when I try to run the Python code from the article: Gtk-CRITICAL **: 12:07:52.524: gtk_socket_get_id: assertion ‘_gtk_widget_get_anchored (GTK_WIDGET (socket))’ failed
The entry widget is not rendered, I am seeing an empty window instead. What am I doing wrong?
Thanks for commenting out, code snippet have been updated now you can try it, Hope so it will work now as per expectation.
Pingback:XFCE-PANEL-PLUGIN development using Python/Javascript – Part 2 – FreshlyBuilt.com