Exemple #1
0
 def coloring_background(self, cr):
     cr.rectangle(0, 0, self.w, self.h)
     R, G, B = rgb(config.getv('bg_area'))
     cr.set_source_rgba(R, G, B, 1.0)
     cr.clip()
     cr.paint()
     #--------------
     cr.move_to(self.w, 0)
     cr.line_to(self.w, self.h)
     cr.set_line_width(1)
     cr.set_source_rgba(0.0, 0.0, 0.0, 0.6)
     cr.stroke()
     #--------------
     cr.move_to(0, 0)
     cr.line_to(0, self.h)
     cr.set_line_width(1)
     cr.set_source_rgba(0.0, 0.0, 0.0, 0.6)
     cr.stroke()
     #--------------
     cr.rectangle(self.st - 2, self.br - 2, self.h1 + 4, self.h1 + 4)
     R, G, B = rgb(config.getv('br_grid'))
     cr.set_source_rgba(R, G, B, 1.0)
     cr.clip()
     cr.paint()
     #--------------
     cr.rectangle(self.st, self.br, self.h1, self.h1)
     R, G, B = rgb(config.getv('bg_grid'))
     cr.set_source_rgba(R, G, B, 1.0)
     cr.clip()
     cr.paint()
     for a in DICT_SPECIAL_CELLS.keys():
         self.coloring_special_cell(cr, a, DICT_SPECIAL_CELLS[a])
Exemple #2
0
 def change_theme(self, *a):
     data = '''
     * {
     background-color: ''' + config.getv('bg_grid') + ''';
     }
     * text selection, *:selected  {
     background-color: ''' + config.getv('bg_lines') + ''';
     }
     '''
     css_provider = Gtk.CssProvider()
     css_provider.load_from_data(data.encode('utf8'))
     context = self.get_style_context()
     context.add_provider(css_provider,
                          Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
Exemple #3
0
 def change_theme(self, *a):
     self.text_tag.set_property('foreground', config.getv('fg_nbr')) 
     data = '''
     * {
     background-color: '''+config.getv('bg_pieces')+''';
     color: '''+config.getv('fg_pieces')+''';
     }
     #View text selection, #View:selected  {
     color: '''+config.getv('bg_pieces')+''';
     background-color: '''+config.getv('fg_pieces')+''';
     }
     '''
     css_provider = Gtk.CssProvider()
     css_provider.load_from_data(data.encode('utf8'))
     context = self.get_style_context()
     context.add_provider(css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)        
Exemple #4
0
 def select_word_textview(self,  widget, event):
     if event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
         if self.view_bfr.get_has_selection():
             sel = self.view_bfr.get_selection_bounds()
             sel_text = self.view_bfr.get_text(sel[0], sel[1],True)
             if config.getv('language_scrabble') == 'العربية': sel_text = stripTashkeel(sel_text)
             self.explanation_word(sel_text)
Exemple #5
0
def show_dict(pt, ls_id):
    dlg = Gtk.Dialog(parent=pt, title=_('Dictionary'))
    #dlg.set_icon_name("asmaa")
    dlg.set_default_size(450, 300)
    area = dlg.get_content_area()
    area.set_spacing(6)
    view_info = Viewer(pt)
    view_info.set_cursor_visible(False)
    view_info.set_editable(False)
    view_info.set_right_margin(10)
    view_info.set_left_margin(10)
    view_info.set_wrap_mode(Gtk.WrapMode.WORD)
    view_info_bfr = view_info.get_buffer()
    scroll = Gtk.ScrolledWindow()
    scroll.set_shadow_type(Gtk.ShadowType.IN)
    scroll.add(view_info)
    text = '\n'
    if config.getv('language_scrabble') == 'العربية':
        for id0 in ls_id:
            pt.dict_chequer.cur.execute('SELECT * FROM dict WHERE id=?',(id0, ))
            rec0 = pt.dict_chequer.cur.fetchall()
            text += rec0[0][1]+': \n'+rec0[0][2]+'\n'
    else:
        pt.dict_chequer.cur.execute('SELECT * FROM dict WHERE term=?',(ls_id[0].lower(), ))
        rec0 = pt.dict_chequer.cur.fetchall()
        if len(rec0) > 0:  text += rec0[0][1]+': \n'+rec0[0][2]+'\n'
    view_info_bfr.set_text(text)
    view_info.with_tag(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '='])

    area.pack_start(scroll, True, True, 0)
    dlg.show_all()
Exemple #6
0
 def load_language_game(self, *a):
     lang = config.getv('language_scrabble')
     self.lang_code = DICT_LANGUAGES_CODE[lang]
     self.list_letters_repeated = get_list_letters_repeated(self.lang_code)
     self.count_pieces = len(self.list_letters_repeated)
     self.sideinfo.label_count_pieces.set_label(
         str(self.count_pieces).zfill(3))
     self.dict_chequer.get_data(self.lang_code)
Exemple #7
0
 def coloring_special_cell(self, cr, cell, special):
     ls = [(_('Start'), config.getv('bg_start')),
           (_('DLS'), config.getv('bg_hX2')),
           (_('TLS'), config.getv('bg_hX3')),
           (_('DWS'), config.getv('bg_kX2')),
           (_('TWS'), config.getv('bg_kX3'))]
     x = int(cell % 15)
     y = int(cell / 15)
     x0 = self.st + (x * self.bwn)
     y0 = self.br + (y * self.bwn)
     text = ls[special][0]
     #--bg--#
     cr.rectangle(x0, y0, self.bwn, self.bwn)
     R, G, B = rgb(ls[special][1])
     cr.set_source_rgba(R, G, B, 1.0)
     cr.fill()
     #--text--#
     szfont, fmfont = split_font(config.getv('font_special'))
     font = '{} {}'.format(fmfont, int((self.bwn / 64) * int(szfont)))
     layout = PangoCairo.create_layout(cr)
     layout.set_text(text, -1)
     desc = Pango.font_description_from_string(font)
     layout.set_font_description(desc)
     layout.set_alignment(1)
     cr.save()
     w, h = layout.get_pixel_size()
     PangoCairo.update_layout(cr, layout)
     R, G, B = rgb(config.getv('fg_cell'))
     cr.set_source_rgb(R, G, B)
     cr.move_to(x0 + (self.bwn - w) / 2, y0 + (self.bwn - h) / 2)
     PangoCairo.show_layout(cr, layout)
     cr.restore()
Exemple #8
0
 def ch_font(self, *a):
     szfont, fmfont = split_font(config.getv('font_win'))
     data = '''* {font-family: "''' + fmfont + '''";
     font-size: ''' + szfont + '''px;}'''
     screen = self.get_screen()
     css_provider = Gtk.CssProvider()
     context = self.get_style_context()
     css_provider.load_from_data(data.encode('utf8'))
     context.add_provider_for_screen(
         screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
Exemple #9
0
 def load(self, *a):
     lang = config.getv('language_scrabble')
     if lang in self.list_language_ready:
         self.load_language_game()
         if config.getn('saved') == 1:
             try:
                 self.start_old_game()
                 return
             except:
                 pass
     self.stack.set_visible_child_name('n0')
     self.hd_bar.show_hide_action_buttons()
Exemple #10
0
 def draw_lines(self, cr):
     #-- V lines --#
     for e in range(16):
         y1 = self.br
         y2 = self.h1 + self.br
         x = self.st + (e * self.bwn)
         cr.move_to(x, y1)
         cr.line_to(x, y2)
         cr.set_line_width(config.getf('br_thick'))
         R, G, B = rgb(config.getv('bg_lines'))
         cr.set_source_rgba(R, G, B, 1.0)
         cr.stroke()
     #-- H lines --#
     for e in range(16):
         x1 = self.st
         x2 = self.h1 + self.st
         y = self.br + (e * self.bwn)
         cr.move_to(x1, y)
         cr.line_to(x2, y)
         cr.set_line_width(config.getf('br_thick'))
         R, G, B = rgb(config.getv('bg_lines'))
         cr.set_source_rgba(R, G, B, 1.0)
         cr.stroke()
Exemple #11
0
 def __init__(self, pt):
     self.pt = pt
     Gtk.TextView.__init__(self)
     self.set_name('View')
     self.set_cursor_visible(False)
     self.set_editable(False)
     self.set_right_margin(10)
     self.set_left_margin(10)
     self.set_wrap_mode(Gtk.WrapMode.WORD)
     self.view_bfr = self.get_buffer()
     self.connect("event", self.select_word_textview)
     self.text_tag = self.view_bfr.create_tag("text_tag")
     self.text_tag.set_property('foreground', config.getv('fg_nbr')) 
     self.change_theme()
     
Exemple #12
0
 def draw_text(self, cr):
     text = ''
     if self.pt.has_msg: text = self.pt.text_msg
     elif self.pt.ended: text = self.pt.text_msg
     if text == '': return
     layout = PangoCairo.create_layout(cr)
     layout.set_text(text, -1)
     desc = Pango.font_description_from_string(config.getv('font_msg'))
     layout.set_font_description(desc)
     cr.save()
     w, h = layout.get_pixel_size()
     #--bg--#
     cr.rectangle((self.w - w) / 2 - 100, (self.h - h) / 2 - 50, w + 200,
                  h + 100)
     R, G, B = rgb(config.getv('bg_start'))
     cr.set_source_rgba(R, G, B, 1.0)
     cr.fill()
     #--text--#
     PangoCairo.update_layout(cr, layout)
     R, G, B = rgb(config.getv('fg_msg'))
     cr.set_source_rgb(R, G, B)
     cr.move_to((self.w - w) / 2, (self.h - h) / 2)
     PangoCairo.show_layout(cr, layout)
     cr.restore()
Exemple #13
0
 def sel_language_scrabble(self, btn):
     name = btn.get_active_text()
     if name == config.getv('language_scrabble'): return
     self.pt.hd_bar.btn_pref.set_active(False)
     if list(self.pt.dict_chequer.values()) == [0,]*225 or self.pt.ended == True: pass
     else:
         res = sure(self.pt, _('If you want to change the language you will need to start a new game. \n Do you want that?'))
         if res == -8: pass
         else:
             btn.set_active(config.getn('language_scrabble')) 
             return
     config.setv('language_scrabble', name)
     self.pt.sideinfo.label_language_scrabble.set_label(name)
     self.pt.pagestarting.label_language_scrabble.set_label(_('Playing language:')+' '+name)
     self.pt.pagestarting.restor_to_starting_page()
     self.pt.restart_game()
Exemple #14
0
 def chose_tile(self, *a):
     lang = config.getv('language_scrabble')
     lang_code = DICT_LANGUAGES_CODE[lang]
     if lang in self.pt.list_language_no_ready_without_stems:
         info(self.pt, _('This language not found'))
         return
     if lang in self.pt.list_language_no_ready_with_stems:
         res = sure(
             self.pt,
             _('Files for this language are not ready.\n Do you want that?')
         )
         if res == -8:
             self.create_db_language_progress_window(lang_code)
         return
     self.pt.load_language_game()
     list_letters = list(DICT_LETTERS[lang_code].keys())
     #==================
     letter1 = random.choice(list_letters)
     list_letters.remove(letter1)
     png_file = get_letter_png(self.pt.lang_code, letter1)
     self.image1.set_from_file(png_file)
     #==================
     letter2 = random.choice(list_letters)
     png_file = get_letter_png(self.pt.lang_code, letter2)
     self.image2.set_from_file(png_file)
     #==================
     self.btn_chose1.set_sensitive(False)
     ls = [letter1, letter2]
     ls.sort()
     if ls[0] == letter1:
         self.lab_bar.set_label(_('<b>Player will start playing.</b>'))
         self.pt.started_player = 'player'
     else:
         self.lab_bar.set_label(_('<b>Computer will start playing.</b>'))
         self.pt.started_player = 'computer'
     self.info_bar.set_message_type(1)
     self.lab_bar.set_alignment(0.5, 0.5)
     self.btn_start.set_sensitive(True)
     self.show_all()
Exemple #15
0
    def build(self, *a):
        Gtk.Dialog.__init__(self, parent=self.pt)
        area = self.get_content_area()
        self.set_icon_name("gscrabble")
        self.set_title(_('Preference'))
        self.set_default_size(500, 450)
        hbox = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL)
        #---------------------------
        self.stack_pref = Gtk.Stack()
        self.stack_pref.set_border_width(7)
        self.stack_pref.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
        self.stack_pref.set_transition_duration(300)
        stack_switcher = Gtk.StackSwitcher(spacing=1,orientation=Gtk.Orientation.VERTICAL)
        stack_switcher.set_homogeneous(True)
        stack_switcher.set_stack(self.stack_pref)
        hbox.pack_start(stack_switcher, False, False, 0)
        hbox.pack_start(self.stack_pref, True, True, 0)
        area.pack_start(hbox, True, True, 0)
        #---------------------------
        view_info = Viewer(self.pt)
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(view_info)
        view_info.view_bfr.set_text(TEXT_HOW_PLAY)
        list_tag = [
            '=',
            _('''How to Play Scrabble'''),
            _('''This is the law of the game in fact'''),
            _('''1- Make sure that you have everything you need to play Scrabble:'''),
            _('''2- Choose a dictionary to use for challenges:'''),
            _('''3- Put the tiles in the bag and shake them:'''),
            _('''4- Determine who goes first:'''),
            _('''5- Draw your tiles:'''),
            _('''6- Play the first word:'''),
            _('''7- Count up your points:'''),
            _('''8- Draw new tiles:'''),
            _('''9- Build on other players’ words:'''),
            _('''10-  Use your tiles to get the highest score possible per turn:'''),
            _('''11-  Challenge other players to dispute a word:'''),
            _('''12- Exchange tiles you don’t want:'''),
            _('''13- Watch for Premium Score squares:'''),
            _('''14- Get 50 points added to your word score if you get a bingo, also known as a bonus:'''),
            _('''15- Add up each player’s scores at the end of the game:'''),
            _('''16- Announce the winner:''')
            ]
        view_info.with_tag(list_tag)
        
        self.stack_pref.add_titled(scroll, 'n0', _('Game Code'))
        
        #---------------------------
        view_hotkeys = Viewer(self.pt)
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(view_hotkeys)
        view_hotkeys.view_bfr.set_text(TEXT_HOT_KEYS)
        view_hotkeys.with_tag(['"A"', '"Q+Ctrl"', '"O"', '"P"', '"U"', '"C"', '"S"', '"W"', '"G"', '"F11"', _('The right button:'), _('The left button:'), _('Mouse:')])
        
        self.stack_pref.add_titled(scroll, 'n00', _('Hot Keys'))
        
        #---------------------------
        vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)        
        hb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL)
        hb.pack_start(Gtk.Label.new(_('Interface language:')), False, False, 0)
        self.combo_language_surface = Gtk.ComboBoxText()
        # self.combo_language_surface.set_wrap_width(2)
        self.combo_language_surface.set_size_request(150, -1)
        for lang in LANGUAGES_SURFACE:
            self.combo_language_surface.append_text(lang)
        self.combo_language_surface.set_active(LANGUAGES_SURFACE.index(config.getv('language_surface')))
        self.combo_language_surface.connect('changed', self.sel_language_surface)
        hb.pack_end(self.combo_language_surface, False, False, 0)
        vb.pack_start(hb, False, False, 0)
        
        hb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL)
        hb.pack_start(Gtk.Label.new(_('Playing language:')), False, False, 0)
        self.combo_language_scrabble = Gtk.ComboBoxText()
        self.combo_language_scrabble.set_wrap_width(2)
        self.combo_language_scrabble.set_size_request(150, -1)
        self.load_languages_play()
        try: i = self.pt.list_language_likely.index(config.getv('language_scrabble'))
        except: i = -1
        self.combo_language_scrabble.set_active(i)
        self.combo_language_scrabble.connect('changed', self.sel_language_scrabble)
        hb.pack_end(self.combo_language_scrabble, False, False, 0)
        vb.pack_start(hb, False, False, 0)
        vb.pack_start(Gtk.Separator(), False, False, 0)
        
        hb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL)
        self.check_add_lang = Gtk.RadioButton.new_with_label_from_widget(None, _('Add language'))
        hb.pack_start(self.check_add_lang, True, True, 0)
        
        self.check_add_dict = Gtk.RadioButton.new_with_label_from_widget(self.check_add_lang, _('Add dictionary'))
        hb.pack_start(self.check_add_dict, True, True, 0)
        vb.pack_start(hb, False, False, 0)
        
        self.view_lang_dict = Viewer(self.pt)
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.IN)
        scroll.add(self.view_lang_dict)
        vb.pack_start(scroll, True, True, 0)
        
        hb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.HORIZONTAL)
        self.combo_dict_lang = Gtk.ComboBoxText()
        self.add_lg_dt = Add_lang_dict(self.pt, self.combo_dict_lang)
        btn_add_dict = Gtk.Button(_('Add'))
        btn_add_dict.connect('clicked', self.add_dict_lang_cb)
        hb.pack_start(btn_add_dict, False, False, 0)
        self.combo_dict_lang.set_size_request(150, -1)
        hb.pack_end(self.combo_dict_lang, False, False, 0)
        vb.pack_start(hb, False, False, 0)
        self.check_add_lang.connect("toggled", self.sel_added, 1)
        self.check_add_dict.connect("toggled", self.sel_added, 2)
        self.check_add_lang.set_active(True)
        self.sel_added()
        
        self.stack_pref.add_titled(vb, 'n1', _('Language'))
        #----------------------------------------------------------------------------------
        vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)    
        vb.pack_start(Gtk.Label.new(_('Difficulty level:')), False, False, 0)

        btn0 = Gtk.RadioButton.new_with_label_from_widget(None, self.pt.LIST_GRADE[0])
        btn0.connect("toggled", self.sel_grade, 0)
        vb.pack_start(btn0, False, False, 0)
        if config.getn('grade') == 0: btn0.set_active(True)
        
        btn1 = Gtk.RadioButton.new_with_label_from_widget(btn0, self.pt.LIST_GRADE[1])
        btn1.connect("toggled", self.sel_grade, 1)
        vb.pack_start(btn1, False, False, 0)
        if config.getn('grade') == 1: btn1.set_active(True)
        
        btn2 = Gtk.RadioButton.new_with_label_from_widget(btn1, self.pt.LIST_GRADE[2])
        btn2.connect("toggled", self.sel_grade, 2)
        vb.pack_start(btn2, False, False, 0)
        if config.getn('grade') == 2: btn2.set_active(True)
        
        btn3 = Gtk.RadioButton.new_with_label_from_widget(btn2, self.pt.LIST_GRADE[3])
        btn3.connect("toggled", self.sel_grade, 3)
        vb.pack_start(btn3, False, False, 0)
        if config.getn('grade') == 3: btn3.set_active(True)
        
        btn4 = Gtk.RadioButton.new_with_label_from_widget(btn3, self.pt.LIST_GRADE[4])
        btn4.connect("toggled", self.sel_grade, 4)
        vb.pack_start(btn4, False, False, 0)
        if config.getn('grade') == 4: btn4.set_active(True)
        
        self.stack_pref.add_titled(vb, 'n2', _('Difficulty'))
        
        #----------------------------
        vb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL)
        vb0 = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL)
        vb0.set_border_width(20)
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.NONE)
        scroll.add(vb0)
        ls_btn_font = [('font_pieces', _('Font of letters')), ('font_special', _('Font of cells')), ('font_msg', _('Font of notification')),('font_win', _('Font of window'))]
        for a in ls_btn_font:
            hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL)
            btn = Gtk.FontButton.new_with_font(config.getv(a[0]))
            btn.set_name(a[0])
            btn.connect('font-set',self.ch_font)
            hb.pack_start(Gtk.Label.new(a[1]), False, False, 0)
            hb.pack_end(btn, False, False, 0)
            vb0.pack_start(hb, False, False, 0)
        hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL)
        adj = Gtk.Adjustment.new(1, 1, 10, 1, 5, 0)
        btn= Gtk.SpinButton()
        btn.set_adjustment(adj)
        btn.set_wrap(True)
        btn.set_value(config.getf('br_thick'))
        btn.connect('value-changed',self.ch_thick)
        hb.pack_start(Gtk.Label.new(_('Lines of grid')), False, False, 0)
        hb.pack_end(btn, False, False, 0)
        vb0.pack_start(hb, False, False, 0)
        
        vb.pack_start(scroll, True, True, 0)
        vb.pack_start(Gtk.Separator(), False, False, 3)
        btn_default = Gtk.ToolButton()
        btn_default.set_label(_('Prepare defaults'))
        vb.pack_start(btn_default, False, False, 0)
        btn_default.connect('clicked', self.set_default, 1)
        self.stack_pref.add_titled(vb, 'n3', _('Fonts'))
        
        #---------------------------
        vb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL)
        vb0 = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL)
        vb0.set_border_width(20)
        scroll = Gtk.ScrolledWindow()
        scroll.set_shadow_type(Gtk.ShadowType.NONE)
        scroll.add(vb0)
        hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL)
        ls_btn_color = [('fg_pieces',_('Color of letter')), ('fg_nbr',_('Color of number')), ('fg_cell',_('Word of cell')), ('bg_pieces',_('Background of letter')), 
                        ('bg_no_install', _('New piece')), ('bg_last_word', _('Last word')), ('br_pieces',_('Border of letter')), 
                        ('bg_area',_('Background')), ('bg_grid',_('Background of grid')), 
                        ('br_grid',_('Border of grid')),('bg_lines',_('Lines of grid')), ('fg_msg',_('Color of notification')),
                        ('bg_start',_('Start')),('bg_hX2',_('Background of DLS')),('bg_hX3',_('Background of TLS')),
                        ('bg_kX2',_('Background of DWS')),('bg_kX3',_('Background of TWS'))]
        for a in ls_btn_color:
            hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL)
            btn = Gtk.ColorButton.new_with_rgba(rgba(config.getv(a[0])))
            btn.set_name(a[0])
            btn.connect('color-set',self.ch_color)
            hb.pack_start(Gtk.Label.new(a[1]), False, False, 0)
            hb.pack_end(btn, False, False, 0)
            vb0.pack_start(hb, False, False, 0)
        vb.pack_start(scroll, True, True, 0)
        
        vb.pack_start(Gtk.Separator(), False, False, 3)
        btn_default = Gtk.ToolButton()
        btn_default.set_label(_('Prepare defaults'))
        vb.pack_start(btn_default, False, False, 0)
        btn_default.connect('clicked', self.set_default, 2)
        self.stack_pref.add_titled(vb, 'n4', _('Colors'))
        
        #---------------------------
        vb = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL)
        vb0 = Gtk.Box(spacing=3,orientation=Gtk.Orientation.VERTICAL)
        vb0.set_border_width(20)
        scroll = Gtk.ScrolledWindow()
        scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        scroll.set_shadow_type(Gtk.ShadowType.NONE)
        scroll.add(vb0)
        
        hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL)
        self.switch_sound = Gtk.Switch()
        self.switch_sound.connect("notify::active", self.on_switch_activated)
        if config.getn('sound') == 1: self.switch_sound.set_active(True)
        else: self.switch_sound.set_active(False)
        hb.pack_start(Gtk.Label.new(_('Enable audio')), False, False, 0)
        hb.pack_start(self.switch_sound, False, False, 0)
        vb.pack_start(hb, False, False, 0)
        vb.pack_start(Gtk.Separator(), False, False, 3)
        
        ls_btn_sound = [('pipe_drop', _('Install a letter')), ('pipe_ok', _('Adoption of the word')), ('pipe_undo', _('Undo a letter')),
                        ('pipe_add', _('Add a letters'))]
        for a in ls_btn_sound:
            hb = Gtk.Box(spacing=10,orientation=Gtk.Orientation.HORIZONTAL)
            adj1 = Gtk.Adjustment.new(20, 1, 1000, 1, 5, 0)
            btn= Gtk.SpinButton()
            btn.set_adjustment(adj1)
            btn.set_wrap(True)
            btn.set_value(config.getf(a[0]+"_ms"))
            btn.set_name(a[0]+"_ms")
            btn.connect('value-changed',self.ch_sound)
            hb.pack_end(btn, False, False, 0)
            #-----------------------------------------
            adj = Gtk.Adjustment.new(1, 0, 10000, 1, 5, 0)
            btn= Gtk.SpinButton()
            btn.set_adjustment(adj)
            btn.set_wrap(True)
            btn.set_value(config.getf(a[0]))
            btn.set_name(a[0])
            btn.connect('value-changed',self.ch_sound)
            hb.pack_end(btn, False, False, 0)
            hb.pack_start(Gtk.Label.new(a[1]), False, False, 0)
            vb0.pack_start(hb, False, False, 0)
        vb.pack_start(scroll, True, True, 0)
        
        vb.pack_start(Gtk.Separator(), False, False, 3)
        btn_default = Gtk.ToolButton()
        btn_default.set_label(_('Prepare defaults'))
        vb.pack_start(btn_default, False, False, 0)
        btn_default.connect('clicked', self.set_default, 3)
        self.stack_pref.add_titled(vb, 'n5', _('Sounds'))
        
        #---------------------------
        vb = Gtk.Box(spacing=7,orientation=Gtk.Orientation.VERTICAL)
        check_autohid_info = Gtk.CheckButton(_('Autohide the information box'))
        if config.getn('autohide_info') == 1: check_autohid_info.set_active(True)
        vb.pack_start(check_autohid_info, False, False, 0)
        check_autohid_info.connect('clicked', self.set_autohide_info)
        
        check_autohid_letters = Gtk.CheckButton(_('Autohide the letters box'))
        if config.getn('autohide_letters') == 1: check_autohid_letters.set_active(True)
        vb.pack_start(check_autohid_letters, False, False, 0)
        check_autohid_letters.connect('clicked', self.set_autohide_letters)

        self.stack_pref.add_titled(vb, 'n6', _('Others'))
        
        
        self.show_all()
        
        
Exemple #16
0
    def build(self, *a):
        Gtk.Box.__init__(self,
                         spacing=20,
                         orientation=Gtk.Orientation.VERTICAL)
        self.info_bar = Gtk.InfoBar(show_close_button=False)
        self.lab_bar = Gtk.Label(_('Former letter will start playing.'))
        self.lab_bar.set_use_markup(True)
        self.info_bar.get_content_area().pack_start(self.lab_bar, True, False,
                                                    0)
        self.pack_start(self.info_bar, False, False, 0)
        #----------------------------------------------------------------------------------
        hb0 = Gtk.Box(spacing=3, orientation=Gtk.Orientation.HORIZONTAL)
        vb = Gtk.Box(spacing=3, orientation=Gtk.Orientation.VERTICAL)
        frame = Gtk.Frame.new()
        vb.set_border_width(25)
        frame.add(vb)
        hb0.pack_start(frame, True, False, 20)
        #----------------------------------------------------------------------------------
        hb = Gtk.Box(spacing=3, orientation=Gtk.Orientation.HORIZONTAL)
        self.label_language_scrabble = Gtk.Label()
        self.label_language_scrabble.set_label(
            _('Playing language:') + ' ' + config.getv('language_scrabble'))
        hb.set_center_widget(self.label_language_scrabble)
        #-------------------------------------------------------------------------------------------
        img = Gtk.Image.new_from_icon_name('view-grid-symbolic', 2)
        btn_show = Gtk.Button()
        btn_show.set_tooltip_text(_('Show all letters'))
        btn_show.connect('clicked', self.show_all_letters)
        btn_show.set_image(img)
        hb.pack_end(btn_show, False, False, 0)
        vb.pack_start(hb, False, False, 0)
        #----------------------------------------------------------------------------------
        vb.pack_start(Gtk.Separator(), False, False, 10)
        #----------------------------------------------------------------------------------
        hb = Gtk.Box(spacing=10, orientation=Gtk.Orientation.HORIZONTAL)
        vb1 = Gtk.Box(spacing=3, orientation=Gtk.Orientation.VERTICAL)
        frame_player = Gtk.Frame.new(_('Choose the player'))
        frame_player.set_label_align(0.5, 0.5)
        frame_player.set_size_request(180, 220)
        frame_player.add(vb1)
        self.image1 = Gtk.Image()
        vb1.pack_start(self.image1, True, False, 0)
        self.btn_chose1 = Gtk.Button(_('Choose'))
        self.btn_chose1.connect('clicked', self.chose_tile)
        vb1.pack_end(self.btn_chose1, False, False, 0)
        hb.pack_start(frame_player, True, False, 20)
        #----------------------------------------------------------------------------------
        vb2 = Gtk.Box(spacing=3, orientation=Gtk.Orientation.VERTICAL)
        frame_computer = Gtk.Frame.new(_('Choose the computer'))
        frame_computer.set_label_align(0.5, 0.5)
        frame_computer.set_size_request(180, 220)
        frame_computer.add(vb2)
        self.image2 = Gtk.Image()
        vb2.pack_start(self.image2, True, False, 0)
        btn_chose2 = Gtk.Button(_('Choose'))
        btn_chose2.set_sensitive(False)
        vb2.pack_end(btn_chose2, False, False, 0)
        hb.pack_start(frame_computer, True, False, 20)
        vb.pack_start(hb, True, False, 0)
        #----------------------------------------------------------------------------------
        vb.pack_start(Gtk.Separator(), False, False, 10)
        #----------------------------------------------------------------------------------
        hb = Gtk.Box(spacing=3, orientation=Gtk.Orientation.HORIZONTAL)
        self.btn_start = Gtk.Button(_('Start game'))
        self.btn_start.set_sensitive(False)
        self.btn_start.connect('clicked', self.start_new_game)
        hb.pack_start(self.btn_start, True, False, 0)
        vb.pack_start(hb, False, False, 0)
        #----------------------------------------------------------------------------------

        self.pack_start(hb0, False, False, 20)

        link1 = Gtk.LinkButton.new_with_label(_('golden scrabble'))
        link1.set_uri('https://sourceforge.net/projects/gscrabble/files/app/')
        self.pack_start(link1, False, False, 0)

        link1 = Gtk.LinkButton.new_with_label(_('Languages to play'))
        link1.set_uri(
            'https://sourceforge.net/projects/gscrabble/files/languages/')
        self.pack_start(link1, False, False, 0)

        link1 = Gtk.LinkButton.new_with_label(_('code source'))
        link1.set_uri('https://github.com/RaaH/gscrabble')
        self.pack_start(link1, False, False, 0)

        self.show_all()
Exemple #17
0
gi.require_version('Gst', '1.0')

from gi.repository import Gtk, Gdk, GObject, Pango, GLib
from gi.repository.GdkPixbuf import Pixbuf
import gettext
import config as config
from about import About
from data import *
import time

# Localization.
DOMAIN = 'gscrabble'
gettext.install(DOMAIN, LOCALDIR)

try:
    lang_name = config.getv('language_surface')
    if lang_name != '< System >':
        if lang_name == 'العربية':
            Gtk.Widget.set_default_direction(Gtk.TextDirection.RTL)
        else:
            Gtk.Widget.set_default_direction(Gtk.TextDirection.LTR)
        lang_code = DICT_LANGUAGES_CODE[lang_name]
        lang = gettext.translation(DOMAIN, LOCALDIR, languages=[lang_code])
        lang.install()
except:
    pass

from side_letters import SideLetters
from side_infos import SideInfo
from chequer_dnd import Chequer
from scrabble_core import Dict_General
Exemple #18
0
 def coloring_no_drop(self, cr):
     cr.rectangle(0, 0, self.w, self.h)
     R, G, B = rgb(config.getv('bg_area'))
     cr.set_source_rgba(R, G, B, 0.4)
     cr.clip()
     cr.paint()
Exemple #19
0
def get_letter_png(lang_code, letter):
    name = config.getv('language_scrabble')
    lang_code = DICT_LANGUAGES_CODE[name]
    im = cairo.ImageSurface(cairo.FORMAT_ARGB32, 80, 80)
    cr = cairo.Context(im)
    #--bg--#
    cr.rectangle(0, 0, 80, 80)
    R, G, B = rgb(config.getv('bg_pieces'))
    cr.set_source_rgba(R, G, B, 1.0)
    cr.fill()
    #--border--#
    cr.rectangle(0, 0, 80, 80)
    R, G, B = rgb(config.getv('br_pieces'))
    cr.set_source_rgba(R, G, B, 1.0)
    cr.set_line_width(1.0)
    cr.stroke()
    if letter in COMPLEX_LETTERS[lang_code].keys():
        letter1 = COMPLEX_LETTERS[lang_code][letter]
    else:
        letter1 = letter
    if lang_code == 'ar':
        #--letter--#
        letter1 = letter.replace('ه', 'هـ')
        szfont, fmfont = split_font(config.getv('font_pieces'))
        font = '{} {}'.format(fmfont, int(4 * int(szfont)))
        layout = PangoCairo.create_layout(cr)
        layout.set_text(letter1, -1)
        desc = Pango.font_description_from_string(font)
        layout.set_font_description(desc)
        layout.set_alignment(1)
        cr.save()
        w1, h1 = layout.get_pixel_size()
        PangoCairo.update_layout(cr, layout)
        R, G, B = rgb(config.getv('fg_pieces'))
        cr.set_source_rgba(R, G, B, 1.0)
        cr.move_to((80 - w1) / 2, (h1 - 80) / 2 - (h1 / 8))
        PangoCairo.show_layout(cr, layout)
        cr.restore()
        #--number--#
        cr.set_font_size(int(40 * (int(szfont) / 20)))
        R, G, B = rgb(config.getv('fg_nbr'))
        cr.set_source_rgba(R, G, B, 1.0)
        cr.move_to(4, 76)
    else:
        #--letter--#
        szfont, fmfont = split_font(config.getv('font_pieces'))
        font = '{} {}'.format(fmfont, int(70 * (int(szfont) / 15)))
        layout = PangoCairo.create_layout(cr)
        layout.set_text(letter1, -1)
        desc = Pango.font_description_from_string(font)
        layout.set_font_description(desc)
        layout.set_alignment(1)
        cr.save()
        w, h = layout.get_pixel_size()
        PangoCairo.update_layout(cr, layout)
        R, G, B = rgb(config.getv('fg_pieces'))
        cr.set_source_rgba(R, G, B, 1.0)
        cr.move_to(3 * (80 - w) / 8, (80 - h) / 2 - 4)
        PangoCairo.show_layout(cr, layout)
        cr.restore()
        #--number--#
        cr.set_font_size(int(40 * (int(szfont) / 20)))
        R, G, B = rgb(config.getv('fg_nbr'))
        cr.set_source_rgba(R, G, B, 1.0)
        xb, yb, w, h, xa, ya = cr.text_extents(
            str(get_letter_value(lang_code, letter))
        )  #xbearing, ybearing, width, height, xadvance, yadvance
        cr.move_to(76 - xa, 76)
    cr.show_text(str(get_letter_value(lang_code, letter)))
    # get_all_letters(cr)
    im.write_to_png(join(HOME_DIR, 'last.png'))
    return join(HOME_DIR, 'last.png')
Exemple #20
0
 def draw_letter(self, cr, letter, x, y, is_new):
     PF = self.bwn / 20
     ls = [
         config.getv('bg_start'),
         config.getv('bg_hX2'),
         config.getv('bg_hX3'),
         config.getv('bg_kX2'),
         config.getv('bg_kX3')
     ]
     x0 = self.st + (x * self.bwn)
     y0 = self.br + (y * self.bwn)
     cell = y * 15 + x
     #--bg--#
     cr.rectangle(x0, y0, self.bwn, self.bwn)
     if is_new: R, G, B = rgb(config.getv('bg_no_install'))
     elif cell in self.pt.dict_new_computer:
         R, G, B = rgb(config.getv('bg_last_word'))
     else:
         R, G, B = rgb(config.getv('bg_pieces'))
     cr.set_source_rgba(R, G, B, 1.0)
     cr.fill()
     #--border--#
     cr.rectangle(x0, y0, self.bwn, self.bwn)
     R, G, B = rgb(config.getv('br_pieces'))
     cr.set_source_rgba(R, G, B, 1.0)
     cr.set_line_width(1.0)
     cr.stroke()
     if letter in COMPLEX_LETTERS[self.pt.lang_code].keys():
         letter1 = COMPLEX_LETTERS[self.pt.lang_code][letter]
     else:
         letter1 = letter
     if self.pt.lang_code == 'ar':
         #--special-cell--#
         if cell in DICT_SPECIAL_CELLS.keys():
             special = DICT_SPECIAL_CELLS[y * 15 + x]
             R, G, B = rgb(ls[special])
             cr.set_source_rgba(R, G, B, 1.0)
             cr.rectangle(x0 + 1, y0 + 1, self.bwn / 3, self.bwn / 3)
             cr.fill()
         #--letter--#
         letter1 = letter.replace('ه', 'هـ')
         szfont, fmfont = split_font(config.getv('font_pieces'))
         font = '{} {}'.format(fmfont, int(PF * int(szfont)))
         layout = PangoCairo.create_layout(cr)
         layout.set_text(letter1, -1)
         desc = Pango.font_description_from_string(font)
         layout.set_font_description(desc)
         layout.set_alignment(1)
         cr.save()
         w1, h1 = layout.get_pixel_size()
         PangoCairo.update_layout(cr, layout)
         if cell in self.pt.cells_empty_letter:
             R, G, B = rgb(config.getv('fg_nbr'))
         else:
             R, G, B = rgb(config.getv('fg_pieces'))
         cr.set_source_rgba(R, G, B, 1.0)
         cr.move_to(x0 + (self.bwn - w1) / 2,
                    y0 - (h1 - self.bwn) / 2 - (h1 / 6))
         PangoCairo.show_layout(cr, layout)
         cr.restore()
         #--number--#
         cr.set_font_size(PF / 2 * int(szfont))
         R, G, B = rgb(config.getv('fg_nbr'))
         cr.set_source_rgba(R, G, B, 1.0)
         cr.move_to(x0 + (self.bwn / 20), (y0 + self.bwn) - (self.bwn / 20))
         if cell in self.pt.cells_empty_letter: cr.show_text('0')
         else:
             cr.show_text(str(get_letter_value(self.pt.lang_code, letter)))
     else:
         #--special-cell--#
         if cell in DICT_SPECIAL_CELLS.keys():
             special = DICT_SPECIAL_CELLS[y * 15 + x]
             R, G, B = rgb(ls[special])
             cr.set_source_rgba(R, G, B, 1.0)
             cr.rectangle(x0 + (2 * self.bwn / 3) - 1, y0 + 1, self.bwn / 3,
                          self.bwn / 3)
             cr.fill()
         #--letter--#
         szfont, fmfont = split_font(config.getv('font_pieces'))
         font = '{} {}'.format(fmfont, int(PF * int(szfont)))
         layout = PangoCairo.create_layout(cr)
         layout.set_text(letter1, -1)
         desc = Pango.font_description_from_string(font)
         layout.set_font_description(desc)
         layout.set_alignment(1)
         cr.save()
         w, h = layout.get_pixel_size()
         PangoCairo.update_layout(cr, layout)
         if cell in self.pt.cells_empty_letter:
             R, G, B = rgb(config.getv('fg_nbr'))
         else:
             R, G, B = rgb(config.getv('fg_pieces'))
         cr.set_source_rgba(R, G, B, 1.0)
         cr.move_to(x0 + (3 * (self.bwn - w) / 8),
                    y0 + (self.bwn - h) / 2 - (self.bwn / 20))
         PangoCairo.show_layout(cr, layout)
         cr.restore()
         #--number--#
         cr.set_font_size(int(PF / 2 * int(szfont)))
         R, G, B = rgb(config.getv('fg_nbr'))
         cr.set_source_rgba(R, G, B, 1.0)
         xb, yb, w, h, xa, ya = cr.text_extents(
             str(get_letter_value(self.pt.lang_code, letter))
         )  #xbearing, ybearing, width, height, xadvance, yadvance
         cr.move_to(x0 + self.bwn - xa - (self.bwn / 20),
                    (y0 + self.bwn) - (self.bwn / 20))
         if cell in self.pt.cells_empty_letter: cr.show_text('0')
         else:
             cr.show_text(str(get_letter_value(self.pt.lang_code, letter)))
     #-------------------------------------------
     if self.pt.select_cell == cell:
         cr.rectangle(x0, y0, self.bwn, self.bwn)
         R, G, B = rgb(config.getv('br_pieces'))
         cr.set_source_rgba(R, G, B, 1.0)
         cr.set_line_width(4.0)
         cr.stroke()
Exemple #21
0
 def sel_added(self, *a):
     self.combo_dict_lang.remove_all()
     if self.check_add_dict.get_active():
         self.combo_dict_lang.set_wrap_width(2)
         self.view_lang_dict.view_bfr.set_text(TEXT_ADD_DICT)
         for lang in self.pt.list_language_ready_without_dict:
             self.combo_dict_lang.append_text(lang)
     else:
         self.view_lang_dict.view_bfr.set_text(TEXT_ADD_LANG)
         self.combo_dict_lang.set_wrap_width(5)
         for lang in self.pt.list_language_no_ready_without_stems:
             self.combo_dict_lang.append_text(lang)
     self.view_lang_dict.with_tag(['"="', '↓', _('How do I add my dictionary?'), _('How do I add my language?')])
     try: self.combo_dict_lang.set_active(self.pt.list_language_ready_without_dict.index(config.getv('language_scrabble')))
     except: self.combo_dict_lang.set_active(0)