Is there any replacement for "GtkRuler" in GTK3? - gtk3

I want to display the horizontal and vertical ruler on the frame with gtk3.
this is my frame:
I want to display ruler on the frame like this:
BUT GtkRuler has been removed from GTK 3 for being unmaintained and too specialized!!
this is my GTK3/c cpde:
/* The horizontal ruler goes on top. As the mouse moves across the
* drawing area, a motion_notify_event is passed to the
* appropriate event handler for the ruler. */
hrule = gtk_hruler_new ();
gtk_ruler_set_metric (GTK_RULER (hrule), GTK_PIXELS);
gtk_ruler_set_range (GTK_RULER (hrule), 7, 13, 0, 20);
g_signal_connect_swapped (area, "motion_notify_event",
G_CALLBACK (EVENT_METHOD (hrule, motion_notify_event)),
hrule);
gtk_table_attach (GTK_TABLE (table), hrule, 1, 2, 0, 1,
GTK_EXPAND|GTK_SHRINK|GTK_FILL, GTK_FILL, 0, 0);
/* The vertical ruler goes on the left. As the mouse moves across
* the drawing area, a motion_notify_event is passed to the
* appropriate event handler for the ruler. */
vrule = gtk_vruler_new ();
gtk_ruler_set_metric (GTK_RULER (vrule), GTK_PIXELS);
gtk_ruler_set_range (GTK_RULER (vrule), 0, YSIZE, 10, YSIZE );
g_signal_connect_swapped (area, "motion_notify_event",
G_CALLBACK (EVENT_METHOD (vrule, motion_notify_event)),
vrule);
gtk_table_attach (GTK_TABLE (table), vrule, 0, 1, 1, 2,
GTK_FILL, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0);
What ideas on how to solve this task would you suggest? Or on what resource on the internet can I find help?

If your code has a compatible license, you can simply copy the GtkRuler out of GTK 2 into your code, making any changes necessary to make it work with GTK 3.

Related

wrong background color for subsequent frame creating a GIF

I'm trying to resize a gif in a smaller version.
this is what i come up with at the moment:
from PIL import Image
def process_gif(in_path, out_path= 'out.gif', size= (32,32)):
with Image.open(in_path) as im :
images = []
durations = []
for i in range(im.n_frames - 1, -1, -1):
im.seek(i)
im.thumbnail(size, Image.Resampling.LANCZOS) # noqa
im_temp = im.copy()
images.insert(0, im_temp)
durations.append(im.info['duration'])
images[0].save(
out_path,
format='gif',
interlace=True,
save_all=True,
append_images=images[1 :],
loop=0,
duration=durations,
disposal=2,
background=(255,255,255,255),
optimize=False
)
when i try to create the gif the first frame have the correct background and the rest have isssue.
with this gif as imput in.gif
i get those frame in the images before saving: 0 1 2 3
and this is the output out.gif
spent some time figuring out where is the error with no clue, the output should have trasparent background in every frame of the GIF
P.S. i noticed imgur colored the trasparent frame, the in.gif, 0, 1, 2, 3 all have trasparent background, open with your image viewer should let you see better
After some other attemp i looked for trasparency doing print(im_temp.info) before inserting the resized image, NOTE that the cycle it's backward to solve another issue so it's last frame to first frame
{'version': b'GIF89a', 'background': 0, 'loop': 0, 'duration': 70}
{'version': b'GIF89a', 'background': 0, 'loop': 0, 'duration': 70}
{'version': b'GIF89a', 'background': 0, 'loop': 0, 'duration': 70}
{'version': b'GIF89a', 'background': 0, 'loop': 0, 'duration': 70, 'transparency': 48, 'extension': (b'NETSCAPE2.0', 219)}
from PIL import GifImagePlugin
GifImagePlugin.LOADING_STRATEGY = GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
using this solved my problem

Multiple Slider for JSSOR

I manage to make a slider with multiple image to show. Here is my created slider:
But the effects is only sliding from right to left. I've already tried what stated here that copied the code here.Below code is my transition codes.
oMultipleJssorOptions: {
$AutoPlay: this.iAutoTransition,
$AutoPlaySteps: 3,
$SlideWidth: this.iWidth,
$SlideSpacing: 45,
$Align: 5,
$ArrowKeyNavigation: 1,
$PlayOrientation: 1,
$DragOrientation: 1,
$ArrowNavigatorOptions: {
$Class: $JssorArrowNavigator$,
$ChanceToShow: 2,
$Steps: 4
},
$BulletNavigatorOptions: {
$Class: $JssorBulletNavigator$,
$ChanceToShow: 3,
$Steps: 4,
$SpacingX: 16
}
}
Edit
This please see the gif for the created transition
Please specify different id for each individual slider.
e.g. if the first slider is jssor_1, the second slider can be jssor_2 then. That's to say, you'd replace all jssor_1 with jssor_2 in the code of the second slider.

Move mouse between two monitors

How can I move the mouse pointer between monitors using a keyboard shortcut? I'm using autohotkey.
I didn't find a straightforward answer to it, so here's what I suggest.
Here's my approach, using Ctrl+Space for this function:
^Space::
CoordMode, Mouse, Screen ; This is needed to assure that you get your mouse coordinates related to the screen, not to the window
MouseGetPos, MouseX, MouseY
if( MouseX > 1920) ; 1920 is the Width of my monitor number 1, replace it with yours
{
MouseMove, -A_ScreenWidth, 0, 0, R
}
else
{
MouseMove, A_ScreenWidth, 0, 0, R
}
return

How to draw on canvas using Cairo and GTK in Julia

I'm trying to use Julia with GTK and Cairo to draw onto a canvas. I think the following code (adapted from the example fragments on the GTK.jl page) should work, but it does not. (Other GTK widgets work, but not the canvas)
I would appreciate if someone can suggest what is wrong with this code, or give a pointer to a complete example.
using Gtk.ShortNames
using Cairo
function drawfn(w)
ctx = Gtk.getgc(w)
Cairo.set_coords(ctx, 0, 0, 800, 600, 0, 800, 0, 600)
h = Gtk.height(w)
w = Gtk.width(w)
Gtk.rectangle(ctx, 0, 0, w/2, h/2)
Gtk.set_source_rgb(ctx, 0, 0, 1)
Gtk.fill(ctx)
end
function main()
win = Gtk.#Window("stuff", 800,600)
c = Gtk.#Canvas()
Gtk.push!(win,c)
Gtk.draw(drawfn, c)
Gtk.showall(win)
end
main()
I think this was a bug in version 0.8.1 of Gtk.jl. I posted an issue to github after which vtjnash fixed it immediately and tagged version 0.8.2.

Generating const arrays in C from a database

I have to provide some C++ code consisting of const arrays initialised with well-known values.
More precisely, several arrays containing
Between 0 and 255 strings for a text-based user interface
Metadata, like lengths and positions of those strings
Data representing a hierarchical menu structure
Metadata connecting the menu structure with the strings and configuration data stored elsewhere
The menu items are accessed by their index in an array, and are related to other linked menu items, also accessed by index.
Here is the code I want to generate automatically from a better editable document:
/* gl_PsNMenuType holds one byte of metadata for each menu. This byte will describe
whether the menu only refers to a bunch of submenus or if it is a terminal item, where
the user actually can enter a setting to be saved */
const uint8_t gl_PsNMenuType[MAXMENUS] PROGMEM = { 0, 0, 0, 0, 0};
/* gl_PsNMenuParent holds the index of each menu's parent menu. i.e. tree one step up */
const uint8_t gl_PsNMenuParent[MAXMENUS] PROGMEM = { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3}; // referenz auf den übergeordneten MP
/* gl_PsNMenuFixTexts is a list of identifiers text snippets which build the layout of
the respective menu. The text snippets are stored in gl_PsFixTexts and the respective
index of a text snippet is saved here. MFTS is a list sentinel*/
const uint8_t gl_PsNMenuFixTexts[MAXMENUS][MAXFIXTEXTSPM] PROGMEM = {
{ 20, 2, MFTS}, // text snippets for menu 0
{2, 9, 1, MFTS}, // for menu 1
{2, 10, MFTS}, //2
{2, 11, MFTS}, //3
{2, 13, MFTS} //4
};
/* gl_PsNMenuParentListText holds the identifiers of the text snippets which shall be
displayed by the parent menu while selection before descending to the submenus. There's
one such snippet for each menu. */
const uint8_t gl_PsNMenuParentListText[MAXMENUS] PROGMEM = { 0, 9, 10, 11, 13};
/* gl_PsNMenuFtPos closely relates to gl_PsNMenuFixTexts. The positions on the display
for each text snippet of a menu are stored here. */
const uint8_t gl_PsNMenuFtPos[MAXMENUS][MAXFIXTEXTSPM] PROGMEM = { // Liste der Fixtextpositionen
{ 0, 5, MFTS, MFTS, MFTS}, // 0
{ 0, 5, MFTS, MFTS, MFTS}, // 1
{ 0, 5, MFTS, MFTS, MFTS}, // 2
{ 0, 5, MFTS, MFTS, MFTS}, // 3
{ 0, 5, MFTS, MFTS, MFTS}, // 4
};
/* gl_PsNMenuChildren stores the indices of all submenus reachable from a certain menu
this is essentially the structure of the menu tree MAXMENUS is used for array size and
also as sentinel*/
const uint8_t gl_PsNMenuChildren[MAXMENUS][MAXMENUCHILDREN] PROGMEM = {
{ 5, 1, 2, 3, 4, MAXMENUS}, // 0
{ 4, 7, 8, 9, MAXMENUS}, // 1
{1, MAXMENUS}, //2
{1, MAXMENUS}, // 3
{3, 5, 6, MAXMENUS} // 4
};
/* finally the text snippets */
const uint8_t gl_PsFixTexts[MAXFIXTEXTS][MAXFIXTEXTLEN] PROGMEM = {
{5, 0x54, 0x65, 0x73, 0x74, 0x31 }, // 0: Test1
{9, 0x62, 0x6c, 0x61, 0x62, 0x6c, 0x61, 0x62, 0x6c, 0x62 }, // 1: bla
{4, 0x4d, 0x65, 0x6e, 0x75}, // 2: Menu
{4, 0x4d, 0x61, 0x69, 0x6e}, // 20: Main
{4, 0x65, 0x78, 0x69, 0x74}, // 21: exit
{4, 0x62, 0x61, 0x63, 0x6b} // 22: back
};
This is shortened for brevity and dysfunctional in this state.
As the contents of those arrays are exclusively uint8_t characters it would be much simpler to write the data automatically, while ensuring that the referencing indices are all correct.
I want some other data describing the menu structure in a more elaborate but maintainable way.
I thought about making a spreadsheet where I could show the hierarchy across the columns and enter all the data. Then some tool would be needed to break down the hierarchy.
I hope someone can let me know of any tools that are suitable for this task. If there's nothing available then I have to write a Perl conversion program. Are there any useful CPAN libraries?
Edit: some further explanation of the use of the arrays
This data will be utilised by an user interface function, which is rather simplicistic. There will be an identifier pointing to the actual menu entry, which is edited or viewed by the user. This identifier will be used as index wherever MAXMENUS is defining the array size. these arrays describe the look and feel of every menu entry. The menu entries refer to different strings (gl_PsFixTexts) and positions (gl_PsNMenuFtPos) which declare, how and where to display strings when processing a certain menu entry.
The most important arrays are gl_PsNMenuParent and gl_PsNMenuChildren which point to the menu entries above and below in hierarchy. This is, how the code will let the user navigate through the menu structure.
There's also some information if this is an terminal entry in the menu tree, i.e. if there's some data to change, which again means modifying a setting for the software.
Here is my best answer, based on what you have told us.
Menu information like that is commonly stored as XML. An XML data file would allow you to relate menu items to their text labels and their children quite expressively.
In the end you could write a GUI front end that would present that XML in a graphical form and allow you as much facility and complexity as want to write.
In the end, it is the XML file that is the authority on the interface structure, and which can be converted very easily with Perl to any format that you desire.
Also, following on from what #MatsPetersson said in his comment, I would much rather see
{9, 'b', 'l', 'a', 'b', 'l', 'a', 'b', 'l', 'a'}, // 1: blablabla
which is certain to be acceptable to as a uint8_t [] initialiser.
If you want further help then you will have to expand your description with a line-by-line explanation of what your "desired output" means in English.