Esempio n. 1
0
 def __init__(self):
     """
     the constructor function of the client.
     """
     self.client_socket = socket.socket()  # the socket of the client.
     self.communicator = Communicator()
     self.events_handler = EventsHandler(self.client_socket)
     self.running = True
     self.display_resolution = DEFAULT_DISPLAY_RESOLUTION
     self.screen = self.get_display()
Esempio n. 2
0
    def __init__(self, at_bottom):
        self._at_bottom = at_bottom
        if self._at_bottom:
            y = c.screen_height - 2 * c.hand_offset_y - c.card_h
        else:
            y = 0
        GameObject.__init__(self, 0, y, c.hand_w, c.hand_h)
        EventsHandler.__init__(self)
        self._cards = []
        self._settle()

        self._up_card = None

        # Карта, готовая отправиться на стол.
        self._table_card = None
Esempio n. 3
0
    def __init__(self,
                 x,
                 y,
                 w,
                 h,
                 text,
                 on_click=lambda x: None,
                 padding=0,
                 active=True):
        GameObject.__init__(self, x, y, w, h)
        EventsHandler.__init__(self, active)

        self._state = 'normal'
        self._on_click = on_click
        self._text = TextObject(x + padding, y + padding, lambda: text,
                                c.button_text_color, c.font_name, c.font_size)
Esempio n. 4
0
    def __init__(self, hand, table, is_offensive):
        Player.__init__(self, hand, table, is_offensive)
        EventsHandler.__init__(self, active=False)
        self.show_hand()

        def on_finish_turn_button_clicked(self):
            self._finish_turn_button_clicked = True

        self._finish_turn_button_clicked = False
        if self.at_bottom:
            finish_button_y = self._hand.top - c.main_menu_button_h
        else:
            finish_button_y = self._hand.bottom
        self.finish_turn_button = Button(self._hand.left, finish_button_y, c.main_menu_button_w, c.main_menu_button_h,
                                         'Завершить ход', lambda button: on_finish_turn_button_clicked(self), padding=5,
                                         active=False)
Esempio n. 5
0
    def __init__(self, x, y, suit, nominal):
        GameObject.__init__(self, x, y, c.card_w, c.card_h)
        EventsHandler.__init__(self)

        self._hidden = True
        self._below = True
        self._moved = False
        self._state = 'normal'
        self._dest_point = (self.left, self.top)
        self._cur_point = (self.left, self.top)
        self._suit = suit
        self._nominal = nominal

        image_path = 'source/images/cards/' + self._suit + '/' + self._nominal + '.png'
        image = pygame.image.load(image_path)
        self._image = pygame.transform.smoothscale(image, (c.card_w, c.card_h))
        self._flop = pygame.transform.smoothscale(c.flop, (c.card_w, c.card_h))
        self._hover_bounds = pygame.transform.smoothscale(
            c.hover_bounds, (c.card_w, c.card_h))
Esempio n. 6
0
    def __init__(self, caption, width, height, back_image, icon, frame_rate):
        EventsHandler.__init__(self)
        self._background_image = back_image
        self._icon = icon
        self._frame_rate = frame_rate
        self._game_over = False
        self._running = True
        self._objects = []
        self._events_handlers = []

        pygame.mixer.pre_init(44100, 16, 2, 4096)
        pygame.init()
        pygame.font.init()

        self._surface = pygame.display.set_mode((width, height))
        pygame.display.set_caption(caption)

        pygame.display.set_icon(self._icon)

        self._clock = pygame.time.Clock()
    def __init__(self, application, FULL_PATH, config, date=None):
        super().__init__(title='گاه‌شمار', application=application)

        if date is None:
            date = datetime.date.today()
        self.date = date

        # config values
        self.full_path = FULL_PATH
        self.config = config
        self.app = application

        pday = PersianDayWidget()
        gday = GeorgianDayWidget()
        self.day_widgets = [pday, gday]

        pcal = PersianCalendarWidget(date)
        pcal.parent = self
        gcal = GeorgianCalendarWidget(date)
        gcal.parent = self
        self.calendars = [pcal, gcal]
        self.handler = EventsHandler(self)

        self.main_grid = Gtk.Grid()
        main_grid = self.main_grid
        self.add(main_grid)
        main_grid.set_column_homogeneous(True)
        main_grid.set_column_spacing(spacing=20)
        # main_grid.set_row_homogeneous(True)
        main_grid.set_row_spacing(spacing=20)

        # setup appindicator
        self.visible = True
        self.setup_appindicator()

        self.draw_interface()

        # update interface every 5 seconds
        GLib.timeout_add_seconds(5, self.handler.update_everything)

        self.connect('style-set', self.set_icon_)
class MainWindow(Gtk.ApplicationWindow):
    def __init__(self, application, FULL_PATH, config, date=None):
        super().__init__(title='گاه‌شمار', application=application)

        if date is None:
            date = datetime.date.today()
        self.date = date

        # config values
        self.full_path = FULL_PATH
        self.config = config
        self.app = application

        pday = PersianDayWidget()
        gday = GeorgianDayWidget()
        self.day_widgets = [pday, gday]

        pcal = PersianCalendarWidget(date)
        pcal.parent = self
        gcal = GeorgianCalendarWidget(date)
        gcal.parent = self
        self.calendars = [pcal, gcal]
        self.handler = EventsHandler(self)

        self.main_grid = Gtk.Grid()
        main_grid = self.main_grid
        self.add(main_grid)
        main_grid.set_column_homogeneous(True)
        main_grid.set_column_spacing(spacing=20)
        # main_grid.set_row_homogeneous(True)
        main_grid.set_row_spacing(spacing=20)

        # setup appindicator
        self.visible = True
        self.setup_appindicator()

        self.draw_interface()

        # update interface every 5 seconds
        GLib.timeout_add_seconds(5, self.handler.update_everything)

        self.connect('style-set', self.set_icon_)

    def draw_interface(self):
        # check if unity is running
        import os
        xdg_current_desktop = os.environ.get('XDG_CURRENT_DESKTOP').lower()

        if 'unity' in xdg_current_desktop:
            offset = 1
        else:
            offset = 0
        main_grid = self.main_grid
        for i, v in enumerate(self.day_widgets):
            main_grid.attach(v, i, 0+offset, 1, 1)
        for i, v in enumerate(self.calendars):
            main_grid.attach(v, i, 1+offset, 1, 1)
        # main_grid.attach(Gtk.VSeparator(), 1, 0, 1, 2)
        self.setup_header_bar(xdg_current_desktop)

    def setup_header_bar(self, xdg_current_desktop=''):

        today_button = Gtk.Button(label='امروز')
        today_button.connect("clicked", self.set_today)
        close_button = Gtk.Button.new_from_icon_name(
            'window-close-symbolic', Gtk.IconSize.BUTTON)
        close_button.connect('clicked', self.toggle_main_win)

        if 'unity' in xdg_current_desktop:
            toolbar = Gtk.Toolbar()
            sep = Gtk.SeparatorToolItem()
            sep.set_expand(True)
            sep.set_draw(False)
            toolbar.add(sep)
            tb_today = Gtk.ToolButton.new(today_button)
            tb_today.connect("clicked", self.set_today)
            toolbar.add(tb_today)
            tb_close = Gtk.ToolButton.new(close_button)
            tb_close.connect('clicked', self.toggle_main_win)
            toolbar.add(tb_close)
            self.main_grid.attach(toolbar, 0, 0, 2, 1)
        else:
            # set header bar
            hb = Gtk.HeaderBar()
            hb.props.title = 'گاه‌شمار'

            if USE_IND:
                hb.props.show_close_button = False
                hb.pack_end(close_button)
            else:
                hb.props.show_close_button = True

            hb.pack_end(today_button)

            # sett_button = Gtk.Button.new_from_icon_name(
            #     'preferences-system', Gtk.IconSize.LARGE_TOOLBAR)
            # sett_button.connect('clicked', self.on_settings_clicked)
            # hb.pack_end(sett_button)
            self.set_titlebar(hb)

    def on_settings_clicked(self, button):
        sett_win = SettingsWindow(self)
        sett_win.show_all()

    def set_today(self, *args):
        self.handler.update_everything(datetime.date.today())

    def toggle_main_win(self, *args):
        if not USE_IND:
            return

        if self.visible:
            self.hide()
            self.visible = False
        else:
            self.show_all()
            self.present()
            self.visible = True

    def setup_appindicator(self):
        self.ind = GahShomarIndicator(self, self.date)

    def set_icon_(self, *args):
        # day = khayyam.JalaliDate.today().day
        icon = Gtk.IconTheme.load_icon(
            Gtk.IconTheme(),
            'persian-calendar',
            512, 0)
        self.set_icon(icon)
Esempio n. 9
0
 def disable(self):
     EventsHandler.disable(self)
     self._state = 'normal'
Esempio n. 10
0
 def disable(self):
     EventsHandler.disable(self)
     self.finish_turn_button.disable()
Esempio n. 11
0
 def enable(self):
     EventsHandler.enable(self)
Esempio n. 12
0
class Client(object):
    """
    Client object define an observer.
    He can see the streamer's screen share.(multiple clients
    can see one stream).
    """
    def __init__(self):
        """
        the constructor function of the client.
        """
        self.client_socket = socket.socket()  # the socket of the client.
        self.communicator = Communicator()
        self.events_handler = EventsHandler(self.client_socket)
        self.running = True
        self.display_resolution = DEFAULT_DISPLAY_RESOLUTION
        self.screen = self.get_display()

    def connect_to_server(self):
        """
        The function connects to the server.
        """
        self.client_socket.connect((SERVER_IP, SERVER_PORT))
        print('[CLIENT] connected to streamer.')

    def get_image(self):
        """
        the function gets a new screenshot from the streamer.
        :return: a new screenshot.
        """
        try:

            message = self.communicator.get_dec_message(self.client_socket)
            output = StringIO.StringIO(message)
            image = pygame.image.load(output)
            return image

        except pygame.error:
            return None
        except socket.error:
            self.close_connection()

    def change_image_on_screen(self, image):
        """
        :param image: PIL image of the streamer's screen.
        the function updated the display image to the new image.
        """
        try:
            self.screen.blit(image, (0, 0))
            pygame.display.flip()
        except pygame.error:
            pass

    def get_display(self):
        """
        :return: a pygame screen(where the screen will be shown)
        """
        pygame.init()
        screen = pygame.display.set_mode(self.display_resolution,
                                         pygame.RESIZABLE)
        pygame.display.set_caption(SCREEN_NAME, SCREEN_NAME)
        return screen

    def run_client(self):
        while self.running:
            try:
                image = self.get_image()
                if image is not None:
                    self.change_image_on_screen(image)
                self.events_handler.display_events(self.screen)
            except pygame.error:
                self.running = False
                self.client_socket.close()

    def close_connection(self):
        """
        The function stops the client functions and disconnects
        from the stream.
        """
        self.running = False
        self.client_socket.close()
Esempio n. 13
0
 def handle_events(self, events):
     EventsHandler.handle_events(self, events)
     for card in self:
         card.handle_events(events)