MCPcopy Index your code
hub / github.com/python/cpython / print_window

Method print_window

Lib/idlelib/iomenu.py:301–349  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

299 return chars.encode('utf-8-sig')
300
301 def print_window(self, event):
302 confirm = messagebox.askokcancel(
303 title="Print",
304 message="Print to Default Printer",
305 default=messagebox.OK,
306 parent=self.text)
307 if not confirm:
308 self.text.focus_set()
309 return "break"
310 tempfilename = None
311 saved = self.get_saved()
312 if saved:
313 filename = self.filename
314 # shell undo is reset after every prompt, looks saved, probably isn't
315 if not saved or filename is None:
316 (tfd, tempfilename) = tempfile.mkstemp(prefix='IDLE_tmp_')
317 filename = tempfilename
318 os.close(tfd)
319 if not self.writefile(tempfilename):
320 os.unlink(tempfilename)
321 return "break"
322 platform = os.name
323 printPlatform = True
324 if platform == 'posix': #posix platform
325 command = idleConf.GetOption('main','General',
326 'print-command-posix')
327 command = command + " 2>&1"
328 elif platform == 'nt': #win32 platform
329 command = idleConf.GetOption('main','General','print-command-win')
330 else: #no printing for this platform
331 printPlatform = False
332 if printPlatform: #we can try to print for this platform
333 command = command % shlex.quote(filename)
334 pipe = os.popen(command, "r")
335 # things can get ugly on NT if there is no printer available.
336 output = pipe.read().strip()
337 status = pipe.close()
338 if status:
339 output = "Printing failed (exit status 0x%x)\n" % \
340 status + output
341 if output:
342 output = "Printing command: %s\n" % repr(command) + output
343 messagebox.showerror("Print status", output, parent=self.text)
344 else: #no printing for this platform
345 message = "Printing is not enabled for this platform: %s" % platform
346 messagebox.showinfo("Print status", message, parent=self.text)
347 if tempfilename:
348 os.unlink(tempfilename)
349 return "break"
350
351 opendialog = None
352 savedialog = None

Callers

nothing calls this directly

Calls 10

get_savedMethod · 0.95
writefileMethod · 0.95
GetOptionMethod · 0.80
quoteMethod · 0.80
focus_setMethod · 0.45
closeMethod · 0.45
unlinkMethod · 0.45
stripMethod · 0.45
readMethod · 0.45
showerrorMethod · 0.45

Tested by

no test coverage detected