mmxbass 2 Light Poster

Well I got past most of the problems with my boxlets application. I wanted to hear what people think of the functionality and if they have any input/suggestions.

Known issues:
* When you already have applications open, their boxlets pile up on top of each other.

Remember, this software requires X11, this is not for windows people.

EDIT: The extra images, etc that it asks for can be found at: http://mmxbass.home.hexnet.com/~mmxbass/boxlets/

#!/usr/bin/python

#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation, either version 3 of the License, or
#	(at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.

import wnck
import pygtk
pygtk.require('2.0')

import gtk
import gobject

boxli = list()
clipb = None

def run():
	global clipb
	clipb = clip()
	
	screen = wnck.screen_get_default()
	screen.force_update()
	for w in screen.get_windows():
		spawnw(screen, w)
	screen.connect("window-opened", spawnw)
	
	gtk.main()

def spawnw(screen, window):
	if window.is_skip_tasklist() == False:
		boxli.append(boxlet(window))

class clip:
	def on_button_press(self, widget, event):
		if (event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1) or event.button == 2:
			if self.boxfloat:
				for box in boxli:
					box.sink()
					self.boxfloat = False
			else:
				for box in boxli:
					box.rise()
					self.boxfloat = True
		elif event.button == 1:
			self.window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
	
	def get_floatstate(self):
		return self.boxfloat
	
	def __init__(self):
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.set_geometry_hints(None,64,64,64,64,64,64,0,0,1,1)
		self.window.set_decorated(False)
		self.window.set_keep_above(True)
		self.window.stick()
		self.window.set_gravity(gtk.gdk.GRAVITY_CENTER)
		self.window.set_property('skip-taskbar-hint', True)
		self.window.set_property('skip-pager-hint', True)
		
		self.window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
		self.window.add_events(gtk.gdk._2BUTTON_PRESS)
		self.window.connect("button-press-event", self.on_button_press)
		
		self.window.set_app_paintable(True)
		self.window.realize()
		
		self.boxfloat = False
		
		self.boxbg = gtk.Image()
		self.boxbg.set_from_file("tile.xpm")
		
		self.image = gtk.Image()
		self.image.set_from_file("up.svg")
		self.window.add(self.image)
		self.image.show()
		
		self.window.window.set_back_pixmap(self.boxbg.get_pixbuf().render_pixmap_and_mask()[0] , False)
		
		self.window.show()
		

class boxlet:
	def on_button_press(self, widget, event):
		self.appw.set_icon_geometry(self.window.get_position()[0],self.window.get_position()[1],self.window.get_size()[0],self.window.get_size()[1])
		print event.type
		if (event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1) or (event.type == gtk.gdk.BUTTON_PRESS and event.button == 2):
			if self.appw.is_minimized():
				self.appw.unminimize(event.time)
			else:
				self.appw.minimize()
		elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
			mnuw = wnck.create_window_action_menu(self.appw)
			mnuw.popup(None, None, None, event.button, event.time, None)
			mnuw.map()
		elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
			#self.appw.activate(event.time)
			self.window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
	
	def winclose_event(self, screen, window):
		if self.appw.get_xid() == window.get_xid():
			boxli.remove(self)
			self.window.destroy()
			return True
		return False
	
	def winspace_event(self, window=None):
		if self.appw.is_pinned():
			self.window.stick()
		else:
			self.window.unstick()
		
		wspace = self.appw.get_workspace()
		if wspace != None:
			if self.mywin == None:
				self.mywin = wnck.window_get(self.xid)
				if self.mywin == None:
					return True
			self.mywin.move_to_workspace(wspace)
		return False
	
	def winicon_event(self, window=None, event=None):
		self.image.set_from_pixbuf(self.appw.get_icon())
	
	def winname_event(self, window=None, event=None):
		self.tooltip .set_tip(self.window, self.appw.get_name(), tip_private=None)
	
	def rise(self):
		self.window.set_keep_below(False)
		self.window.set_keep_above(True)
	
	def sink(self):
		self.window.set_keep_above(False)
		self.window.set_keep_below(True)
	
	def __init__(self, appw):
		self.appw = appw
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.set_geometry_hints(None,64,64,64,64,64,64,0,0,1,1)
		self.window.set_decorated(False)
		if clipb.get_floatstate():
			self.rise()
		else:
			self.sink()
		self.window.set_gravity(gtk.gdk.GRAVITY_CENTER)
		self.window.set_property('skip-taskbar-hint', True)
		self.window.set_property('skip-pager-hint', True)
		
		self.appw.set_icon_geometry(self.window.get_position()[0],self.window.get_position()[1],self.window.get_size()[0],self.window.get_size()[1])
		
		self.window.set_app_paintable(True)
		self.window.realize()
		
		self.xid = self.window.window.xid
		self.mywin = None
		
		self.boxbg = gtk.Image()
		self.boxbg.set_from_file("tile.xpm")
		
		self.image = gtk.Image()
		self.image.set_from_pixbuf(self.appw.get_icon())
		self.window.add(self.image)
		self.image.show()
		
		self.tooltip = gtk.Tooltips()
		self.tooltip .set_tip(self.window, self.appw.get_name(), tip_private=None)
		
		self.window.window.set_back_pixmap(self.boxbg.get_pixbuf().render_pixmap_and_mask()[0] , False) 
		
		gobject.idle_add(self.winspace_event)
		
		self.window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
		self.window.add_events(gtk.gdk._2BUTTON_PRESS)
		self.window.connect("button-press-event", self.on_button_press)
		
		self.appw.get_screen().connect("window-closed", self.winclose_event)
		self.appw.connect("workspace-changed", self.winspace_event)
		self.appw.connect("icon-changed", self.winicon_event)
		self.appw.connect("name-changed", self.winname_event)
		
		self.window.show()
		

if __name__ == "__main__":
	run()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.