...

Gtksharp что это за программа

GtkSharp

GtkSharp is a C# wrapper for Gtk and its related components. The component list includes the following libraries: glib, gio, cairo, pango, atk, gdk. This is a fork of https://github.com/mono/gtk-sharp and is maintained completely separately from that project.

Differences can be seen with the following table:

Building from source

Pre requirements for building from source are that you have .Net 6 installed on the system.

To build the repository, simply do:

git clone https://github.com/GtkSharp/GtkSharp.git cd GtkSharp dotnet tool restore dotnet cake build.cake 

A breakdown on how the source is structured:

  • Tools that are needed to generate wrapper code are found in Tools folder
  • The actual wrappers code is found in Libs folder
  • Templates are located in Templates folder
  • Build script is separated between build.cake and CakeScripts folder

Using the library

On macOS, you’ll need to manually install Gtk, see Installing Gtk on Mac wiki page for more details on how to do it.

Available NuGet packages:

To create a new gtk app project, simply use dotnet new templating engine:

  • install: dotnet new —install GtkSharp.Template.CSharp
  • uninstall: dotnet new —uninstall GtkSharp.Template.CSharp
  • generate project: dotnet new gtkapp

License

GtkSharp and its related components are licensed under LGPL v2.0 license, while Samples are licenced under The Unlicense.

GtkSharp

Gtk# is a Graphical User Interface Toolkit for mono and .Net. The project binds the gtk+ toolkit and assorted GNOME libraries, enabling fully native graphical Gnome application development using the Mono and .Net development frameworks.

  • Frequently Asked Questions
  • Contacting the Mono/Gtk# Team
  • Bug reporting

References

  • Online API Documentation
  • What’s New?
  • Release Plans
  • Articles and Tutorials on Gtk#
  • Gtk# Widget Overview
  • GTK# Component Descriptions

Features

  • Multi-platform (UNIX, Windows, MacOS).
  • Wide range of Widgets/Controls.
  • Accessible via the ATK accessibility toolkit.
  • Internationalization.
  • Available from C#, Java, Python, VB.Net and more.
  • UI Builder support.
  • Open Source, Free Software.

Gtk# in the Real World

Md2.png

Want to know how Gtk# is being used in the real world?

Check out some screenshots of Gtk# Applications. Some of our more prominent users include:

Availability

Our current stable release targets the GNOME 2.20 release.

Current Source Releases:

Sources for releases up to 2.12.10 are available from GNOME FTP, while later 2.12.x releases are only available from MONO DOWNLOAD.

Source packages for GTK#3 beta releases (2.99.x) are only available from GNOME FTP.

GtkSharp — Part 1 — Cross Platform Toolkits

I decided to have a look into the different toolkit’s available for writing .Net code with a GUI that can be used across multiple platforms. Some of these platforms would include Microsoft Windows 10, Linux and embedded devices such as the Raspberry Pi

I’ve posted some example code here for GtkSharp

There were four main options I looked into

  • WinForms
  • QtSharp
  • Eto.Forms
  • GtkSharp

WinForms

winformsimg

Winforms is traditionally the toolkit used by Microsoft for .Net / with Visual Studio, it dates back to the good old VB6 days. The Xamarin and mono team have put a lot of work into making sure that that this toolkit can run on both windows and Linux via mono. However, when you google Winforms and cross compatibility it looks as if the main focus is now on GTK instead as the main alternative. The one main advantage to Winforms is that it’s designable via Visual Studio’s inbuilt GUI. Upon googling most of the opinions online, the code base has been largely untouched for a long while on the mono side.

QtSharp

QtFormImage

Qt for me has the best looking toolkit, also it has QML which is a form of descriptive language for describing the layout of forms similar in some respects to Xaml. There’s been a few different attempts at a .Net binding for Qt, first there was a very old project called QtSharp, then another project to replace that one called Qyoto which seems to have now been abandoned, and finally the latest incarnation which has re-used the name of QtSharp.

QtSharp uses the CppSharp library as a way of generating the bindings from the c++ Qt libraries into the .Net space. At this stage it’s still very new and in alpha state, after testing it myself it does appear to actually be able to create and show windows, however there are a couple of gotcha’s still.

  • The code is still in Alpha state, which means it may be a while before it’s ready for production
  • Currently CppSharp doesn’t support templated functions (c++ generics) so certain function calls and properties are currently unavailable (such as iterating over the child controls within a form or container)
  • QML based apps are going to require some special coding before they can be used from .Net

I’m still hopeful this will be useful in the future since I’m quite keen on Qt. Looking at some of the c++ projects online there seems to have been a lot of talk of projects moving from Gtk to Qt due to issues with the newer versions of Gtk and it being largely Gnome focused. For now, it still needs a lot of work however.

For some example code to experiment with QtSharp

You may also want to check out the official repositories (the gitlab repo is the most up-to-date one)

  • https://github.com/mono/CppSharp
  • https://gitlab.com/ddobrev/QtSharp
  • https://github.com/ddobrev/QtSharp

Eto.Forms

EtoFormsImg

Eto.Forms was the next toolkit I looked into. It’s basically a wrapper that sits on top of other toolkits such as windows forms, GtkSharp, WPF, etc. It’s one advantage is that it has the ability to create forms based on Xaml similar to WPF Forms

There are a couple of downsides though

  • The range of controls for containers is still a bit limited
  • Currently there’s no GUI / drag and drop designer, but there is a window to preview the rendered Xaml

GtkSharp

GtkSharpImg

The final toolkit I tried looking into was GtkSharp. This seems to be a lot more mature than the other toolkits in relation to .Net with bug fixes and patches. There does seem to be a bit of confusion over which version to use and how to set it up. After a fair bit of digging around online I finally managed to figure out how to get a basic GTK3 based GtkSharp Application up and running under .Net. Given that some of the documentation is still a bit sparse when it comes to the GTK3 version I figured I’d put some information up on how to get it going with Visual Studio.

One advantage to GtkSharp which I’m also interested in is the use of cairo for vector graphics, there’s also some unofficial methods of getting it to work with Monogame which is a cross platform 3D library originally based on XNA.

  • GTK-Sharp — The Main .Net library for creating GTK based GUI Applications
  • GLIB-Sharp — Glib Sharp is a library used by GTK for Core Functionality such as memory management
  • GDK-Sharp — Gimp Drawing Kit, this is a low level drawing library used by GTK for graphics rendering
  • GIO-Sharp — The Gio library deals with low level Gnome IO for File system / Network / Process Handling / DBUS / Application Settings
  • Cairo-Sharp — Cairo can be used for 2D Vector graphics
  • Pango-Sharp — pango handles all of the font and text related functions for GTK
  • ATK-Sharp — atk deals with accessibility
  • Open-GL with Cairo

GTK Versions

After a bit of digging around online there appears to be two versions of GtkSharp available at the moment. One for GTK2 and one for GTK3

GTK2

The one for GTK2 is probably more stable and widely used, but the one I’m interested in here is the GTK3 version. If you look for the default windows .msi installer on the mono site

This is actually the older GTK2 version which installs under «C:\Program Files (x86)\GtkSharp\2.12\» on Windows. The official GitHub account for GtkSharp seems to mirror this (latest version 2.12.30)

GTK3

If you look for the NuGet packages online NuGet Link. As far as I can tell I think these versions are unofficial (although quite useful)

  • GtkSharp (3.1.3) — GTK3 .Net libraries
  • GtkSharp.Win32 — GTK3 C libraries for Windows
  • GtkSharp.Linux — GTK3 C libraries for Linux

This is the version I’ll be using in the following articles. I suspect although I’m not entirely sure that the source code for this version is based on the below GitHub Link.

При подготовке материала использовались источники:
https://www.opensourceagenda.com/projects/gtksharp
https://www.mono-project.com/docs/gui/gtksharp/
https://grbd.github.io/posts/2016/01/28/gtksharp-part-1-cross-platform-toolkits/

Оцените статью