def loadPosition(window): #log.debug("keepWindowSize.loadPosition: %s" % window.title) width, height = window.get_size_request() if conf.hasKey(key + "_width") and conf.hasKey(key + "_height"): width = conf.getStrict(key + "_width") height = conf.getStrict(key + "_height") log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) elif defaultSize: width, height = defaultSize log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) if conf.hasKey(key + "_x") and conf.hasKey(key + "_y"): log.debug("Moving window to x=%s y=%s" % (conf.getStrict(key + "_x"), conf.getStrict(key + "_y"))) window.move(conf.getStrict(key + "_x"), conf.getStrict(key + "_y")) elif defaultPosition in (POSITION_CENTER, POSITION_GOLDEN): monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds( ) x = int(monitor_width / 2 - width / 2) + monitor_x if defaultPosition == POSITION_CENTER: y = int(monitor_height / 2 - height / 2) + monitor_y else: # Place the window on the upper golden ratio line y = int(monitor_height / 2.618 - height / 2) + monitor_y log.debug("Moving window to x=%s y=%s" % (x, y)) window.move(x, y)
def loadPosition(window): width, height = window.get_size_request() if conf.hasKey(key + "_width") and conf.hasKey(key + "_height"): width = conf.getStrict(key + "_width") height = conf.getStrict(key + "_height") window.resize(width, height) elif defaultSize: width, height = defaultSize window.resize(width, height) if conf.hasKey(key + "_x") and conf.hasKey(key + "_y"): window.move(conf.getStrict(key + "_x"), conf.getStrict(key + "_y")) elif defaultPosition in (POSITION_CENTER, POSITION_GOLDEN): monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds( ) x = int(monitor_width / 2 - width / 2) + monitor_x if defaultPosition == POSITION_CENTER: y = int(monitor_height / 2 - height / 2) + monitor_y else: # Place the window on the upper golden ratio line y = int(monitor_height / 2.618 - height / 2) + monitor_y window.move(x, y)
def loadPosition (window): #log.debug("keepWindowSize.loadPosition: %s" % window.title) width, height = window.get_size_request() if conf.hasKey(key+"_width") and conf.hasKey(key+"_height"): width = conf.getStrict(key+"_width") height = conf.getStrict(key+"_height") log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) elif defaultSize: width, height = defaultSize log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) if conf.hasKey(key+"_x") and conf.hasKey(key+"_y"): log.debug("Moving window to x=%s y=%s" % (conf.getStrict(key+"_x"), conf.getStrict(key+"_y"))) window.move(conf.getStrict(key+"_x"), conf.getStrict(key+"_y")) elif defaultPosition in (POSITION_CENTER, POSITION_GOLDEN): monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds() x = int(monitor_width/2-width/2) + monitor_x if defaultPosition == POSITION_CENTER: y = int(monitor_height/2-height/2) + monitor_y else: # Place the window on the upper golden ratio line y = int(monitor_height/2.618-height/2) + monitor_y log.debug("Moving window to x=%s y=%s" % (x, y)) window.move(x, y)
def loadPosition (window): width, height = window.get_size_request() if conf.hasKey(key+"_width") and conf.hasKey(key+"_height"): width = conf.getStrict(key+"_width") height = conf.getStrict(key+"_height") window.resize(width, height) elif defaultSize: width, height = defaultSize window.resize(width, height) if conf.hasKey(key+"_x") and conf.hasKey(key+"_y"): window.move(conf.getStrict(key+"_x"), conf.getStrict(key+"_y")) elif defaultPosition in (POSITION_CENTER, POSITION_GOLDEN): monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds() x = int(monitor_width/2-width/2) + monitor_x if defaultPosition == POSITION_CENTER: y = int(monitor_height/2-height/2) + monitor_y else: # Place the window on the upper golden ratio line y = int(monitor_height/2.618-height/2) + monitor_y window.move(x, y)
def loadPosition(window): # log.debug("keepWindowSize.loadPosition: %s" % window.title) # Just to make sphinx happy... try: width, height = window.get_size_request() except TypeError: pass if conf.hasKey(key + "_width") and conf.hasKey(key + "_height"): width = conf.get(key + "_width") height = conf.get(key + "_height") log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) elif defaultSize: width, height = defaultSize log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) elif key == "mainwindow": monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds( ) width = int(monitor_width / 2) height = int(monitor_height / 4) * 3 log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) elif key == "preferencesdialogwindow": monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds( ) width = int(monitor_width / 2) height = int(monitor_height / 4) * 3 window.resize(1, 1) else: monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds( ) width = int(monitor_width / 2) height = int(monitor_height / 4) * 3 if conf.hasKey(key + "_x") and conf.hasKey(key + "_y"): x = max(0, conf.get(key + "_x")) y = max(0, conf.get(key + "_y")) log.debug("Moving window to x=%s y=%s" % (x, y)) window.move(x, y) elif defaultPosition in (POSITION_CENTER, POSITION_GOLDEN): monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds( ) x_loc = int(monitor_width / 2 - width / 2) + monitor_x if defaultPosition == POSITION_CENTER: y_loc = int(monitor_height / 2 - height / 2) + monitor_y else: # Place the window on the upper golden ratio line y_loc = int(monitor_height / 2.618 - height / 2) + monitor_y log.debug("Moving window to x=%s y=%s" % (x_loc, y_loc)) window.move(x_loc, y_loc)
def loadPosition(window): # log.debug("keepWindowSize.loadPosition: %s" % window.title) # Just to make sphinx happy... try: width, height = window.get_size_request() except TypeError: pass if conf.hasKey(key + "_width") and conf.hasKey(key + "_height"): width = conf.get(key + "_width") height = conf.get(key + "_height") log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) elif defaultSize: width, height = defaultSize log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) elif key == "mainwindow": monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds() width = int(monitor_width / 2) height = int(monitor_height / 4) * 3 log.debug("Resizing window to width=%s height=%s" % (width, height)) window.resize(width, height) elif key == "preferencesdialogwindow": monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds() width = int(monitor_width / 2) height = int(monitor_height / 4) * 3 window.resize(1, 1) else: monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds() width = int(monitor_width / 2) height = int(monitor_height / 4) * 3 if conf.hasKey(key + "_x") and conf.hasKey(key + "_y"): x = max(0, conf.get(key + "_x")) y = max(0, conf.get(key + "_y")) log.debug("Moving window to x=%s y=%s" % (x, y)) window.move(x, y) elif defaultPosition in (POSITION_CENTER, POSITION_GOLDEN): monitor_x, monitor_y, monitor_width, monitor_height = getMonitorBounds() x_loc = int(monitor_width / 2 - width / 2) + monitor_x if defaultPosition == POSITION_CENTER: y_loc = int(monitor_height / 2 - height / 2) + monitor_y else: # Place the window on the upper golden ratio line y_loc = int(monitor_height / 2.618 - height / 2) + monitor_y log.debug("Moving window to x=%s y=%s" % (x_loc, y_loc)) window.move(x_loc, y_loc)
def saveDialogWidget(widget, widget_name, config_number, get_value_=None): key = widget_name + "-" + str(config_number) if widget is None: raise AttributeError("key '%s' isn't in widgets" % widget_name) for class_, methods_ in METHODS: if isinstance(widget, class_): getter, setter, signal = methods_ break else: if get_value_ is None: raise AttributeError("I don't have any knowledge of type: '%s'" % widget) if get_value_: def get_value(): return get_value_(widget) else: get_value = getattr(widget, getter) if not conf.hasKey(key) or conf.get(key) != get_value(): conf.set(key, get_value())
def loadDialogWidget( widget, widget_name, config_number, get_value_=None, set_value_=None, first_value=None, ): key = widget_name + "-" + str(config_number) if widget is None: raise AttributeError("key '%s' isn't in widgets" % widget_name) for class_, methods_ in METHODS: if isinstance(widget, class_): getter, setter, signal = methods_ break else: if set_value_ is None: raise AttributeError("I don't have any knowledge of type: '%s'" % widget) if get_value_: def get_value(): return get_value_(widget) else: get_value = getattr(widget, getter) if set_value_: def set_value(v): return set_value_(widget, v) else: set_value = getattr(widget, setter) if conf.hasKey(key): try: v = conf.get(key) except TypeError: log.warning( "uistuff.loadDialogWidget: Key '%s' from conf had the wrong type '%s', ignored" % (key, type(conf.get(key)))) if first_value is not None: conf.set(key, first_value) else: conf.set(key, get_value()) else: set_value(v) elif first_value is not None: conf.set(key, first_value) set_value(conf.get(key)) else: log.warning( 'Didn\'t load widget "%s": no conf value and no first_value arg' % widget_name)
def keep(widget, key, get_value_=None, set_value_=None): # , first_value=None): if widget is None: raise AttributeError("key '%s' isn't in widgets" % key) for class_, methods_ in METHODS: # Use try-except just to make spinx happy... try: if isinstance(widget, class_): getter, setter, signal = methods_ break except TypeError: getter, setter, signal = methods_ break else: raise AttributeError("I don't have any knowledge of type: '%s'" % widget) if get_value_: def get_value(): return get_value_(widget) else: get_value = getattr(widget, getter) if set_value_: def set_value(v): return set_value_(widget, v) else: set_value = getattr(widget, setter) def setFromConf(): try: v = conf.get(key) except TypeError: log.warning( "uistuff.keep.setFromConf: Key '%s' from conf had the wrong type '%s', ignored" % (key, type(conf.get(key)))) # print("uistuff.keep TypeError %s %s" % (key, conf.get(key))) else: set_value(v) def callback(*args): if not conf.hasKey(key) or conf.get(key) != get_value(): conf.set(key, get_value()) widget.connect(signal, callback) conf.notify_add(key, lambda *args: setFromConf()) if conf.hasKey(key): setFromConf() elif conf.get(key) is not None: conf.set(key, conf.get(key))
def keep(widget, key, get_value_=None, set_value_=None, first_value=None): if widget is None: raise AttributeError("key '%s' isn't in widgets" % key) for class_, methods_ in METHODS: # Use try-except just to make spinx happy... try: if isinstance(widget, class_): getter, setter, signal = methods_ break except TypeError: getter, setter, signal = methods_ break else: raise AttributeError("I don't have any knowledge of type: '%s'" % widget) if get_value_: def get_value(): return get_value_(widget) else: get_value = getattr(widget, getter) if set_value_: def set_value(v): return set_value_(widget, v) else: set_value = getattr(widget, setter) def setFromConf(): try: v = conf.get(key) except TypeError: log.warning("uistuff.keep.setFromConf: Key '%s' from conf had the wrong type '%s', ignored" % (key, type(conf.get(key)))) if first_value is not None: conf.set(key, first_value) else: conf.set(key, get_value()) else: set_value(v) def callback(*args): if not conf.hasKey(key) or conf.get(key) != get_value(): conf.set(key, get_value()) widget.connect(signal, callback) conf.notify_add(key, lambda *args: setFromConf()) if conf.hasKey(key): setFromConf() elif first_value is not None: conf.set(key, first_value)
def loadDialogWidget(widget, widget_name, config_number, get_value_=None, set_value_=None, first_value=None): key = widget_name + "-" + str(config_number) if widget is None: raise AttributeError("key '%s' isn't in widgets" % widget_name) for class_, methods_ in METHODS: if isinstance(widget, class_): getter, setter, signal = methods_ break else: if set_value_ is None: raise AttributeError("I don't have any knowledge of type: '%s'" % widget) if get_value_: def get_value(): return get_value_(widget) else: get_value = getattr(widget, getter) if set_value_: def set_value(v): return set_value_(widget, v) else: set_value = getattr(widget, setter) if conf.hasKey(key): try: v = conf.get(key) except TypeError: log.warning("uistuff.loadDialogWidget: Key '%s' from conf had the wrong type '%s', ignored" % (key, type(conf.get(key)))) if first_value is not None: conf.set(key, first_value) else: conf.set(key, get_value()) else: set_value(v) elif first_value is not None: conf.set(key, first_value) set_value(conf.get(key)) else: log.warning("Didn't load widget \"%s\": no conf value and no first_value arg" % widget_name)
def loadDialogWidget(widget, widget_name, config_number, get_value_=None, set_value_=None, first_value=None): key = widget_name + "-" + str(config_number) if widget == None: raise AttributeError, "key '%s' isn't in widgets" % widget_name for class_, methods_ in METHODS: if isinstance(widget, class_): getter, setter, signal = methods_ break else: if set_value_ == None: raise AttributeError, "I don't have any knowledge of type: '%s'" % widget if get_value_: get_value = lambda: get_value_(widget) else: get_value = getattr(widget, getter) if set_value_: set_value = lambda v: set_value_(widget, v) else: set_value = getattr(widget, setter) if conf.hasKey(key): try: v = conf.getStrict(key) except TypeError: log.warn("uistuff.loadDialogWidget: Key '%s' from conf had the wrong type '%s', ignored" % \ (key, type(conf.getStrict(key)))) if first_value != None: conf.set(key, first_value) else: conf.set(key, get_value()) else: set_value(v) elif first_value != None: conf.set(key, first_value) set_value(conf.getStrict(key)) else: log.warn("Didn't load widget \"%s\": no conf value and no first_value arg" % \ widget_name)
def keep(widget, key, get_value_=None, set_value_=None, first_value=None): if widget == None: raise AttributeError("key '%s' isn't in widgets" % key) for class_, methods_ in METHODS: if isinstance(widget, class_): getter, setter, signal = methods_ break else: raise AttributeError("I don't have any knowledge of type: '%s'" % widget) if get_value_: get_value = lambda: get_value_(widget) else: get_value = getattr(widget, getter) if set_value_: set_value = lambda v: set_value_(widget, v) else: set_value = getattr(widget, setter) def setFromConf(): try: v = conf.getStrict(key) except TypeError: log.warning("uistuff.keep.setFromConf: Key '%s' from conf had the wrong type '%s', ignored" % \ (key, type(conf.getStrict(key)))) if first_value != None: conf.set(key, first_value) else: conf.set(key, get_value()) else: set_value(v) def callback(*args): if not conf.hasKey(key) or conf.getStrict(key) != get_value(): conf.set(key, get_value()) widget.connect(signal, callback) conf.notify_add(key, lambda *args: setFromConf()) if conf.hasKey(key): setFromConf() elif first_value != None: conf.set(key, first_value)
def saveDialogWidget (widget, widget_name, config_number, get_value_=None): key = widget_name + "-" + str(config_number) if widget == None: raise AttributeError("key '%s' isn't in widgets" % widget_name) for class_, methods_ in METHODS: if isinstance(widget, class_): getter, setter, signal = methods_ break else: if get_value_ == None: raise AttributeError("I don't have any knowledge of type: '%s'" % widget) if get_value_: get_value = lambda: get_value_(widget) else: get_value = getattr(widget, getter) if not conf.hasKey(key) or conf.getStrict(key) != get_value(): conf.set(key, get_value())
self.widgets["inv_ana_combobox"], "inv_ana_combobox", anal_combo_get_value, lambda combobox, value: anal_combo_set_value( combobox, value, "spy_mode", "inv_analyzer_check", SPY)) uistuff.keep(self.widgets["max_analysis_spin"], "max_analysis_spin", first_value=3) # Sound initing # Setup default sounds EXT = "wav" if sys.platform == "win32" else "ogg" for i in range(11): if not conf.hasKey("soundcombo%d" % i): conf.set("soundcombo%d" % i, SOUND_URI) if not conf.hasKey("sounduri0"): conf.set("sounduri0", "file:" + pathname2url(addDataPrefix("sounds/move1.%s" % EXT))) if not conf.hasKey("sounduri1"): conf.set("sounduri1", "file:" + pathname2url(addDataPrefix("sounds/check1.%s" % EXT))) if not conf.hasKey("sounduri2"): conf.set("sounduri2", "file:" + pathname2url(addDataPrefix("sounds/capture1.%s" % EXT))) if not conf.hasKey("sounduri3"): conf.set("sounduri3", "file:" + pathname2url(addDataPrefix("sounds/start1.%s" % EXT))) if not conf.hasKey("sounduri4"): conf.set("sounduri4",
self.widgets["ana_combobox"], "ana_combobox", anal_combo_get_value, lambda combobox, value: anal_combo_set_value(combobox, value, "hint_mode", "analyzer_check", HINT)) uistuff.keep( self.widgets["inv_ana_combobox"], "inv_ana_combobox", anal_combo_get_value, lambda combobox, value: anal_combo_set_value(combobox, value, "spy_mode", "inv_analyzer_check", SPY)) uistuff.keep(self.widgets["max_analysis_spin"], "max_analysis_spin", first_value=3) # Sound initing # Setup default sounds EXT = "wav" if sys.platform == "win32" else "ogg" for i in range(11): if not conf.hasKey("soundcombo%d" % i): conf.set("soundcombo%d" % i, SOUND_URI) if not conf.hasKey("sounduri0"): conf.set("sounduri0", "file:" + pathname2url(addDataPrefix("sounds/move1.%s" % EXT))) if not conf.hasKey("sounduri1"): conf.set("sounduri1", "file:" + pathname2url(addDataPrefix("sounds/check1.%s" % EXT))) if not conf.hasKey("sounduri2"): conf.set("sounduri2", "file:" + pathname2url(addDataPrefix("sounds/capture1.%s" % EXT))) if not conf.hasKey("sounduri3"): conf.set("sounduri3", "file:" + pathname2url(addDataPrefix("sounds/start1.%s" % EXT))) if not conf.hasKey("sounduri4"): conf.set("sounduri4",
def callback(*args): if not conf.hasKey(key) or conf.getStrict(key) != get_value(): conf.set(key, get_value())
def callback(*args): if not conf.hasKey(key) or conf.get(key) != get_value(): conf.set(key, get_value())