How to Create File Chooser in Gtk using gotk3 ?

If you just want the complete code snippet, here is it. package main import ( "github.com/gotk3/gotk3/gdk" "github.com/gotk3/gotk3/gtk" ) func main() { gtk.Init(nil) win, _ := gtk.WindowNew(gtk.WINDOW_TOPLEVEL) win.SetTitle("sample app") win.Connect("destroy", func() { gtk.MainQuit() }) grid, _ := gtk.GridNew() win.Add(grid) imgview, _ := gtk.ImageNew() pbuf, _ := gdk.PixbufNewFromFileAtScale("./img/default.png", 400, 400, true) imgview.SetFromPixbuf(pbuf) grid.Attach(imgview, 0, 0, 1, 1) textentry, _ := gtk.EntryNew() grid.AttachNextTo(textentry, imgview, gtk.POS_BOTTOM, 1, 1) btnChoose, _ := gtk.ButtonNewWithLabel("Choose An Image") grid.AttachNextTo(btnChoose, textentry, gtk.POS_BOTTOM, 1, 1) btnChoose.Connect("clicked", func() { dlg, _ := gtk.FileChooserDialogNewWith2Buttons( "choose an image", nil, gtk.FILE_CHOOSER_ACTION_OPEN, "Open", gtk.RESPONSE_OK, "Cancel", gtk.RESPONSE_CANCEL, ) dlg.SetDefaultResponse(gtk.RESPONSE_OK) filter, _ := gtk.FileFilterNew() filter.SetName("images") filter.AddMimeType("image/png") filter.AddMimeType("image/jpeg") filter.

How to Shutdown your PC using Python ?

If you want to shutdown your Windows PC from your Python code, just use this code snippet. import os os.system("shutdown /s /t 1") That’s it. I hope this helps. Do you recommend reading this blog post? share it!

How to Shutdown PC using C++ ?

If you want to shutdown your Windows PC from your C++ code, use this code snippet. #include <stdio.h> #include <stdlib.h> int main() { system("c:\\Windows\\system32\\shutdown /s"); return 0; } I hope this helps. Do you recommend reading this blog post? share it!

How to Fix (main:30677): Gtk-WARNING **: cannot open display: ?

If you are facing this error (main:30677): Gtk-WARNING **: 05:40:47.665: cannot open display: just install Gtk+ development library, and set the display screen to 0. Installing Gtk+ using Homebrew If you are using a UNIX-like OS such as Mac OS X, or a Linux distribution. You can use Homebrew package manager to install Gtk+ as following. brew install Gtk+ Install Gtk+ using apt If you are using Debian, Ubuntu, Elementary OS, Linux Mint, .. You can use this command to install Gtk+. sudo apt-get install libgtk-3-dev Set DISPLAY Environment Variable If the error persists, just run this command on terminal to set the display to the current display/monitor/screen.

How to Tune Garbage Collector in Go Language ?

How to set the GOGC value ? You can set its value in the terminal like this. GOGC=200 Or you can change it in yaml file of the environment variable when using docker or kubernetes. What is the default value of GOGC ? The default value of GOGC is 100 which means that the garbage collection process will run when the allocations doubled from previous allocations count. What can I do to reduce the effect of garbage collection in Go ? If your Go program has a large static data set, set the GOGC to a smaller percentage; for example GOGC=50.

How to Draw Rectangle on Imageview ?

If you already have a bitmap image in your code, just use this code snippet. bmp = bmp.copy(Bitmap.Config.RGB_565, true); That code will recreate the bitmap image as a mutable. So you can edit that bitmap image on canvas as you like. But if you do not have a bitmap image in code, create a new one using this code snippet. Bitmap bmp=Bitmap.createBitmap(img.getHeight(),img.getWidth(),Bitmap.Config.RGB_565); where img is another bitmap image you want to make a new one with the height and width of it. If you want to create one from scratch here is the code snippet. Bitmap bmp=Bitmap.createBitmap(400,700,Bitmap.Config.RGB_565); After that, create a canvas and pass the bitmap image you have.

Linux Laptop Boot Battery Optimizations

Boot Optimization use sudo systemd-analyze critical-chain to get the most time consuming services. If you don’t need those services just disable them by this command sudo systemctl disable service-name.service and replace the service-name with the name of the service you want to disable. BIOS Optimization Just disable any feature you do not use such as fingerprint scanner. To reboot into your BIOS settings, use this command sudo systemctl reboot --firmware-setup. Battery Optimization Use tlp to manage your battery, and use powertop to get the power consumption statistics. Install tlp and powertop using this command sudo apt install tlp powertop. To enable tlp to manage your laptop battery, run this command in terminal sudo systemctl enable tlp.

Ubuntu boots to black screen after trying to install proprietary Nvidia graphics driver

The problem occured after installing proprietary Nvidia graphics driver using those commands. sudo apt-get update && clear && apt-cache search nvidia-[0-9] | grep 'binary driver' sudo apt-get purge nvidia* sudo apt-get install nvidia-340 nvidia-settings sudo nvidia-xconfig The fix is to let the built-in ubuntu-drivers program decide automatically which graphics driver to install. Open the terminal and type this command to update the apt repositories. sudo apt update Then, remove all packages started with nvidia using this command. sudo apt remove '^nvidia' After that, let the apt remove not needed packages automatically using this command. sudo apt autoremove Finally, let ubuntu-drivers automatically install the suitable proprietary Nvidia graphics driver for your GPU.

How to Create Bash Function ?

First step: create a utilities.sh file to add all your bash functions in it. 2nd step: add your bash function/s like this. ## utilities.sh convertMP4toMP3(){ echo -n "Enter source mp4 file : " read sourceFile echo -n "Enter destination mp3 file : " read destFile avconv -i $sourceFile -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 $destFile } I created a bash function to convert mp4 video file to mp3 audio file from command line. 3rd step: source the utilities.sh Bash file source utilities.sh Finally, you can call the function from the command line (terminal) and use it like this.

Convert Mp4 to Mp3 in Linux Terminal

First things first, install the required software packages. sudo apt-get install ffmpeg && sudo apt-get install libavcodec-extra-53 Then use it. For FFmpeg with Constant Bitrate Encoding (CBR) ffmpeg -i video.mp4 -vn \ -acodec libmp3lame -ac 2 -ab 160k -ar 48000 \ audio.mp3 or if you want to use Variable Bitrate Encoding (VBR) ffmpeg -i video.mp4 -vn \ -acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 \ audio.mp3 If it says ffmpeg is depricated use this command instead. avconv -i video.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 audio.mp3 The meaning of arguments argv meaning -i input file name -vn disable video recording -acodec force audio codec to libmp3lame -ac set the number of audio channels -ar set the audio sampling frequency I hope this helps.