Reply
Thread Tools
Jaffa's Avatar
Posts: 2,535 | Thanked: 6,681 times | Joined on Mar 2008 @ UK
#21
Perthaps someone should write a HOWTO for the wiki?
__________________
Andrew Flegg -- mailto:andrew@bleb.org | http://www.bleb.org
 
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#22
A new entry to the wiki would be a good idea. As soon as I can get clean examples of each plus all the parts needed. The home / statusbar / taskbar is a set and I'd prefer to get all three going with full examples in a deb if possible. I have the first two.
 

The Following 4 Users Say Thank You to tz1 For This Useful Post:
Posts: 1,208 | Thanked: 1,028 times | Joined on Oct 2007
#23
Originally Posted by tz1 View Post
May I impose on your code wizardry once more - how about a taskbar item. I'd like to replace Contacts with a shell program launcher or something similar.

Changing Statusbar to Taskbar (and adding an appropriate desktop file under the hildon-navigator directory, Type=python) makes it recognized in Panels, but no icon, and the taskbar shifts up. I didn't put a menu in (yet) so that might be the problem.
In first example button size request might be unnecessary, I was look at the wrong C example.

Here's tasknavigator plugin, wich opens proper menu. (again from C example)

Code:
import gtk
import hildondesktop


class statusbar_applet(hildondesktop.TaskNavigatorItem):
    def __init__(self):
        hildondesktop.TaskNavigatorItem.__init__(self)
        
        self.button = gtk.Button()
        self.button.set_image(gtk.image_new_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU))
        self.button.set_name("hildon-navigator-button-one")
        self.button.set_size_request(80,80)
        self.button.connect("clicked",self.popup_menu)
        self.create_menu()

        self.add(self.button)
        self.show_all()

    def create_menu(self):
    	self.menu = gtk.Menu()
        menu_item = gtk.MenuItem("Hello World!")
        menu_item.connect('activate',self.show_dialog)
        self.menu.append(menu_item)
        self.menu.set_name("menu_from_navigator")
        self.menu.show_all()
        
    def popup_menu(self,widget,data=None):
        self.menu.popup(None,None,self.menu_position,0,gtk.get_current_event_time())

    def show_dialog(self,widget,data=None):
        mdlg = gtk.MessageDialog(None,0,gtk.MESSAGE_INFO,gtk.BUTTONS_OK,"Hello World!")
        mdlg.run()
        mdlg.destroy() 
        
    def menu_position(self,data=None):
        x = self.button.allocation.x + self.button.allocation.width
        y = self.button.allocation.y
        return (x,y,True)
        
        
def hd_plugin_get_objects():
    plugin = statusbar_applet()
    return [plugin]
 

The Following User Says Thank You to mikkov For This Useful Post:
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#24
Thanks again!.

Saved the above to /usr/lib/hildon-desktop/pytaskbar.py and created /usr/share/applications/hildon-navigator/pytaskbar.desktop with:

Code:
[Desktop Entry]
Name=PyTask
Type=python
X-Path=pytaskbar
I'll see if I can package this and/or write something up (including the home hello world).

I'm really beginning to like Python as my middle level language (between C and simple shell scripts).
 
Posts: 1,208 | Thanked: 1,028 times | Joined on Oct 2007
#25
Originally Posted by TrueJournals View Post
Unfortunately, like tz1 said, there are NO error messages when something fails...
Desktop plugins are much easier to develop in scratchbox.

When starting desktop environmet with af-sb-init.sh start, debug prints are printed to console, including python errors.
 
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#26
http://www.zdez.org/pydesktop.tgz and http://www.zdez.org/PythonHildonDesktopExample-0.1.deb are available.

I don't have a readme, but this includes the home (which doesn't pop-up anything, but pyculator and other demos are fuller examples and available), statusbar, and taskbar applet and desktop files (close to the posts here, but with a few of my mods).

It would be nice to move them somewhere in the maemo garage.

Also, feel free to improve on them. The Debian installs the files, the tgz is the source/install tree (since you can text-edit the python code I didn't bother with a source-move-to-destination, but did include a packager script that creates the .deb file).

I don't have a postinst file, and that may be necessary to activate them automatically instead of using the control panel.

Speaking of which, python control panel applets...?
 
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#27
I've tried in scratchbox, but much of what I want to do is dependent on the hardware (e.g. GPS) that isn't emulated. I haven't but should try the QEMUed N8x0 but that is fairly new. The Ubuntu hildon stuff isn't exactly the same as Nokia/Maemo. I also get confused building under the X86 then switching to ARMEL, and switching back.

A lot of hiccups are in the desktop or other resource files and it is hard to keep my tablet and scratchbox environment (x2 - armel/x86) enough in sync to make it work smoothly but not so much as something breaks. I have enough trouble when I forget to fix the DNS entry in scratchbox (it copies resolv.conf from the main at install, but if I can't see the DNS servers because I've moved things break).

The (earlier?) hello-world-desktop in C was all three applets mixed together plus control panel, and I couldn't even get them successfully separated.

But for all that, Scratchbox/Maemo is actually a nice environment, but it has a few annoyances and I haven't mastered it. I really should spend some time going through it instead of rushing to get programs out.
 
TrueJournals's Avatar
Posts: 480 | Thanked: 378 times | Joined on Apr 2008 @ Chicago-ish
#28
WOW! Great job to everyone working on this. I'm trying to adapt the task navigator menu to the statusbar item. Here's the code I have:
Code:
import gtk
import hildondesktop

class statusbar_applet(hildondesktop.StatusbarItem):
	def __init__(self):
		hildondesktop.StatusbarItem.__init__(self)
		
		self.button = gtk.Button()
		self.button.set_image(gtk.image_new_from_file("/usr/share/icons/hicolor/40x40/hildon/pyrdesktop.png"))
		self.button.set_name("hildon-statusbar-button-one")
		self.button.set_size_request(40,40)
		self.button.connect("clicked",self.popup_menu)
		self.create_menu()
		
		self.add(self.button)
		self.show_all()
		
	def create_menu(self):
		self.menu = gtk.Menu()
		menu_item = gtk.MenuItem("Hello World!")
		menu_item.connect('activate',self.show_dialog)
		self.menu.append(menu_item)
		self.menu.set_name("menu_from_statusbar")
		self.menu.show_all()
		
	def popup_menu(self,widget,data=None):
		self.menu.popup(None,None,self.menu_position,0,gtk.get_current_event_time())

	def show_dialog(self,widget,data=None):
		mdlg = gtk.MessageDialog(None,0,gtk.MESSAGE_INFO,gtk.BUTTONS_OK,"Hello World!")
		mdlg.run()
		mdlg.destroy() 
        
	def menu_position(self,data=None):
		x = self.button.get_allocation().x
		y = self.button.get_allocation().y + self.button.get_allocation().height
		return (x,y,True)
		    
def hd_plugin_get_objects():
	plugin = statusbar_applet()
	return [plugin]
And here's a screenshot of how the menu comes up:


As you can see, the menu shows up in the wrong spot by... a lot... any ideas?
__________________
Disclaimer: If a program I wrote doesn't work/breaks your tablet... It's not my fault
mcedit | Utility Calculators (WIP) | PyRDesktop
My Blog | Twitter

Last edited by TrueJournals; 2008-08-20 at 17:34.
 
tz1's Avatar
Posts: 716 | Thanked: 236 times | Joined on Dec 2007
#29
You need to do the python equivalent of gtk_window_move(menu,x,y) and probably eventually gtk_widget_set_size_request(menu,w,h) on the menu object.

The osso-statusbar-cpu applet and advanced backlight applet have the C code for doing very similar things like menus and updates.
 
TrueJournals's Avatar
Posts: 480 | Thanked: 378 times | Joined on Apr 2008 @ Chicago-ish
#30
OK, I got the menu working! I looked at the code for osso-statusbar-cpu, and tried to translate it to python. Eventually, I got it working. Here's the code I came up with for the menu_position function on a statusbar:
Code:
	def menu_position(self,data=None):
		(reqw, reqh) = self.menu.get_size_request()
		sw = self.button.get_screen().get_width()
		
		(x,y) = self.button.get_parent_window().get_position()
		
		y = y + self.button.get_allocation().y + self.button.get_allocation().height
		x = x + self.button.get_allocation().x
		
		greater = x + reqw
		
		if (greater > sw) :
			x = x - req.width - self.button.get_allocation().width;
		
		return (x,y,True)
It works great! It even handles if the menu is too big to fit on the screen!

[edit]And here's the full source code for a button in the statusbar. It's actually a ToggleButton, so it'll be active when the menu is popped up, and inactive when it's not!

Code:
import gtk
import hildondesktop

class statusbar_applet(hildondesktop.StatusbarItem):
	def __init__(self):
		hildondesktop.StatusbarItem.__init__(self)
		
		self.button = gtk.ToggleButton()
		self.button.set_image(gtk.image_new_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU))
		self.button.set_name("hildon-statusbar-button-one")
		self.button.set_size_request(40,40)
		self.button.connect("clicked",self.popup_menu)
		
		self.add(self.button)
		self.show_all()
		
	def create_menu(self):
		self.menu = gtk.Menu()
		menu_item = gtk.MenuItem("Hello World!")
		menu_item.connect('activate',self.show_dialog)
		self.menu.append(menu_item)
		self.menu.set_name("menu_from_statusbar")
		self.menu.connect("selection-done", self.menu_done)
		self.menu.show_all()
		
	def popup_menu(self,widget,data=None):
		if (self.button.get_active() == True) :
			self.create_menu()
			self.menu.popup(None,None,self.menu_position,0,gtk.get_current_event_time())

	def show_dialog(self,widget,data=None):
		mdlg = gtk.MessageDialog(None,0,gtk.MESSAGE_INFO,gtk.BUTTONS_OK,"Hello World!")
		mdlg.run()
		mdlg.destroy()
	
	def menu_done(self, widget, data=None):
		self.button.set_active(False)
		self.menu.destroy()

	def menu_position(self,data=None):
		(reqw, reqh) = self.menu.get_size_request()
		sw = self.button.get_screen().get_width()
		
		(x,y) = self.button.get_parent_window().get_position()
		
		y = y + self.button.get_allocation().y + self.button.get_allocation().height
		x = x + self.button.get_allocation().x
		
		greater = x + reqw
		
		if (greater > sw) :
			x = x - req.width - self.button.get_allocation().width;
		
		return (x,y,True)
		    
def hd_plugin_get_objects():
	plugin = statusbar_applet()
	return [plugin]
__________________
Disclaimer: If a program I wrote doesn't work/breaks your tablet... It's not my fault
mcedit | Utility Calculators (WIP) | PyRDesktop
My Blog | Twitter

Last edited by TrueJournals; 2008-08-20 at 21:23. Reason: Full source code for example
 

The Following User Says Thank You to TrueJournals For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 07:48.