def init(self): skin_config.wrap_skin_window(self) self.set_decorated(False) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.frame_radius = 2 self.shadow_is_visible = True self.window_frame = gtk.VBox() self.add(self.window_frame) self.shape_flag = True if enable_shadow(self) and self.shadow_visible: self.shadow_padding = self.shadow_radius - self.frame_radius else: self.shadow_padding = 0 # Init shadow window. if enable_shadow(self) and self.shadow_visible: self.window_shadow = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window_shadow.add_events(gtk.gdk.ALL_EVENTS_MASK) self.window_shadow.set_decorated(False) self.window_shadow.set_transient_for(self) self.window_shadow.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_MENU) # Handle signal. self.connect_after("expose-event", self.expose_window) self.connect("size-allocate", self.shape_window) self.connect("window-state-event", self.monitor_window_state) self.connect("configure-event", self.adjust_window_shadow) if enable_shadow(self) and self.shadow_visible: self.window_shadow.connect("expose-event", self.expose_window_shadow) self.window_shadow.connect("size-allocate", self.shape_window_shadow) self.window_shadow.connect("button-press-event", self.resize_window) self.window_shadow.connect("motion-notify-event", self.motion_notify)
def init(self): skin_config.wrap_skin_window(self) self.set_decorated(False) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.window_shadow = gtk.Alignment() self.window_frame = gtk.VBox() self.shadow_is_visible = True self.cursor_type = None # Shadow setup. if enable_shadow(self) and self.shadow_visible: self.shadow_padding = self.shadow_radius - self.frame_radius self.window_frame.connect("size-allocate", self.shape_window_frame) self.window_shadow.connect("expose-event", self.expose_window_shadow) else: # Disable shadow when composited is false. self.shadow_padding = 0 self.connect("size-allocate", self.shape_window_frame) # Init window frame. self.window_shadow.set(0.0, 0.0, 1.0, 1.0) self.window_shadow.set_padding(self.shadow_padding, self.shadow_padding, self.shadow_padding, self.shadow_padding) # Connect widgets. self.add(self.window_shadow) self.window_shadow.add(self.window_frame) # Handle signal. self.connect_after("expose-event", self.expose_window_background) self.connect_after("size-allocate", lambda w, e: self.queue_draw()) self.connect("motion-notify-event", self.motion_notify) self.connect("leave-notify-event", self.leave_notify) self.connect("button-press-event", self.resize_window) self.connect("window-state-event", self.monitor_window_state) self.window_frame.connect("expose-event", self.expose_window_frame)
def __init__(self, enable_resize=False, shadow_radius=6, window_type=gtk.WINDOW_TOPLEVEL): ''' Initialise the Window class. @param enable_resize: If True, the window will be set resizable. By default, it's False. @param shadow_radius: The radius of the shadow. @param window_type: A flag of type gtk._gtk.WindowType, which indicates the type of the window. By default, it's gtk.WINDOW_TOPLEVEL. ''' # Init. WindowBase.__init__(self, window_type) self.shadow_radius = shadow_radius self.enable_resize = enable_resize self.background_color = (0, 0, 0, 0) # FIXME: Because mplayer don't allowed window redirect colormap to screen. # We build shadow window to emulate it, but shadow's visual effect # is not good enough, so we disable shadow temporary for future fixed. self.shadow_visible = False if enable_shadow(self) and self.shadow_visible: self.window_shadow.set_colormap( gtk.gdk.Screen().get_rgba_colormap()) self.init()
def show_shadow(self): """ Show the window shadow. """ self.shadow_is_visible = True if enable_shadow(self) and self.shadow_visible: self.window_shadow.show_all()
def show_window(self): ''' Show the window. ''' self.show_all() if enable_shadow(self) and self.shadow_visible: self.window_shadow.show_all()
def show_shadow(self): ''' Show the window shadow. ''' self.shadow_is_visible = True if enable_shadow(self) and self.shadow_visible: self.window_shadow.show_all()
def hide_shadow(self): ''' Hide the window shadow. ''' self.shadow_is_visible = False if enable_shadow(self) and self.shadow_visible: self.window_shadow.hide_all()
def hide_shadow(self): """ Hide the window shadow. """ self.shadow_is_visible = False if enable_shadow(self) and self.shadow_visible: self.window_shadow.hide_all()
def __init__(self, enable_resize=False, shadow_radius=6, window_type=gtk.WINDOW_TOPLEVEL): '''Init mplayer window.''' # Init. gtk.Window.__init__(self, window_type) skin_config.wrap_skin_window(self) self.set_decorated(False) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.shadow_radius = shadow_radius self.frame_radius = 2 self.shadow_is_visible = True self.enable_resize = enable_resize self.window_frame = gtk.VBox() self.add(self.window_frame) self.shape_flag = True # FIXME: Because mplayer don't allowed window redirect colormap to screen. # We build shadow window to emulate it, but shadow's visual effect # is not good enough, so we disable shadow temporary for future fixed. self.shadow_visible = False if enable_shadow(self) and self.shadow_visible: self.shadow_padding = self.shadow_radius - self.frame_radius else: self.shadow_padding = 0 # Init shadow window. if enable_shadow(self) and self.shadow_visible: self.window_shadow = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window_shadow.add_events(gtk.gdk.ALL_EVENTS_MASK) self.window_shadow.set_decorated(False) self.window_shadow.set_colormap(gtk.gdk.Screen().get_rgba_colormap()) self.window_shadow.set_transient_for(self) self.window_shadow.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_MENU) # Handle signal. self.connect_after("expose-event", self.expose_window) self.connect("size-allocate", self.shape_window) self.connect("window-state-event", self.monitor_window_state) self.connect("configure-event", self.adjust_window_shadow) if enable_shadow(self) and self.shadow_visible: self.window_shadow.connect("expose-event", self.expose_window_shadow) self.window_shadow.connect("size-allocate", self.shape_window_shadow) self.window_shadow.connect("button-press-event", self.resize_window) self.window_shadow.connect("motion-notify-event", self.motion_notify)
def get_shadow_size(self): '''Get shadow size.''' if enable_shadow(self) and self.shadow_visible: window_state = self.window.get_state() if window_state in [gtk.gdk.WINDOW_STATE_MAXIMIZED, gtk.gdk.WINDOW_STATE_FULLSCREEN]: return (0, 0) else: return (self.shadow_padding, self.shadow_padding) else: return (0, 0)
def adjust_window_shadow(self, widget, event): '''Adjust window shadow position and size. ''' if enable_shadow(self) and self.shadow_visible: (x, y) = self.get_position() (width, height) = self.get_size() self.window_shadow.get_window().move_resize( x - self.shadow_padding, y - self.shadow_padding, width + self.shadow_padding * 2, height + self.shadow_padding * 2 )
def init(self): skin_config.wrap_skin_window(self) self.set_decorated(False) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.frame_radius = 2 self.shadow_is_visible = True self.window_frame = gtk.VBox() self.add(self.window_frame) self.shape_flag = True if enable_shadow(self) and self.shadow_visible: self.shadow_padding = self.shadow_radius - self.frame_radius else: self.shadow_padding = 0 # Init shadow window. if enable_shadow(self) and self.shadow_visible: self.window_shadow = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window_shadow.add_events(gtk.gdk.ALL_EVENTS_MASK) self.window_shadow.set_decorated(False) self.window_shadow.set_transient_for(self) self.window_shadow.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_MENU) # Handle signal. self.connect_after("expose-event", self.expose_window) self.connect("size-allocate", self.shape_window) self.connect("window-state-event", self.monitor_window_state) self.connect("configure-event", self.adjust_window_shadow) if enable_shadow(self) and self.shadow_visible: self.window_shadow.connect("expose-event", self.expose_window_shadow) self.window_shadow.connect("size-allocate", self.shape_window_shadow) self.window_shadow.connect("button-press-event", self.resize_window) self.window_shadow.connect("motion-notify-event", self.motion_notify)
def shape_window_shadow(self, widget, rect): """ Internal function to draw the shaped window's shadow. @param widget: A widget of type gtk.Widget. @param rect: The bounding region of the window. """ if rect.width > 0 and rect.height > 0: # Init. x, y, w, h = rect.x, rect.y, rect.width, rect.height bitmap = gtk.gdk.Pixmap(None, w, h, 1) cr = bitmap.cairo_create() # Clear the bitmap cr.set_source_rgb(0.0, 0.0, 0.0) cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() # Draw our shape into the bitmap using cairo. cr.set_source_rgb(1.0, 1.0, 1.0) cr.set_operator(cairo.OPERATOR_OVER) # Four side. cr.rectangle(x, y, w, self.shadow_padding) cr.rectangle(x, y + self.shadow_padding, self.shadow_padding, h - self.shadow_padding * 2) cr.rectangle(x + w - self.shadow_padding, y + self.shadow_padding, self.shadow_padding, h - self.shadow_padding * 2) cr.rectangle(x, y + h - self.shadow_padding, w, self.shadow_padding) # Four 2-pixel rectange. cr.rectangle(x + self.shadow_padding, y + self.shadow_padding, 2, 1) cr.rectangle(x + w - self.shadow_padding - 2, y + self.shadow_padding, 2, 1) cr.rectangle(x + self.shadow_padding, y + h - self.shadow_padding - 1, 2, 1) cr.rectangle(x + w - self.shadow_padding - 2, y + h - self.shadow_padding - 1, 2, 1) # Four 1-pixel rectange. cr.rectangle(x + self.shadow_padding, y + self.shadow_padding + 1, 1, 1) cr.rectangle(x + w - self.shadow_padding - 1, y + self.shadow_padding + 1, 1, 1) cr.rectangle(x + self.shadow_padding, y + h - self.shadow_padding - 2, 1, 1) cr.rectangle(x + w - self.shadow_padding - 1, y + h - self.shadow_padding - 2, 1, 1) cr.fill() # Shape with given mask. widget.shape_combine_mask(bitmap, 0, 0) # Redraw whole window. self.queue_draw() if enable_shadow(self) and self.shadow_visible: self.window_shadow.queue_draw()
def adjust_window_shadow(self, widget, event): """ Internal function to adjust postion and size of the shadow of the window. @param widget: the widget of type gtk.Widget. @param event: the event of gtk.gdk.Event. """ if enable_shadow(self) and self.shadow_visible: (x, y) = self.get_position() (width, height) = self.get_size() self.window_shadow.get_window().move_resize( x - self.shadow_padding, y - self.shadow_padding, width + self.shadow_padding * 2, height + self.shadow_padding * 2 )
def get_shadow_size(self): ''' Get the shadow size. @return: return the shadow size or (0, 0) ''' if enable_shadow(self) and self.shadow_visible: window_state = self.window.get_state() if (window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN == gtk.gdk.WINDOW_STATE_FULLSCREEN or window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED == gtk.gdk.WINDOW_STATE_MAXIMIZED): return (0, 0) else: return (self.shadow_padding, self.shadow_padding) else: return (0, 0)
def shape_window(self, widget, rect): ''' Internal function to draw the shaped window. @param widget: A widget of type gtk.Widget. @param rect: The bounding region of the window. ''' if widget.window != None and widget.get_has_window( ) and rect.width > 0 and rect.height > 0: # Init. x, y, w, h = rect.x, rect.y, rect.width, rect.height bitmap = gtk.gdk.Pixmap(None, w, h, 1) cr = bitmap.cairo_create() # Clear the bitmap cr.set_source_rgb(0.0, 0.0, 0.0) cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() # Draw our shape into the bitmap using cairo. cr.set_source_rgb(1.0, 1.0, 1.0) cr.set_operator(cairo.OPERATOR_OVER) if not self.shape_flag: # Don't clip corner when window is fullscreen state. cr.rectangle(x, y, w, h) elif (self.window.get_state() & gtk.gdk.WINDOW_STATE_FULLSCREEN == gtk.gdk.WINDOW_STATE_FULLSCREEN or self.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED == gtk.gdk.WINDOW_STATE_MAXIMIZED): # Don't clip corner when window is fullscreen state. cr.rectangle(x, y, w, h) else: cr.rectangle(x + 2, y, w - 4, 1) cr.rectangle(x + 1, y + 1, w - 2, 1) cr.rectangle(x, y + 2, w, h - 4) cr.rectangle(x + 1, y + h - 2, w - 2, 1) cr.rectangle(x + 2, y + h - 1, w - 4, 1) cr.fill() # Shape with given mask. widget.shape_combine_mask(bitmap, 0, 0) # Redraw whole window. self.queue_draw() if enable_shadow(self) and self.shadow_visible: self.window_shadow.queue_draw()
def get_shadow_size(self): ''' Get the shadow size. @return: return the shadow size or (0, 0) ''' if enable_shadow(self) and self.shadow_visible: window_state = self.window.get_state() if (window_state & gtk.gdk.WINDOW_STATE_FULLSCREEN == gtk.gdk.WINDOW_STATE_FULLSCREEN or window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED == gtk.gdk.WINDOW_STATE_MAXIMIZED): return (0, 0) else: return (self.shadow_padding, self.shadow_padding) else: return (0, 0)
def shape_window(self, widget, rect): ''' Internal function to draw the shaped window. @param widget: A widget of type gtk.Widget. @param rect: The bounding region of the window. ''' if widget.window != None and widget.get_has_window() and rect.width > 0 and rect.height > 0: # Init. x, y, w, h = rect.x, rect.y, rect.width, rect.height bitmap = gtk.gdk.Pixmap(None, w, h, 1) cr = bitmap.cairo_create() # Clear the bitmap cr.set_source_rgb(0.0, 0.0, 0.0) cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() # Draw our shape into the bitmap using cairo. cr.set_source_rgb(1.0, 1.0, 1.0) cr.set_operator(cairo.OPERATOR_OVER) if not self.shape_flag: # Don't clip corner when window is fullscreen state. cr.rectangle(x, y, w, h) elif (self.window.get_state() & gtk.gdk.WINDOW_STATE_FULLSCREEN == gtk.gdk.WINDOW_STATE_FULLSCREEN or self.window.get_state() & gtk.gdk.WINDOW_STATE_MAXIMIZED == gtk.gdk.WINDOW_STATE_MAXIMIZED): # Don't clip corner when window is fullscreen state. cr.rectangle(x, y, w, h) else: cr.rectangle(x + 2, y, w - 4, 1) cr.rectangle(x + 1, y + 1, w - 2, 1) cr.rectangle(x, y + 2, w, h - 4) cr.rectangle(x + 1, y + h - 2, w - 2, 1) cr.rectangle(x + 2, y + h - 1, w - 4, 1) cr.fill() # Shape with given mask. widget.shape_combine_mask(bitmap, 0, 0) # Redraw whole window. self.queue_draw() if enable_shadow(self) and self.shadow_visible: self.window_shadow.queue_draw()
def __init__(self, enable_resize=False, shadow_radius=6, window_type=gtk.WINDOW_TOPLEVEL, shadow_visible=True): '''Init window.''' # Init. gtk.Window.__init__(self, window_type) skin_config.wrap_skin_window(self) self.set_decorated(False) self.set_colormap(gtk.gdk.Screen().get_rgba_colormap()) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.window_shadow = gtk.Alignment() self.window_frame = gtk.VBox() self.shadow_radius = shadow_radius self.frame_radius = 2 self.shadow_is_visible = True self.cursor_type = None self.enable_resize = enable_resize self.shadow_visible = shadow_visible # Shadow setup. if enable_shadow(self) and self.shadow_visible: self.shadow_padding = self.shadow_radius - self.frame_radius self.window_frame.connect("size-allocate", self.shape_window_frame) self.window_shadow.connect("expose-event", self.expose_window_shadow) else: # Disable shadow when composited is false. self.shadow_padding = 0 self.connect("size-allocate", self.shape_window_frame) # Init window frame. self.window_shadow.set(0.0, 0.0, 1.0, 1.0) self.window_shadow.set_padding(self.shadow_padding, self.shadow_padding, self.shadow_padding, self.shadow_padding) # Connect widgets. self.add(self.window_shadow) self.window_shadow.add(self.window_frame) # Handle signal. self.connect_after("expose-event", self.expose_window_background) self.connect_after("size-allocate", lambda w, e: self.queue_draw()) self.connect("motion-notify-event", self.motion_notify) self.connect("button-press-event", self.resize_window) self.connect("window-state-event", self.monitor_window_state) self.window_frame.connect("expose-event", self.expose_window_frame)
def adjust_window_shadow(self, widget, event): ''' Internal function to adjust postion and size of the shadow of the window. @param widget: the widget of type gtk.Widget. @param event: the event of gtk.gdk.Event. ''' if enable_shadow(self) and self.shadow_visible: (x, y) = self.get_position() (width, height) = self.get_size() self.window_shadow.get_window().move_resize( x - self.shadow_padding, y - self.shadow_padding, width + self.shadow_padding * 2, height + self.shadow_padding * 2) # NOTE: Some desktop environment will disable window minimum operation instead with hide window operation # to get the realtime preview of application, then window will got wrong shape mask after un-minimum. # So we do shape window when `configure-event` event emit to fixed the compatible problem. self.shape_window(widget, widget.allocation)
def adjust_window_shadow(self, widget, event): ''' Internal function to adjust postion and size of the shadow of the window. @param widget: the widget of type gtk.Widget. @param event: the event of gtk.gdk.Event. ''' if enable_shadow(self) and self.shadow_visible: (x, y) = self.get_position() (width, height) = self.get_size() self.window_shadow.get_window().move_resize( x - self.shadow_padding, y - self.shadow_padding, width + self.shadow_padding * 2, height + self.shadow_padding * 2 ) # NOTE: Some desktop environment will disable window minimum operation instead with hide window operation # to get the realtime preview of application, then window will got wrong shape mask after un-minimum. # So we do shape window when `configure-event` event emit to fixed the compatible problem. self.shape_window(widget, widget.allocation)
def init(self): skin_config.wrap_skin_window(self) self.set_decorated(False) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.window_shadow = gtk.Alignment() self.window_frame = gtk.VBox() self.shadow_is_visible = True self.cursor_type = None # Shadow setup. if enable_shadow(self) and self.shadow_visible: self.shadow_padding = self.shadow_radius - self.frame_radius self.window_frame.connect("size-allocate", self.shape_window_frame) self.window_shadow.connect("expose-event", self.expose_window_shadow) else: # Disable shadow when composited is false. self.shadow_padding = 0 self.connect("size-allocate", self.shape_window_frame) # Init window frame. self.window_shadow.set(0.0, 0.0, 1.0, 1.0) self.window_shadow.set_padding(self.shadow_padding, self.shadow_padding, self.shadow_padding, self.shadow_padding) # Connect widgets. self.add(self.window_shadow) self.window_shadow.add(self.window_frame) # Handle signal. self.connect_after("expose-event", self.expose_window_background) self.connect_after("size-allocate", lambda w, e: self.queue_draw()) self.connect("motion-notify-event", self.motion_notify) self.connect("leave-notify-event", self.leave_notify) self.connect("button-press-event", self.resize_window) self.connect("window-state-event", self.monitor_window_state) self.window_frame.connect("expose-event", self.expose_window_frame)
def __init__(self, enable_resize=False, shadow_radius=6, window_type=gtk.WINDOW_TOPLEVEL): """ Initialise the Window class. @param enable_resize: If True, the window will be set resizable. By default, it's False. @param shadow_radius: The radius of the shadow. @param window_type: A flag of type gtk._gtk.WindowType, which indicates the type of the window. By default, it's gtk.WINDOW_TOPLEVEL. """ # Init. WindowBase.__init__(self, window_type) self.shadow_radius = shadow_radius self.enable_resize = enable_resize self.background_color = (0, 0, 0, 0) # FIXME: Because mplayer don't allowed window redirect colormap to screen. # We build shadow window to emulate it, but shadow's visual effect # is not good enough, so we disable shadow temporary for future fixed. self.shadow_visible = False if enable_shadow(self) and self.shadow_visible: self.window_shadow.set_colormap(gtk.gdk.Screen().get_rgba_colormap()) self.init()
def shape_window_shadow(self, widget, rect): ''' Internal function to draw the shaped window's shadow. @param widget: A widget of type gtk.Widget. @param rect: The bounding region of the window. ''' if rect.width > 0 and rect.height > 0: # Init. x, y, w, h = rect.x, rect.y, rect.width, rect.height bitmap = gtk.gdk.Pixmap(None, w, h, 1) cr = bitmap.cairo_create() # Clear the bitmap cr.set_source_rgb(0.0, 0.0, 0.0) cr.set_operator(cairo.OPERATOR_CLEAR) cr.paint() # Draw our shape into the bitmap using cairo. cr.set_source_rgb(1.0, 1.0, 1.0) cr.set_operator(cairo.OPERATOR_OVER) # Four side. cr.rectangle(x, y, w, self.shadow_padding) cr.rectangle(x, y + self.shadow_padding, self.shadow_padding, h - self.shadow_padding * 2) cr.rectangle(x + w - self.shadow_padding, y + self.shadow_padding, self.shadow_padding, h - self.shadow_padding * 2) cr.rectangle(x, y + h - self.shadow_padding, w, self.shadow_padding) # Four 2-pixel rectange. cr.rectangle(x + self.shadow_padding, y + self.shadow_padding, 2, 1) cr.rectangle(x + w - self.shadow_padding - 2, y + self.shadow_padding, 2, 1) cr.rectangle(x + self.shadow_padding, y + h - self.shadow_padding - 1, 2, 1) cr.rectangle(x + w - self.shadow_padding - 2, y + h - self.shadow_padding - 1, 2, 1) # Four 1-pixel rectange. cr.rectangle(x + self.shadow_padding, y + self.shadow_padding + 1, 1, 1) cr.rectangle(x + w - self.shadow_padding - 1, y + self.shadow_padding + 1, 1, 1) cr.rectangle(x + self.shadow_padding, y + h - self.shadow_padding - 2, 1, 1) cr.rectangle(x + w - self.shadow_padding - 1, y + h - self.shadow_padding - 2, 1, 1) cr.fill() # Shape with given mask. widget.shape_combine_mask(bitmap, 0, 0) # Redraw whole window. self.queue_draw() if enable_shadow(self) and self.shadow_visible: self.window_shadow.queue_draw()
def show_shadow(self): '''Show shadow.''' self.shadow_is_visible = True if enable_shadow(self) and self.shadow_visible: self.window_shadow.show_all()
def hide_shadow(self): '''Hide shadow.''' self.shadow_is_visible = False if enable_shadow(self) and self.shadow_visible: self.window_shadow.hide_all()