def __init__(self, screen):
        super().__init__()
        #inorder to make these butts appear we need a screen
        #screen is passed as an argument
        self.screen = screen
        self.settings = Settings()
        #An instance for the surface created
        self.image = pygame.image.load('Img/butts.png')
        #Above line loads the images on the surface
        self.rect = self.image.get_rect()
        #Here, in pygame the game elements referred as rects
        #so, the loaded images is converted into an image rects
        self.screen_rect = screen.get_rect()
        #screen_rect is the surface rectangle

        #start at the bottom center of surface
        self.rect.centerx = float(self.screen_rect.centerx)
        '''imgrect.centerx'''
        #surface center(screen_rect.centerx) is stored in
        self.rect.bottom = self.screen_rect.bottom
        '''imgrect.bottom'''
        #surface bottom(screen_rect.bottom) is stored in

        #butt movement
        self.moving_right = False
        self.moving_left = False
        self.bullet_pos = self.rect.right
        #fart sound when farted
        self.fart_sound = pygame.mixer.Sound("sounds/fartsound2.wav")
Exemple #2
0
def run_game():
    #initialize game & screen objectt
    pygame.init()  #called the pygame init constructor
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    #set the background code
    #the screen object is called a surface
    #On that surface we'll keep our elements
    pygame.display.set_caption("What the Fart!")
    #Object creation of items on the screen
    butt = Butt(screen)
    #creating a group of noses using sprite.Group()
    noses = Group()
    #create a group of aliens
    bullets = Group()
    #creating group of bullets
    gf.create_fleet(settings, screen, noses)
    while True:
        x = gf.check_events(butt, bullets, screen)
        #checks the events in for loop get_events()
        butt.update()
        #updating the butt positions
        gf.bullet_update(butt, bullets, x)
        #creating and updating bullets
        gf.rm_oldbullet(bullets)
        #removing old bullets from the sprite group
        gf.update_noses(noses)
        #update noses and their movement
        gf.check_collisions(bullets, noses, settings, screen)
        #collision between noses and bullet farts
        gf.update_surface(settings, butt, bullets, noses, x, screen)
Exemple #3
0
    def __init__(self, screen):
        '''a fart object at butts current position'''
        super().__init__()
        #ready state
        self.screen = screen
        self.butt = Butt(screen)
        self.settings = Settings()
        self.bullet = pygame.image.load('Img/fart2.png')
        self.rect = self.bullet.get_rect()
        self.rect.bottom = self.butt.rect.top
        #self.bullet_state = 'ready'

        #for sprites
        self.x = self.rect.x
 def __init__(self, screen):
     super().__init__()
     self.settings = Settings()
     self.screen = screen
     self.image = pygame.image.load("Img/nose2.png")
     self.rect = self.image.get_rect()
     self.rect.bottom = float(90.0)
     # Start each new nose near the top left of the screen
     self.rect.top = -100
     #Store the nose's exact position
     self.x = float(self.rect.x)
     #nose movement parameters
     self.nose_moving_left = False
     self.nose_moving_right = True
Exemple #5
0
 def _init_settings(self):
     self.settings=Settings(SETTINGS_ID, '/eu/zderadicka/thetool/')
     self.settings.connect("changed", self.on_settings_changed)
Exemple #6
0
class TheTool(Gtk.Application):
    UI_FILES=[]
    STATUS_IDLE, STATUS_POWER_OFF_TIMER= "Idle", "Will Power Off"
    NAME="TheTool"
    def __init__(self):
        Gtk.Application.__init__(self, application_id=SETTINGS_ID)
        self.register(None)
        already_registered=self.get_is_remote()
        if already_registered:
            raise DuplicateInstance
        
        self._init_settings()
        self.icon_normal=GdkPixbuf.Pixbuf.new_from_file(os.path.join(_curr_dir, 'pics', 'tools.png'))

        self._define_actions()
        self._build_menus()
        self.tray_icon=tray.create(self.popup, self.activate)
        self.ui=UiHelper(self)
        self._cancel_power_off()
        self._load_actions()
        self._start_nm()
        
        
    def set_tooltip(self, status, message=None, time=None): 
        tt=self.NAME+" - %s" 
        if message:
            tt=tt+"- %s" 
            tt=tt% (status,message)
        else:
            tt=tt%status
        self.tray_icon.set_tooltip_text(tt, time=time)
        
        
    def _build_menus(self):    
        menu_manager=Gtk.UIManager()
        menu_manager.insert_action_group(self.core_actions)
        menu_manager.insert_action_group(self.power_type_actions)
        menu_manager.add_ui_from_file(os.path.join(_curr_dir, 'ui', 'menus.xml'))
        self.menu_manager=menu_manager
        self.popup=menu_manager.get_widget('/popup')
        self._build_po_menu()
        self._build_actions_menu()
        power_off_menu=self.menu_manager.get_widget('/popup/power_menu/').get_submenu()
        power_off_menu.connect('show', self.on_power_off_menu_shown)
        
        
    def _build_po_menu(self):
        po_item=self.menu_manager.get_widget('/popup/power_menu/')
        power_off_menu=po_item.get_submenu()
        #remove default Empty child and previous items
        power_off_menu.foreach(lambda x,_: power_off_menu.remove(x), None)
        intervals=self.settings.get_unpacked('poweroff-intervals')
        item=Gtk.MenuItem()
        item.set_related_action(self.core_actions.get_action('power_off_after_player_stops'))
        power_off_menu.add(item)
        for interval in intervals:
            item=Gtk.MenuItem("%d mins"%interval)
            item.connect('activate',self.on_power_off_action, interval)
            power_off_menu.add(item)
        power_off_menu.show_all()
        po_item.set_visible(True)
        
    def _build_actions_menu(self):
        qa_item=self.menu_manager.get_widget('/popup/actions_menu/')
        qa_menu=qa_item.get_submenu()
        #remove default Empty child
        qa_menu.foreach(lambda x,_: qa_menu.remove(x), None)
        actions_list=self.settings.get_unpacked('quick-actions')
        for a in actions_list:
            item=Gtk.MenuItem(a)
            item.connect('activate',self.on_quick_action, a)
            qa_menu.add(item)
        if actions_list:
            qa_menu.show_all()
            qa_item.set_visible(True)
        else:
            qa_item.set_visible(False)
        
    def _define_actions(self):
        ca=Gtk.ActionGroup('core_actions')
        
        ca.add_actions([('dummy', None, 'dummy', None, None, None ),
                        ('about_action', Gtk.STOCK_ABOUT, None, None, None, 
                        self.on_about_action_activate),
                       ('quit_action', Gtk.STOCK_QUIT, None, None, None,
                        self.on_quit_action_activate),
                        ('settings_action', None, 'Settings ...', None, None,
                         self.on_settings_action_activate),
                        ('monitor_action', None, 'Turn Off Monitor Now', None, None,
                         self.on_monitor_action_activate),
                        ('power_menu_action', None, 'Power Off After ...', None, None, None),
                        ('actions_menu_action', None, 'Quick Actions ...', None, None, None),
                        ('power_off_type_action', None, 'Power Off Type', None, None, None)
                       ])
        action1=Gtk.Action('cancel_power_off_action', 'Cancel Power Off', None, None)
        action1.connect('activate', self.on_cancel_power_off_action)
        ca.add_action(action1)
        action2=Gtk.Action('power_off_after_player_stops', "Player Stops", None, None)
        action2.connect('activate', self.on_power_off_after_player_stops)
        ca.add_action(action2)
        self.core_actions=ca
        
        
        pt=Gtk.ActionGroup('power_types_actions')
        action=Gtk.RadioAction("shutdown", "Shut Down", None, None, 1)
        pt.add_action(action)
        action2=Gtk.RadioAction("suspend", "Suspend", None, None, 2)
        action2.join_group(action)
        pt.add_action(action2)
        action3=Gtk.RadioAction("hibernate", "Hibernate", None, None, 3)
        action3.join_group(action)
        pt.add_action(action3)
        curr_type=self.settings.get_unpacked('poweroff-types')
        pt.get_action(curr_type).set_active(True)
        action.connect('activate', self.on_power_type_activated, "shutdown")
        action2.connect('activate', self.on_power_type_activated, "suspend")
        action3.connect('activate', self.on_power_type_activated, "hibernate")
        self.power_type_actions=pt
        
    def _start_nm(self):
        if self.settings.get_unpacked('monitor-networks'):
            self.nm=NetMonitor(self.settings, self.on_network_changed)
            self.nm.start()
            if hasattr(self, 'open_settings') and self.open_settings:
                self.open_settings.set_netmanager(self.nm)
        else:
            if hasattr(self,'nm') and self.nm:
                self.nm.stop()
            self.nm=None
            
    
    def _load_actions(self):
        actions.ACTIONS_FILE=self.settings.get_unpacked('actions-file')
        actions.load()
        
        
    def main(self):
        GObject.threads_init()
        Gdk.threads_init()
        
        try:
            Gtk.main()
        except KeyboardInterrupt:
            Gtk.main_quit()
        Notify.uninit()
         
    def activate(self):   
        log.debug('Activate')
        if self.timer_id:
            self.on_cancel_power_off_action(None)
        else:
            pass
            #self.on_power_off_action(None, self.settings.get_unpacked('default-poweroff-timeout'))
            
        
    def _init_settings(self):
        self.settings=Settings(SETTINGS_ID, '/eu/zderadicka/thetool/')
        self.settings.connect("changed", self.on_settings_changed)
            
    def on_quit_action_activate(self, action):
        log.debug('Quiting')
        if hasattr(self,'open_settings') and self.open_settings:
            self.open_settings.destroy()
        Gtk.main_quit()
    def on_about_action_activate(self, action):
        log.debug('About Action')
        d=Gtk.AboutDialog()
        d.set_program_name(self.NAME)
        d.set_version(__version__)
        d.set_copyright('Ivan')
        d.set_license('GPL v3 - http://www.gnu.org/licenses/gpl.html')
        d.set_website('http://zderadicka.eu/thetool-quick-actions-for-desktop/')
        d.set_comments("""The Tool to do some quick 
actions on your desktop
like schedule power off ...
Thanks to Gnome Team for great GUI libraries
Linux desktop rocks! (most of the time:)""")
        d.set_logo(self.icon_normal)
        res=d.run()
        d.hide()
    def on_settings_action_activate(self, action):
        log.debug('Showing Settings')
        if hasattr(self,'open_settings') and self.open_settings:
            self.open_settings.present()
        else:
            dialog=SettingsDialog(self.settings, self.power_type_actions, self.nm)
            dialog.set_icon(self.icon_normal)
            self.open_settings=dialog
            log.debug('Openning dialog')
            dialog.show()
            log.debug('Dialog done')
           
    def on_monitor_action_activate(self, action):
        def turn_off():
            os.system('xset dpms force off')
            return False
        timer_id=GObject.timeout_add(1000,turn_off)
        
    def on_power_off_action(self, item, interval):
        log.debug("Will power off in %d mins", interval)
        self.start_power_off(interval)
    
    def on_power_off_after_player_stops(self, item):
        log.debug("Will power-off when player stops")
        player_monitor=mplayer2.PlayerMonitor(self.on_player_stopped)
        if not player_monitor.is_active():
            log.warn('No player is playing')
            return
        self._destroy_current_timer()
        player_name=player_monitor.name
        self._start_power_off(player_monitor, 
                              "After Player %s Stops" % player_name, 
                              "Will Power Off After Player %s Stops" % player_name)
        
    def on_player_stopped(self):
        log.debug("Player Stopped")
        timeout=self.settings.get_unpacked('player-poweroff-timeout')
        if timeout:
            self.start_power_off(timeout)
        else:
            self.power_off()
    def on_power_off_menu_shown(self, item):
        is_playing=mplayer2.get_active_player() is not None
        self.core_actions.get_action('power_off_after_player_stops').set_sensitive(is_playing)
        log.debug("Power-off menu shown")
        
    def on_quick_action(self, item, action):
        log.debug("Quick action %s initiated", action)
        actions.ActionsRunner([action], 
                              self._notify_failed_action,
                              False).start()
    
    def _notify_failed_action(self, ok, failed):  
        if failed:
            action, error= failed[0]
            self.send_notification("Action %s <b>failed</b> with error %s" % (action,error))
        
    def on_power_type_activated(self, action, name):
        if action.get_active():
            log.debug("Power Off Type changed to %s", name)
            self.settings.set_string('poweroff-types',name)
            
    def on_settings_changed(self, settings, key, data=None):
        log.debug( "Setting changed %s", key)
        if key=='poweroff-intervals':
            self._build_po_menu()
        elif key=="monitor-networks":
            self._start_nm()
        elif key=="actions-file":
            self._load_actions()
        elif key=="quick-actions":
            self._build_actions_menu()
            
            
    def start_power_off(self, mins):
        if self.timer_id:
            self._destroy_current_timer()
        
        self.time_to_power_off=time.time()+mins*60
        self._start_power_off(GObject.timeout_add(6000, self.timeout_ticks),
                           "in %d mins" % mins,
                            "Will Power Off In %d Minutes"%mins, mins=mins)
        
        
    def _start_power_off(self, timer_object, tooltip_text, notification_text=None, mins=None):
        self.timer_id=timer_object
        self.set_tooltip(self.STATUS_POWER_OFF_TIMER,tooltip_text, time=mins)
        if notification_text:
            self.send_notification(notification_text)
        self.tray_icon.set_attention(True)
        self.core_actions.get_action('cancel_power_off_action').set_visible(True)
        
        
        
    def timeout_ticks(self):
        log.debug('Power off timeout running')
        remaining=self.time_to_power_off-time.time()
        if remaining <= 0:
            self.power_off()
            return False
        remaining=int(math.ceil(remaining/60))
        self.set_tooltip(self.STATUS_POWER_OFF_TIMER, "in %d mins" % remaining, time=remaining)
        if remaining <= self.settings.get_unpacked('notify-before-poweroff') and \
            not self.power_off_notification_sent:
            self.send_notification("Last Warning - Will Power Off in %d Minutes"% remaining)
            self.power_off_notification_sent=True
        return True
    
    def _cancel_power_off(self):  
        self.timer_id=None
        self.time_to_power_off=None
        self.set_tooltip(self.STATUS_IDLE)
        self.tray_icon.set_attention(False)
        self.core_actions.get_action('cancel_power_off_action').set_visible(False)  
        #self.core_actions.get_action('power_off_after_player_stops').set_sensitive(False) 
        self.power_off_notification_sent=False
          
    def power_off(self):
        log.debug('Powering Off Now')
        self._destroy_current_timer()
        self._cancel_power_off()
        mplayer2.pause_all()
        power_off_type=self.settings.get_unpacked('poweroff-types')
        gdbus.power_off(power_off_type)
        
    def on_cancel_power_off_action(self, action):
        log.debug('Canceling Power Off')
        self._destroy_current_timer()
        self._cancel_power_off()
    
    def _destroy_current_timer(self):
        if self.timer_id and isinstance(self.timer_id, numbers.Integral):
            #it is timer_id
            GObject.source_remove(self.timer_id)
        elif self.timer_id and isinstance(self.timer_id, mplayer2.PlayerMonitor):
            self.timer_id.close()
            
    
    def on_tray_icon_clicked(self, icon, event):
        log.debug("Button clicked on tray icon button:%d, time: %d", event.button, event.time)
        #for now show menu also on button1
        if event.button==1:
            self.popup.popup(None, None, None, None, event.button, event.time )
            
    def send_notification(self, message):
        if not self.settings.get_unpacked('enable-notifications'):
            return
        if not Notify.is_initted ():
            Notify.init(self.NAME)
        notification = Notify.Notification.new(
        self.NAME,
        message,
        None# 'dialog-information'
        )
        notification.set_image_from_pixbuf(self.icon_normal)
        notification.show()
        
    def on_network_changed(self, path):
        if path:
            net_settings=self.settings.get_settings_under(NET_SETTINGS_ID, path)
            name=net_settings.get_unpacked('name')
            log.debug("Connected to known net %s",name)
            actions_list=net_settings.get_unpacked('network-actions')
            if actions_list:
                actions.ActionsRunner(actions_list, 
                                      functools.partial(self.notify_network, name),
                                      False).start()
            else:
                self.notify_network(name)                     
            
        else:
            log.debug("Connected to unknown net")
            actions_list=self.settings.get_unpacked('unknown-network-actions')
            if actions_list:
                actions.ActionsRunner(actions_list, 
                                      functools.partial(self.notify_network, None),
                                      False).start()
            else:
                self.notify_network(None)   
            
            
    def notify_network(self, name, ok=[], failed=[]):
        if name:
            msg=" Network %s" %name
        else:
            msg="Network Unknown"
        
        if ok:
            msg+=" (%s)" %', '.join(ok)
        if failed:
            failures=map(lambda x: str(x), failed)
            msg+="/n<b>Errors:</b> %s" % ', '.join(failures)
            
        self.send_notification(msg)
Exemple #7
0
# imports
from PyQt5.QtWidgets import QDialog, QGridLayout, QFileDialog, QLabel, QPushButton, QComboBox
from PyQt5 import QtGui, QtCore
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QRect
import sys

# module imports
import file_system as fs
from gsettings import Settings

# set global settings
settings = Settings.instance()

class SettingsPage(QDialog):
	def __init__(self):
		super().__init__()

		# set window
		self.setWindowIcon(QtGui.QIcon('./logo.png'))
		self.setWindowTitle("Settings")
		self.move(100, 100)

		# ==============================
		# Dir Layout
		# ==============================
		dir_layout = QGridLayout()

		# ********************
		# row 0
		# ********************