Ejemplo n.º 1
0
	def execute(self,bind):
		"""
		Execute a dialog synchronously.

		As argument a dictionary mapping widget names to return values
		is expected. Events from these widgets will cause this function
		to return with the associated return value.

		This function will not return until such an event occurs.
		The widget will be shown before execution and hidden afterwards.
		You can only execute root widgets.

		Note: This feature is not tested well, and the API will probably
		change. Otherwise have fun::
		  # Okay this a very condensed example :-)
		  return pychan.loadXML("contents/gui/dialog.xml").execute({ 'okButton' : True, 'closeButton' : False })

		"""
		if not get_manager().can_execute:
			raise RuntimeError("Synchronous execution is not set up!")
		if self._parent:
			raise RuntimeError("You can only 'execute' root widgets, not %s!" % str(self))

		for name,returnValue in bind.items():
			def _quitThisDialog(returnValue = returnValue ):
				get_manager().breakFromMainLoop( returnValue )
				self.hide()
			self.findChild(name=name).capture( _quitThisDialog )
		self.show()
		return get_manager().mainLoop()
Ejemplo n.º 2
0
def loadFonts(filename):
    """
	Load fonts from a config file. These are then available via their name.
	"""
    from internal import get_manager

    for font in Font.loadFromFile(filename):
        get_manager().addFont(font)
Ejemplo n.º 3
0
def loadFonts(filename):
	"""
	Load fonts from a config file. These are then available via their name.
	"""
	from internal import get_manager

	for font in Font.loadFromFile(filename):
		get_manager().addFont(font)
Ejemplo n.º 4
0
	def show(self):
		"""
		Show the widget and all contained widgets.
		"""
		if self._parent:
			raise RuntimeError(Widget.HIDE_SHOW_ERROR)
		if self._visible: return
		self.adaptLayout()
		self.beforeShow()
		get_manager().show(self)
		self._visible = True
Ejemplo n.º 5
0
	def hide(self):
		"""
		Hide the widget and all contained widgets.
		"""
		if self._parent:
			raise RuntimeError(Widget.HIDE_SHOW_ERROR)
		if not self._visible: return

		get_manager().hide(self)

		self.afterHide()
		self._visible = False
Ejemplo n.º 6
0
	def _setHoverImage(self,image):
		self._hoverimage_source = image
		try:
			self._hoverimage = get_manager().loadImage(image)
			self.real_widget.setHoverImage( self._hoverimage )
		except:
			self._hoverimage = _DummyImage()
Ejemplo n.º 7
0
	def _setDownImage(self,image):
		self._downimage_source = image
		try:
			self._downimage = get_manager().loadImage(image)
			self.real_widget.setDownImage( self._downimage )
		except:
			self._downimage = _DummyImage()
Ejemplo n.º 8
0
	def __init__(self,name,get):
		from internal import get_manager
		self.font = None
		self.name = name
		self.typename = get("type")
		self.source = get("source")
		self.row_spacing = int(get("row_spacing",0))
		self.glyph_spacing = int(get("glyph_spacing",0))

		if self.typename == "truetype":
			self.size = int(get("size"))
			self.antialias = bool(get("antialias",True))
			self.bold = bool(get("bold",False))
			self.italic = bool(get("italic",False))
			self.underline = bool(get("underline",False))
			self.recoloring = bool(get("recoloring",False))
			self.color = map(int,get("color","255,255,255").split(','))
			self.font = get_manager().createFont(self.source,self.size,"")

			if self.font is None:
				raise InitializationError("Could not load font %s" % name)

			self.font.setAntiAlias(self.antialias)
			self.font.setBoldStyle(self.bold)
			self.font.setItalicStyle(self.italic)
			self.font.setUnderlineStyle(self.underline)
			self.font.setDynamicColoring(self.recoloring)
			self.font.setColor(*self.color)
		else:
			raise InitializationError("Unsupported font type %s" % self.typename)

		self.font.setRowSpacing( self.row_spacing )
		self.font.setGlyphSpacing( self.glyph_spacing )
Ejemplo n.º 9
0
    def __init__(self, name, get):
        from internal import get_manager
        self.font = None
        self.name = name
        self.typename = get("type")
        self.source = get("source")
        self.row_spacing = int(get("row_spacing", 0))
        self.glyph_spacing = int(get("glyph_spacing", 0))

        if self.typename == "truetype":
            self.size = int(get("size"))
            self.antialias = bool(get("antialias", True))
            self.bold = bool(get("bold", False))
            self.italic = bool(get("italic", False))
            self.underline = bool(get("underline", False))
            self.recoloring = bool(get("recoloring", False))
            self.color = map(int, get("color", "255,255,255").split(','))
            self.font = get_manager().createFont(self.source, self.size, "")

            if self.font is None:
                raise InitializationError("Could not load font %s" % name)

            self.font.setAntiAlias(self.antialias)
            self.font.setBoldStyle(self.bold)
            self.font.setItalicStyle(self.italic)
            self.font.setUnderlineStyle(self.underline)
            self.font.setDynamicColoring(self.recoloring)
            self.font.setColor(*self.color)
        else:
            raise InitializationError("Unsupported font type %s" %
                                      self.typename)

        self.font.setRowSpacing(self.row_spacing)
        self.font.setGlyphSpacing(self.glyph_spacing)
Ejemplo n.º 10
0
	def __init__(self,name,get):
		from internal import get_manager
		self.font = None
		self.name = name
		self.typename = get("type")
		self.source = get("source")
		self.row_spacing = int(get("row_spacing",0))
		self.glyph_spacing = int(get("glyph_spacing",0))

		if self.typename == "truetype":
			self.size = int(get("size"))
			self.antialias = int(get("antialias",1))
			self.color = map(int,get("color","255,255,255").split(','))
			self.font = get_manager().hook.engine.getGuiManager().createFont(self.source,self.size,"")

			if self.font is None:
				raise InitializationError("Could not load font %s" % name)

			self.font.setAntiAlias(self.antialias)
			self.font.setColor(*self.color)
		else:
			raise InitializationError("Unsupported font type %s" % self.typename)

		self.font.setRowSpacing( self.row_spacing )
		self.font.setGlyphSpacing( self.glyph_spacing )
Ejemplo n.º 11
0
    def __init__(self, name, get):
        from internal import get_manager
        self.font = None
        self.name = name
        self.typename = get("type")
        self.source = get("source")
        self.row_spacing = int(get("row_spacing", 0))
        self.glyph_spacing = int(get("glyph_spacing", 0))

        if self.typename == "truetype":
            self.size = int(get("size"))
            self.antialias = int(get("antialias", 1))
            self.color = map(int, get("color", "255,255,255").split(','))
            self.font = get_manager().createFont(self.source, self.size, "")

            if self.font is None:
                raise InitializationError("Could not load font %s" % name)

            self.font.setAntiAlias(self.antialias)
            self.font.setColor(*self.color)
        else:
            raise InitializationError("Unsupported font type %s" %
                                      self.typename)

        self.font.setRowSpacing(self.row_spacing)
        self.font.setGlyphSpacing(self.glyph_spacing)
Ejemplo n.º 12
0
	def __init__(self):
		super(EventListenerBase,self).__init__()
		self.events = {}
		self.indent = 0
		self.debug = get_manager().debug
		self.is_attached = False
		
		self._timers = []
		self._deadtimers = []		
Ejemplo n.º 13
0
    def __init__(self):
        super(EventListenerBase, self).__init__()
        self.events = {}
        self.indent = 0
        self.debug = get_manager().debug
        self.is_attached = False

        self._timers = []
        self._deadtimers = []
Ejemplo n.º 14
0
	def __init__(self,widget):
		super(EventMapper,self).__init__()
		self.widget = widget
		self.listener = {
			KEY_EVENT    : _KeyEventListener(),
			ACTION_EVENT : _ActionEventListener(),
			MOUSE_EVENT  : _MouseEventListener(),
		}
		self.is_attached = False
		self.debug = get_manager().debug
Ejemplo n.º 15
0
	def __init__(self):
		super(EventListenerBase,self).__init__()
		self.events = {}
		self.indent = 0
		self.debug = get_manager().debug
		self.is_attached = False

		# Enables event redirection to next pump cycle by default
		self._redirect = True
		self._timers = []
		self._deadtimers = []		
Ejemplo n.º 16
0
	def __init__(self,widget):
		super(EventMapper,self).__init__()
		self.widget_ref = weakref.ref(widget)
		self.callbacks = {}
		self.listener = {
			KEY_EVENT    : _KeyEventListener(),
			ACTION_EVENT : _ActionEventListener(),
			MOUSE_EVENT  : _MouseEventListener(),
			WIDGET_EVENT : _WidgetEventListener()
		}
		self.is_attached = False
		self.debug = get_manager().debug
Ejemplo n.º 17
0
	def setBackgroundImage(self,image):
		self._background = getattr(self,'_background',None)
		if image is None:
			self._background_image = image
			map(self.real_widget.remove,self._background)
			self._background = []

		# Background generation is done in _resetTiling

		if not isinstance(image, guichan.Image):
			image = get_manager().loadImage(image)
		self._background_image = image
Ejemplo n.º 18
0
 def __init__(self, widget):
     super(EventMapper, self).__init__()
     self.widget_ref = weakref.ref(widget)
     self.callbacks = {}
     self.listener = {
         KEY_EVENT: _KeyEventListener(),
         ACTION_EVENT: _ActionEventListener(),
         MOUSE_EVENT: _MouseEventListener(),
         WIDGET_EVENT: _WidgetEventListener()
     }
     self.is_attached = False
     self.debug = get_manager().debug
Ejemplo n.º 19
0
	def _setImage(self,source):
		if isinstance(source,str):
			self._source = source
			self._image = get_manager().loadImage(source)
		elif isinstance(source,guichan.GuiImage):
			self._source = None
			self._image = source
		else:
			raise RuntimeError("Icon.image only accepts Image and python strings, not '%s'" % repr(source))
		self.real_widget.setImage( self._image )

		# Set minimum size accoriding to image
		self.min_size = self.real_widget.getWidth(),self.real_widget.getHeight()
		self.size  = self.max_size = self.min_size
Ejemplo n.º 20
0
			def _quitThisDialog(returnValue = returnValue ):
				get_manager().breakFromMainLoop( returnValue )
				self.hide()
Ejemplo n.º 21
0
	def _setFont(self, font):
		self._font = font
		self.real_font = get_manager().getFont(font)
		self.real_widget.setFont(self.real_font)
Ejemplo n.º 22
0
 def translateEvent(self, event_type, event):
     if event_type == MOUSE_EVENT:
         return get_manager().hook.translate_mouse_event(event)
     if event_type == KEY_EVENT:
         return get_manager().hook.translate_key_event(event)
     return event
Ejemplo n.º 23
0
	def _setStyle(self,style):
		self._style = style
		get_manager().stylize(self,style)
Ejemplo n.º 24
0
Archivo: events.py Proyecto: m64/PEG
	def translateEvent(self,event_type,event):
		if event_type == MOUSE_EVENT:
			return get_manager().hook.translate_mouse_event(event)
		if event_type == KEY_EVENT:
			return get_manager().hook.translate_key_event(event)
		return event
Ejemplo n.º 25
0
		def _restyle(widget):
			get_manager().stylize(widget,style,**kwargs)