界面初步完成
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| /target | ||||
							
								
								
									
										8
									
								
								.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| # Default ignored files | ||||
| /shelf/ | ||||
| /workspace.xml | ||||
| # Editor-based HTTP Client requests | ||||
| /httpRequests/ | ||||
| # Datasource local storage ignored files | ||||
| /dataSources/ | ||||
| /dataSources.local.xml | ||||
							
								
								
									
										46
									
								
								.idea/inspectionProfiles/Project_Default.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								.idea/inspectionProfiles/Project_Default.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| <component name="InspectionProjectProfileManager"> | ||||
|   <profile version="1.0"> | ||||
|     <option name="myName" value="Project Default" /> | ||||
|     <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true"> | ||||
|       <option name="ignoredPackages"> | ||||
|         <value> | ||||
|           <list size="24"> | ||||
|             <item index="0" class="java.lang.String" itemvalue="blinker" /> | ||||
|             <item index="1" class="java.lang.String" itemvalue="autopep8" /> | ||||
|             <item index="2" class="java.lang.String" itemvalue="Flask-Cors" /> | ||||
|             <item index="3" class="java.lang.String" itemvalue="Werkzeug" /> | ||||
|             <item index="4" class="java.lang.String" itemvalue="Flask-HTTPAuth" /> | ||||
|             <item index="5" class="java.lang.String" itemvalue="SQLAlchemy" /> | ||||
|             <item index="6" class="java.lang.String" itemvalue="cryptography" /> | ||||
|             <item index="7" class="java.lang.String" itemvalue="MarkupSafe" /> | ||||
|             <item index="8" class="java.lang.String" itemvalue="click" /> | ||||
|             <item index="9" class="java.lang.String" itemvalue="Flask-SQLAlchemy" /> | ||||
|             <item index="10" class="java.lang.String" itemvalue="casbin" /> | ||||
|             <item index="11" class="java.lang.String" itemvalue="pip-review" /> | ||||
|             <item index="12" class="java.lang.String" itemvalue="Authlib" /> | ||||
|             <item index="13" class="java.lang.String" itemvalue="filelock" /> | ||||
|             <item index="14" class="java.lang.String" itemvalue="platformdirs" /> | ||||
|             <item index="15" class="java.lang.String" itemvalue="certifi" /> | ||||
|             <item index="16" class="java.lang.String" itemvalue="virtualenv" /> | ||||
|             <item index="17" class="java.lang.String" itemvalue="charset-normalizer" /> | ||||
|             <item index="18" class="java.lang.String" itemvalue="casbin-sqlalchemy-adapter" /> | ||||
|             <item index="19" class="java.lang.String" itemvalue="gevent" /> | ||||
|             <item index="20" class="java.lang.String" itemvalue="Flask" /> | ||||
|             <item index="21" class="java.lang.String" itemvalue="typing_extensions" /> | ||||
|             <item index="22" class="java.lang.String" itemvalue="greenlet" /> | ||||
|             <item index="23" class="java.lang.String" itemvalue="Flask-APScheduler" /> | ||||
|           </list> | ||||
|         </value> | ||||
|       </option> | ||||
|     </inspection_tool> | ||||
|     <inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true"> | ||||
|       <option name="ignoredErrors"> | ||||
|         <list> | ||||
|           <option value="N803" /> | ||||
|           <option value="N802" /> | ||||
|           <option value="N806" /> | ||||
|         </list> | ||||
|       </option> | ||||
|     </inspection_tool> | ||||
|   </profile> | ||||
| </component> | ||||
							
								
								
									
										8
									
								
								.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="ProjectModuleManager"> | ||||
|     <modules> | ||||
|       <module fileurl="file://$PROJECT_DIR$/.idea/wisun_download_rust.iml" filepath="$PROJECT_DIR$/.idea/wisun_download_rust.iml" /> | ||||
|     </modules> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="VcsDirectoryMappings"> | ||||
|     <mapping directory="" vcs="Git" /> | ||||
|   </component> | ||||
| </project> | ||||
							
								
								
									
										11
									
								
								.idea/wisun_download_rust.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								.idea/wisun_download_rust.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <module type="EMPTY_MODULE" version="4"> | ||||
|   <component name="NewModuleRootManager"> | ||||
|     <content url="file://$MODULE_DIR$"> | ||||
|       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||||
|       <excludeFolder url="file://$MODULE_DIR$/target" /> | ||||
|     </content> | ||||
|     <orderEntry type="inheritedJdk" /> | ||||
|     <orderEntry type="sourceFolder" forTests="false" /> | ||||
|   </component> | ||||
| </module> | ||||
							
								
								
									
										4035
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										4035
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										14
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| [package] | ||||
| name = "wisun_download_rust" | ||||
| version = "0.1.0" | ||||
| edition = "2021" | ||||
|  | ||||
| [dependencies] | ||||
| iced = "0.13.1" | ||||
| anyhow = "1.0.91" | ||||
| serde = {version = "1.0.213", features = ["derive"]} | ||||
| serde_json = "1.0.132" | ||||
|  | ||||
| [package.metadata.windows] | ||||
| link-args=["/SUBSYSTEM:WINDOWS"] | ||||
| subsystem="windows" | ||||
							
								
								
									
										164
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,164 @@ | ||||
| use iced::widget::{button, center, checkbox, column, container, horizontal_rule, pick_list, progress_bar, radio, row, scrollable, slider, text, text_editor, text_input, toggler, vertical_rule, vertical_space, Checkbox, Scrollable}; | ||||
| use iced::{Center, Element, Fill, Length, Size, Task, Theme}; | ||||
| use iced::widget::scrollable::{scroll_to, AbsoluteOffset}; | ||||
| use iced::widget::text_editor::Action::Scroll; | ||||
| use iced::widget::text_editor::Edit; | ||||
|  | ||||
| pub fn main() ->iced::Result { | ||||
|     iced::application("WisunDownload V0.1", MainWindow::update, MainWindow::view) | ||||
|         .window_size((830.0, 600.0)) | ||||
|         .run() | ||||
| } | ||||
|  | ||||
| #[derive(Default)] | ||||
| struct MainWindow { | ||||
|     is_online: bool, | ||||
|     mysql_config: MysqlConfig, | ||||
|     selection: Option<DownloadType>, | ||||
|     label: String, | ||||
|     log_content: text_editor::Content, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Default)] | ||||
| struct MysqlConfig{ | ||||
|     ip: String, | ||||
|     port: String, | ||||
|     username: String, | ||||
|     password: String, | ||||
|     database: String, | ||||
|     work_order: String, | ||||
| } | ||||
| #[derive(Debug, Clone)] | ||||
| enum Message{ | ||||
|     Start(), | ||||
|     IpChanged(String), | ||||
|     PortChanged(String), | ||||
|     UsernameChanged(String), | ||||
|     PasswordChanged(String), | ||||
|     DatabaseChanged(String), | ||||
|     WorkOrderChanged(String), | ||||
|     LabelChanged(String), | ||||
|     TypeSelected(DownloadType), | ||||
|     OnlineChecked(bool), | ||||
|     AddLog(String), | ||||
|     LogContentChanged(text_editor::Action) | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||||
| enum DownloadType{ | ||||
|     BootLoader, | ||||
|     App, | ||||
|     Cal | ||||
| } | ||||
|  | ||||
| impl MainWindow{ | ||||
|     pub fn add_log(&mut self, msg: String){ | ||||
|         self.update(Message::AddLog(msg)) | ||||
|     } | ||||
|  | ||||
|     fn update(&mut self, message: Message){ | ||||
|         match message{ | ||||
|             Message::Start() => { | ||||
|                 println!("Start: {:?}", self.mysql_config); | ||||
|                 println!("Start: {:?}", self.is_online); | ||||
|                 println!("Start: {:?}", self.selection); | ||||
|                 self.add_log(self.label.clone()); | ||||
|                 self.add_log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_string()); | ||||
|                 self.add_log("bbbbbbbbbbbbbbbb".to_string()); | ||||
|                 self.add_log("cccccccccccccccc".to_string()); | ||||
|                 println!("{:?}", self.log_content.text()); | ||||
|             } | ||||
|             Message::IpChanged(ip) => { | ||||
|                 self.mysql_config.ip = ip; | ||||
|             } | ||||
|             Message::PortChanged(port) => { | ||||
|                 self.mysql_config.port = port; | ||||
|             } | ||||
|             Message::UsernameChanged(username)=>{ | ||||
|                 self.mysql_config.username = username | ||||
|             } | ||||
|             Message::PasswordChanged(password)=>{ | ||||
|                 self.mysql_config.password = password | ||||
|             } | ||||
|             Message::DatabaseChanged(database)=>{ | ||||
|                 self.mysql_config.database = database | ||||
|             } | ||||
|             Message::WorkOrderChanged(work_order)=>{ | ||||
|                 self.mysql_config.work_order = work_order | ||||
|             } | ||||
|             Message::TypeSelected(download_type)=>{ | ||||
|                 self.selection = Some(download_type) | ||||
|             } | ||||
|             Message::LabelChanged(label)=>{ | ||||
|                 self.label = label | ||||
|             } | ||||
|             Message::OnlineChecked(is_online)=>{ | ||||
|                 self.is_online = is_online | ||||
|             } | ||||
|             Message::AddLog(log)=>{ | ||||
|                 for c in log.chars(){ | ||||
|                     self.log_content.perform(text_editor::Action::Edit(Edit::Insert(c))) | ||||
|                 } | ||||
|                 self.log_content.perform(text_editor::Action::Edit(Edit::Enter)); | ||||
|                 let line_size = self.log_content.lines().count(); | ||||
|                 self.log_content.perform(Scroll{lines: line_size as i32 }); | ||||
|             } | ||||
|             Message::LogContentChanged(action)=>{ | ||||
|                 if action.is_edit(){ | ||||
|                   return | ||||
|                 } | ||||
|                 self.log_content.perform(action) | ||||
|             } | ||||
|             _=>{} | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fn view(&self) -> Element<Message>{ | ||||
|         let ip_input = text_input( | ||||
|             "IP Address", | ||||
|             &self.mysql_config.ip, | ||||
|         ).on_input(Message::IpChanged); | ||||
|         let port_input = text_input( | ||||
|             "Port", | ||||
|             &self.mysql_config.port, | ||||
|         ).on_input(Message::PortChanged); | ||||
|         let username_input = text_input( | ||||
|             "Username", | ||||
|             &self.mysql_config.username | ||||
|         ).on_input(Message::UsernameChanged); | ||||
|         let password_input = text_input( | ||||
|             "Password", | ||||
|             &self.mysql_config.password | ||||
|         ).on_input(Message::PasswordChanged); | ||||
|         let database_input = text_input( | ||||
|             "Database", | ||||
|             &self.mysql_config.database | ||||
|         ).on_input(Message::DatabaseChanged); | ||||
|         let work_order_input = text_input( | ||||
|             "WorkOrder", | ||||
|             &self.mysql_config.work_order | ||||
|         ).on_input(Message::WorkOrderChanged); | ||||
|         let label_input = text_input( | ||||
|             "label", | ||||
|             &self.label | ||||
|         ).on_input(Message::LabelChanged).on_submit(Message::Start()).width(Length::Fill); | ||||
|         let content = column![ | ||||
|             row![ip_input, port_input].spacing(5), | ||||
|             row![username_input, password_input].spacing(5), | ||||
|             row![database_input, work_order_input].spacing(5), | ||||
|             row![ | ||||
|                 radio("BootLoader", DownloadType::BootLoader,self.selection,Message::TypeSelected), | ||||
|                 radio("App", DownloadType::App,self.selection,Message::TypeSelected), | ||||
|                 radio("Cal", DownloadType::Cal,self.selection,Message::TypeSelected), | ||||
|                 checkbox("online", self.is_online).on_toggle(Message::OnlineChecked) | ||||
|             ].spacing(10), | ||||
|             row![label_input,button("Start").on_press(Message::Start())].spacing(10), | ||||
|             text_editor(&self.log_content).on_action(Message::LogContentChanged).height(Length::Fill) | ||||
|         ].spacing(10).padding(5); | ||||
|  | ||||
|         let container = container(content).padding(20); | ||||
|         container.into() | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user