Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)
Paste
Pasted as Python by George ( 15 years ago )
#!/usr/bin/python
import gobject
import gtk
ui_info_main = \
'''<ui>
<toolbar name='ToolBar'>
<toolitem action='Start' />
<toolitem action='Stop' />
<separator />
<toolitem action='Quit' />
</toolbar>
</ui>'''
class ApplicationMainWindow( gtk.Window ):
def __init__( self, parent = None ):
gtk.Window.__init__(self)
try:
self.set_screen( parent.get_screen() )
except AttributeError:
self.connect( 'destroy', lambda *w: gtk.main_quit() )
self.set_title( 'Countdown' )
self.set_default_size( 160, 60 )
merge = gtk.UIManager()
self.set_data( 'ui-manager', merge )
merge.insert_action_group( self.__create_action_group(), 0 )
self.add_accel_group( merge.get_accel_group() )
try:
mergeid = merge.add_ui_from_string( ui_info_main )
except gobject.GError, msg:
print "building menu failed: %s" % msg
table = gtk.Table( 1, 4, False )
self.add( table )
bar = merge.get_widget( "/ToolBar" )
bar.set_tooltips( True )
bar.show()
table.attach( bar,
0, 1, 0, 1,
gtk.EXPAND | gtk.FILL, 0,
0, 0 );
self.textentry = gtk.Entry()
self.textentry.set_max_length(5)
self.textentry.set_text( '60' )
self.textentry.show()
table.attach( self.textentry,
0, 1, 1, 2,
gtk.EXPAND | gtk.FILL, 0,
0, 0 );
self.show_all()
def __create_action_group( self ):
entries = (
( 'Start', gtk.STOCK_MEDIA_PLAY, '_Start', '<control>s', 'Start', self.action_start ),
( 'Stop', gtk.STOCK_MEDIA_STOP, '_Stop', None, 'Stop', self.action_stop ),
( 'Quit', gtk.STOCK_QUIT, '_Quit', '<control>Q', 'Quit', self.action_quit )
);
action_group = gtk.ActionGroup( 'AppWindowActions' )
action_group.add_actions( entries )
return action_group
def action_start( self, action ):
if self.textentry.get_text() > 0:
self.counter = int( self.textentry.get_text() )
else:
self.counter = 60
gobject.timeout_add( 1000, self.counter_decrement )
def action_stop( self, action ):
self.counter = 0
def action_quit( self, action ):
gtk.main_quit()
def countdown_end( self ):
dialog = gtk.MessageDialog(self,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
"Countdown is end" )
dialog.set_property( 'title', 'Countdown' )
dialog.run()
dialog.destroy()
self.set_keep_above( False )
def counter_decrement( self ):
if self.counter > 0:
self.counter -= 1
else:
return 0
self.textentry.set_text( str( self.counter ) )
if self.counter == 0:
self.countdown_end()
return 0
elif self.counter == 1:
self.set_keep_above( True )
gobject.timeout_add( 1000, self.counter_decrement )
def main():
ApplicationMainWindow()
gtk.main()
if __name__ == '__main__':
main()
Revise this Paste