diff --git a/src/routes/wiki/development/c/_module.svelte b/src/routes/wiki/development/c/_module.svelte new file mode 100644 index 0000000..ce29d89 --- /dev/null +++ b/src/routes/wiki/development/c/_module.svelte @@ -0,0 +1,5 @@ + + C Programming + + + diff --git a/src/routes/wiki/development/c/c-00-101.md b/src/routes/wiki/development/c/c-00-101.md new file mode 100644 index 0000000..1dd847e --- /dev/null +++ b/src/routes/wiki/development/c/c-00-101.md @@ -0,0 +1,88 @@ +#### 2024.05.20 - [Aliriza Keskin](https://github.com/sulincix) + +# C gtk tutorial + +C is one of the most fundamental programming languages. +Being a compiled language, it requires a compiler such as gcc or clang. + +## Installing compiler + +You can use `apt install gcc` command to install gcc. + +```shell +$ apt install gcc +``` + +Or you can prefer clang: +You can use `apt install clang` command to install clang. + +```shell +$ apt install clang +``` + +## Standard C Library (libc) + +Every GNU/Linux distribution comes with a libc. +Libc is the most basic library on the system, and all programs, regardless of what they are written in, eventually call libc functions somewhere. +Writing programs without using libc functions is very difficult. + +Pardus GNU/Linux prefer glibc as libc library. + +You must install **libc6-dev** package for libc development files. + +```shell +$ apt install libc6-dev +``` + +## Write Simple C application + +Lets write simple hello world program: + +```c +#include + +int main(int argc, char** argv){ + printf("Hello World\n"); + return 0; +} +``` + +### Explaining hello world + +```c +#include +``` + +- `#include ` This line is a preprocessor directive that tells the compiler to include the contents of the stdio.h header file. + This header file contains declarations for standard input/output functions like printf and scanf, which are used in the program. + +```c +int main(int argc, char** argv) { +``` + +- `int main(int argc, char** argv) {` This line defines the main function of the program. + In C, every program must have a main function, which serves as the entry point of the program. It takes two arguments: argc, an integer representing the number of command-line arguments passed to the program, and argv, an array of strings containing the actual command-line arguments. + +```c +printf("Hello World\n"); +``` + +- `printf("Hello World\n");` This line uses the printf function to print the string "Hello World" to the standard output (usually the console). + The \n represents a newline character, which moves the cursor to the next line after printing "Hello World". + +```c +} +``` + +- This closing curly brace marks the end of the main function block. + All the code within the main function is enclosed between `{` and `}`. + +### Compile code + +Compile code like this and run: + +```shell +$ gcc main.c -o main +$ ./main +>>> Hello World +``` diff --git a/src/routes/wiki/development/c/c-01-syntax.md b/src/routes/wiki/development/c/c-01-syntax.md new file mode 100644 index 0000000..8af8b64 --- /dev/null +++ b/src/routes/wiki/development/c/c-01-syntax.md @@ -0,0 +1,193 @@ +#### 2024.05.20 - [Aliriza Keskin](https://github.com/sulincix) + +# C Syntax + +C is a compiled programming language. +This means that the code needs to be translated into a form understandable by the computer it will run on. +We can compile using gcc or clang. + +```shell +# Generate .o file from code +$ gcc -c main.c +# Generate executable file from .o file +$ gcc -o main main.o +# Run the code +$ ./main +-> Hello World +``` + +In the example above, we first generate a .o object file. +This file represents the compiled but not yet executable version of the code. +Therefore, we need to pass the .o files through the linking process to get the final executable. + +Note: Our compiler can also directly compile without generating .o. + +```shell +$ gcc -o main main.c +``` + +## Commenting + +There are three ways to comment in C code: + +for single-line comments: + +```c +// This is a comment line. +``` + +for multi-line comments: + +```c +/* This + is + a + comment */ +``` + +`#if 0` for conditional comments: + +```c +#if 0 +This is a +comment +#endif +``` + +## Indentation + +Blocks in C programming are denoted by `{}`. +Indentation is not necessary but improves readability. +You can use either 4 spaces or 1 tab for indentation. + +A block has the following structure: + +```c +aaaa (bbbb) { + cccc; + ddd; +} +``` + +Note: Each line must end with a semicolon (;). + +## First Program + +When C programs are executed, the main function is called. +Below is an example main function: + +```c +int main(int argc, char** argv) { + return 0; +} +``` + + In int main, int is the return type, main is the function name. + argc specifies the number of arguments. + argv specifies the argument list. + return 0 statement exits with a status of 0. + +In C, the main function can also be defined as void. +If not using arguments, they don't need to be defined: + +```c +void main(){} +``` + +## Printing to Screen + +First, we need to include stdio.h library. +Then, we can use the printf function to print to the screen. + +The first parameter of printf is the format string, and the others specify the data to be printed. + +```c +#include + +int main(int argc, char** argv) { + printf("%s\n", "Hello World!"); + return 0; +} +``` + + In the include directive, the specified files are found in /usr/include directory. + In printf function, %s is for strings, %c is for characters, %d is for integers. + +## Variables + +Variables in C are declared as follows: + +```c +... +int number = 12; +char* text = "test"; +char character = 'c'; +float number2 = 12.42; +... +``` + +Additionally, using #define, you can replace occurrences of specified values in the code before compilation. +These values are not treated as variables because they are replaced before compilation. + +```c +#define number 12 +... +printf("%d\n",number); +... +``` + +## Arrays + +Arrays can be declared in two ways: + +Using pointers, which allows dynamic sizing. +The length doesn't need to be specified at the beginning. + +```c +int *array = {12, 22, 31}; +``` + +Or, declaring with a specified length: + +```c +int array[3] = {12, 22, 31}; +``` + +C doesn't have a string data type. +Instead, character arrays are used. + +```c +char *txt = "deneme123"; +``` + +To access an element in an array: + +```c +int *array = {12, 22, 31}; +int c = array[1]; // the second element of the array +``` + +Note: Array indices start from 0. + +To find the length of an array, you divide the total size of the array by the size of each element. +You can use the sizeof function for this. + +```c +int *array = {11, 22, 31}; +int l = sizeof(array) / sizeof(int); +``` + +## Input from Keyboard + +To receive input from the keyboard, scanf function is used. +The first parameter is the format, and the rest specify the memory addresses of the variables. + +```c +int number; +scanf("%d\n", &number); +``` + +Note: Using this method, invalid input can be entered. +If this happens, the variable will be assigned NULL, meaning it has no value. +This can cause issues in code execution. +Therefore, always check for NULL before using the variable. diff --git a/src/routes/wiki/development/c/index.md b/src/routes/wiki/development/c/index.md new file mode 100644 index 0000000..31ff918 --- /dev/null +++ b/src/routes/wiki/development/c/index.md @@ -0,0 +1,3 @@ +# C documentations + +### This section provide C related documentations. diff --git a/src/routes/wiki/development/index.md b/src/routes/wiki/development/index.md index 9b790bd..7d96bb7 100644 --- a/src/routes/wiki/development/index.md +++ b/src/routes/wiki/development/index.md @@ -1,26 +1,3 @@ -# Introduction to GTK Development with Python +# Development Area -GTK (GIMP Toolkit) is a popular toolkit for creating graphical user interfaces (GUIs) for desktop applications. It provides a set of libraries and tools to build interactive and visually appealing applications. In this introduction, we will focus on using GTK with Python, which provides a simple and elegant way to develop cross-platform GUI applications. - -## Learning Resources - -Below are some useful resources for learning GTK development with Python: - -1. [GTK4 Official Documentation](https://docs.gtk.org/gtk4/) - > For the most comprehensive and up-to-date information, the official GTK4 documentation is the go-to resource. It covers all aspects of GTK4 development in detail, including widgets, layout management, event handling, and more. - -2. [GTK4 Python (lazka) Documentation](https://lazka.github.io/pgi-docs/) - > This resource provides comprehensive documentation for the PyGObject library, which is the Python binding for GTK4. It includes detailed information on classes, methods, and properties available in GTK4, making it an essential reference for GTK development in Python. - -3. [GTK4 Python (amoleenar) Documentation](https://amolenaar.pages.gitlab.gnome.org/pygobject-docs/) - > This documentation complements the official documentation by offering more insights into GTK4 development with Python. It can be particularly helpful in understanding specific examples and use cases. - -4. [GTK3 Python (readthedocs) Tutorial](https://python-gtk-3-tutorial.readthedocs.io/en/latest/) - > Although this tutorial focuses on GTK3, it can still be valuable for beginners to understand the basic concepts of GTK development with Python. Many of the fundamental principles and functionalities remain consistent between GTK3 and GTK4, making this a good starting point for learning the basics. - -5. [Style Classes (libadwaita)](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/style-classes.html) - > While developing GTK applications, understanding style classes and their usage is crucial for creating consistent and visually appealing UIs. This resource provides insight into libadwaita's style classes, a set of CSS-like style rules that can be applied to GTK widgets. - -## Note: Updating Resources - -We are committed to keeping this guide up-to-date with the latest resources. As new documentation or tutorials for GTK development with Python become available, we will review and add them to the list above. Be sure to check back regularly for new and improved learning materials! +### You can find various development documentation here. diff --git a/src/routes/wiki/development/python/_module.svelte b/src/routes/wiki/development/python/_module.svelte new file mode 100644 index 0000000..f7dc1de --- /dev/null +++ b/src/routes/wiki/development/python/_module.svelte @@ -0,0 +1,6 @@ + + Python Programming + + + + diff --git a/src/routes/wiki/development/python/index.md b/src/routes/wiki/development/python/index.md new file mode 100644 index 0000000..9b790bd --- /dev/null +++ b/src/routes/wiki/development/python/index.md @@ -0,0 +1,26 @@ +# Introduction to GTK Development with Python + +GTK (GIMP Toolkit) is a popular toolkit for creating graphical user interfaces (GUIs) for desktop applications. It provides a set of libraries and tools to build interactive and visually appealing applications. In this introduction, we will focus on using GTK with Python, which provides a simple and elegant way to develop cross-platform GUI applications. + +## Learning Resources + +Below are some useful resources for learning GTK development with Python: + +1. [GTK4 Official Documentation](https://docs.gtk.org/gtk4/) + > For the most comprehensive and up-to-date information, the official GTK4 documentation is the go-to resource. It covers all aspects of GTK4 development in detail, including widgets, layout management, event handling, and more. + +2. [GTK4 Python (lazka) Documentation](https://lazka.github.io/pgi-docs/) + > This resource provides comprehensive documentation for the PyGObject library, which is the Python binding for GTK4. It includes detailed information on classes, methods, and properties available in GTK4, making it an essential reference for GTK development in Python. + +3. [GTK4 Python (amoleenar) Documentation](https://amolenaar.pages.gitlab.gnome.org/pygobject-docs/) + > This documentation complements the official documentation by offering more insights into GTK4 development with Python. It can be particularly helpful in understanding specific examples and use cases. + +4. [GTK3 Python (readthedocs) Tutorial](https://python-gtk-3-tutorial.readthedocs.io/en/latest/) + > Although this tutorial focuses on GTK3, it can still be valuable for beginners to understand the basic concepts of GTK development with Python. Many of the fundamental principles and functionalities remain consistent between GTK3 and GTK4, making this a good starting point for learning the basics. + +5. [Style Classes (libadwaita)](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/style-classes.html) + > While developing GTK applications, understanding style classes and their usage is crucial for creating consistent and visually appealing UIs. This resource provides insight into libadwaita's style classes, a set of CSS-like style rules that can be applied to GTK widgets. + +## Note: Updating Resources + +We are committed to keeping this guide up-to-date with the latest resources. As new documentation or tutorials for GTK development with Python become available, we will review and add them to the list above. Be sure to check back regularly for new and improved learning materials! diff --git a/src/routes/wiki/development/python-gtk-00.md b/src/routes/wiki/development/python/python-gtk-00.md similarity index 76% rename from src/routes/wiki/development/python-gtk-00.md rename to src/routes/wiki/development/python/python-gtk-00.md index 3fb07cd..b79d4a0 100644 --- a/src/routes/wiki/development/python-gtk-00.md +++ b/src/routes/wiki/development/python/python-gtk-00.md @@ -1,18 +1,24 @@ -#### 12.05.2023 - [Osman Coskun](https://github.com/osmancoskun) -# Developing Linux GUI Applications with Python and GTK4 +#### 2023.05.12 - [Osman Coskun](https://github.com/osmancoskun) + +# Developing Linux GUI Applications with Python and GTK4 Unlock the potential of Linux GUI application development using Python and GTK4. In this guide, we explore the powerful combination of Python's simplicity with GTK4's extensive widget library. Whether you're a beginner or experienced Python developer, this post provides a solid foundation to create stunning cross-platform desktop applications. Explore the core concepts, set up your development environment, build your first application, explore advanced topics, and learn about packaging and deployment. Let's improve ourselves to shape the future of Linux application development. + #### Python is very easy to read and understand programming language. All we have to do is creating a `.py` file and start coding. -* Just use your favourite text editor. You dont need an full-featured IDE to start coding. I suggest you to use ** [Visual Studio Code](https://code.visualstudio.com/) ** -* I assume that you know basic level programming on Python. So we can start by reading some documents. For documents you can use ** [this link](https://amolenaar.github.io/pgi-docgen/) ** which is GTK4 documentation for Python. Also you can use ** [Black Formatter](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter) ** Visual Studio Code extension for GTK4 widgets, their classes and functions that can be used with. -* Now create a file that ends with `.py` . For example lets say `myapp.py` -* For using GTK4 we need to import `gi` and specify GTK with version 4. Now lets add following code into our application. + +- Just use your favourite text editor. You dont need an full-featured IDE to start coding. I suggest you to use ** [Visual Studio Code](https://code.visualstudio.com/) ** +- I assume that you know basic level programming on Python. So we can start by reading some documents. For documents you can use ** [this link](https://amolenaar.github.io/pgi-docgen/) ** which is GTK4 documentation for Python. Also you can use ** [Black Formatter](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter) ** Visual Studio Code extension for GTK4 widgets, their classes and functions that can be used with. +- Now create a file that ends with `.py` . For example lets say `myapp.py` +- For using GTK4 we need to import `gi` and specify GTK with version 4. Now lets add following code into our application. + ```python import gi gi.require_version('Gtk','4.0') from gi.repository import Gtk ``` -* Now we can start using GTK widgets. But first we need a window to show our application. + +- Now we can start using GTK widgets. But first we need a window to show our application. + ```python def on_activate(app): win = Gtk.ApplicationWindow(application=app) @@ -21,9 +27,13 @@ app = Gtk.Application() app.connect('activate', on_activate) app.run(None) ``` -* Now we can run our application with + +- Now we can run our application with + ```bash python myapp.py ``` + ![Simple Window](https://raw.githubusercontent.com/pardus/pardus.github.io/main/src/lib/assets/python-gtk-00-1.png) -* We will go deeper on next posts. \ No newline at end of file + +- We will go deeper on next posts. diff --git a/src/routes/wiki/development/python-gtk-01.md b/src/routes/wiki/development/python/python-gtk-01.md similarity index 98% rename from src/routes/wiki/development/python-gtk-01.md rename to src/routes/wiki/development/python/python-gtk-01.md index 8d814ab..7d74c9f 100644 --- a/src/routes/wiki/development/python-gtk-01.md +++ b/src/routes/wiki/development/python/python-gtk-01.md @@ -1,4 +1,4 @@ -#### 26.05.2023 - [Osman Coskun](https://github.com/osmancoskun) +#### 2023.05.26 - [Osman Coskun](https://github.com/osmancoskun) # Utilizing GTK Containers for Linux GUI Application Development with Python @@ -52,7 +52,6 @@ app.run(None) Now, let's create a button called Button: - ```python button = Gtk.Button(label='Button') ``` @@ -73,7 +72,6 @@ box.append(button) Currently, we have a box with a button in it. We can set this container as a child of our application: - ```python win.set_child(box) ``` @@ -85,6 +83,7 @@ To adjust the size of our application window, we can set a fixed size by definin ```python win.set_size_request(200, 200) ``` + ![](https://raw.githubusercontent.com/pardus/pardus.github.io/main/src/lib/assets/python-gtk-01-2.png) Below is the complete code: