11# -*- coding: utf-8 -*-
22'''
3- Copyright (C) 2012-2018 Diego Torres Milano
3+ Copyright (C) 2012-2019 Diego Torres Milano
44 Created on oct 30, 2014
55
66 Licensed under the Apache License, Version 2.0 (the "License");
1818 @author: Diego Torres Milano
1919 @author: Ahmed Kasem
2020 '''
21+ import platform
2122
22- __version__ = '15.5.1 '
23+ __version__ = '15.6.0 '
2324
2425import Tkinter
2526import ttk
27+ import subprocess
2628
2729from com .dtmilano .android .culebron import Operation , Color
2830
2931
3032class Key :
31- GOOGLE_NOW = 'KEYCODE_ASSIST'
32- PERIOD = 'KEYCODE_PERIOD'
33- GO = 'KEYCODE_ENTER'
33+ GOOGLE_NOW = 'KEYCODE_ASSIST'
34+ PERIOD = 'KEYCODE_PERIOD'
35+ GO = 'KEYCODE_ENTER'
36+
3437
3538class Layout :
36- BUTTON_WIDTH = 13
37- BUTTONS_NUMBER = 9
39+ BUTTON_WIDTH = 13
40+ BUTTONS_NUMBER = 9
41+
3842
3943class ControlPanel (Tkinter .Toplevel ):
44+ osName = platform .system ()
45+ ''' The OS name. We sometimes need specific behavior. '''
46+ isDarwin = (osName == 'Darwin' )
47+ ''' Is it Mac OSX? '''
4048
4149 def __init__ (self , culebron , printOperation , ** kwargs ):
4250 self .culebron = culebron
@@ -53,57 +61,92 @@ def __init__(self, culebron, printOperation, **kwargs):
5361 self .childWindow .resizable (width = Tkinter .FALSE , height = Tkinter .FALSE )
5462 self .childWindow .printOperation = printOperation
5563 self .childWindow .grid ()
56- self .childWindow .column = self .childWindow .row = 0
64+ self .childWindow .column = 0
65+ self .childWindow .row = 0
66+ if self .isDarwin :
67+ out = subprocess .check_output (["defaults" , "read" , "-g" , "AppleInterfaceStyle" ])
68+ self .isDarkMode = ('Dark' in out )
69+ else :
70+ self .isDarkMode = False
71+ if self .isDarkMode :
72+ self .fg = Color .DARK_GRAY
73+ self .bg = Color .LIGHT_GRAY
74+ self .highlightbackground = Color .LIGHT_GRAY
75+ else :
76+ self .fg = Color .DARK_GRAY
77+ self .bg = Color .LIGHT_GRAY
78+ self .highlightbackground = Color .DARK_GRAY
5779 self .createKeycodeTab ()
5880 self .createKeyboardTab ()
81+ self .childWindow .update ()
82+ if self .isDarwin :
83+ if platform .mac_ver ()[0 ].startswith ("10.14" ):
84+ self .childWindow .after (0 , self .fix )
85+
86+ def fix (self ):
87+ """
88+ Fix a problem with Tkinter Buttons in Mojave.
89+ See https://stackoverflow.com/questions/52529403/button-text-of-tkinter-not-works-in-mojave
90+ """
91+ a = self .childWindow .winfo_geometry ().split ('+' )[0 ]
92+ b = a .split ('x' )
93+ w = int (b [0 ])
94+ h = int (b [1 ])
95+ self .childWindow .geometry ('%dx%d' % (w + 1 , h + 1 ))
5996
6097 def createKeycodeTab (self ):
6198 ''' KEYCODE '''
62- self .keycodeList = [
63- 'KEYCODE_HOME' , 'KEYCODE_DPAD_UP' , 'KEYCODE_BACK' , 'KEYCODE_SEARCH' , 'KEYCODE_CHANNEL_UP' , 'KEYCODE_TV' ,
64- 'KEYCODE_MUSIC' , 'KEYCODE_EXPLORER' , 'KEYCODE_CAMERA' , 'KEYCODE_POWER' , 'KEYCODE_DPAD_LEFT' ,'KEYCODE_DPAD_DOWN' ,
65- 'KEYCODE_DPAD_RIGHT' , 'KEYCODE_PAGE_UP' , 'KEYCODE_CHANNEL_DOWN' , 'KEYCODE_VOLUME_UP' , 'KEYCODE_MEDIA_PLAY' ,
66- 'KEYCODE_CONTACTS' , 'KEYCODE_ZOOM_IN' , 'SNAPSHOPT' , 'KEYCODE_MENU' , 'KEYCODE_DPAD_CENTER' , 'KEYCODE_ENTER' ,
67- 'KEYCODE_PAGE_DOWN' , 'KEYCODE_BRIGHTNESS_DOWN' , 'KEYCODE_VOLUME_DOWN' , 'KEYCODE_MEDIA_PAUSE' , 'KEYCODE_BOOKMARK' ,
68- 'KEYCODE_ZOOM_OUT' , 'REFRESH' , 'KEYCODE_APP_SWITCH' , 'KEYCODE_GOOGLE_NOW' , 'KEYCODE_CALL' , 'KEYCODE_ESCAPE' ,
69- 'KEYCODE_BRIGHTNESS_UP' , 'KEYCODE_VOLUME_MUTE' , 'KEYCODE_MEDIA_STOP' , 'KEYCODE_CALCULATOR' , 'KEYCODE_SETTINGS' , 'QUIT'
70- ]
71- for keycode in self .keycodeList :
72- self .keycode = ControlPanelButton (self .keycodeTab , self .culebron , self .printOperation , value = keycode , text = keycode [8 :],
73- width = Layout .BUTTON_WIDTH , bg = Color .DARK_GRAY , fg = Color .LIGHT_GRAY ,
74- highlightbackground = Color .DARK_GRAY )
99+ _keycodeList = [
100+ 'KEYCODE_HOME' , 'KEYCODE_DPAD_UP' , 'KEYCODE_BACK' , 'KEYCODE_SEARCH' , 'KEYCODE_CHANNEL_UP' , 'KEYCODE_TV' ,
101+ 'KEYCODE_MUSIC' , 'KEYCODE_EXPLORER' , 'KEYCODE_CAMERA' , 'KEYCODE_POWER' , 'KEYCODE_DPAD_LEFT' ,
102+ 'KEYCODE_DPAD_DOWN' ,
103+ 'KEYCODE_DPAD_RIGHT' , 'KEYCODE_PAGE_UP' , 'KEYCODE_CHANNEL_DOWN' , 'KEYCODE_VOLUME_UP' , 'KEYCODE_MEDIA_PLAY' ,
104+ 'KEYCODE_CONTACTS' , 'KEYCODE_ZOOM_IN' , 'SNAPSHOPT' , 'KEYCODE_MENU' , 'KEYCODE_DPAD_CENTER' , 'KEYCODE_ENTER' ,
105+ 'KEYCODE_PAGE_DOWN' , 'KEYCODE_BRIGHTNESS_DOWN' , 'KEYCODE_VOLUME_DOWN' , 'KEYCODE_MEDIA_PAUSE' ,
106+ 'KEYCODE_BOOKMARK' ,
107+ 'KEYCODE_ZOOM_OUT' , 'REFRESH' , 'KEYCODE_APP_SWITCH' , 'KEYCODE_GOOGLE_NOW' , 'KEYCODE_CALL' , 'KEYCODE_ESCAPE' ,
108+ 'KEYCODE_BRIGHTNESS_UP' , 'KEYCODE_VOLUME_MUTE' , 'KEYCODE_MEDIA_STOP' , 'KEYCODE_CALCULATOR' ,
109+ 'KEYCODE_SETTINGS' , 'QUIT'
110+ ]
111+ for keycode in _keycodeList :
112+ _cpb = ControlPanelButton (self .keycodeTab , self .culebron , self .printOperation , value = keycode ,
113+ text = keycode [8 :],
114+ width = Layout .BUTTON_WIDTH ,
115+ bg = self .bg , fg = self .fg ,
116+ highlightbackground = self .highlightbackground )
75117
76118 if keycode == 'REFRESH' :
77- self .keycode .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = self .keycode .refreshScreen )
78- self .keycode .grid (column = self .childWindow .column , row = self .childWindow .row )
119+ _cpb .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = _cpb .refreshScreen )
79120 elif keycode == 'SNAPSHOPT' :
80- self .keycode .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = self .keycode .takeSnapshot )
81- self .keycode .grid (column = self .childWindow .column , row = self .childWindow .row )
121+ _cpb .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = _cpb .takeSnapshot )
82122 elif keycode == 'QUIT' :
83- self .keycode .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = self .childWindow .destroy )
84- self .keycode .grid (column = self .childWindow .column , row = self .childWindow .row )
123+ _cpb .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = self .childWindow .destroy )
85124 else :
86- self . keycode . configure (command = self . keycode .command )
87- self . keycode .grid (column = self .childWindow .column , row = self .childWindow .row )
125+ _cpb . configure (command = _cpb .command )
126+ _cpb .grid (column = self .childWindow .column , row = self .childWindow .row )
88127 self .tabLayout ()
89128
90129 def createKeyboardTab (self ):
91130 ''' KEYBOARD '''
92- self .keyboardList = [
93- 'KEYCODE_1' , 'KEYCODE_2' , 'KEYCODE_3' , 'KEYCODE_4' , 'KEYCODE_5' , 'KEYCODE_6' , 'KEYCODE_7' , 'KEYCODE_8' , 'KEYCODE_9' , 'KEYCODE_0' ,
94- 'KEYCODE_Q' , 'KEYCODE_W' , 'KEYCODE_E' , 'KEYCODE_R' , 'KEYCODE_T' , 'KEYCODE_Y' , 'KEYCODE_U' , 'KEYCODE_I' , 'KEYCODE_O' , 'KEYCODE_P' ,
95- 'KEYCODE_A' , 'KEYCODE_S' , 'KEYCODE_D' , 'KEYCODE_F' , 'KEYCODE_G' , 'KEYCODE_H' , 'KEYCODE_J' , 'KEYCODE_K' , 'KEYCODE_L' ,
96- 'KEYCODE_DEL' , 'KEYCODE_Z' , 'KEYCODE_X' , 'KEYCODE_C' , 'KEYCODE_V' , 'KEYCODE_B' , 'KEYCODE_N' , 'KEYCODE_M' ,
97- 'KEYCODE_.' , 'KEYCODE_SPACE' , 'KEYCODE_GO'
98- ]
99-
100- for keyboard in self .keyboardList :
101- self .keyboard = ControlPanelButton (self .keyboardTab , self .culebron , self .printOperation , value = keyboard , text = keyboard [8 :],
102- width = Layout .BUTTON_WIDTH , bg = Color .DARK_GRAY , fg = Color .LIGHT_GRAY ,
103- highlightbackground = Color .DARK_GRAY )
104-
105- self .keyboard .configure (command = self .keyboard .command )
106- self .keyboard .grid (column = self .childWindow .column , row = self .childWindow .row )
131+ _keyboardList = [
132+ 'KEYCODE_1' , 'KEYCODE_2' , 'KEYCODE_3' , 'KEYCODE_4' , 'KEYCODE_5' , 'KEYCODE_6' , 'KEYCODE_7' , 'KEYCODE_8' ,
133+ 'KEYCODE_9' , 'KEYCODE_0' ,
134+ 'KEYCODE_Q' , 'KEYCODE_W' , 'KEYCODE_E' , 'KEYCODE_R' , 'KEYCODE_T' , 'KEYCODE_Y' , 'KEYCODE_U' , 'KEYCODE_I' ,
135+ 'KEYCODE_O' , 'KEYCODE_P' ,
136+ 'KEYCODE_A' , 'KEYCODE_S' , 'KEYCODE_D' , 'KEYCODE_F' , 'KEYCODE_G' , 'KEYCODE_H' , 'KEYCODE_J' , 'KEYCODE_K' ,
137+ 'KEYCODE_L' ,
138+ 'KEYCODE_DEL' , 'KEYCODE_Z' , 'KEYCODE_X' , 'KEYCODE_C' , 'KEYCODE_V' , 'KEYCODE_B' , 'KEYCODE_N' , 'KEYCODE_M' ,
139+ 'KEYCODE_.' , 'KEYCODE_SPACE' , 'KEYCODE_GO'
140+ ]
141+
142+ for keyboard in _keyboardList :
143+ _cpb = ControlPanelButton (self .keyboardTab , self .culebron , self .printOperation , value = keyboard ,
144+ text = keyboard [8 :],
145+ width = Layout .BUTTON_WIDTH , bg = self .bg , fg = self .fg ,
146+ highlightbackground = self .highlightbackground )
147+
148+ _cpb .configure (command = _cpb .command )
149+ _cpb .grid (column = self .childWindow .column , row = self .childWindow .row )
107150 self .tabLayout ()
108151
109152 def tabLayout (self ):
0 commit comments