Skip to content

Commit

Permalink
[Interposer] Some changes to pcbnew_do export and 3d_view
Browse files Browse the repository at this point in the history
- Detecting the GTK main loop
- Using open_dialog_i
  • Loading branch information
set-soft committed Aug 7, 2022
1 parent 9bfb79c commit 631c6df
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 6 deletions.
21 changes: 21 additions & 0 deletions interposer/interposer.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,24 @@ int close(int fd)
fflush(stdout);
return res;
}


void gtk_main(void)
{
static void (*next_func)(void)=NULL;

if (next_func==NULL)
{ /* Initialization */
char *msg;
printf("* wrapping gtk_main\n");
next_func=dlsym(RTLD_NEXT,"gtk_main");
if ((msg=dlerror())!=NULL)
printf("** dlopen failed : %s\n", msg);
}

printf("GTK:Main:In\n");
fflush(stdout);
next_func();
printf("GTK:Main:Out\n");
fflush(stdout);
}
Binary file modified interposer/libinterposer.so
Binary file not shown.
98 changes: 98 additions & 0 deletions interposer/not_used.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <sys/epoll.h>
#include <sys/select.h>
Random pieces of code used for the interposer during tests.

GtkPageOrientation orie=gtk_print_settings_get_orientation(set);
Expand Down Expand Up @@ -349,3 +351,99 @@ void gtk_toolbar_insert(GtkToolbar *toolbar, GtkToolItem *item, gint pos)
fflush(stdout);
}


gboolean gtk_main_iteration(void)
{
static gboolean (*next_func)(void)=NULL;
gboolean res;

if (next_func==NULL)
{ /* Initialization */
char *msg;
printf("* wrapping gtk_main_iteration\n");
next_func=dlsym(RTLD_NEXT,"gtk_main_iteration");
if ((msg=dlerror())!=NULL)
printf("** dlopen failed : %s\n", msg);
}

printf("GTK:gtk_main_iteration:In\n");
fflush(stdout);
res=next_func();
printf("GTK:gtk_main_iteration:Out %d\n", res);
fflush(stdout);

return res;
}


int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
{
static int(*next_func)(int , struct epoll_event *, int , int )=NULL;
int res;

if (next_func==NULL)
{ /* Initialization */
char *msg;
printf("* wrapping epoll_wait\n");
next_func=dlsym(RTLD_NEXT,"epoll_wait");
if ((msg=dlerror())!=NULL)
printf("** dlopen failed : %s\n", msg);
}

printf("IO:Event:In\n");
fflush(stdout);
res=next_func(epfd, events, maxevents, timeout);
printf("IO:Event:Out %d\n", res);
fflush(stdout);

return res;
}


int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
static int (*next_func)(int , fd_set *, fd_set *, fd_set *, struct timeval *)=NULL;
int res;

if (next_func==NULL)
{ /* Initialization */
char *msg;
printf("* wrapping select\n");
next_func=dlsym(RTLD_NEXT,"select");
if ((msg=dlerror())!=NULL)
printf("** dlopen failed : %s\n", msg);
}

printf("IO:Select:In\n");
fflush(stdout);
res=next_func(nfds, readfds, writefds, exceptfds, timeout);
printf("IO:Select:Out %d\n", res);
fflush(stdout);

return res;
}


int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const __sigset_t *sigmask)
{
static int (*next_func)(int , fd_set *, fd_set *, fd_set *, const struct timespec *, const __sigset_t *)=NULL;
int res;

if (next_func==NULL)
{ /* Initialization */
char *msg;
printf("* wrapping pselect\n");
next_func=dlsym(RTLD_NEXT,"pselect");
if ((msg=dlerror())!=NULL)
printf("** dlopen failed : %s\n", msg);
}

printf("IO:Select:In\n");
fflush(stdout);
res=next_func(nfds, readfds, writefds, exceptfds, timeout, sigmask);
printf("IO:Select:Out %d\n", res);
fflush(stdout);

return res;
}

2 changes: 1 addition & 1 deletion interposer/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# We use LANG=C to avoid translations, this works on Debian 11
#LANG=C LD_PRELOAD=`pwd`/libinterposer.so eeschema "$@" | grep "GTK:"
#LANG=C LD_PRELOAD=`pwd`/libinterposer.so eeschema "$@"
LANG=C LD_PRELOAD=`pwd`/libinterposer.so pcbnew "$@" | grep "GTK:Tooltip"
LANG=C LD_PRELOAD=`pwd`/libinterposer.so pcbnew "$@" | grep "GTK:Main"
#LANG=C LD_PRELOAD=`pwd`/libinterposer.so pcbnew "$@"
7 changes: 7 additions & 0 deletions kiauto/interposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ def exit_kicad_i(cfg):
xdotool(keys_exit)


def wait_close_dialog_i(cfg):
""" Wait for the end of the main loop for the dialog.
Then the main loop for the parent exits and enters again. """
wait_queue(cfg, 'GTK:Main:Out', times=2)
wait_queue(cfg, 'GTK:Main:In')


def wait_start_by_msg(cfg):
cfg.logger.info('Waiting for PCB new window ...')
pre = 'GTK:Window Title:'
Expand Down
10 changes: 5 additions & 5 deletions src/pcbnew_do
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ from kiauto.misc import (REC_W, REC_H, __version__, NO_PCB, PCBNEW_CFG_PRESENT,
CORRUPTED_PCB, __copyright__, __license__, TIME_OUT_MULT, get_en_locale, KICAD_CFG_PRESENT,
MISSING_TOOL, KICAD_DIED)
from kiauto.interposer import (check_interposer, dump_interposer_dialog, start_queue, setup_interposer_filename,
create_interposer_print_options_file, wait_queue, wait_start_by_msg,
create_interposer_print_options_file, wait_queue, wait_start_by_msg, wait_close_dialog_i,
wait_swap, set_kicad_process, open_dialog_i, wait_kicad_ready_i, paste_bogus_filename,
paste_output_file_i, exit_kicad_i, send_keys, wait_create_i, save_interposer_print_data)
from kiauto.ui_automation import (PopenContext, xdotool, wait_not_focused, wait_for_window, recorded_xvfb,
Expand Down Expand Up @@ -371,8 +371,8 @@ def print_layers_i(cfg, id_pcbnew, print_dialog_keys):
wait_create_i(cfg, 'print', fname)
# Close KiCad Print dialog
send_keys(cfg, 'Close Print dialog', 'Escape')
# Wait sleeping
wait_kicad_ready_i(cfg, swaps=0)
# Wait for KiCad to get the control again
wait_close_dialog_i(cfg)
# Move the file to the user selected name
shutil.move(fname, cfg.output_file)
# Exit
Expand Down Expand Up @@ -1036,8 +1036,7 @@ def capture_3d_view_i(cfg):

# Save the image as PNG
# Open the Save dialog
logger.info('Saving the image')
open_save_image_i(cfg, id)
open_dialog_i(cfg, '3D Image File Name', ['key', 'alt+f', 'Return'], show=True)
# Paste the name
paste_bogus_filename(cfg)
# Wait for the image to be created
Expand Down Expand Up @@ -1319,6 +1318,7 @@ def parse_color(color):

def wait_pcbnew_start_by_msg(cfg):
wait_start_by_msg(cfg)
wait_queue(cfg, 'GTK:Main:In')
# Make sure pcbnew has the focus, I saw problems with WM pop-ups getting the focus
return wait_pcbnew()

Expand Down

0 comments on commit 631c6df

Please sign in to comment.