def set_custom_search_depth(self, b): dialog = Gtk.MessageDialog( None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK_CANCEL, None) markup = "<b>Set User-Defined Level</b>" dialog.set_markup(markup) #create the text input fields entry = Gtk.Entry() entry.set_text(str(self.custom_search_depth)) entry.set_max_length(2) entry.set_width_chars(5) entry2 = Gtk.Entry() entry2.set_text(str(self.custom_time_limit)) entry2.set_max_length(5) entry2.set_width_chars(5) #allow the user to press enter to do ok entry.connect("activate", self.response_to_dialog, dialog, Gtk.ResponseType.OK) entry2.connect("activate", self.response_to_dialog, dialog, Gtk.ResponseType.OK) tbl = Gtk.Table(2, 2, True) tbl.attach(Gtk.Label(label="Search Depth\n(max 52)\n"), 0, 1, 0, 1) tbl.attach(entry, 1, 2, 0, 1) tbl.attach(Gtk.Label(label="Time Limit\n(in seconds)"), 0, 1, 1, 2) tbl.attach(entry2, 1, 2, 1, 2) #some secondary text markup = 'Enter values for Search Depth\n' markup += 'and Time Limit.' dialog.format_secondary_markup(markup) dialog.vbox.add(tbl) dialog.show_all() # If user hasn't clicked on OK then exit now if dialog.run() != Gtk.ResponseType.OK: dialog.destroy() return # user clicked OK so update with the values entered depth = entry.get_text() time = entry2.get_text() dialog.destroy() # if valid number entered then set search depth try: d = int(depth) if d >= 0 and d <= 52: self.custom_search_depth = d except ValueError: pass # if valid number entered then set time limit try: t = int(time) if t >= 0: self.custom_time_limit = t except ValueError: pass # if using user defined level then call engine with the new settings if self.level == 3: engine.setlevel(self.level, self.custom_search_depth, self.custom_time_limit)
def set_level(self, w, data): self.level = data.get_current_value() engine.setlevel(data.get_current_value(), self.custom_search_depth, self.custom_time_limit)