1818 @author: Diego Torres Milano
1919 @author: Ahmed Kasem
2020 '''
21+ import platform
2122
22- __version__ = '15.5 .1'
23+ __version__ = '15.8 .1'
2324
2425import tkinter
2526import tkinter .ttk
27+ import subprocess
2628
2729from com .dtmilano .android .culebron import Operation , Color
2830
@@ -36,7 +38,12 @@ class Layout:
3638 BUTTON_WIDTH = 13
3739 BUTTONS_NUMBER = 9
3840
41+
3942class ControlPanel (tkinter .Toplevel ):
43+ osName = platform .system ()
44+ ''' The OS name. We sometimes need specific behavior. '''
45+ isDarwin = (osName == 'Darwin' )
46+ ''' Is it Mac OSX? '''
4047
4148 def __init__ (self , culebron , printOperation , ** kwargs ):
4249 self .culebron = culebron
@@ -53,57 +60,92 @@ def __init__(self, culebron, printOperation, **kwargs):
5360 self .childWindow .resizable (width = tkinter .FALSE , height = tkinter .FALSE )
5461 self .childWindow .printOperation = printOperation
5562 self .childWindow .grid ()
56- self .childWindow .column = self .childWindow .row = 0
63+ self .childWindow .column = 0
64+ self .childWindow .row = 0
65+ if self .isDarwin :
66+ out = subprocess .check_output (["defaults" , "read" , "-g" , "AppleInterfaceStyle" ])
67+ self .isDarkMode = ('Dark' in out )
68+ else :
69+ self .isDarkMode = False
70+ if self .isDarkMode :
71+ self .fg = Color .DARK_GRAY
72+ self .bg = Color .LIGHT_GRAY
73+ self .highlightbackground = Color .LIGHT_GRAY
74+ else :
75+ self .fg = Color .DARK_GRAY
76+ self .bg = Color .LIGHT_GRAY
77+ self .highlightbackground = Color .DARK_GRAY
5778 self .createKeycodeTab ()
5879 self .createKeyboardTab ()
80+ self .childWindow .update ()
81+ if self .isDarwin :
82+ if platform .mac_ver ()[0 ].startswith ("10.14" ):
83+ self .childWindow .after (0 , self .fix )
84+
85+ def fix (self ):
86+ """
87+ Fix a problem with Tkinter Buttons in Mojave.
88+ See https://stackoverflow.com/questions/52529403/button-text-of-tkinter-not-works-in-mojave
89+ """
90+ a = self .childWindow .winfo_geometry ().split ('+' )[0 ]
91+ b = a .split ('x' )
92+ w = int (b [0 ])
93+ h = int (b [1 ])
94+ self .childWindow .geometry ('%dx%d' % (w + 1 , h + 1 ))
5995
6096 def createKeycodeTab (self ):
6197 ''' 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 )
98+ _keycodeList = [
99+ 'KEYCODE_HOME' , 'KEYCODE_DPAD_UP' , 'KEYCODE_BACK' , 'KEYCODE_SEARCH' , 'KEYCODE_CHANNEL_UP' , 'KEYCODE_TV' ,
100+ 'KEYCODE_MUSIC' , 'KEYCODE_EXPLORER' , 'KEYCODE_CAMERA' , 'KEYCODE_POWER' , 'KEYCODE_DPAD_LEFT' ,
101+ 'KEYCODE_DPAD_DOWN' ,
102+ 'KEYCODE_DPAD_RIGHT' , 'KEYCODE_PAGE_UP' , 'KEYCODE_CHANNEL_DOWN' , 'KEYCODE_VOLUME_UP' , 'KEYCODE_MEDIA_PLAY' ,
103+ 'KEYCODE_CONTACTS' , 'KEYCODE_ZOOM_IN' , 'SNAPSHOPT' , 'KEYCODE_MENU' , 'KEYCODE_DPAD_CENTER' , 'KEYCODE_ENTER' ,
104+ 'KEYCODE_PAGE_DOWN' , 'KEYCODE_BRIGHTNESS_DOWN' , 'KEYCODE_VOLUME_DOWN' , 'KEYCODE_MEDIA_PAUSE' ,
105+ 'KEYCODE_BOOKMARK' ,
106+ 'KEYCODE_ZOOM_OUT' , 'REFRESH' , 'KEYCODE_APP_SWITCH' , 'KEYCODE_GOOGLE_NOW' , 'KEYCODE_CALL' , 'KEYCODE_ESCAPE' ,
107+ 'KEYCODE_BRIGHTNESS_UP' , 'KEYCODE_VOLUME_MUTE' , 'KEYCODE_MEDIA_STOP' , 'KEYCODE_CALCULATOR' ,
108+ 'KEYCODE_SETTINGS' , 'QUIT'
109+ ]
110+ for keycode in _keycodeList :
111+ _cpb = ControlPanelButton (self .keycodeTab , self .culebron , self .printOperation , value = keycode ,
112+ text = keycode [8 :],
113+ width = Layout .BUTTON_WIDTH ,
114+ bg = self .bg , fg = self .fg ,
115+ highlightbackground = self .highlightbackground )
75116
76117 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 )
118+ _cpb .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = _cpb .refreshScreen )
79119 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 )
120+ _cpb .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = _cpb .takeSnapshot )
82121 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 )
122+ _cpb .configure (fg = Color .BLUE , bg = Color .DARK_GRAY , text = keycode , command = self .childWindow .destroy )
85123 else :
86- self . keycode . configure (command = self . keycode .command )
87- self . keycode .grid (column = self .childWindow .column , row = self .childWindow .row )
124+ _cpb . configure (command = _cpb .command )
125+ _cpb .grid (column = self .childWindow .column , row = self .childWindow .row )
88126 self .tabLayout ()
89127
90128 def createKeyboardTab (self ):
91129 ''' 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 )
130+ _keyboardList = [
131+ 'KEYCODE_1' , 'KEYCODE_2' , 'KEYCODE_3' , 'KEYCODE_4' , 'KEYCODE_5' , 'KEYCODE_6' , 'KEYCODE_7' , 'KEYCODE_8' ,
132+ 'KEYCODE_9' , 'KEYCODE_0' ,
133+ 'KEYCODE_Q' , 'KEYCODE_W' , 'KEYCODE_E' , 'KEYCODE_R' , 'KEYCODE_T' , 'KEYCODE_Y' , 'KEYCODE_U' , 'KEYCODE_I' ,
134+ 'KEYCODE_O' , 'KEYCODE_P' ,
135+ 'KEYCODE_A' , 'KEYCODE_S' , 'KEYCODE_D' , 'KEYCODE_F' , 'KEYCODE_G' , 'KEYCODE_H' , 'KEYCODE_J' , 'KEYCODE_K' ,
136+ 'KEYCODE_L' ,
137+ 'KEYCODE_DEL' , 'KEYCODE_Z' , 'KEYCODE_X' , 'KEYCODE_C' , 'KEYCODE_V' , 'KEYCODE_B' , 'KEYCODE_N' , 'KEYCODE_M' ,
138+ 'KEYCODE_.' , 'KEYCODE_SPACE' , 'KEYCODE_GO'
139+ ]
140+
141+ for keyboard in _keyboardList :
142+ _cpb = ControlPanelButton (self .keyboardTab , self .culebron , self .printOperation , value = keyboard ,
143+ text = keyboard [8 :],
144+ width = Layout .BUTTON_WIDTH , bg = self .bg , fg = self .fg ,
145+ highlightbackground = self .highlightbackground )
146+
147+ _cpb .configure (command = _cpb .command )
148+ _cpb .grid (column = self .childWindow .column , row = self .childWindow .row )
107149 self .tabLayout ()
108150
109151 def tabLayout (self ):
0 commit comments