How to put Gtk:Grid in Gtk:Window with gtkmm - gtkmm

How can I put Gtk:Grid in Gtk:Window using gtkmm. It says "no known conversion for argument 1 from «Gtk::Grid()» to «Gtk::Widget&»" when I'm trying to call main_win.add(grid);
This works but it's too ugly:
...
int main (int argc, char *argv[])
{
Main kit(argc, argv);
Label label1("Hello1",0,0.5);
Label label2("Hello2",0,0.5);
Grid grid;
(*((Container*)&grid)).add(label1);
(*((Container*)&grid)).add(label2);
Window main_win(Gtk::WINDOW_TOPLEVEL);
main_win.add(*((Widget*)&grid));
main_win.show_all();
kit.run(main_win);
return 0;
}

You don't need any of those crazy casts.
Grid grid
Window window;
window.add(grid)
will work just fine.

Hm... Now it works... I think I did nothing... I'm not sure but it looks like Grid grid(); was in my source code because it causes the same error.

Related

Processing can't access PShape array

I'm afraid I have a problem with a "NullPointerException".
I'm writing a Processing (v4) Sketch, which should load multiple svg files from a folder, into a PShape Array. Initializing the array works fine, giving it a length works fine but somehow when I want to overwrite a value, I get a NullPointerException.
int imageCount = 1;
PShape[] images;
void setup() {
images = new PShape[imageCount];
for (int i = 0; i<images.length; i++) {
println(images.length); //prints the expected result 1
images[i] = loadShape("platzhalter/Platzhalter_2_"+str(i)+".svg");
// throws NullPointerException
}
}
I hope someone here can help me, thx!
Okay so I solved it in the meantime.
Turns out that processing has some kind of limitations in terms of interpreting svg files. I had to transform text to outlines in the adobe illustrator export settings to make it work. Hope this helps anyone with the same issue.

SDL left mouse button event without press on startup

On the start-up of my SDL program a left mouse button event is registered without me pressing the physical left mouse button. The next physical left button press is not registered. All other keys and buttons work normal. When clicking the .exe the mouse is not located within the location of the window.
Here are the specifications of that event (taken from the SDL_Event struct):
type=1025 (SDL_MOUSEBUTTONDOWN)
timestamp=24
windowID=1
which=0
button=1 (SDL_BUTTON_LEFT)
state=1
clicks=1
x=0
y=0
I am on windows 8.1 compiling with MinGW (gcc version 4.8.1).
I have SDL version 2.0.3
This is my source code:
#include <stdio.h>
#include <SDL.h>
int main(int argc, char* argv[])
{
SDL_Window* window = NULL;
SDL_Surface* screen = NULL;
SDL_Event ev;
SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_CreateWindow("SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, 0);
screen = SDL_GetWindowSurface(window);
while (1) {
while (SDL_PollEvent(&ev)) {
if (ev.type == SDL_QUIT)
return 0;
else {
if (ev.type == SDL_MOUSEBUTTONDOWN) {
if (ev.button.button == SDL_BUTTON_LEFT) {
printf("MOUSE DOWN\n");
printf("type=%d\n", ev.button.type);
printf("timestamp=%d\n", ev.button.timestamp);
printf("windowID=%d\n", ev.button.windowID);
printf("which=%d\n", ev.button.which);
printf("button=%d\n", ev.button.button);
printf("state=%d\n", ev.button.state);
printf("clicks=%d\n", ev.button.clicks);
printf("x=%d\n", ev.button.x);
printf("y=%d\n\n", ev.button.y);
}
}
}
}
SDL_UpdateWindowSurface(window);
SDL_Delay(5);
}
SDL_FreeSurface(screen);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
I have tried to solve it by calling SDL_PumpEvents() and SDL_FlushEvents() and while this removed the first (erroneous) event, the second press was still not registered.
Something strange I noticed was that it worked as expected when I opened the program .exe by right clicking and then pressing 'open'.
It'd be very grateful if somebody could shed light on this issue.

Disable autosuggest

My textfield name is searchtextfeild.
When I type anything, it autosuggests as in the given picture.
Now, I simply do not want to show this autosuggest. I want to disable it.
I tried,
searchtextfeild.autoautocorrectionType = FALSE;
Strange thing is though searchtextfeild is textfield, it does not have property autoautocorrectionType.
Anyway, how can I disable this autosuggest?
autocorrectionType property has type UITextAutocorrectionType which is enum:
typedef NS_ENUM(NSInteger, UITextAutocorrectionType) {
UITextAutocorrectionTypeDefault,
UITextAutocorrectionTypeNo,
UITextAutocorrectionTypeYes,
};
So you just need to do
searchtextfeild.autocorrectionType = UITextAutocorrectionTypeNo;
Check this please:
searchtextfeild.autocorrectionType = TRUE;
For some strange reason it works for me.

Print complete WebKitWebView (not only visible part) into PDF with gtk3 and cairo

I want to save a webpage using webkit, gtk3 and cairo into a pdf.
What works: The visible part (visible in window) gets correctly printed into the pdf
What doesn't work, but should work: The invisible part (the part when you scroll down) should be printed into that pdf, too. Any ideas?
That's my code:
#include <gtk/gtk.h>
#include <webkit/webkit.h>
#include <cairo-pdf.h>
static void save_as_pdf (GtkWidget *widget, const char *filename)
{
GtkAllocation allocation;
printf("Saving PDF to file %s\n", filename);
gtk_widget_get_allocation(GTK_WIDGET(widget), &allocation);
printf("height: %d width: %d\n", allocation.height, allocation.width);
cairo_surface_t *surface = cairo_pdf_surface_create( filename, allocation.width, allocation.height);
cairo_t *cr = cairo_create(surface);
gtk_widget_draw(widget, cr);
cairo_destroy(cr);
cairo_surface_destroy(surface);
}
static void notifyProgressCb(WebKitWebView* webView, GParamSpec* pspec, GtkWidget* window)
{
float progress = webkit_web_view_get_progress(webView);
printf("\x1b[1G\t\x1b[1G%f", progress * 100); fflush(stdout);
if (progress == 1.0)
save_as_pdf(window, "test.pdf");
}
int main (int argc, char *argv[])
{
GtkWidget *window;
WebKitWebView *webView;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 1024, 768);
webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
gtk_container_set_resize_mode(GTK_CONTAINER(webView), GTK_RESIZE_PARENT);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView));
g_signal_connect(webView, "notify::progress", G_CALLBACK(notifyProgressCb), webView);
webkit_web_view_load_uri(webView, "http://www.heise.de");
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show_all (window);
gtk_main();
return 0;
}
compile with:
gcc pkg-config --cflags --libs gtk+-3.0 pkg-config --libs --cflags webkitgtk-3.0 yourfile.c
Supposedly the cairo_create() method only draws the part of the WebView widget, which is visible inside the window. In this case, I would completely circumvent the WebkitGtk objects and include some code which downloads the web page, renders it and saves the output into a PDF file; HTML2PDF, for instance. It may be a dirty low-level approach, but it's more robust and easier to implement.
You are looking for this:
Save a page as a PDF:
screenshot.pl --output cpan.pdf http://search.cpan.org/

How to make a MovieClip remove itself in AS3?

What is the equivalent to removeMovieClip() in AS3?
Apparently many have the same question:
StackOverflow:
How to completely remove a movieclip in as3
Remove movie clip as3
How to remove childmovieclip and add to new parent movieclip
Others:
removeMovieClip(this) in AS3?
Destroy/Delete a Movieclip???
Remove movie clip
But none of their solutions seem to work, for me:
Im working on flash CS4 with AS3:
I have a very simple movie with a single button called click. On pressing the button, a new instance of coin is created:
this.click.addEventListener(MouseEvent.CLICK,justclick);
function justclick(e:MouseEvent){
var money=new coin
this.addChild(money)
money.x=e.stageX
money.y=e.stageY
}
It might not be the best code, but it works fine. Now, the coin MovieClip is supposed to show a small animation and remove itself. In good old AS2 I would have added:
this.removeMovieClip()
in the last frame of the animation. But this doesn't exist in AS3.
I have tried, without success:
this.parent.removeChild(this) // 'Cannot access a property or method of nullobject reference'...
this.removeMovieClip() // 'removeMovieClip is not a function'
removeMovieClip(this) //'call to possibly undefined method removeMovieClip'
unloadMovie(this)//'call to possibly undefined method removeMovieClip'
Solutions?
Thanks,
this.parent.removeChild(this);
This one should be working; it's what I use. One problem I had when I switched to AS3 is that sometimes it wouldn't be added as a child right, so you might want to check that. You also have to import flash.display via putting this at the top if you're not already:
import flash.display.*
You should also remove the event listener on it before removing it.
If your animation is ending on frame 20.
note: using 19 because flash count frames from zero(0) similar to array index.
class animatedCloud
{
public function animatedCloud(){
addFrameScript(19, frame20);
}
private function frame20(){
parent.removeChild(this);
}
}
Always ensure that those self removing movieclips can get garbage collected.
This solution wiped away all my instances from a loaded swf's library symbol:
var mc:MovieClip = new definition() as MovieClip;
addChild(mc);
mc.x = 1000 * Math.random();
mc.y = 1000 * Math.random();
mc.addFrameScript(mc.totalFrames - 1, function onLastFrame():void
{
mc.stop();
mc.parent.removeChild(mc);
mc = null;
});
public static function removeDisplayObject(displayObject:DisplayObject):void {
/* normal code
if(displayObject && displayObject.parent){
displayObject.parent.removeChild(displayObject);
}
*/
displayObject ? displayObject.parent ? displayObject.parent.removeChild(displayObject) : null : null;
}
I use, in an extra blank keyframe at the end of the MovieClip which should remove itself:
stop();
MovieClip(parent).removeChild(this);
Found it to be the proper and best solution.