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

Class HelpSource

Lib/idlelib/query.py:245–333  ·  view source on GitHub ↗

Get menu name and help source for Help menu.

Source from the content-addressed store, hash-verified

243
244
245class HelpSource(Query):
246 "Get menu name and help source for Help menu."
247 # Used in ConfigDialog.HelpListItemAdd/Edit, (941/9)
248
249 def __init__(self, parent, title, *, menuitem='', filepath='',
250 used_names={}, _htest=False, _utest=False):
251 """Get menu entry and url/local file for Additional Help.
252
253 User enters a name for the Help resource and a web url or file
254 name. The user can browse for the file.
255 """
256 self.filepath = filepath
257 message = 'Name for item on Help menu:'
258 super().__init__(
259 parent, title, message, text0=menuitem,
260 used_names=used_names, _htest=_htest, _utest=_utest)
261
262 def create_extra(self):
263 "Add path widjets to rows 10-12."
264 frame = self.frame
265 pathlabel = Label(frame, anchor='w', justify='left',
266 text='Help File Path: Enter URL or browse for file')
267 self.pathvar = StringVar(self, self.filepath)
268 self.path = Entry(frame, textvariable=self.pathvar, width=40)
269 browse = Button(frame, text='Browse', width=8,
270 command=self.browse_file)
271 self.path_error = Label(frame, text=' ', foreground='red',
272 font=self.error_font)
273
274 pathlabel.grid(column=0, row=10, columnspan=3, padx=5, pady=[10,0],
275 sticky=W)
276 self.path.grid(column=0, row=11, columnspan=2, padx=5, sticky=W+E,
277 pady=[10,0])
278 browse.grid(column=2, row=11, padx=5, sticky=W+S)
279 self.path_error.grid(column=0, row=12, columnspan=3, padx=5,
280 sticky=W+E)
281
282 def askfilename(self, filetypes, initdir, initfile): # htest #
283 # Extracted from browse_file so can mock for unittests.
284 # Cannot unittest as cannot simulate button clicks.
285 # Test by running htest, such as by running this file.
286 return filedialog.Open(parent=self, filetypes=filetypes)\
287 .show(initialdir=initdir, initialfile=initfile)
288
289 def browse_file(self):
290 filetypes = [
291 ("HTML Files", "*.htm *.html", "TEXT"),
292 ("Text Files", "*.txt", "TEXT"),
293 ("All Files", "*")]
294 path = self.pathvar.get()
295 if path:
296 dir, base = os.path.split(path)
297 else:
298 base = None
299 if platform[:3] == 'win':
300 dir = os.path.join(os.path.dirname(executable), 'Doc')
301 if not os.path.isdir(dir):
302 dir = os.getcwd()

Callers 2

helplist_item_addMethod · 0.90
helplist_item_editMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…