[rkward-cvs] SF.net SVN: rkward: [943] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Mon Nov 27 11:31:41 UTC 2006


Revision: 943
          http://svn.sourceforge.net/rkward/?rev=943&view=rev
Author:   tfry
Date:     2006-11-27 03:31:41 -0800 (Mon, 27 Nov 2006)

Log Message:
-----------
Started adding dev.copy (), dev.set (), and dev.print () functionality
Some cleanups and documentation

Modified Paths:
--------------
    trunk/rkward/TODO
    trunk/rkward/rkward/rbackend/rinterface.cpp
    trunk/rkward/rkward/windows/rkwindowcatcher.cpp
    trunk/rkward/rkward/windows/rkwindowcatcher.h

Modified: trunk/rkward/TODO
===================================================================
--- trunk/rkward/TODO	2006-11-27 00:14:14 UTC (rev 942)
+++ trunk/rkward/TODO	2006-11-27 11:31:41 UTC (rev 943)
@@ -26,6 +26,7 @@
 UI-stuff
 	- Access to dev.copy (), dev.print (), and a function to copy gaphics to rkward output
 		- probably in Windows-menu for now
+		- cleanup DISABLE_RKWINDOWCATCHER (either get rid of it, or do it right)
 	- Output window should gain some sort of auto-update functionality:
 		- After user commands, should check, whether the output file was modified. If so, reload
 	- Option to save workplace per session instead of per workspace
@@ -178,9 +179,6 @@
 
 ################## Some internal notes below ##############
 
-Notes for x11-window capturing:
-- See deactived class-header rbackend/rkwindowcatcher.h
-
 ################## menu structure file/workspace ###########
 File
 	New

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2006-11-27 00:14:14 UTC (rev 942)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2006-11-27 11:31:41 UTC (rev 943)
@@ -62,8 +62,7 @@
 	RK_TRACE (RBACKEND);
 	
 #ifndef DISABLE_RKWINDOWCATCHER
-	window_catcher = new RKWindowCatcher (0);
-	window_catcher->hide ();
+	window_catcher = new RKWindowCatcher ();
 #endif // DISABLE_RKWINDOWCATCHER
 	
 // If R_HOME is not set, most certainly the user called the binary without the wrapper script
@@ -108,6 +107,7 @@
 
 	delete flush_timer;
 	delete watch;
+	delete window_catcher;
 }
 
 void RInterface::startThread () {

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2006-11-27 00:14:14 UTC (rev 942)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.cpp	2006-11-27 11:31:41 UTC (rev 943)
@@ -31,7 +31,7 @@
 #include "qxembedcopy.h"
 #include "../debug.h"
 
-RKWindowCatcher::RKWindowCatcher (QWidget *parent) : QWidget (parent) {
+RKWindowCatcher::RKWindowCatcher () {
 	RK_TRACE (MISC);
 }
 
@@ -58,12 +58,15 @@
 			RKWorkplace::mainWorkplace ()->newX11Window (w, new_cur_device);
 			//new RKCatchedX11Window (w, new_cur_device);
 		} else {
-			KMessageBox::sorry (0, i18n ("You have created a new X11 device window in R. Usually, RKWard tries to detect such windows, to take control of them, and add a menu-bar to them. This time, however, RKWard failed to detect, which window was created, and so can not embed it.\nIf you created the window on a different screen or X11 display, that is to be expected. You might want to consider changing options(\"display\"), then.\nIf you can see the X11 window on the same screen as this message, then RKWard should do better. In this case, please contact us at rkward-devel at lists.sourceforge.net with details on your setup, so we can try to fix this in future versions of RKWard."), i18n ("Could not embed R X11 window"));
+			KMessageBox::information (0, i18n ("You have created a new X11 device window in R. Usually, RKWard tries to detect such windows, to take control of them, and add a menu-bar to them. This time, however, RKWard failed to detect, which window was created, and so can not embed it.\nIf you created the window on a different screen or X11 display, that is to be expected. You might want to consider changing options(\"display\"), then.\nIf you can see the X11 window on the same screen as this message, then RKWard should do better. In this case, please contact us at rkward-devel at lists.sourceforge.net with details on your setup, so we can try to fix this in future versions of RKWard."), i18n ("Could not embed R X11 window"), "failure_to_detect_x11_device");
 		}
 	}
 	last_cur_device = new_cur_device;
 }
 
+///////////////////////////////// END RKWindowCatcher //////////////////////////////////
+/**************************************************************************************/
+//////////////////////////////// BEGIN RKCatchedX11Window //////////////////////////////
 
 
 #include <qscrollview.h>
@@ -74,6 +77,9 @@
 #include <kdialogbase.h>
 #include <knuminput.h>
 
+#include "../rkglobals.h"
+#include "../rbackend/rinterface.h"
+
 RKCatchedX11Window::RKCatchedX11Window (WId window_to_embed, int device_number) : RKMDIWindow (0, X11Window) {
 	RK_TRACE (MISC);
 
@@ -206,9 +212,48 @@
 	delete dialog;
 }
 
+void RKCatchedX11Window::activateDevice () {
+	RK_TRACE (MISC);
 
+	RKGlobals::rInterface ()->issueCommand ("dev.set (" + QString::number (device_number) + ")", RCommand::App, i18n ("Activate graphics device number %1").arg (QString::number (device_number)));
+}
 
+void RKCatchedX11Window::copyDeviceToOutput () {
+	RK_TRACE (MISC);
 
+	RKGlobals::rInterface ()->issueCommand ("dev.set (" + QString::number (device_number) + ")\ndev.copy (device=rk.graph.on)\nrk.graph.off ()", RCommand::App | RCommand::DirectToOutput, i18n ("Copy contents of graphics device number %1 to output").arg (QString::number (device_number)));
+}
+
+void RKCatchedX11Window::printDevice () {
+	RK_TRACE (MISC);
+
+	RKGlobals::rInterface ()->issueCommand ("dev.set (" + QString::number (device_number) + ")\ndev.print ()", RCommand::App, i18n ("Print contents of graphics device number %1").arg (QString::number (device_number)));
+
+	#warning TODO: options ("printcmd") should be made configurable, and set to kprinter by default
+}
+
+void RKCatchedX11Window::copyDeviceToRObject () {
+	RK_TRACE (MISC);
+
+	KMessageBox::information (0, i18n ("Not yet implemented"), i18n ("Not yet implemented"));
+
+	#warning implement or deactivate action
+}
+
+void RKCatchedX11Window::copyDeviceToFile () {
+	RK_TRACE (MISC);
+
+	KMessageBox::information (0, i18n ("Not yet implemented"), i18n ("Not yet implemented"));
+
+	#warning implement or deactivate action
+}
+
+
+///////////////////////////////// END RKWindowCatchedWindow ////////////////////////////
+/**************************************************************************************/
+//////////////////////////////// BEGIN RKCatchedX11WindowPart //////////////////////////
+
+
 RKCatchedX11WindowPart::RKCatchedX11WindowPart (RKCatchedX11Window *window) : KParts::Part (0) {
 	RK_TRACE (MISC);
 
@@ -227,6 +272,11 @@
 	new KAction (i18n ("Set fixed size 2000x2000"), 0, window, SLOT (setFixedSize3 ()), actionCollection (), "set_fixed_size_3");
 	new KAction (i18n ("Set specified fixed size..."), 0, window, SLOT (setFixedSizeManual ()), actionCollection (), "set_fixed_size_manual");
 
+	new KAction (i18n ("Make active"), 0, window, SLOT (activateDevice ()), actionCollection (), "device_activate");
+	new KAction (i18n ("Copy to output"), 0, window, SLOT (copyDeviceToOutput ()), actionCollection (), "device_copy_to_output");
+	new KAction (i18n ("Print"), 0, window, SLOT (printDevice ()), actionCollection (), "device_print");
+	new KAction (i18n ("Store as R object"), 0, window, SLOT (copyDeviceToRObject ()), actionCollection (), "device_copy_to_r_object");
+	new KAction (i18n ("Export"), 0, window, SLOT (copyDeviceToFile ()), actionCollection (), "device_copy_to_file");
 }
 
 RKCatchedX11WindowPart::~RKCatchedX11WindowPart () {

Modified: trunk/rkward/rkward/windows/rkwindowcatcher.h
===================================================================
--- trunk/rkward/rkward/windows/rkwindowcatcher.h	2006-11-27 00:14:14 UTC (rev 942)
+++ trunk/rkward/rkward/windows/rkwindowcatcher.h	2006-11-27 11:31:41 UTC (rev 943)
@@ -23,21 +23,16 @@
 
 #include <qwidget.h>
 
-/** This class will be used to find out, when R opens a new X11-device, find out the id of that device and embed it into a QWidget.
+/** This is a simple helper class helping in catching R X11 device windows. The start () and stop () functions are called from RInterface, and then this class takes care of handling those.
 
-Unfortunately this does not work, yet. Right when trying to embed the window, there is a crash (R segfaults; this also happens when trying to catch a window from another separate R process, so it really seems to be R's fault!). Therefore this class is currently deactivated.
-To reactivate it, modify the corresponding Makefile.am, uncomment the x11-override in rpackages/rkward/R/internal.R, and uncomment the
-window_catcher/RKWindowCatcher lines in rinterface.h and rinterface.cpp. Maybe I'll add some #ifdefs instead...
+The main difficulty to overcome in this context, is to find out, when an R X11 window is created, and what is its X Window id. The notes below are some thoughts on that matter. Probably mostly obsolete, now (the current approach is basically Plan C, and seems to work ok), but maybe Plans A or B or something similar will become necessary some day:
 
-Given the problems with fetching the window Id (currently only possible by searching for the window title), it's probably a lot easier to instead create a single R call: .rk.catch.window (title="R Graphics: Device...", graph_device_number) that will directly trigger catching.
-
-
-Here are some more notes I have taken on the subject of catching R's x11 windows. Current approach is Plan C for simplicity.
+Catch R X11 device windows
 - Plan A:
 	- initialization function seems to be in_do_X11
 	- it might be possible to put a wrapper around this using R_setX11Routines
 	- this wrapper could watch the list of devices (curDevice, numDevices), see also addDevice to find out how the list is kept internally
-	- if a new device gets added grab its winId and capture (using QXEmbed?)!
+	- if a new device gets added grab its winId and capture
 - Plan B:
 	- it looks like there's no way to get acces to R_setX11Routines or at least the needed struct R_X11Routines. (?)
 	- the level above that seems to be do_X11
@@ -53,27 +48,31 @@
 - remaining problem: how to get the window id given the device id?
 	- http://tronche.com/gui/x/xlib/events/window-state-change/create.html#XCreateWindowEvent
 	- for active / inactive: XPropertyEvent WM_NAME
-	- we may catch this using KApplication::installX11EventFilter
-		- XSelectInput -> QWidget::x11Event()?
+	- we may catch this using KApplication::x11EventFilter
 	- event filter should only be active during the wrapper (Plan A-C)
 	- event filter should probably do some sanity checking
 	- this should give us the window id corresponding to the x11-call
 
 @author Thomas Friedrichsmeier
 */
-class RKWindowCatcher : public QWidget {
-	Q_OBJECT
+class RKWindowCatcher {
 public:
-	RKWindowCatcher (QWidget *parent);
+/** ctor. Probably you'll only ever need one instance of RKWindowCatcher. */
+	RKWindowCatcher ();
+/** dtor */
+	~RKWindowCatcher ();
 
-	~RKWindowCatcher ();
-	
+/** call this function to start looking out for new R X11 device windows.
+ at param prev_cur_device the device number that was active before a new device window was (potentially) created */
 	void start (int prev_cur_device);
+/** end looking out for new R X11 windows. If a new window was in fact created, this is captured by creating an RKCatchedX11Window
+ at param new_cur_device the new active device number, i.e. the device number of the created window */
 	void stop (int new_cur_device);
 private:
 	int last_cur_device;
 };
 
+
 #include "rkmdiwindow.h"
 
 class RKCatchedX11WindowPart;
@@ -86,25 +85,42 @@
 class RKCatchedX11Window : public RKMDIWindow {
 	Q_OBJECT
 public:
+/** ctor
+ at param window_to_embed the Window id of the R X11 device window to embed
+ at param device_number the device number corresponding to that window */
 	RKCatchedX11Window (WId window_to_embed, int device_number);
-
+/** dtor */
 	~RKCatchedX11Window ();
 
 	KParts::Part *getPart ();
-	QString getRDescription () { return "unimplemtend"; };
+/** TODO */
+	QString getRDescription () { return "unimplemented"; };
+/** TODO? */
 	bool isModified () { return false; };
 
+/** reimplemented from RKMDIWindow to switch to fixed size mode, and disable the dynamic_size_action */
 	void prepareToBeAttached ();
+/** see prepareToBeAttached (). Reenable the dynamic_size_action */
 	void prepareToBeDetached ();
 public slots:
-	/** Do not invoke directly. Meant to be called from the toggle action */
+/** Do not invoke directly. Meant to be called from the toggle action */
 	void toggleFixedSize ();
+/** Switch to fixed size mode, and set size1 (currently 500*500) */
 	void setFixedSize1 ();
+/** Switch to fixed size mode, and set size2 (currently 1000*1000) */
 	void setFixedSize2 ();
+/** Switch to fixed size mode, and set size3 (currently 2000*2000) */
 	void setFixedSize3 ();
+/** Switch to fixed size mode, and set user specified size (size read from a dialog) */
 	void setFixedSizeManual ();
+
+	void activateDevice ();
+	void copyDeviceToOutput ();
+	void printDevice ();
+	void copyDeviceToRObject ();
+	void copyDeviceToFile ();
 private:
-	friend class RKCatchedX11WindowPart;
+	friend class RKCatchedX11WindowPart;	// needs access to the actions
 	int device_number;
 	WId embedded;
 	RKCatchedX11WindowPart *part;
@@ -116,10 +132,11 @@
 	KToggleAction *dynamic_size_action;
 };
 
+/** Provides a KPart interface for RKCatchedX11Window. */
 class RKCatchedX11WindowPart : public KParts::Part {
 public:
 /** constructor.
- at param console The console for this part */
+ at param window The RKCatehdX11Window for this part */
 	RKCatchedX11WindowPart (RKCatchedX11Window *window);
 /** destructor */
 	~RKCatchedX11WindowPart ();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list