kopia lustrzana https://github.com/stlink-org/stlink
Merge pull request #1411 from hyves42/gui_improvements
[feature] Improvements for stlink-guipull/1416/head
commit
68629c050e
|
@ -50,6 +50,17 @@ static void stlink_gui_init(STlinkGUI *self) {
|
|||
self->file_mem.base = 0;
|
||||
}
|
||||
|
||||
static void help(void)
|
||||
{
|
||||
puts("usage: stlink-gui [options] file\n");
|
||||
puts("options:");
|
||||
puts(" --version/-v Print version information.");
|
||||
puts(" --help/-h Show this help.");
|
||||
puts("");
|
||||
puts("examples:");
|
||||
puts(" stlink-gui path/to/file");
|
||||
}
|
||||
|
||||
static gboolean set_info_error_message_idle(STlinkGUI *gui) {
|
||||
if (gui->error_message != NULL) {
|
||||
gchar *markup;
|
||||
|
@ -87,6 +98,8 @@ static void stlink_gui_set_sensitivity(STlinkGUI *gui, gboolean sensitivity) {
|
|||
gtk_widget_set_sensitive(GTK_WIDGET(gui->flash_button), sensitivity);
|
||||
}
|
||||
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->reset_button), sensitivity && (gui->sl != NULL));
|
||||
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->export_button), sensitivity && (gui->sl != NULL));
|
||||
}
|
||||
|
||||
|
@ -522,6 +535,7 @@ static void stlink_gui_set_disconnected(STlinkGUI *gui) {
|
|||
gtk_widget_set_sensitive(GTK_WIDGET(gui->export_button), FALSE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->disconnect_button), FALSE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->connect_button), TRUE);
|
||||
gtk_widget_set_sensitive(GTK_WIDGET(gui->reset_button), FALSE);
|
||||
}
|
||||
|
||||
static void disconnect_button_cb(GtkWidget *widget, gpointer data) {
|
||||
|
@ -552,6 +566,16 @@ static void stlink_gui_open_file(STlinkGUI *gui) {
|
|||
"_Open", GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
|
||||
/* Start file chooser from last used directory */
|
||||
if (gui->filename != NULL){
|
||||
gchar *last_dir = g_path_get_dirname(gui->filename);
|
||||
if (last_dir){
|
||||
gtk_file_chooser_set_current_folder(
|
||||
GTK_FILE_CHOOSER(dialog), last_dir);
|
||||
g_free(last_dir);
|
||||
}
|
||||
}
|
||||
|
||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
gui->filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
|
||||
|
@ -571,6 +595,17 @@ static void stlink_gui_open_file(STlinkGUI *gui) {
|
|||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
|
||||
static gboolean open_file_from_args(STlinkGUI *gui) {
|
||||
if (gui->filename != NULL) {
|
||||
stlink_gui_set_sensitivity(gui, FALSE);
|
||||
gtk_notebook_set_current_page(gui->notebook, PAGE_FILEMEM);
|
||||
gtk_widget_show(GTK_WIDGET(gui->progress.bar));
|
||||
gtk_progress_bar_set_text(gui->progress.bar, "Reading file");
|
||||
g_thread_new("file", (GThreadFunc)stlink_gui_populate_filemem_view, gui);
|
||||
}
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
static void open_button_cb(GtkWidget *widget, gpointer data) {
|
||||
STlinkGUI *gui;
|
||||
(void)widget;
|
||||
|
@ -643,6 +678,20 @@ static void flash_button_cb(GtkWidget *widget, gpointer data) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void reset_button_cb(GtkWidget *widget, gpointer data) {
|
||||
STlinkGUI *gui;
|
||||
(void)widget;
|
||||
|
||||
gui = STLINK_GUI(data);
|
||||
g_return_if_fail(gui->sl != NULL);
|
||||
|
||||
stlink_exit_debug_mode(gui->sl);
|
||||
stlink_reset(gui->sl, RESET_AUTO);
|
||||
stlink_enter_swd_mode(gui->sl);
|
||||
|
||||
}
|
||||
|
||||
int32_t export_to_file(const char*filename, const struct mem_t flash_mem) {
|
||||
printf("%s\n", filename);
|
||||
FILE * f = fopen(filename, "w");
|
||||
|
@ -817,6 +866,9 @@ static void stlink_gui_build_ui(STlinkGUI *gui) {
|
|||
gui->flash_button = GTK_TOOL_BUTTON(gtk_builder_get_object(builder, "flash_button"));
|
||||
g_signal_connect(G_OBJECT(gui->flash_button), "clicked", G_CALLBACK(flash_button_cb), gui);
|
||||
|
||||
gui->reset_button = GTK_TOOL_BUTTON(gtk_builder_get_object(builder, "reset_button"));
|
||||
g_signal_connect(G_OBJECT(gui->reset_button), "clicked", G_CALLBACK(reset_button_cb), gui);
|
||||
|
||||
gui->export_button = GTK_TOOL_BUTTON(gtk_builder_get_object(builder, "export_button"));
|
||||
g_signal_connect(G_OBJECT(gui->export_button), "clicked", G_CALLBACK(export_button_cb), gui);
|
||||
|
||||
|
@ -899,6 +951,26 @@ int32_t main(int32_t argc, char **argv) {
|
|||
stlink_gui_build_ui(gui);
|
||||
stlink_gui_init_dnd(gui);
|
||||
|
||||
/* Parse remaining cli arguments */
|
||||
argc--;
|
||||
argv++;
|
||||
while (argc > 0){
|
||||
if (strcmp(argv[0], "--version") == 0 || strcmp(argv[0], "-v") == 0) {
|
||||
printf("v%s\n", STLINK_VERSION);
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (strcmp(argv[0], "--help") == 0 || strcmp(argv[0], "-h") == 0) {
|
||||
help();
|
||||
return 1;
|
||||
}
|
||||
if (argc == 1 && g_file_test(*argv, G_FILE_TEST_IS_REGULAR)){
|
||||
/* Open hex file at app startup */
|
||||
gui->filename = g_strdup(*argv);
|
||||
g_idle_add((GSourceFunc)open_file_from_args, gui);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
gtk_main();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ struct _STlinkGUI {
|
|||
GtkToolButton *flash_button;
|
||||
GtkToolButton *export_button;
|
||||
GtkToolButton *open_button;
|
||||
GtkToolButton *reset_button;
|
||||
|
||||
/* flash dialog */
|
||||
GtkDialog *flash_dialog;
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
Name=stlink
|
||||
GenericName=Stlink Tools
|
||||
Comment=Open source STM32 MCU programming toolset
|
||||
Exec=stlink-gui
|
||||
Exec=stlink-gui %f
|
||||
Icon=stlink-gui
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=Development;Electronics;
|
||||
MimeType=text/plain;
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
<object class="GtkButton" id="flash_dialog_ok_button">
|
||||
<property name="label">gtk-ok</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="has_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
|
@ -174,6 +175,20 @@
|
|||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="reset_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Reset</property>
|
||||
<property name="label" translatable="yes">Reset</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-refresh</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="homogeneous">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToolButton" id="export_button">
|
||||
<property name="visible">True</property>
|
||||
|
|
Ładowanie…
Reference in New Issue