Sorry. -u this time: --- /home/walter/Desktop/walters-sugar-clone/extensions/deviceicon/touchpad.py 2010-07-20 13:23:44.000000000 -0400 +++ touchpad.py 2010-07-29 22:25:37.000000000 -0400 @@ -32,8 +32,8 @@ STATUS_TEXT = {TOUCHPAD_MODES[0]: _('finger'), TOUCHPAD_MODES[1]: _('stylus')} STATUS_ICON = {TOUCHPAD_MODES[0]: 'touchpad-' + TOUCHPAD_MODES[0], TOUCHPAD_MODES[1]: 'touchpad-' + TOUCHPAD_MODES[1]} -# FLAG_PATH is used to preserve status between boots. -FLAG_PATH = '/home/olpc/.olpc-pentablet-mode' +# FLAG_FILE is used to preserve status between boots. +FLAG_FILE = '.olpc-pentablet-mode' # NODE_PATH is used to communicate with the touchpad device. NODE_PATH = '/sys/devices/platform/i8042/serio1/ptmode'
@@ -102,6 +102,10 @@ """ Touchpad palette only appears when the device exisits. """ if os.path.exists(NODE_PATH): tray.add_device(DeviceView()) + # if _flag_path exists, set the initial device value to stylus + _flag_path = os.join(os.environ['HOME'], FLAG_FILE) + if os.path.exists(_flag_path): + write_to_node_file(str(TOUCHPAD_MODES.index('stylus'))) def read_touchpad_mode(): @@ -117,13 +121,23 @@ """ Write the touchpad mode to the node path and set/unset the flag. """ touchpad_mode_index = TOUCHPAD_MODES.index(touchpad) - node_file_handle = open(NODE_PATH, 'w') - node_file_handle.write(str(touchpad_mode_index)) - node_file_handle.close() + write_to_node_file(str(touchpad_mode_index)) + _flag_path = os.join(os.environ['HOME'], FLAG_FILE) if touchpad_mode_index == 0: - if os.path.exists(FLAG_PATH): + if os.path.exists(_flag_path): os.remove(FLAG_PATH) else: - flag_file_handle = open(FLAG_PATH, 'w') + flag_file_handle = open(_flag_path, 'w') flag_file_handle.close() + + +def write_to_node_file(value): + """ Write to node path, catching exception is there is a problem """ + try: + node_file_handle = open(NODE_PATH, 'w') + except IOError, e: + print e + return + node_file_handle.write(value) + node_file_handle.close() On Thu, Jul 29, 2010 at 11:20 PM, Paul Fox <p...@laptop.org> wrote: > walter wrote: > > On Thu, Jul 29, 2010 at 5:37 PM, Paul Fox <p...@laptop.org> wrote: > > > walter wrote: > > > > On Thu, Jul 29, 2010 at 6:27 AM, pbrobin...@gmail.com > > > > <pbrobin...@gmail.com> wrote: > > > > > On Wed, Jul 28, 2010 at 3:41 PM, Sascha Silbe > > > > > <sascha-ml-ui-sugar-de...@silbe.org> wrote: > > > > >> Excerpts from Paul Fox's message of Wed Jul 28 16:01:22 +0200 2010: > > > > >>> sascha wrote: > > > > >>> > Even your latest patch still contains code that is specific to > OLPC > > > > builds and will break on other systems. > > > > >>> > Of course it's perfectly fine for you to say you only care > about > > OLPC > > > > builds for XO-1 (because the number of XO-1s running non-OLPC builds > is > > > > minimal, especially if you don't count developers). But in that case > your > > patch > > > > should be included in the OLPC builds, not in Sugar mainline. > > > > >>> > > > > >>> can you remind me of the specific issue(s) here? > > > > >> I can remember two issues (there might be others as well): > > > > >> - hardcoded, absolute path (/home/olpc/whatever) > > > > > > > > > > I agree that it shouldn't ever user /home/olpc as hardcoded. At > least > > > > > you ~/.olpc-blah as it will then work on what ever distro and what > > > > > ever user. I'm not sure of the general standard to use for this. > > > > > > > > How's this look? > > > > > > walter -- i didn't think of this when we were designing all of > > > this: how about if, in addition to this patch, you checked at sugar > > > startup time and used the presence of that file in $HOME as an > > > indication that you should set ptmode for the user? then i could > > > eliminate a chunk of the code from olpc-utils that sascha was > > > complaining about. > > > > > > btw -- i just looked at your patch again -- what happens if > > > NODE_PATH can't be opened for writing? write_touchpad_mode() > > > should fail gracefully in that case. making the node writeable > > > is the one line of code that will need to remain external to > > > sugar, and we shouldn't assume that it has happened. i'm > > > referring to this: > > > > > > +def write_touchpad_mode(touchpad): > > > + """ Write the touchpad mode to the node path and set/unset the > flag. > > """ > > > + touchpad_mode_index = TOUCHPAD_MODES.index(touchpad) > > > + > > > + node_file_handle = open(NODE_PATH, 'w') > > > + node_file_handle.write(str(touchpad_mode_index)) > > > + node_file_handle.close() > > > + > > > + if touchpad_mode_index == 0: > > > + if os.path.exists(FLAG_PATH): > > > + os.remove(FLAG_PATH) > > > + else: > > > + flag_file_handle = open(FLAG_PATH, 'w') > > > + flag_file_handle.close() > > > > > > paul > > > > > > > > > > > > > > 35,36c35,36 > > > > < # FLAG_PATH is used to preserve status between boots. > > > > < FLAG_PATH = '/home/olpc/.olpc-pentablet-mode' > > > > --- > > > > > # FLAG_FILE is used to preserve status between boots. > > > > > FLAG_FILE = '.olpc-pentablet-mode' > > > > 123a124 > > > > > _flag_path = os.join(os.environ['HOME'], FLAG_FILE) > > > > 125,126c126,127 > > > > < if os.path.exists(FLAG_PATH): > > > > < os.remove(FLAG_PATH) > > > > --- > > > > > if os.path.exists(_flag_path): > > > > > os.remove(_flag_path) > > > > 128c129 > > > > < flag_file_handle = open(FLAG_PATH, 'w') > > > > --- > > > > > flag_file_handle = open(_flag_path, 'w') > > > > > > > > -walter > > > > > > > > > > Peter > > > > > _______________________________________________ > > > > > Sugar-devel mailing list > > > > > Sugar-devel@lists.sugarlabs.org > > > > > http://lists.sugarlabs.org/listinfo/sugar-devel > > > > > > > > > > > > > > > > > > > > > -- > > > > Walter Bender > > > > Sugar Labs > > > > http://www.sugarlabs.org > > > > _______________________________________________ > > > > Sugar-devel mailing list > > > > Sugar-devel@lists.sugarlabs.org > > > > http://lists.sugarlabs.org/listinfo/sugar-devel > > > > > > =--------------------- > > > paul fox, p...@laptop.org > > > > > > > This do the trick? > > it might. it's really hard to tell without the -u option to > patch. line number patches are so last century. ;-) > > paul > > > > > 35,36c35,36 > > < # FLAG_PATH is used to preserve status between boots. > > < FLAG_PATH = '/home/olpc/.olpc-pentablet-mode' > > --- > > > # FLAG_FILE is used to preserve status between boots. > > > FLAG_FILE = '.olpc-pentablet-mode' > > 104a105,108 > > > _flag_path = os.join(os.environ['HOME'], FLAG_FILE) > > > # if _flag_path exists, set the initial device value to stylus > > > if os.path.exists(_flag_path): > > > write_to_node_file(str(TOUCHPAD_MODES.index('stylus'))) > > 120,122c124 > > < node_file_handle = open(NODE_PATH, 'w') > > < node_file_handle.write(str(touchpad_mode_index)) > > < node_file_handle.close() > > --- > > > write_to_node_file(str(touchpad_mode_index)) > > 123a126 > > > _flag_path = os.join(os.environ['HOME'], FLAG_FILE) > > 125c128 > > < if os.path.exists(FLAG_PATH): > > --- > > > if os.path.exists(_flag_path): > > 128c131 > > < flag_file_handle = open(FLAG_PATH, 'w') > > --- > > > flag_file_handle = open(_flag_path, 'w') > > 129a133,143 > > > > > > > > > def write_to_node_file(value): > > > """ Write to node path, catching exception is there is a problem """ > > > try: > > > node_file_handle = open(NODE_PATH, 'w') > > > except IOError, e: > > > print e > > > return > > > node_file_handle.write(value) > > > node_file_handle.close() > > > > -walter > > -- > > Walter Bender > > Sugar Labs > > http://www.sugarlabs.org > > =--------------------- > paul fox, p...@laptop.org > -- Walter Bender Sugar Labs http://www.sugarlabs.org _______________________________________________ Sugar-devel mailing list Sugar-devel@lists.sugarlabs.org http://lists.sugarlabs.org/listinfo/sugar-devel