Code Monkey home page Code Monkey logo

Comments (3)

Pagliacii avatar Pagliacii commented on May 26, 2024

https://github.com/mfitzp/15-minute-apps/blob/b99eb330310fe7302ead39473ef0d34cccb3d12d/browser_tabbed/browser_tabbed.py#L217

Traceback (most recent call last):
  File "browser_tabbed.py", line 217, in print_page
    dlg.paintRequested.connect(self.browser.print_)
AttributeError: 'MainWindow' object has no attribute 'browser'

from pythonguis-examples.

richlysakowski avatar richlysakowski commented on May 26, 2024

I get the same error as above. The error show up in the console log when the user selects the File submenu "File... Print..."

0-MyProjects/PyQt5-15mins-apps/browser_tabbed')
Traceback (most recent call last):

File "C:\Users...!0-MyProjects\PyQt5-15mins-apps\browser_tabbed\browser_tabbed-RSL-WIP.py", line 226, in print_page
dlg.paintRequested.connect(self.browser.print_)

AttributeError: 'MainWindow' object has no attribute 'browser

Should this dlg.paintRequested.connect(self.browser.print_) refer to QPrintPreviewDialog() or should it refer to print_action instantiated earlier, i.e., print_action.triggered.connect(self.print_page) ?

Why is it using the paintRequested attribute for the .connect() signal, instead of actually invoking the QPrintPreviewDialog box?

Please suggest a fix for this, and clarify the fix with an explanation?

Thank you.

Richard

from pythonguis-examples.

Pagliacii avatar Pagliacii commented on May 26, 2024

AttributeError: 'MainWindow' object has no attribute 'browser

@richdevboston You can fix this by adding the method below into the browser_tabbed.MainWindow class.

def handle_paint_request(self, printer):
    painter = QPainter(printer)
    browser = self.tabs.currentWidget()
    painter.setViewport(browser.rect())
    painter.setWindow(browser.rect())
    browser.render(painter)
    painter.end()

And change the print_page method:

def print_page(self):
    dlg = QPrintPreviewDialog()
-   dlg.paintRequested.connect(self.browser.print_)
+   dlg.paintRequested.connect(self.handle_paint_request)
    dlg.exec_()

FYI, these links below can help you if something wrong:

To fix browser.MainWindow.print_page method, the handle_paint_request must be changed a little:

def handle_paint_request(self, printer):
    painter = QPainter(printer)
-   browser = self.tabs.currentWidget()
-   painter.setViewport(browser.rect())
-   painter.setWindow(browser.rect())
-   browser.render(painter)
+   painter.setViewport(self.browser.rect())
+   painter.setWindow(self.browser.rect())
+   self.browser.render(painter)
    painter.end()

HTH
Jason

from pythonguis-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.