@@ -45,8 +45,10 @@ def __init__(self, window: Tk) -> None:
4545 self .url_stock : str = "https://www.nseindia.com/api/option-chain-equities?symbol="
4646 self .url_symbols : str = "https://www.nseindia.com/products-services/" \
4747 "equity-derivatives-list-underlyings-information"
48- self .url_icon : str = "https://raw.githubusercontent.com/VarunS2002/" \
49- "Python-NSE-Option-Chain-Analyzer/master/nse_logo.png"
48+ self .url_icon_png : str = "https://raw.githubusercontent.com/VarunS2002/" \
49+ "Python-NSE-Option-Chain-Analyzer/master/nse_logo.png"
50+ self .url_icon_ico : str = "https://raw.githubusercontent.com/VarunS2002/" \
51+ "Python-NSE-Option-Chain-Analyzer/master/nse_logo.ico"
5052 self .headers : Dict [str , str ] = {
5153 'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, '
5254 'like Gecko) Chrome/80.0.3987.149 Safari/537.36' ,
@@ -101,17 +103,25 @@ def get_symbols(self) -> None:
101103 column += 1
102104
103105 def get_icon (self ) -> None :
104- self .icon_path : str
106+ self .icon_png_path : str
107+ self .icon_ico_path : str
105108 try :
106109 # noinspection PyProtectedMember,PyUnresolvedReferences
107110 base_path : str = sys ._MEIPASS
108- self .icon_path = os .path .join (base_path , 'nse_logo.png' )
111+ self .icon_png_path = os .path .join (base_path , 'nse_logo.png' )
112+ self .icon_ico_path = os .path .join (base_path , 'nse_logo.ico' )
109113 except AttributeError :
110- icon_raw : requests .Response = requests .get (self .url_icon , headers = self .headers , stream = True )
114+ icon_png_raw : requests .Response = requests .get (self .url_icon_png , headers = self .headers , stream = True )
111115 with open ('.NSE-OCA.png' , 'wb' ) as f :
112- for chunk in icon_raw .iter_content (1024 ):
116+ for chunk in icon_png_raw .iter_content (1024 ):
113117 f .write (chunk )
114- self .icon_path = '.NSE-OCA.png'
118+ self .icon_png_path = '.NSE-OCA.png'
119+ if is_windows_10 :
120+ icon_ico_raw : requests .Response = requests .get (self .url_icon_ico , headers = self .headers , stream = True )
121+ with open ('.NSE-OCA.ico' , 'wb' ) as f :
122+ for chunk in icon_ico_raw .iter_content (1024 ):
123+ f .write (chunk )
124+ self .icon_ico_path = '.NSE-OCA.ico'
115125
116126 def check_for_updates (self , auto : bool = True ) -> None :
117127 release_data : requests .Response = requests .get (
@@ -373,16 +383,14 @@ def get_data_refresh(self) -> Optional[Tuple[Optional[requests.Response], Any]]:
373383 def login_win (self , window : Tk ) -> None :
374384 self .login : Tk = window
375385 self .login .title ("NSE-Option-Chain-Analyzer" )
376- self .login .protocol ('WM_DELETE_WINDOW' , lambda file = '.NSE-OCA.png' : (os .remove (file )
377- if os .path .isfile (file )
378- else None ) or self .login .destroy ())
386+ self .login .protocol ('WM_DELETE_WINDOW' , self .close_login )
379387 window_width : int = self .login .winfo_reqwidth ()
380388 window_height : int = self .login .winfo_reqheight ()
381389 position_right : int = int (self .login .winfo_screenwidth () / 2 - window_width / 2 )
382390 position_down : int = int (self .login .winfo_screenheight () / 2 - window_height / 2 )
383391 self .login .geometry ("320x160+{}+{}" .format (position_right , position_down ))
384392 self .login .resizable (False , False )
385- self .login .iconphoto (True , PhotoImage (file = self .icon_path ))
393+ self .login .iconphoto (True , PhotoImage (file = self .icon_png_path ))
386394 self .login .rowconfigure (0 , weight = 1 )
387395 self .login .rowconfigure (1 , weight = 1 )
388396 self .login .rowconfigure (2 , weight = 1 )
@@ -728,7 +736,7 @@ def about_window(self) -> Toplevel:
728736 position_right : int = int (self .info .winfo_screenwidth () / 2 - window_width / 2 )
729737 position_down : int = int (self .info .winfo_screenheight () / 2 - window_height / 2 )
730738 self .info .geometry ("250x150+{}+{}" .format (position_right , position_down ))
731- self .info .iconphoto (True , PhotoImage (file = self .icon_path ))
739+ self .info .iconphoto (True , PhotoImage (file = self .icon_png_path ))
732740 self .info .attributes ('-topmost' , True )
733741 self .info .grab_set ()
734742 self .info .focus_force ()
@@ -775,15 +783,25 @@ def about(self, event: Optional[Event] = None) -> None:
775783 updates .grid (row = 5 , column = 0 , columnspan = 2 , sticky = N + S + W + E )
776784 self .info .mainloop ()
777785
786+ def close_login (self ) -> None :
787+ self .session .close ()
788+ if self .logging :
789+ print ('----------Quitting Program----------' )
790+ os .remove ('.NSE-OCA.png' ) if os .path .isfile ('.NSE-OCA.png' ) else None
791+ os .remove ('.NSE-OCA.ico' ) if os .path .isfile ('.NSE-OCA.ico' ) else None
792+ self .login .destroy ()
793+ sys .exit ()
794+
778795 # noinspection PyUnusedLocal
779- def close (self , event : Optional [Event ] = None ) -> None :
796+ def close_main (self , event : Optional [Event ] = None ) -> None :
780797 ask_quit : bool = messagebox .askyesno ("Quit" , "All unsaved data will be lost.\n Proceed to quit?" , icon = 'warning' ,
781798 default = 'no' )
782799 if ask_quit :
783800 self .session .close ()
784801 if self .logging :
785802 print ('----------Quitting Program----------' )
786803 os .remove ('.NSE-OCA.png' ) if os .path .isfile ('.NSE-OCA.png' ) else None
804+ os .remove ('.NSE-OCA.ico' ) if os .path .isfile ('.NSE-OCA.ico' ) else None
787805 self .root .destroy ()
788806 sys .exit ()
789807 elif not ask_quit :
@@ -793,13 +811,13 @@ def main_win(self) -> None:
793811 self .root : Tk = Tk ()
794812 self .root .focus_force ()
795813 self .root .title ("NSE-Option-Chain-Analyzer" )
796- self .root .protocol ('WM_DELETE_WINDOW' , self .close )
814+ self .root .protocol ('WM_DELETE_WINDOW' , self .close_main )
797815 window_width : int = self .root .winfo_reqwidth ()
798816 window_height : int = self .root .winfo_reqheight ()
799817 position_right : int = int (self .root .winfo_screenwidth () / 3 - window_width / 2 )
800818 position_down : int = int (self .root .winfo_screenheight () / 3 - window_height / 2 )
801819 self .root .geometry ("815x560+{}+{}" .format (position_right , position_down ))
802- self .root .iconphoto (True , PhotoImage (file = self .icon_path ))
820+ self .root .iconphoto (True , PhotoImage (file = self .icon_png_path ))
803821 self .root .rowconfigure (0 , weight = 1 )
804822 self .root .columnconfigure (0 , weight = 1 )
805823
@@ -822,7 +840,7 @@ def main_win(self) -> None:
822840 self .options .add_command (label = f"Debug Logging: { 'On' if self .logging else 'Off' } " , accelerator = "(Ctrl+L)" ,
823841 command = self .log )
824842 self .options .add_command (label = "About" , accelerator = "(Ctrl+M)" , command = self .about )
825- self .options .add_command (label = "Quit" , accelerator = "(Ctrl+Q)" , command = self .close )
843+ self .options .add_command (label = "Quit" , accelerator = "(Ctrl+Q)" , command = self .close_main )
826844 menubar .add_cascade (label = "Menu" , menu = self .options )
827845 self .root .config (menu = menubar )
828846
@@ -835,7 +853,7 @@ def main_win(self) -> None:
835853 self .root .bind ('<Control-u>' , self .toggle_updates )
836854 self .root .bind ('<Control-l>' , self .log )
837855 self .root .bind ('<Control-m>' , self .about )
838- self .root .bind ('<Control-q>' , self .close )
856+ self .root .bind ('<Control-q>' , self .close_main )
839857
840858 top_frame : Frame = Frame (self .root )
841859 top_frame .rowconfigure (0 , weight = 1 )
@@ -1026,7 +1044,7 @@ def set_values(self) -> None:
10261044 self .toaster .show_toast ("Upper Boundary Strike Price changed "
10271045 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
10281046 f"Changed from { self .old_max_call_oi_sp } to { self .max_call_oi_sp } " ,
1029- duration = 4 , threaded = True , icon_path = self .icon_path )
1047+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
10301048 self .old_max_call_oi_sp = self .max_call_oi_sp
10311049
10321050 if self .first_run or self .old_max_call_oi_sp_2 == self .max_call_oi_sp_2 :
@@ -1036,7 +1054,7 @@ def set_values(self) -> None:
10361054 self .toaster .show_toast ("Upper Boundary Strike Price 2 changed "
10371055 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
10381056 f"Changed from { self .old_max_call_oi_sp_2 } to { self .max_call_oi_sp_2 } " ,
1039- duration = 4 , threaded = True , icon_path = self .icon_path )
1057+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
10401058 self .old_max_call_oi_sp_2 = self .max_call_oi_sp_2
10411059
10421060 if self .first_run or self .old_max_put_oi_sp == self .max_put_oi_sp :
@@ -1046,7 +1064,7 @@ def set_values(self) -> None:
10461064 self .toaster .show_toast ("Lower Boundary Strike Price changed "
10471065 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
10481066 f"Changed from { self .old_max_put_oi_sp } to { self .max_put_oi_sp } " ,
1049- duration = 4 , threaded = True , icon_path = self .icon_path )
1067+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
10501068 self .old_max_put_oi_sp = self .max_put_oi_sp
10511069
10521070 if self .first_run or self .old_max_put_oi_sp_2 == self .max_put_oi_sp_2 :
@@ -1056,7 +1074,7 @@ def set_values(self) -> None:
10561074 self .toaster .show_toast ("Lower Boundary Strike Price 2 changed "
10571075 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
10581076 f"Changed from { self .old_max_put_oi_sp_2 } to { self .max_put_oi_sp_2 } " ,
1059- duration = 4 , threaded = True , icon_path = self .icon_path )
1077+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
10601078 self .old_max_put_oi_sp_2 = self .max_put_oi_sp_2
10611079
10621080 red : str = "#e53935"
@@ -1083,7 +1101,7 @@ def set_values(self) -> None:
10831101 self .toaster .show_toast ("Open Interest changed "
10841102 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
10851103 f"Changed from { self .old_oi_label } to { oi_label } " ,
1086- duration = 4 , threaded = True , icon_path = self .icon_path )
1104+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
10871105 self .old_oi_label = oi_label
10881106
10891107 if self .put_call_ratio >= 1 :
@@ -1121,7 +1139,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
11211139 self .toaster .show_toast ("Call ITM changed "
11221140 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
11231141 f"Changed from { self .old_call_label } to { call } " ,
1124- duration = 4 , threaded = True , icon_path = self .icon_path )
1142+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
11251143 self .old_call_label = call
11261144
11271145 self .old_put_label : str
@@ -1139,7 +1157,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
11391157 self .toaster .show_toast ("Put ITM changed "
11401158 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
11411159 f"Changed from { self .old_put_label } to { put } " ,
1142- duration = 4 , threaded = True , icon_path = self .icon_path )
1160+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
11431161 self .old_put_label = put
11441162
11451163 self .old_call_exits_label : str
@@ -1163,7 +1181,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
11631181 self .toaster .show_toast ("Call Exits changed "
11641182 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
11651183 f"Changed from { self .old_call_exits_label } to { call_exits_label } " ,
1166- duration = 4 , threaded = True , icon_path = self .icon_path )
1184+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
11671185 self .old_call_exits_label = call_exits_label
11681186
11691187 self .old_put_exits_label : str
@@ -1187,7 +1205,7 @@ def set_itm_labels(call_change: float, put_change: float) -> str:
11871205 self .toaster .show_toast ("Put Exits changed "
11881206 f"for { self .index if self .option_mode == 'Index' else self .stock } " ,
11891207 f"Changed from { self .old_put_exits_label } to { put_exits_label } " ,
1190- duration = 4 , threaded = True , icon_path = self .icon_path )
1208+ duration = 4 , threaded = True , icon_path = self .icon_ico_path )
11911209 self .old_put_exits_label = put_exits_label
11921210
11931211 output_values : List [Union [str , float , numpy .float64 ]] = [self .str_current_time , self .points , self .call_sum ,
0 commit comments