Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@demonxweb
Copy link

Expose DragHandler.OnDragEnter
Expose DialogHandler.onFileDialog

demon added 2 commits July 20, 2017 18:17
 + Expose DialogHandler.onFileDialog
 + Expose methods IsFile, IsFileName, IsFileNames in DragData.
 + Expose FileDialogCallback
@cztomczak cztomczak changed the title Expose OnDragEnter & OnFileDialog in ClientHandler Expose OnDragEnter & OnFileDialog in ClientHandler (#188, #361) Jul 21, 2017
@cztomczak
Copy link
Owner

Related issues:
#188 ("Implement CefDragHandler to allow dragging of local files into window to be cancelled")
#361 ("Expose DialogHandler and OnFileDialog callback")

Copy link
Owner

@cztomczak cztomczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On what platforms have you tested these changes? (I guess Windows only)

Please provide an example with which I can test the new functionality. You can either add unit tests. Or you can attach a script in this PR through gist: https://gist.github.com/ .

I see you've modified cef_version_win.h and set to an older version of CEF (v57). Looks like you're using CEF Python v57 and in this case you should have made this PR to branch cefpython57 instead of master. Your change alters CEF version and also removes DragData.GetImageHotspot() function which you can't do.

}

#if defined(OS_LINUX)
//#if defined(OS_LINUX)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the comment

return this;
}
#endif
//#endif
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one too

#if defined(OS_LINUX)
return dialog_handler_->OnFileDialog(browser,
bool result;
result = DialogHandlerr_OnFileDialog(browser,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix typo in the function name "DialogHandlerr_OnFileDialog" - there are two "r"

if(result){
return result;
}else{

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the blank line

return result;
}else{

#if defined(OS_LINUX)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preprocessor conditions like #if #else #endif should be without indent as in the original source file

returnValue = callback(browser=pyBrowser,
dragData=drag_data,
mask=mask)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blank lines

callback = pyBrowser.GetClientCallback("OnDragEnter")
if callback:
returnValue = callback(browser=pyBrowser,
dragData=drag_data,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indent for func arguments

sys.excepthook(exc_type, exc_value, exc_trace)

return False

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blank lines


#define CEF_VERSION "3.2987.1601.gf035232"
#define CEF_VERSION_MAJOR 3
#define CEF_COMMIT_NUMBER 1604
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't modify this file in this PR, this was explained by me in the other comment

//#define CHROME_VERSION_BUILD 3029
//#define CHROME_VERSION_PATCH 81

#define CEF_VERSION "3.2987.1601.gf035232"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you're using CEF Python v57, but you made this PR to branch master which uses CEF Python v58.

@demonxweb
Copy link
Author

Thanks for reviewing my code. I'll fixed the coding style.

I only tested in Windows 7 platform.
I'll try to provide a example or test case for you.
By the way, I'm interesting how did you test all of platform and python version.
I'll be glad that you cloud share your experiences with me.

Sorry about changed CEF_VERSION in cef_version_win.h.
Cause I didn't successfully compile CEF v58 yet.
I'll try to resolve this problem.

@cztomczak
Copy link
Owner

When running the build.py / build_distrib.py tools unit tests and examples are run automatically. The build_distrib.py tool tests multiple python versions automatically, read top comments in sources.

You can build master using these instructions that use Spotify binaries:
https://github.com/cztomczak/cefpython/blob/master/docs/Build-instructions.md#build-using-cef-binaries-from-spotify-automated-builds

But first you have to satisfy requirements:
https://github.com/cztomczak/cefpython/blob/master/docs/Build-instructions.md#requirements

@cztomczak
Copy link
Owner

If having problems building master please ask on the Forum, as this is off-topic here.

@cztomczak
Copy link
Owner

Useful resources in regards to installing multiple python versions with pyenv or editing cefpython's code using PyCharm are labeled Knowledge Base in the tracker.

@demonxweb
Copy link
Author

Thanks for your comments.
I'll study that you provide information.

return result;
}else{
#if defined(OS_LINUX)
return dialog_handler_->OnFileDialog(browser,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indent, should be only 4 spaces.

api/DragData.md Outdated

Table of contents:
* [Methods](#methods)
* [IsFile](#isfile)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sections should be ordered alphabetically, then re-generate TOC.

#include "drag_handler.h"


bool DragHandler::OnDragEnter(CefRefPtr<CefBrowser> browser,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that API doc for OnDragEnter is missing.

PyToCefString(text,cefText)
self.cef_drag_data.get().SetFragmentText(cefText)

cpdef py_void SetFragmentHtml(self, html ):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An unnecessary space before closing parentheses.


cpdef py_void SetFragmentText(self, text):
cdef CefString cefText
PyToCefString(text,cefText)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please separate arguments with a space after comma.


cpdef py_void SetFragmentHtml(self, html ):
cdef CefString cefHtml
PyToCefString(html,cefHtml)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.

cdef CefString cefPath
cdef CefString cefDisplayName
PyToCefString(path,cefPath)
PyToCefString(display_name,cefDisplayName)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space please.

cdef CefString cefDisplayName
PyToCefString(path,cefPath)
PyToCefString(display_name,cefDisplayName)
self.cef_drag_data.get().AddFile(cefPath,cefDisplayName)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too.


cdef extern from "include/cef_drag_data.h":
cdef cppclass CefDragData:
cpp_bool IsFile()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the methods were ordered alphabetically before then please keep an alphabetic order when adding new ones.

def __init__(self):
self.OnPaint_called = False

def OnConsoleMessage(self, message, **_):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates code from main_test.py. Can we create _common.py file in unittests/ and move the duplicate code there? The DisplayHandler from main_test.py should be moved there and be imported in main_test.py and osr_test.py.

browser.DragSourceEndedAt(303, 23, cef.DRAG_OPERATION_COPY )
browser.DragSourceSystemDragEnded()


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blank lines.

self.OnConsoleMessage_True = True
subtest_message(message)

def OnDragEnter(self, browser, dragData, mask):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the naming convention for handlers as in main_test.py, so that there are DragHandler (with OnDragEnter and StartDragging) and LoadHandler (with OnLoadEnd) classes.

"""

g_datauri = "data:text/html;base64," + base64.b64encode(g_datauri_data.encode(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please get rid of the duplicate code. Define "html_to_data_uri" function in _common.py. Code from tutorial.py:

    html = html.encode("utf-8", "replace")
    b64 = base64.b64encode(html).decode("utf-8", "replace")
    ret = "data:text/html;base64,{data}".format(data=b64)
    return ret

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace these code with a call to html_to_data_uri in both main_test.py and osr_test.py.


g_subtests_ran = 0

def subtest_message(message):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please get rid of duplicate code in all tests by moving subtest_message to _common.py along with the g_subtests_ran variable.



class OSRTest_IsolatedTest(unittest.TestCase):
def test_dragdrop(self):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this comment in main_test.py:

 def test_main(self):
        """Main entry point."""
        # All this code must run inside one single test, otherwise strange
        # things happen.

When working on main_test.py I noticed that you can't initialize CEF in one test run some other tests and then shutdown CEF in last test. I couldn't make it work with python's unittest module, strange things happened. The solution that worked was to run all tests inside on single test (test_main method) and introduce "subtest_message" function to report about results of various tests.

You can however run to separate tests by using IsolatedTest feature. See isolated_test.py - there are two classes defined IsolatedTest1 and IsolatedTest2 which run using separate python processes. This is the only way for CEF to work, because CEF can be initialized/shutdown only once during app lifetime.

I think the easiest thing is to define test_osr() and put both test_dragdrop() and test_dragdata() inside there. I don't mean to put all the code from test_dragdata() inside test_osr(), just make a call from there and the code should be in some separate function as it is now, but just don't make it a separate test.

The test_dragdata code seems to work now, however this seems to be invalid. Most of CEF API is intended to be called only after CEF was initialized. In your case CEF is initialized in test_dragdrop(), however this is a separate test and it shuts down CEF at the end, so after shut down you are not allowed to call any of CEF API anymore. You shouldn't instantiate cef.DragData() aftert CEF was shut down.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just info for the future - with IsolatedTest you can have multiple separate tests in one test file and each of these isolated tests can initalize CEF and shutdown CEF, because they are run using separate processes. But I don't think we need to put these two tests (dragdata and dragdrop) as isolated tests, it would just increase the time to run both tests (CEF initalization, shutdown, message loop - it all takes time). If there is a case for it, when two tests need to be run in separate processes as they might affect each other, then sure go for it and create two isolated tests or more in one test file.


def test_dragdata(self):
dragData = cef.DragData()
testString = 'Testing DragData'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use double quotes everywhere to be consistent.

testString = 'Testing DragData'
fileUri = r"C:\temp\ninja\README"
dragData.SetFragmentText(testString)
self.assertEqual(testString,dragData.GetFragmentText(),'SetFragmentText')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sepearate arguments with spaces.

subtest_message('DragData.GetFileNames() OK')

if __name__ == "__main__":
unittests._test_runner.main(basename(__file__)) No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line at eof.

dragData = cef.DragData()
dragData.SetFragmentText('Test')
dragData.ResetFileContents()
browser.DragTargetDragEnter(dragData, 301, 21, cef.DRAG_OPERATION_COPY )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary space before closing parantheses - on this line and other lines below it as well.


def OnLoadEnd(self,browser,frame,http_code):
subtest_message('cef.OnLoadEnd() OK')
#testing mouse event
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start a comment with a space and from upper case letter.

browser.SendMouseMoveEvent(305, 25, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)
browser.SendMouseClickEvent(305, 25, cef.MOUSEBUTTON_LEFT, True, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)

# testing drag event
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start a comment with a space and from upper case letter.

subtest_message('cef.OnLoadEnd() OK')
#testing mouse event
browser.SendMouseClickEvent(300, 20, cef.MOUSEBUTTON_LEFT, False, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)
browser.SendMouseMoveEvent(305, 25, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the code below before send the first mouse click event. As I explained on the Forum, you must first send move event to the location at which you will trigger a click event. Try this:

browser.SendMouseMoveEvent(305, 25, False, 0)
browser.SendMouseClickEvent(300, 20, cef.MOUSEBUTTON_LEFT, False, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)
browser.SendMouseMoveEvent(305, 25, False, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)
browser.SendMouseClickEvent(305, 25, cef.MOUSEBUTTON_LEFT, True, 1, cef.EVENTFLAG_LEFT_MOUSE_BUTTON)

If this code doesn't work as expected then add comment about it that StartDragging is currently never called and is on TODO list. Add a comment with a link to the Forum post in which I referenced code from upstream CEF unit tests on how it should be done.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be 300/20 coordinates:

browser.SendMouseMoveEvent(300, 20, False, 0)

@cztomczak
Copy link
Owner

Just FYI: I've just created Contributing code document.

| mask | int |
| __Return__ | bool |

Called when an external drag event enters the browser window.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description is not enough. Please copy complete description from CEF headers using template like: "Description from upstream CEF: ...." - similarly to how it is done in API docs for some of other callbacks.

CefRefPtr<CefFileDialogCallback> callback)
{
bool result;
result = DialogHandler_OnFileDialog(browser,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing API docs for OnFileDialog.

@cztomczak
Copy link
Owner

Hi DemonXWeb, I see that you still haven't addressed many of my comments. Also I've noted some other issues that I commented about a few times, but still aren't addressed correctly. If you don't have time to work on this further or are overwhelmed by the requirements I can understand this. The features are good and I want them merged. I can make the necessary changes myself later, but the schedule for that is unknown for now. Cheers!

@cztomczak
Copy link
Owner

Off-screen rendering test added in rev e72609c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.