@@ -99,10 +99,26 @@ def compose(self) -> ComposeResult:
9999 yield Disassembly ()
100100 yield Footer ()
101101
102+ def _show_source (self , source : Path ) -> None :
103+ """Load up the content of a Python source file.
104+
105+ Args:
106+ source: The path to the source file to load.
107+ """
108+ try :
109+ self .query_one (Source ).load_text (source .read_text ())
110+ except IOError as error :
111+ self .notify (str (error ), title = f"Unable to load { source } " , severity = "error" )
112+ return
113+ with update_configuration () as config :
114+ config .last_load_location = str (source .absolute ().parent )
115+
102116 def on_mount (self ) -> None :
103117 """Configure the display once the DOM is mounted."""
104118 self .query_one (Disassembly ).show_offset = load_configuration ().show_offsets
105119 self .query_one (Disassembly ).show_opcodes = load_configuration ().show_opcodes
120+ if isinstance (to_open := self ._arguments .source , Path ):
121+ self ._show_source (to_open )
106122
107123 def _watch_horizontal_layout (self ) -> None :
108124 """React to the horizontal layout setting being changed."""
@@ -133,7 +149,7 @@ def action_new_code_command(self) -> None:
133149
134150 @work
135151 async def action_load_file_command (self ) -> None :
136- """Load the content of a file."""
152+ """Browse for and open a Python source file."""
137153 if not (
138154 start_location := Path (load_configuration ().last_load_location or "." )
139155 ).is_dir ():
@@ -153,13 +169,7 @@ async def action_load_file_command(self) -> None:
153169 ),
154170 )
155171 ):
156- try :
157- self .query_one (Source ).load_text (python_file .read_text ())
158- except IOError as error :
159- self .notify (str (error ), title = "Unable to load that file" )
160- return
161- with update_configuration () as config :
162- config .last_load_location = str (python_file .absolute ().parent )
172+ self ._show_source (python_file )
163173
164174 def action_switch_layout_command (self ) -> None :
165175 """Switch the layout of the window."""
0 commit comments