def gtkTextviewCompare(widgetpath, targettext, tolerance=None): widget = gtklogger.findWidget(widgetpath) msgbuffer = gtklogger.findWidget(widgetpath).get_buffer() text = msgbuffer.get_text(msgbuffer.get_start_iter(), msgbuffer.get_end_iter()) if not fp_string_compare(text, targettext, tolerance): print >> sys.stderr, ("Textview compare failed for %s, >%s<!=>%s<." % (widgetpath, text, targettext)) return False return True
def skeletonSelectionTBSizeCheck(windowname, category, n): # Check that the right size is displayed in the Skeleton Selection # toolbox. 'category' must be "Element", "Node", or "Segment". text = gtklogger.findWidget( '%s:Pane0:Pane1:Pane2:TBScroll:Skeleton Selection:%s:size' % (windowname, category)) return eval(text.get_text()) == n
def menuSensitive(menu, item): topmenuwidget = gtklogger.findWidget(menu) if not topmenuwidget: print >> sys.stderr, "Didn't find widget for", menu menuitemwidget = gtklogger.findMenu(topmenuwidget, item) if not menuitemwidget: print >> sys.stderr, "Didn't find widget for %s:%s" % (menu, item) return _widget_sensitive(menuitemwidget)
def treeViewSelectCheck(widgetpath, col): # Returns the contents of the given column of a TreeStore in the # selected row of the given TreeView. treeview = gtklogger.findWidget(widgetpath) selection = treeview.get_selection() model, iter = selection.get_selected() if iter is not None: return model[iter][col]
def listViewSelectedRowNo(widgetpath): # widgetpath must be a TreeView displaying a ListStore. Returns # the index of the selected row, or None if nothing is selected. treeview = gtklogger.findWidget(widgetpath) selection = treeview.get_selection() model, iter = selection.get_selected() if iter is not None: return model.get_path(iter)[0] return None # nothing selected
def chooserStateCheck(widgetpath, choice): # only for ChooserWidget, not ChooserListWidget. Checks that the # currently selected item is 'choice'. combobox = gtklogger.findWidget(widgetpath) index = combobox.get_active() if index == -1: return choice is None model = combobox.get_model() return choice == model[index][0]
def gtkTextviewHead(widgetpath, targettext): msgbuffer = gtklogger.findWidget(widgetpath).get_buffer() text = msgbuffer.get_text(msgbuffer.get_start_iter(), msgbuffer.get_end_iter()) ok = text.startswith(targettext) if not ok: print >> sys.stderr, \ ("gtkTextviewHead failed for %s: text =>%s< doesn't start with >%s<" % (widgetpath, text, targettext)) return ok
def gtkTextviewTail(widgetpath, targettext, tolerance=None): msgbuffer = gtklogger.findWidget(widgetpath).get_buffer() text = msgbuffer.get_text(msgbuffer.get_start_iter(), msgbuffer.get_end_iter()) if not fp_string_compare_tail(text, targettext, tolerance): print >> sys.stderr, (("gtkTextviewTail failed for %s\n" "expected =>%s<=\ngot =>%s<=") % (widgetpath, targettext, text)) return False return True
def gtkTextCompare(widgetpath, targettext, tolerance=None): gtktxt = gtklogger.findWidget(widgetpath) if not gtktxt: print >> sys.stderr, "Text widget not found: %s." % widgetpath return False sourcetext = string.strip(gtktxt.get_text()) if not fp_string_compare(sourcetext, targettext, tolerance): print >> sys.stderr, ("Text compare failed for path %s, >%s< != >%s<" % (widgetpath, sourcetext, targettext)) return False return True
def selectedPropertyCheck(propertypath): # Check that the given Property is selected in the Property Pane. from ooflib.engine.IO.GUI import materialsPage propertyTree = materialsPage.materialspage.propertypane.propertytree prop = propertyTree.tree[propertypath] treeview = gtklogger.findWidget( 'OOF2:Materials Page:Pane:Property:PropertyScroll:PropertyTree') selection = treeview.get_selection() model, iter = selection.get_selected() return model[iter][1] is prop
def gtkFloatCompare(widgetpath, targetval, tolerance=1.e-6): gtktxt = gtklogger.findWidget(widgetpath) if not gtktxt: print >> sys.stderr, "Text widget not found: %s." % widgetpath return False sourceval = float(gtktxt.get_text()) if abs(sourceval - targetval) > tolerance: print >> sys.stderr, ("Floating point comparison failed for %s, %g!=%g" % (widgetpath, sourceval, targetval)) return False return True
def gtkFloatCompare(widgetpath, targetval, tolerance=1.e-6): gtktxt = gtklogger.findWidget(widgetpath) if not gtktxt: print >> sys.stderr, "Text widget not found: %s." % widgetpath return False sourceval = float(gtktxt.get_text()) if abs(sourceval - targetval) > tolerance: print >> sys.stderr, ( "Floating point comparison failed for %s, %g!=%g" % (widgetpath, sourceval, targetval)) return False return True
def chooserListStateCheckN(widgetpath, choices): # Just like chooserListStateCheck, but choices is a list of integers treeview = gtklogger.findWidget(widgetpath) selection = treeview.get_selection() model, paths = selection.get_selected_rows() if len(paths) != len(choices): print >> sys.stderr, "Wrong number of selections:", len(paths), "!=", len(choices) return False selected = [p[0] for p in paths] if selected == choices: return True print >> sys.stderr, "Selected rows are", selected return False
def pixelSelectionTBSizeCheck(windowname, minpxls, maxpxls=None): # Check that the pixel selection size is displayed correctly in # the graphics window. Since different versions of ImageMagick # can cause pixel selection operations to work differently after # image modifications, it's possible to specify a range of pixel # counts for this test. text = gtklogger.findWidget( '%s:Pane0:Pane1:Pane2:TBScroll:Pixel Selection:size' % windowname) n = eval(text.get_text()) if maxpxls is None: return n == minpxls else: return minpxls <= n <= maxpxls
def chooserListStateCheckN(widgetpath, choices): # Just like chooserListStateCheck, but choices is a list of integers treeview = gtklogger.findWidget(widgetpath) selection = treeview.get_selection() model, paths = selection.get_selected_rows() if len(paths) != len(choices): print >> sys.stderr, "Wrong number of selections:", len( paths), "!=", len(choices) return False selected = [p[0] for p in paths] if selected == choices: return True print >> sys.stderr, "Selected rows are", selected return False
def selectedMatlPropertyCheck(propertypath): # Check that the given Property is selected in the list of # Properties in the Material Pane. propertypath should be None if # no Property is selected. matproplist = gtklogger.findWidget( 'OOF2:Materials Page:Pane:Material:PropertyListScroll:PropertyList') selection = matproplist.get_selection() model, iter = selection.get_selected() if not iter and propertypath is None: return True if model[iter][0] == propertypath: return True print "Selected property is %s. Expected %s." \ % (model[iter][0], propertypath) return False
def treeViewColCheck(widgetpath, col, choices, tolerance=None): # Check that the contents of the given column of a TreeView match # the given list of choices. 'widgetpath' is the gtklogger path # to the gtk TreeView. 'col' is actually a TreeStore or ListStore # column number. treeview = gtklogger.findWidget(widgetpath) liststore = treeview.get_model() if len(liststore) != len(choices): print >> sys.stderr, "length mismatch: %d!=%d" % (len(liststore), len(choices)) return False for i,x in enumerate(liststore): if choices[i] != None: if not fp_string_compare(x[col], choices[i], tolerance): print >> sys.stderr, x[col], '!=', choices[i] return False return True
def treeViewColCheck(widgetpath, col, choices, tolerance=None): # Check that the contents of the given column of a TreeView match # the given list of choices. 'widgetpath' is the gtklogger path # to the gtk TreeView. 'col' is actually a TreeStore or ListStore # column number. treeview = gtklogger.findWidget(widgetpath) liststore = treeview.get_model() if len(liststore) != len(choices): print >> sys.stderr, "length mismatch: %d!=%d" % (len(liststore), len(choices)) return False for i, x in enumerate(liststore): if choices[i] != None: if not fp_string_compare(x[col], choices[i], tolerance): print >> sys.stderr, x[col], '!=', choices[i] return False return True
def chooserListStateCheck(widgetpath, choices, tolerance=None): # for ChooserListWidget and friends, including MultiListWidget. # Checks that everything in the list 'choices' is selected. treeview = gtklogger.findWidget(widgetpath) selection = treeview.get_selection() model, paths = selection.get_selected_rows() if len(paths) != len(choices): print >> sys.stderr, "Wrong number of selections:", len(paths), "!=", len(choices) return False for path in paths: # loop over actually selected objects val = model[path][0] for choice in choices: if fp_string_compare(val, choice, tolerance): break else: print >> sys.stderr, "Expected:", choices print >> sys.stderr, " Got:", [model[p][0] for p in paths] return False return True
def chooserListStateCheck(widgetpath, choices, tolerance=None): # for ChooserListWidget and friends, including MultiListWidget. # Checks that everything in the list 'choices' is selected. treeview = gtklogger.findWidget(widgetpath) selection = treeview.get_selection() model, paths = selection.get_selected_rows() if len(paths) != len(choices): print >> sys.stderr, "Wrong number of selections:", len( paths), "!=", len(choices) return False for path in paths: # loop over actually selected objects val = model[path][0] for choice in choices: if fp_string_compare(val, choice, tolerance): break else: print >> sys.stderr, "Expected:", choices print >> sys.stderr, " Got:", [model[p][0] for p in paths] return False return True
def gtkTextviewGetLines(widgetpath): msgbuffer = gtklogger.findWidget(widgetpath).get_buffer() text = msgbuffer.get_text(msgbuffer.get_start_iter(), msgbuffer.get_end_iter()).split('\n') return text
def treeViewColValues(widgetpath, col): treeview = gtklogger.findWidget(widgetpath) liststore = treeview.get_model() return [x[col] for x in iter(liststore)]
def is_sensitive(widgetpath): return _widget_sensitive(gtklogger.findWidget(widgetpath))
def _statusText(): return gtklogger.findWidget( 'OOF3D:Skeleton Selection Page:Pane:status').get_text()
def _statusText(): return gtklogger.findWidget( 'OOF2:Skeleton Selection Page:Pane:status').get_text()
def treeViewSizeCheck(widgetpath): # Returns the contents of the given column of a TreeStore in the # selected row of the given TreeView. treeview = gtklogger.findWidget(widgetpath) selection = treeview.get_selection() return selection.count_selected_rows() + 1
def treeViewLength(widgetpath): # Return the number of items in the given TreeView. treeview = gtklogger.findWidget(widgetpath) return len(treeview.get_model())