Changeset 1083:a5f219c25f2a


Ignore:
Timestamp:
03/15/23 19:01:30 (22 months ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

Updates for CEF 108 and the corresponding CEFPython.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • setup.py

    r1046 r1083  
    126126    cefDir = os.environ.get("CEFDIR")
    127127    if cefDir:
    128         for fileName in ["icudtl.dat", "subprocess.exe", "natives_blob.bin",
     128        for fileName in ["icudtl.dat", "subprocess.exe",
    129129                         "snapshot_blob.bin", "v8_context_snapshot.bin",
    130                          "cef.pak", "cef_100_percent.pak",
    131                          "cef_200_percent.pak", "cef_extensions.pak"]:
     130                         "chrome_100_percent.pak", "chrome_200_percent.pak",
     131                         "resources.pak"]:
    132132            data_files.append(("", [os.path.join(cefDir, fileName)]))
    133133
  • src/mlx/gui/acars.py

    r996 r1083  
    2727        super(ACARS, self).__init__()
    2828        self._gui = gui
     29        self._browser = None
    2930
    3031    def start(self):
     
    3435        self.pack_start(container, True, True, 0)
    3536
    36         cef.startInContainer(container, ACARS.URL)
     37        self._browser = cef.startInContainer(container, ACARS.URL)
     38
     39    def stop(self):
     40        """Close the browser."""
     41        if self._browser is not None:
     42            self._browser.CloseBrowser(False)
     43            self._browser = None
  • src/mlx/gui/cef.py

    r997 r1083  
    9292        self._browser.SetFocus(True)
    9393        self._browser.SetClientCallback("OnLoadEnd", self._onLoadEnd)
    94 
    95         bindings = cefpython.JavascriptBindings(bindToFrames=True,
    96                                                 bindToPopups=True)
    97         bindings.SetFunction("briefingData", self._briefingDataAvailable)
    98         bindings.SetFunction("formFilled", self._formFilled)
    99         self._browser.SetJavascriptBindings(bindings)
     94        self._browser.SetClientCallback("OnLoadError", self._onLoadError)
     95        self._browser.SetClientCallback("OnBeforeBrowse",
     96                                        lambda browser, frame, request,
     97                                        user_gesture, is_redirect: False)
    10098
    10199    def call(self, plan, getCredentials, updateProgress, htmlFilePath):
     
    112110        self._updateProgress(SIMBRIEF_PROGRESS_LOADING_FORM,
    113111                             SIMBRIEF_RESULT_NONE, None)
     112
     113    def finalize(self):
     114        """Close the browser and release it."""
     115        self._browser.CloseBrowser()
     116        self._browser = None
    114117
    115118    def _onLoadEnd(self, browser, frame, http_code):
     
    182185                                 SIMBRIEF_RESULT_ERROR_OTHER, None)
    183186
    184     def _resultsAvailable(self, flightInfo):
    185         """Called from the result retrieval thread when the result is
    186         available.
    187 
    188         It checks for the plan being not None, as we may time out."""
    189         if self._plan is not None:
    190             self._updateProgress(SIMBRIEF_PROGRESS_DONE,
    191                                  SIMBRIEF_RESULT_OK, flightInfo)
     187    def _onLoadError(self, browser, frame, error_code, error_text_out,
     188                     failed_url):
     189        """Called when loading of an URL fails."""
     190        print("gui.cef.SimBriefHandler._onLoadError", browser, frame, error_code, error_text_out, failed_url)
     191        self._updateProgress(self._lastProgress,
     192                             SIMBRIEF_RESULT_ERROR_OTHER, None)
    192193
    193194    def _updateProgress(self, progress, results, flightInfo):
     
    281282        "browser_subprocess_path": "%s/%s" % \
    282283            (cefpython.GetModuleDirectory(), "subprocess"),
     284        "windowless_rendering_enabled": True,
     285        "cache_path": os.path.join(GLib.get_user_cache_dir(),
     286                                   "mlxcef")
    283287    }
    284288
     
    307311    """Get a container object suitable for running a browser instance
    308312    within."""
    309     if os.name=="nt":
    310         container = Gtk.DrawingArea()
    311         container.set_property("can-focus", True)
    312         container.connect("size-allocate", _handleSizeAllocate)
    313     else:
    314         container = Gtk.DrawingArea()
    315 
     313    container = Gtk.DrawingArea()
     314    container.set_property("can-focus", True)
     315    container.connect("size-allocate", _handleSizeAllocate)
    316316    container.show()
    317317
     
    333333        container.windowID = windowID
    334334        Gdk.threads_leave()
     335        windowRect = [0, 0, 1, 1]
    335336    else:
    336337        container.set_visual(container.get_screen().lookup_visual(0x21))
    337338        windowID = container.get_window().get_xid()
     339        windowRect = None
    338340
    339341    windowInfo = cefpython.WindowInfo()
    340342    if windowID is not None:
    341         windowInfo.SetAsChild(windowID)
    342 
    343     return cefpython.CreateBrowserSync(windowInfo,
    344                                        browserSettings = browserSettings,
    345                                        navigateUrl = url)
     343        windowInfo.SetAsChild(windowID, windowRect = windowRect)
     344
     345    browser = cefpython.CreateBrowserSync(windowInfo,
     346                                          browserSettings = browserSettings,
     347                                          navigateUrl = url)
     348    container.browser = browser
     349
     350    return browser
    346351
    347352#------------------------------------------------------------------------------
     
    350355    def GetRootScreenRect(self, browser, rect_out):
    351356        #print "GetRootScreenRect"
    352         rect_out += [0, 0, 800, 600]
     357        rect_out += [0, 0, 1920, 1080]
    353358        return True
    354359
    355360    def GetViewRect(self, browser, rect_out):
    356361        #print "GetViewRect"
    357         rect_out += [0, 0, 800, 600]
     362        rect_out += [0, 40, 1920, 1040]
    358363        return True
    359364
     
    387392        pass
    388393
    389     def OnBeforePopup(self, browser, frame, targetURL, targetFrameName,
    390                       popupFeatures, windowInfo, client, browserSettings,
    391                       noJavascriptAccess):
     394    def OnBeforePopup(self, browser, frame, target_url, target_frame_name,
     395                      target_disposition, user_gesture,
     396                      popup_features, window_info_out, client,
     397                      browser_settings_out, no_javascript_access_out,
     398                      **kwargs):
    392399        wInfo = cefpython.WindowInfo()
    393400        wInfo.SetAsOffscreen(int(0))
    394401
    395         windowInfo.append(wInfo)
     402        window_info_out.append(wInfo)
    396403
    397404        return False
     
    417424    global _toQuit
    418425    _toQuit = True
     426
     427    _simBriefHandler.finalize()
     428
    419429    cefpython.Shutdown()
    420430
     
    433443def _handleSizeAllocate(widget, sizeAlloc):
    434444    """Handle the size-allocate event on Windows."""
    435     if widget is not None:
    436         cefpython.WindowUtils.OnSize(widget.windowID, 0, 0, 0)
     445    if os.name=="nt":
     446        if widget is not None and hasattr(widget, "windowID"):
     447            cefpython.WindowUtils.OnSize(widget.windowID, 0, 0, 0)
     448    else:
     449         if widget is not None and hasattr(widget, "browser") and \
     450            widget.browser is not None:
     451             widget.browser.SetBounds(sizeAlloc.x, sizeAlloc.y,
     452                                      sizeAlloc.width, sizeAlloc.height)
  • src/mlx/gui/common.py

    r1002 r1083  
    3535from gi.repository import Pango
    3636from gi.repository import PangoCairo
     37from gi.repository import GLib
    3738
    3839import codecs
  • src/mlx/gui/gui.py

    r1081 r1083  
    484484        singleton.raiseCallback = None
    485485
     486        self._acars.stop()
     487
    486488        cef.finalize()
    487489
Note: See TracChangeset for help on using the changeset viewer.