forked from badabing2005/PixelFlasher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
4028 lines (3703 loc) · 209 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
import argparse
import contextlib
import ctypes
import json
import locale
import math
import ntpath
import os
import sys
import time
import traceback
import webbrowser
from datetime import datetime
from urllib.parse import urlparse
import darkdetect
import wx
import wx.adv
import wx.lib.agw.aui as aui
import wx.lib.inspection
import wx.lib.mixins.inspection
from packaging.version import parse
import images as images
with contextlib.suppress(Exception):
ctypes.windll.shcore.SetProcessDpiAwareness(True)
from advanced_settings import AdvancedSettings
from backup_manager import BackupManager
from wifi import Wireless
from config import Config
from constants import *
from magisk_downloads import MagiskDownloads
from magisk_modules import MagiskModules
from message_box_ex import MessageBoxEx
from modules import (adb_kill_server, auto_resize_boot_list,
check_platform_tools, flash_phone, live_flash_boot_phone,
patch_boot_img, populate_boot_list, process_file,
select_firmware, set_flash_button_state)
from package_manager import PackageManager
from partition_manager import PartitionManager
from phone import get_connected_devices
from runtime import *
# see https://discuss.wxpython.org/t/wxpython4-1-1-python3-8-locale-wxassertionerror/35168
locale.setlocale(locale.LC_ALL, 'C')
# For troubleshooting, set inspector = True
inspector = False
dont_initialize = False
# Declare global_args at the global scope
global_args = None
# ============================================================================
# Class RedirectText
# ============================================================================
class RedirectText():
def __init__(self,aWxTextCtrl):
self.out=aWxTextCtrl
logfile = os.path.join(get_config_path(), 'logs', f"PixelFlasher_{datetime.now():%Y-%m-%d_%Hh%Mm%Ss}.log")
self.logfile = open(logfile, "w", buffering=1, encoding="ISO-8859-1", errors="replace")
set_logfile(logfile)
def write(self,string):
wx.CallAfter(self.out.AppendText, string)
global global_args
if hasattr(global_args, 'console') and global_args.console:
# Print to console as well
sys.__stdout__.write(string)
if not self.logfile.closed:
self.logfile.write(string)
# noinspection PyMethodMayBeStatic
def flush(self):
# noinspection PyStatementEffect
None
# ============================================================================
# Class DropDownButton
# ============================================================================
class DropDownButton(wx.BitmapButton):
def __init__(self, parent, id=wx.ID_ANY, bitmap=wx.NullBitmap, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.BU_AUTODRAW):
super().__init__(parent, id, bitmap, pos, size, style)
self.Bind(wx.EVT_BUTTON, self.OnButtonClick)
self.popup_menu = wx.Menu()
def OnButtonClick(self, event):
self.PopupMenu(self.popup_menu)
def AddLink(self, label, url, icon=None):
item = self.popup_menu.Append(wx.ID_ANY, label)
if icon:
item.SetBitmap(icon)
self.Bind(wx.EVT_MENU, lambda event, url=url: self.OnLinkSelected(event, url), item)
def OnLinkSelected(self, event, url):
# Handle the selected link here
print(f"Selected link: {url}")
open_device_image_download_link(url)
# ============================================================================
# Class PixelFlasher
# ============================================================================
class PixelFlasher(wx.Frame):
def __init__(self, parent, title):
config_file = get_config_file_path()
self.config = Config.load(config_file)
self.init_complete = False
self.wipe = False
set_config(self.config)
init_db()
wx.Frame.__init__(self, parent, -1, title, size=(self.config.width, self.config.height),
style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE | wx.SYSTEM_MENU | wx.CLOSE_BOX)
# Base first run size on resolution.
if self.config.first_run:
x = int((self.CharWidth * self.config.width) / 11)
y = int((self.CharHeight * self.config.height) / 25)
self.SetSize(x, y)
self.toolbar_flags = self.get_toolbar_config()
self.Center()
self._build_status_bar()
self._set_icons()
self._build_menu_bar()
self._init_ui()
sys.stdout = RedirectText(self.console_ctrl)
sys.stderr = RedirectText(self.console_ctrl)
# self.Centre(wx.BOTH)
if self.config.pos_x and self.config.pos_y:
self.SetPosition((self.config.pos_x,self.config.pos_y))
self.resizing = False
if not dont_initialize:
self.initialize()
self.Show(True)
# -----------------------------------------------
# initialize
# -----------------------------------------------
def initialize(self):
t = f":{datetime.now():%Y-%m-%d %H:%M:%S}"
print(f"PixelFlasher {VERSION} started on {t}")
puml(f"{t};\n")
puml(f"#palegreen:PixelFlasher {VERSION} started;\n")
start = time.time()
print(f"Platform: {sys.platform}")
puml(f"note left:Platform: {sys.platform}\n")
# check timezone
timezone_offset = time.timezone if (time.localtime().tm_isdst == 0) else time.altzone
print(f"System Timezone: {time.tzname} Offset: {timezone_offset / 60 / 60 * -1}")
print(f"Configuration Folder Path: {get_config_path()}")
print(f"Configuration File Path: {get_config_file_path()}")
puml(":Loading Configuration;\n")
puml(f"note left: {get_config_path()}\n")
# load verbose settings
if self.config.verbose:
self.verbose_checkBox.SetValue(self.config.verbose)
set_verbose(self.config.verbose)
if self.config.first_run:
print("First Run: No previous configuration file is found.")
else:
print(f"{json.dumps(self.config.data, indent=4, sort_keys=True)}")
puml("note right\n")
puml(f"{json.dumps(self.config.data, indent=4, sort_keys=True)}\n")
puml("end note\n")
# enable / disable advanced_options
if self.config.advanced_options:
self._advanced_options_hide(False)
else:
self._advanced_options_hide(True)
# check codepage
print(f"System Default Encoding: {sys.getdefaultencoding()}")
print(f"File System Encoding: {sys.getfilesystemencoding()}")
get_code_page()
# delete specified libraries from the bundle
print(f"Bundle Directory: {get_bundle_dir()}")
delete_bundled_library(self.config.delete_bundled_libs)
# Get Available Memory
free_memory, total_memory = get_free_memory()
formatted_free_memory = format_memory_size(free_memory)
formatted_total_memory = format_memory_size(total_memory)
print(f"Available Free Memory: {formatted_free_memory} / {formatted_total_memory}")
# Get available free disk on system drive
print(f"Available Free Disk on system drive: {str(get_free_space())} GB")
print(f"Available Free Disk on PixelFlasher data drive: {str(get_free_space(get_config_path()))} GB\n")
# load android_versions into a dict.
with contextlib.suppress(Exception):
with open('android_versions.json', 'r', encoding='ISO-8859-1', errors="replace") as file:
android_versions = json.load(file)
set_android_versions(android_versions)
# load android_devices into a dict.
with contextlib.suppress(Exception):
with open('android_devices.json', 'r', encoding='ISO-8859-1', errors="replace") as file:
android_devices = json.load(file)
set_android_devices(android_devices)
# load Magisk Package Name
set_magisk_package(self.config.magisk)
# load the low_mem settings
set_low_memory(self.config.low_mem)
# load Linux Shell
set_linux_shell(self.config.linux_shell)
# load firmware_has_init_boot
set_firmware_has_init_boot(self.config.firmware_has_init_boot)
# load rom_has_init_boot
set_rom_has_init_boot(self.config.rom_has_init_boot)
# extract firmware info
if self.config.firmware_path and os.path.exists(self.config.firmware_path):
self.firmware_picker.SetPath(self.config.firmware_path)
firmware = ntpath.basename(self.config.firmware_path)
filename, extension = os.path.splitext(firmware)
extension = extension.lower()
firmware = filename.split("-")
if len(firmware) == 1:
set_firmware_model(None)
set_firmware_id(filename)
else:
try:
set_firmware_model(firmware[0])
if firmware[1] == 'ota' or firmware[0] == 'crDroidAndroid':
set_firmware_id(f"{firmware[0]}-{firmware[1]}-{firmware[2]}")
self.config.firmware_is_ota = True
else:
set_firmware_id(f"{firmware[0]}-{firmware[1]}")
except Exception as e:
set_firmware_model(None)
set_firmware_id(filename)
set_ota(self, self.config.firmware_is_ota)
if self.config.firmware_sha256:
print("Using previously stored firmware SHA-256 ...")
firmware_hash = self.config.firmware_sha256
else:
print("Computing firmware SHA-256 ...")
firmware_hash = sha256(self.config.firmware_path)
self.config.firmware_sha256 = firmware_hash
print(f"Firmware SHA-256: {firmware_hash}")
self.firmware_picker.SetToolTip(f"SHA-256: {firmware_hash}")
# Check to see if the first 8 characters of the checksum is in the filename, Google published firmwares do have this.
if firmware_hash[:8] in self.config.firmware_path:
print(f"Expected to match {firmware_hash[:8]} in the firmware filename and did. This is good!")
puml(f"#CDFFC8:Checksum matches portion of the firmware filename {self.config.firmware_path};\n")
# self.toast("Firmware SHA256", "SHA256 of the selected file matches the segment in the filename.")
set_firmware_hash_validity(True)
else:
print(f"WARNING: Expected to match {firmware_hash[:8]} in the firmware filename but didn't, please double check to make sure the checksum is good.")
puml("#orange:Unable to match the checksum in the filename;\n")
self.toast("Firmware SHA256", "WARNING! SHA256 of the selected file does not match segments in the filename.\nPlease double check to make sure the checksum is good.")
set_firmware_hash_validity(False)
# check platform tools
res_sdk = check_platform_tools(self)
if res_sdk != -1:
# load platform tools value
if self.config.platform_tools_path and get_adb() and get_fastboot():
self.platform_tools_picker.SetPath(self.config.platform_tools_path)
# if adb is found, display the version
if get_sdk_version():
self.platform_tools_label.SetLabel(f"Android Platform Tools\nVersion {get_sdk_version()}")
# load custom_rom settings
self.custom_rom_checkbox.SetValue(self.config.custom_rom)
if self.config.custom_rom_path and os.path.exists(self.config.custom_rom_path):
self.custom_rom.SetPath(self.config.custom_rom_path)
set_custom_rom_id(os.path.splitext(ntpath.basename(self.config.custom_rom_path))[0])
if self.config.rom_sha256:
rom_hash = self.config.rom_sha256
else:
rom_hash = sha256(self.config.custom_rom_path)
self.config.rom_sha256 = rom_hash
self.custom_rom.SetToolTip(f"SHA-256: {rom_hash}")
# refresh boot.img list
populate_boot_list(self)
# set the flash mode
mode = self.config.flash_mode
# set flash option
self.flash_both_slots_checkBox.SetValue(self.config.flash_both_slots)
self.flash_to_inactive_slot_checkBox.SetValue(self.config.flash_to_inactive_slot)
self.disable_verity_checkBox.SetValue(self.config.disable_verity)
self.disable_verification_checkBox.SetValue(self.config.disable_verification)
self.fastboot_force_checkBox.SetValue(self.config.fastboot_force)
self.fastboot_verbose_checkBox.SetValue(self.config.fastboot_verbose)
self.temporary_root_checkBox.SetValue(self.config.temporary_root)
self.no_reboot_checkBox.SetValue(self.config.no_reboot)
self.wipe_checkBox.SetValue(self.wipe)
# get the image choice and update UI
set_image_mode(self.image_choice.Items[self.image_choice.GetSelection()])
# set the state of flash button.
set_flash_button_state(self)
self._update_custom_flash_options()
if res_sdk != -1:
print("\nLoading Device list ...")
puml(":Loading device list;\n", True)
print("This could take a while, please be patient.\n")
debug("Populate device list")
connected_devices = get_connected_devices()
self.device_choice.AppendItems(connected_devices)
d_list_string = '\n'.join(connected_devices)
puml(f"note right\n{d_list_string}\nend note\n")
# select configured device
debug("select configured device")
self._select_configured_device()
self._refresh_ui()
# check version if we are running the latest
l_version = check_latest_version()
if self.config.update_check and parse(VERSION) < parse(l_version):
print(f"\nA newer PixelFlasher v{l_version} can be downloaded from:")
print("https://github.com/badabing2005/PixelFlasher/releases/latest")
from About import AboutDlg
about = AboutDlg(self)
about.ShowModal()
about.Destroy()
end = time.time()
print(f"Load time: {math.ceil(end - start)} seconds")
# set the ui fonts
self.set_ui_fonts()
# update widgets
self.update_widget_states()
self.spinner.Hide()
self.spinner_label.Hide()
self.init_complete = True
# -----------------------------------------------
# enable_disable_radio_buttons
# -----------------------------------------------
def enable_disable_radio_button(self, name, state, selected=False, just_select=False):
radio_buttons = self.mode_sizer.GetChildren()
if isinstance(name, str):
for child in radio_buttons:
radio_button = child.GetWindow()
if radio_button and radio_button.GetName() == f"mode-{name}":
if not just_select:
radio_button.Enable(state)
if state and selected:
radio_button.SetValue(True)
# -----------------------------------------------
# set_ui_fonts
# -----------------------------------------------
def set_ui_fonts(self):
if self.config.customize_font:
font = wx.Font(self.config.pf_font_size, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.NORMAL, underline=False, faceName=self.config.pf_font_face)
# device list
self.device_choice.SetFont(font)
# boot img list
self.list.SetFont(font)
self.list.SetHeaderAttr(wx.ItemAttr(wx.Colour('BLUE'),wx.Colour('DARK GREY'), wx.Font(font)))
# console
self.console_ctrl.SetFont(font)
else:
font = wx.Font(9, family=wx.DEFAULT, style=wx.NORMAL, weight=wx.NORMAL, underline=False, faceName='Segoe UI')
# device list
self.device_choice.SetFont(wx.Font(9, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL))
# boot img list
self.list.SetHeaderAttr(wx.ItemAttr(wx.Colour('BLUE'),wx.Colour('DARK GREY'), wx.Font(wx.FontInfo(10))))
if sys.platform == "win32":
self.list.SetFont(font)
else:
self.list.SetFont(wx.Font(11, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL))
# console
self.console_ctrl.SetFont(wx.Font(9, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL))
if darkdetect.isLight():
self.console_ctrl.SetBackgroundColour(wx.WHITE)
self.console_ctrl.SetForegroundColour(wx.BLUE)
self.console_ctrl.SetDefaultStyle(wx.TextAttr(wx.BLUE))
self._refresh_ui()
# -----------------------------------------------
# _set_icons
# -----------------------------------------------
def _set_icons(self):
self.SetIcon(images.Icon_256.GetIcon())
# -----------------------------------------------
# _build_status_bar
# -----------------------------------------------
def _build_status_bar(self):
self.statusBar = self.CreateStatusBar(2, wx.STB_SIZEGRIP)
self.statusBar.SetStatusWidths([-2, -1])
status_text = f"Welcome to PixelFlasher {VERSION}"
self.statusBar.SetStatusText(status_text, 0)
# -----------------------------------------------
# _build_toolbar
# -----------------------------------------------
def _build_toolbar(self, flags, destroy=False):
try:
if destroy:
self.tb.Destroy()
tb = self.CreateToolBar(flags)
# tb = MultiLineToolbar(self, flags) # Use the custom MultiLineToolbar class
self.tb = tb
tsize = (64, 64)
null_bmp = wx.BitmapBundle(wx.NullBitmap)
tb.SetToolBitmapSize(tsize)
# Install APK
if self.config.toolbar['visible']['install_apk']:
tb.AddTool(toolId=5, label="Install APK", bitmap=images.install_apk_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Install APK on the device", longHelp="Install APK on the device", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=5)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=5)
# Package Manager
if self.config.toolbar['visible']['package_manager']:
tb.AddTool(toolId=8, label="App Manager", bitmap=images.packages_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Package Manager", longHelp="Manage Apps / Packages", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=8)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=8)
# separator
if self.config.toolbar['visible']['install_apk'] or self.config.toolbar['visible']['package_manager']:
tb.AddSeparator()
# Shell
if self.config.toolbar['visible']['adb_shell']:
tb.AddTool(toolId=10, label="ADB Shell", bitmap=images.shell_64.GetBitmap(), bmpDisabled=images.shell_64_disabled.GetBitmap(), kind=wx.ITEM_NORMAL, shortHelp="Open ADB shell to the device.", longHelp="Open adb shell to the device", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=10)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=10)
# Scrcpy
if self.config.toolbar['visible']['scrcpy']:
tb.AddTool(toolId=15, label="Scrcpy", bitmap=images.scrcpy_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Launch Screen Copy", longHelp="Launch Screen Copy", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=15)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=15)
# Device Info
if self.config.toolbar['visible']['device_info']:
tb.AddTool(toolId=20, label="Device Info", bitmap=images.about_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Dump Full Device Info", longHelp="Dump Full Device Info", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=20)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=20)
# Check Verity / Verification
# if self.config.toolbar['visible']['check_verity']:
# tb.AddTool(toolId=30, label="Verify", bitmap=images.shield_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Check Verity / Verification status", longHelp="Check Verity / Verification status", clientData=None)
# self.Bind(wx.EVT_TOOL, self.OnToolClick, id=30)
# self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=30)
# Partition Manager
if self.config.toolbar['visible']['partition_manager'] and self.config.advanced_options:
tb.AddTool(toolId=40, label="Partitions", bitmap=images.partition_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Partition Manager", longHelp="Partition Manager", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=40)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=40)
# separator
if self.config.toolbar['visible']['adb_shell'] or self.config.toolbar['visible']['scrcpy'] or self.config.toolbar['visible']['device_info'] or self.config.toolbar['visible']['check_verity'] or (self.config.toolbar['visible']['partition_manager'] and self.config.advanced_options):
tb.AddSeparator()
# Switch Slot
if self.config.toolbar['visible']['switch_slot'] and self.config.advanced_options:
tb.AddTool(toolId=100, label="Switch Slot", bitmap=images.switch_slot_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Switch to the other Slot", longHelp="Switch to the other Slot", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=100)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=100)
# separator
tb.AddSeparator()
# Reboot to System
if self.config.toolbar['visible']['reboot_system']:
tb.AddTool(toolId=110, label="System", bitmap=images.reboot_system_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Reboot to System", longHelp="Reboot to System", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=110)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=110)
# Reboot to Bootloader
if self.config.toolbar['visible']['reboot_bootloader']:
tb.AddTool(toolId=120, label="Bootloader", bitmap=images.reboot_bootloader_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Reboot to Bootloader", longHelp="Reboot to Bootloader", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=120)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=120)
# Reboot to fastbootd
if self.config.toolbar['visible']['reboot_fastbootd']:
tb.AddTool(toolId=125, label="fastbootd", bitmap=images.reboot_fastbootd_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Reboot to userspace fastboot (fastbootd)", longHelp="Reboot to userspace fastboot (fastbootd)", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=125)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=125)
# Reboot to Recovery
if self.config.toolbar['visible']['reboot_recovery'] and self.config.advanced_options:
tb.AddTool(toolId=130, label="Recovery", bitmap=images.reboot_recovery_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Reboot to Recovery", longHelp="Reboot to Recovery", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=130)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=130)
# Reboot to Safe Mode
if self.config.toolbar['visible']['reboot_safe_mode'] and self.config.advanced_options:
tb.AddTool(toolId=140, label="Safe Mode", bitmap=images.reboot_safe_mode_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Reboot to Safe Mode", longHelp="Reboot to Safe Mode", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=140)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=140)
# Reboot to Download
if self.config.toolbar['visible']['reboot_download'] and self.config.advanced_options:
tb.AddTool(toolId=150, label="Download", bitmap=images.reboot_download_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Reboot to Download Mode", longHelp="Reboot to Download Mode", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=150)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=150)
# Reboot to Sideload
if self.config.toolbar['visible']['reboot_sideload'] and self.config.advanced_options:
tb.AddTool(toolId=160, label="Sideload", bitmap=images.reboot_sideload_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Reboot to Sideload Mode", longHelp="Reboot to Sideload Mode", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=160)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=160)
# separator
if self.config.toolbar['visible']['reboot_system'] or self.config.toolbar['visible']['reboot_bootloader'] or (self.config.toolbar['visible']['reboot_recovery'] and self.config.advanced_options) or (self.config.toolbar['visible']['reboot_safe_mode'] and self.config.advanced_options) or (self.config.toolbar['visible']['reboot_download'] and self.config.advanced_options) or (self.config.toolbar['visible']['reboot_sideload'] and self.config.advanced_options) or (self.config.toolbar['visible']['reboot_fastbootd'] and self.config.advanced_options):
tb.AddSeparator()
# Manage Magisk Settings (json file knows this and magisk_modules)
if self.config.toolbar['visible']['magisk_modules']:
tb.AddTool(toolId=200, label="Magisk", bitmap=images.magisk_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Manage Magisk modules and settings", longHelp="Manage Magisk modules and settings", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=200)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=200)
# Download and Install Magisk Manager
if self.config.toolbar['visible']['install_magisk']:
tb.AddTool(toolId=210, label="Install Magisk", bitmap=images.install_magisk_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Download and Install Magisk Manager", longHelp="Download and Install Magisk Manager", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=210)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=210)
# Magisk Backup Manager
if self.config.toolbar['visible']['magisk_backup_manager']:
tb.AddTool(toolId=220, label="Magisk Backup", bitmap=images.backup_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Magisk Backup Manager", longHelp="Magisk Backup Manager", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=220)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=220)
# SOS, Disable Magisk Modules
if self.config.toolbar['visible']['sos'] and self.config.advanced_options:
tb.AddTool(toolId=230, label="SOS", bitmap=images.sos_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp=u"Disable Magisk Modules\nThis button issues the following command:\n adb wait-for-device shell magisk --remove-modules\nThis helps for cases where device bootloops due to incompatible magisk modules(YMMV).", longHelp="SOS", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=230)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=230)
# separator
if self.config.toolbar['visible']['magisk_modules'] or self.config.toolbar['visible']['install_magisk'] or self.config.toolbar['visible']['magisk_backup_manager'] or (self.config.toolbar['visible']['sos'] and self.config.advanced_options):
tb.AddSeparator()
# Lock Bootloader
if self.config.toolbar['visible']['lock_bootloader'] and self.config.advanced_options:
tb.AddTool(toolId=300, label="Lock", bitmap=images.lock_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Lock Bootloader", longHelp="Lock Bootloader", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=300)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=300)
# UnLock Bootloader
if self.config.toolbar['visible']['unlock_bootloader'] and self.config.advanced_options:
tb.AddTool(toolId=310, label="UnLock", bitmap=images.unlock_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="UnLock Bootloader\nCaution will wipe data", longHelp="UnLock Bootloader", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=310)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=310)
# separator
if (self.config.toolbar['visible']['lock_bootloader'] or self.config.toolbar['visible']['unlock_bootloader']) and self.config.advanced_options:
tb.AddSeparator()
tb.AddStretchableSpace()
if self.config.toolbar['visible']['configuration']:
# Configuration
tb.AddTool(toolId=900, label="Settings", bitmap=images.settings_64.GetBitmap(), bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Settings", longHelp="Configuration Settings", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=900)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=900)
# Create Support
support_bmp = wx.ArtProvider.GetBitmapBundle(wx.ART_HELP, wx.ART_TOOLBAR, tsize)
tb.AddTool(toolId=910, label="Support", bitmap=support_bmp, bmpDisabled=null_bmp, kind=wx.ITEM_NORMAL, shortHelp="Create Support file", longHelp="Create Support file", clientData=None)
self.Bind(wx.EVT_TOOL, self.OnToolClick, id=910)
self.Bind(wx.EVT_TOOL_RCLICKED, self.OnToolRClick, id=910)
# tb.EnableTool(10, False) # False means disabled
# self.disable_all_toolbar_tools(tb)
tb.SetToolSeparation(10)
a = tb.GetMargins()
# tb.SetMargins(80, 80)
b = tb.GetMargins()
tb.Realize()
except Exception as e:
print("Exception occurred while building the toolbar:", e)
traceback.print_exc()
# -----------------------------------------------
# disable_all_toolbar_tools
# -----------------------------------------------
def disable_all_toolbar_tools(self, tb):
tools_count = tb.GetToolsCount()
for i in range(tools_count):
tool = tb.GetToolByPos(i)
tb.EnableTool(tool.GetId(), False)
# -----------------------------------------------
# OnToolClick
# -----------------------------------------------
def OnToolClick(self, event):
# print("tool %s clicked\n" % event.GetId())
id = event.GetId()
if id == 5:
self._on_install_apk(event)
elif id == 8:
self._on_package_manager(event)
elif id == 10:
self._on_adb_shell(event)
elif id == 15:
self._on_scrcpy(event)
elif id == 20:
self._on_device_info(event)
# elif id == 30:
# self._on_verity_check(event)
elif id == 40:
self._on_partition_manager(event)
elif id == 100:
self._on_switch_slot(event)
elif id == 110:
self._on_reboot_system(event)
elif id == 120:
self._on_reboot_bootloader(event)
elif id == 125:
self._on_reboot_fastbootd(event)
elif id == 130:
self._on_reboot_recovery(event)
elif id == 140:
self._on_reboot_safemode(event)
elif id == 150:
self._on_reboot_download(event)
elif id == 160:
self._on_reboot_sideload(event)
elif id == 200:
self._on_magisk(event)
elif id == 210:
self._on_magisk_install(event)
elif id == 220:
self._on_backup_manager(event)
elif id == 230:
self._on_sos(event)
elif id == 300:
self._on_lock_bootloader(event)
elif id == 310:
self._on_unlock_bootloader(event)
elif id == 900:
self._on_advanced_config(event)
elif id == 910:
self._on_support_zip(event)
else:
print(f"UNKNOWN tool id: {id}")
# -----------------------------------------------
# OnToolRClick
# -----------------------------------------------
def OnToolRClick(self, event):
# print("tool %s right-clicked\n" % event.GetId())
return
# -----------------------------------------------
# _on_device_info
# -----------------------------------------------
def _on_device_info(self, event):
try:
if self.config.device:
self._on_spin('start')
device = get_phone()
print(f"Device Info:\n------------\n{device.device_info}")
except Exception as e:
print(f"\n{datetime.now():%Y-%m-%d %H:%M:%S} ERROR: Encountered an error while getting device info")
traceback.print_exc()
self._on_spin('stop')
# -----------------------------------------------
# _on_verity_check
# -----------------------------------------------
# def _on_verity_check(self, event):
# try:
# if self.config.device:
# self._on_spin('start')
# with contextlib.suppress(Exception):
# device = get_phone()
# verity = device.get_verity_verification('verity')
# if verity != -1:
# print(f"\n{verity}")
# verification = device.get_verity_verification('verification')
# if verification != -1:
# print(f"\n{verification}")
# except Exception as e:
# print(f"\n{datetime.now():%Y-%m-%d %H:%M:%S} ERROR: Encountered an error while checking verity")
# traceback.print_exc()
# self._on_spin('stop')
# -----------------------------------------------
# _build_menu_bar
# -----------------------------------------------
def _build_menu_bar(self):
# create the main menu object
self.menuBar = wx.MenuBar()
# Create the File menu
file_menu = wx.Menu()
# Create the Device menu
device_menu = wx.Menu()
# Create the Toolbar menu
tb_menu = wx.Menu()
# Create the Help menu
help_menu = wx.Menu()
# File Menu Items
# ---------------
# Settings Menu
config_item = file_menu.Append(wx.ID_ANY, "Settings", "Settings")
config_item.SetBitmap(images.settings_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_advanced_config, config_item)
# seperator
file_menu.AppendSeparator()
# Exit Menu
wx.App.SetMacExitMenuItemId(wx.ID_EXIT)
exit_item = file_menu.Append(wx.ID_EXIT, "E&xit\tCtrl-Q", "Exit PixelFlasher")
exit_item.SetBitmap(images.exit_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_exit_app, exit_item)
# Device Menu Items
# ----------------
# Install APK
self.install_apk = device_menu.Append(wx.ID_ANY, "Install APK", "Install APK")
self.install_apk.SetBitmap(images.install_apk_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_install_apk, self.install_apk)
# Package Manager
self.package_manager = device_menu.Append(wx.ID_ANY, "Package Manager", "Package Manager")
self.package_manager.SetBitmap(images.packages_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_package_manager, self.package_manager)
# seperator
device_menu.AppendSeparator()
# ADB Shell Menu
self.shell_menu_item = device_menu.Append(wx.ID_ANY, "ADB Shell", "Open adb shell to the device")
self.shell_menu_item.SetBitmap(images.shell_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_adb_shell, self.shell_menu_item)
# Scrcpy Menu
self.scrcpy_menu_item = device_menu.Append(wx.ID_ANY, "Scrcpy", "Launch Screen Copy")
self.scrcpy_menu_item.SetBitmap(images.scrcpy_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_scrcpy, self.scrcpy_menu_item)
# Device Info Menu
self.device_info_menu_item = device_menu.Append(wx.ID_ANY, "Device Info", "Dump Full Device Info")
self.device_info_menu_item.SetBitmap(images.about_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_device_info, self.device_info_menu_item)
# # Verity / Verification Menu
# self.verity_menu_item = device_menu.Append(wx.ID_ANY, "Verity / Verification Status", "Check Verity / Verification Status")
# self.verity_menu_item.SetBitmap(images.shield_24.GetBitmap())
# self.Bind(wx.EVT_MENU, self._on_verity_check, self.verity_menu_item)
# Partitions Manager
self.partitions_menu = device_menu.Append(wx.ID_ANY, "Partitions Manager", "Backup / Erase Partitions")
self.partitions_menu.SetBitmap(images.partition_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_partition_manager, self.partitions_menu)
# seperator
device_menu.AppendSeparator()
# Switch Slot
self.switch_slot_menu = device_menu.Append(wx.ID_ANY, "Switch Slot", "Switch to the other slow")
self.switch_slot_menu.SetBitmap(images.switch_slot_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_switch_slot, self.switch_slot_menu)
# seperator
device_menu.AppendSeparator()
# Reboot Submenu
reboot = wx.Menu()
self.reboot_system_menu = reboot.Append(wx.ID_ANY, "System")
self.reboot_bootloader_menu = reboot.Append(wx.ID_ANY, "Bootloader")
self.reboot_fastbootd_menu = reboot.Append(wx.ID_ANY, "Fastbootd")
self.reboot_recovery_menu = reboot.Append(wx.ID_ANY, "Recovery")
self.reboot_safe_mode_menu = reboot.Append(wx.ID_ANY, "Safe Mode")
self.reboot_download_menu = reboot.Append(wx.ID_ANY, "Download")
self.reboot_sideload_menu = reboot.Append(wx.ID_ANY, "Sideload")
self.reboot_system_menu.SetBitmap(images.reboot_System_24.GetBitmap())
self.reboot_bootloader_menu.SetBitmap(images.reboot_bootloader_24.GetBitmap())
self.reboot_fastbootd_menu.SetBitmap(images.reboot_fastbootd_24.GetBitmap())
self.reboot_recovery_menu.SetBitmap(images.reboot_recovery_24.GetBitmap())
self.reboot_safe_mode_menu.SetBitmap(images.reboot_safe_mode_24.GetBitmap())
self.reboot_download_menu.SetBitmap(images.reboot_download_24.GetBitmap())
self.reboot_sideload_menu.SetBitmap(images.reboot_sideload_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_reboot_system, self.reboot_system_menu)
self.Bind(wx.EVT_MENU, self._on_reboot_bootloader, self.reboot_bootloader_menu)
self.Bind(wx.EVT_MENU, self._on_reboot_fastbootd, self.reboot_fastbootd_menu)
self.Bind(wx.EVT_MENU, self._on_reboot_recovery, self.reboot_recovery_menu)
self.Bind(wx.EVT_MENU, self._on_reboot_safemode, self.reboot_safe_mode_menu)
self.Bind(wx.EVT_MENU, self._on_reboot_download, self.reboot_download_menu)
self.Bind(wx.EVT_MENU, self._on_reboot_sideload, self.reboot_sideload_menu)
self.reboot_menu = device_menu.Append(wx.ID_ANY, 'reboot', reboot)
self.reboot_menu.SetBitmap(images.reboot_24.GetBitmap())
# seperator
device_menu.AppendSeparator()
# Magisk Settings
self.magisk_menu = device_menu.Append(wx.ID_ANY, "Magisk", "Manage Magisk modules and settings")
self.magisk_menu.SetBitmap(images.magisk_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_magisk, self.magisk_menu)
# Install Magisk
self.install_magisk_menu = device_menu.Append(wx.ID_ANY, "Install Magisk", "Download and Install Magisk")
self.install_magisk_menu.SetBitmap(images.install_magisk_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_magisk_install, self.install_magisk_menu)
# Magisk Backup Manager
self.magisk_backup_manager_menu = device_menu.Append(wx.ID_ANY, "Magisk Backup Manager", "Manage Magisk Backups")
self.magisk_backup_manager_menu.SetBitmap(images.backup_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_backup_manager, self.magisk_backup_manager_menu)
# SOS
self.sos_menu = device_menu.Append(wx.ID_ANY, "SOS", "Disable Magisk Modules")
self.sos_menu.SetBitmap(images.sos_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_sos, self.sos_menu)
# seperator
device_menu.AppendSeparator()
# Lock Bootloader
self.bootloader_lock_menu = device_menu.Append(wx.ID_ANY, "Lock Bootloader", "Lock Bootloader")
self.bootloader_lock_menu.SetBitmap(images.lock_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_lock_bootloader, self.bootloader_lock_menu)
# Unlock Bootloader
self.bootloader_unlock_menu = device_menu.Append(wx.ID_ANY, "Unlock Bootloader", "Unlock Bootloader (Will wipe data)")
self.bootloader_unlock_menu.SetBitmap(images.unlock_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_unlock_bootloader, self.bootloader_unlock_menu)
# Toolbar Menu Items
# ------------------
# Top
tb_top_item = tb_menu.Append(1010, 'Top', 'Top', wx.ITEM_RADIO)
tb_top_item.SetBitmap(images.top_24.GetBitmap())
if self.config.toolbar and self.config.toolbar['tb_position'] == 'top':
tb_top_item.Check()
self.Bind(wx.EVT_MENU, self._on_tb_update, tb_top_item)
# Left
tb_left_item = tb_menu.Append(1020, 'Left', 'Left', wx.ITEM_RADIO)
tb_left_item.SetBitmap(images.left_24.GetBitmap())
if self.config.toolbar and self.config.toolbar['tb_position'] == 'left':
tb_left_item.Check()
self.Bind(wx.EVT_MENU, self._on_tb_update, tb_left_item)
# Right
tb_right_item = tb_menu.Append(1030, 'Right', 'Right', wx.ITEM_RADIO)
tb_right_item.SetBitmap(images.right_24.GetBitmap())
if self.config.toolbar and self.config.toolbar['tb_position'] == 'right':
tb_right_item.Check()
self.Bind(wx.EVT_MENU, self._on_tb_update, tb_right_item)
# Bottom
tb_bottom_item = tb_menu.Append(1040, 'Bottom', 'Bottom', wx.ITEM_RADIO)
tb_bottom_item.SetBitmap(images.bottom_24.GetBitmap())
if self.config.toolbar and self.config.toolbar['tb_position'] == 'bottom':
tb_bottom_item.Check()
self.Bind(wx.EVT_MENU, self._on_tb_update, tb_bottom_item)
# separator
tb_menu.AppendSeparator()
# Checkboxes
self.tb_show_text_item = tb_menu.Append(1100, "Show Button Text", "Show Button Text", wx.ITEM_CHECK)
if self.config.toolbar and self.config.toolbar['tb_show_text']:
self.tb_show_text_item.Check()
self.Bind(wx.EVT_MENU, self._on_tb_update, self.tb_show_text_item)
self.tb_show_button_item = tb_menu.Append(1200, "Show Button Icon", "Show Button Icon", wx.ITEM_CHECK)
if self.config.toolbar and self.config.toolbar['tb_show_icons']:
self.tb_show_button_item.Check()
self.Bind(wx.EVT_MENU, self._on_tb_update, self.tb_show_button_item)
# separator
# Show / Hide Buttons Menu
tb_buttons_menu = wx.Menu()
tb_buttons_menu.Append(5, "Install APK", "", wx.ITEM_CHECK).SetBitmap(images.install_apk_24.GetBitmap())
tb_buttons_menu.Append(8, "Package Manager", "", wx.ITEM_CHECK).SetBitmap(images.packages_24.GetBitmap())
tb_buttons_menu.Append(10, "ADB Shell", "", wx.ITEM_CHECK).SetBitmap(images.shell_24.GetBitmap())
tb_buttons_menu.Append(15, "Scrcpy", "", wx.ITEM_CHECK).SetBitmap(images.scrcpy_24.GetBitmap())
tb_buttons_menu.Append(20, "Device Info", "", wx.ITEM_CHECK).SetBitmap(images.about_24.GetBitmap())
# tb_buttons_menu.Append(30, "Verity Verification Status", "", wx.ITEM_CHECK).SetBitmap(images.shield_24.GetBitmap())
tb_buttons_menu.Append(40, "Partitions Manager", "", wx.ITEM_CHECK).SetBitmap(images.partition_24.GetBitmap())
tb_buttons_menu.Append(100, "Switch Slot", "", wx.ITEM_CHECK).SetBitmap(images.switch_slot_24.GetBitmap())
tb_buttons_menu.Append(110, "Reboot System", "", wx.ITEM_CHECK).SetBitmap(images.reboot_System_24.GetBitmap())
tb_buttons_menu.Append(120, "Reboot Bootloader", "", wx.ITEM_CHECK).SetBitmap(images.reboot_bootloader_24.GetBitmap())
tb_buttons_menu.Append(125, "Reboot Fastbootd", "", wx.ITEM_CHECK).SetBitmap(images.reboot_fastbootd_24.GetBitmap())
tb_buttons_menu.Append(130, "Reboot Recovery", "", wx.ITEM_CHECK).SetBitmap(images.reboot_recovery_24.GetBitmap())
tb_buttons_menu.Append(140, "Reboot Safe Mode", "", wx.ITEM_CHECK).SetBitmap(images.reboot_safe_mode_24.GetBitmap())
tb_buttons_menu.Append(150, "Reboot Download", "", wx.ITEM_CHECK).SetBitmap(images.reboot_download_24.GetBitmap())
tb_buttons_menu.Append(160, "Reboot Sideload", "", wx.ITEM_CHECK).SetBitmap(images.reboot_sideload_24.GetBitmap())
tb_buttons_menu.Append(200, "Magisk", "", wx.ITEM_CHECK).SetBitmap(images.magisk_24.GetBitmap())
tb_buttons_menu.Append(210, "Install Magisk", "", wx.ITEM_CHECK).SetBitmap(images.install_magisk_24.GetBitmap())
tb_buttons_menu.Append(220, "Magisk Backup Manager", "", wx.ITEM_CHECK).SetBitmap(images.backup_24.GetBitmap())
tb_buttons_menu.Append(230, "SOS", "", wx.ITEM_CHECK).SetBitmap(images.sos_24.GetBitmap())
tb_buttons_menu.Append(300, "Lock Bootloader", "", wx.ITEM_CHECK).SetBitmap(images.lock_24.GetBitmap())
tb_buttons_menu.Append(310, "Unlock Bootloader", "", wx.ITEM_CHECK).SetBitmap(images.unlock_24.GetBitmap())
tb_buttons_menu.Append(900, "Configuration", "", wx.ITEM_CHECK).SetBitmap(images.settings_24.GetBitmap())
tb_buttons_menu.Bind(wx.EVT_MENU, self._on_button_menu)
tb_menu.AppendSubMenu(tb_buttons_menu, "Show / Hide Buttons")
# update tb_buttons_menu items based on config.
tb_buttons_menu.Check(5, self.config.toolbar['visible']['install_apk'])
tb_buttons_menu.Check(8, self.config.toolbar['visible']['package_manager'])
tb_buttons_menu.Check(10, self.config.toolbar['visible']['adb_shell'])
tb_buttons_menu.Check(15, self.config.toolbar['visible']['scrcpy'])
tb_buttons_menu.Check(20, self.config.toolbar['visible']['device_info'])
# tb_buttons_menu.Check(30, self.config.toolbar['visible']['check_verity'])
tb_buttons_menu.Check(40, self.config.toolbar['visible']['partition_manager'])
tb_buttons_menu.Check(100, self.config.toolbar['visible']['switch_slot'])
tb_buttons_menu.Check(110, self.config.toolbar['visible']['reboot_system'])
tb_buttons_menu.Check(120, self.config.toolbar['visible']['reboot_bootloader'])
tb_buttons_menu.Check(125, self.config.toolbar['visible']['reboot_fastbootd'])
tb_buttons_menu.Check(130, self.config.toolbar['visible']['reboot_recovery'])
tb_buttons_menu.Check(140, self.config.toolbar['visible']['reboot_safe_mode'])
tb_buttons_menu.Check(150, self.config.toolbar['visible']['reboot_download'])
tb_buttons_menu.Check(160, self.config.toolbar['visible']['reboot_sideload'])
tb_buttons_menu.Check(200, self.config.toolbar['visible']['magisk_modules'])
tb_buttons_menu.Check(210, self.config.toolbar['visible']['install_magisk'])
tb_buttons_menu.Check(220, self.config.toolbar['visible']['magisk_backup_manager'])
tb_buttons_menu.Check(230, self.config.toolbar['visible']['sos'])
tb_buttons_menu.Check(300, self.config.toolbar['visible']['lock_bootloader'])
tb_buttons_menu.Check(310, self.config.toolbar['visible']['unlock_bootloader'])
tb_buttons_menu.Check(900, self.config.toolbar['visible']['configuration'])
# Help Menu Items
# ---------------
# Report an issue
issue_item = help_menu.Append(wx.ID_ANY, 'Report an Issue', 'Report an Issue')
issue_item.SetBitmap(images.bug_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_report_an_issue, issue_item)
# # Feature Request
feature_item = help_menu.Append(wx.ID_ANY, 'Feature Request', 'Feature Request')
feature_item.SetBitmap(images.feature_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_feature_request, feature_item)
# # Project Home
project_page_item = help_menu.Append(wx.ID_ANY, 'PixelFlasher Project Page', 'PixelFlasher Project Page')
project_page_item.SetBitmap(images.github_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_project_page, project_page_item)
# Community Forum
forum_item = help_menu.Append(wx.ID_ANY, 'PixelFlasher Community (Forum)', 'PixelFlasher Community (Forum)')
forum_item.SetBitmap(images.forum_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_forum, forum_item)
# seperator
help_menu.AppendSeparator()
# Links Submenu
links = wx.Menu()
linksMenuItem1 = links.Append(wx.ID_ANY, "Homeboy76\'s Guide")
linksMenuItem2 = links.Append(wx.ID_ANY, "V0latyle\'s Guide")
linksMenuItem3 = links.Append(wx.ID_ANY, "roirraW\'s Guide")
linksMenuItem4 = links.Append(wx.ID_ANY, "kdrag0n\'s safetynet-fix")
linksMenuItem5 = links.Append(wx.ID_ANY, "Displax\'s safetynet-fix")
linksMenuItem6 = links.Append(wx.ID_ANY, "Get the Google USB Driver")
linksMenuItem7 = links.Append(wx.ID_ANY, "Android Security Update Bulletins")
linksMenuItem1.SetBitmap(images.guide_24.GetBitmap())
linksMenuItem2.SetBitmap(images.guide_24.GetBitmap())
linksMenuItem3.SetBitmap(images.guide_24.GetBitmap())
linksMenuItem4.SetBitmap(images.open_link_24.GetBitmap())
linksMenuItem5.SetBitmap(images.open_link_24.GetBitmap())
linksMenuItem6.SetBitmap(images.open_link_24.GetBitmap())
linksMenuItem7.SetBitmap(images.open_link_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_guide1, linksMenuItem1)
self.Bind(wx.EVT_MENU, self._on_guide2, linksMenuItem2)
self.Bind(wx.EVT_MENU, self._on_guide3, linksMenuItem3)
self.Bind(wx.EVT_MENU, self._on_link1, linksMenuItem4)
self.Bind(wx.EVT_MENU, self._on_link2, linksMenuItem5)
self.Bind(wx.EVT_MENU, self._on_link3, linksMenuItem6)
self.Bind(wx.EVT_MENU, self._on_link4, linksMenuItem7)
links_item = help_menu.Append(wx.ID_ANY, 'Links', links)
links_item.SetBitmap(images.open_link_24.GetBitmap())
# seperator
help_menu.AppendSeparator()
# Open configuration Folder
config_folder_item = help_menu.Append(wx.ID_ANY, 'Open Configuration Folder', 'Open Configuration Folder')
config_folder_item.SetBitmap(images.folder_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_open_config_folder, config_folder_item)
if get_config_path() != get_sys_config_path():
# Open pf_home
pf_home_item = help_menu.Append(wx.ID_ANY, 'Open PixelFlasher Working Directory', 'Open PixelFlasher Working Directory')
pf_home_item.SetBitmap(images.folder_24.GetBitmap())
self.Bind(wx.EVT_MENU, self._on_open_pf_home, pf_home_item)
# Create sanitized support.zip
support_zip_item = help_menu.Append(wx.ID_ANY, 'Create a Sanitized support.zip', 'Create a Sanitized support.zip')
support_zip_item.SetBitmap(images.support_24.GetBitmap())