gboolean refresh(PROC_T *p){ if(!p->entry_iseed) create_entry(p); switch(p->status.info){ case 0: break; case S_RUNNING: break; case S_WAIT: /*waiting to start */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Waiting"); break; case S_START: /*just started. */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Started"); { char lb[12]; char stime[80]; snprintf(lb,12," %5d",p->pid); struct tm *tim=localtime(&(p->status.timstart)); strftime(stime,80,"[%F %k:%M:%S]",tim); strcat(stime,lb); gtk_label_set_text(GTK_LABEL(p->entry_pid), stime); } notify_user(p); break; case S_QUEUED: /*queued in scheduler */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Queued"); break; case S_FINISH:/*Finished */ p->frac=1; change_button(p,GTK_STOCK_APPLY,(GCallback)delete_hbox_event); /*progress bar color. */ gtk_widget_modify_bg(p->entry_timing,GTK_STATE_SELECTED,&green); notify_user(p); break; case S_CRASH:/*Error */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Error"); change_button(p,GTK_STOCK_CLOSE,(GCallback)delete_hbox_event); gtk_widget_modify_base(p->entry_timing,GTK_STATE_NORMAL,&red); notify_user(p); break; case S_TOKILL:/*kill command sent */ gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Kill command sent"); change_button(p,GTK_STOCK_CLOSE,(GCallback)delete_hbox_event); gtk_widget_modify_base(p->entry_timing,GTK_STATE_NORMAL,&yellow); break; case S_KILLED: gtk_entry_set_text(GTK_ENTRY(p->entry_timing),"Killed"); change_button(p,GTK_STOCK_CLOSE,(GCallback)delete_hbox_event); gtk_widget_modify_base(p->entry_timing,GTK_STATE_NORMAL,&red); notify_user(p); break; default: warning("Unknown info\n"); } update_prog(p); return 0; }
static void create_entry(PROC_T *p){ p->hbox=gtk_hbox_new(FALSE,0); char lb[12]; char stime[80]; snprintf(lb,12," %5d",p->pid); struct tm *tim=localtime(&(p->status.timstart)); strftime(stime,80,"[%F %k:%M:%S]",tim); strcat(stime,lb); p->entry_pid=new_label(stime,WIDTH_PID,0); p->entry_path=new_label(p->path,WIDTH_PATH,1); gtk_label_set_selectable(GTK_LABEL(p->entry_path), TRUE); gtk_label_set_ellipsize(GTK_LABEL(p->entry_path),PANGO_ELLIPSIZE_START); #if GTK_MAJOR_VERSION>=3 || GTK_MINOR_VERSION >= 12 gtk_widget_set_tooltip_text(p->entry_path, p->path); #endif p->entry_errlo=new_label("Lo (nm)",WIDTH_ERRLO,1); p->entry_errhi=new_label("Hi (nm)",WIDTH_ERRHI,1); p->entry_iseed=new_entry("iSEED",WIDTH_ISEED,0.5); p->entry_timing=new_entry("Timing",WIDTH_TIMING,1); /*kill_button_new(p); */ change_button(p, GTK_STOCK_STOP, (GCallback)kill_job_event); int irow=nrows[p->hid]; nrows[p->hid]++; gtk_table_resize(GTK_TABLE(tables[p->hid]), nrows[p->hid],ncol); grid_attach(tables[p->hid], p->entry_pid, 0,1,irow,irow+1,0); grid_attach(tables[p->hid], p->entry_path, 1,2,irow,irow+1,7); grid_attach(tables[p->hid], p->entry_errlo, 2,3,irow,irow+1,0); grid_attach(tables[p->hid], p->entry_errhi, 3,4,irow,irow+1,0); grid_attach(tables[p->hid], p->entry_iseed, 4,5,irow,irow+1,0); grid_attach(tables[p->hid], p->entry_timing, 5,6,irow,irow+1,0); grid_attach(tables[p->hid], p->btn, 6,7,irow,irow+1,0); gtk_widget_show_all(tables[p->hid]); gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook),p->hid); }
static void create_entry(PROC_T *p){ p->hbox=gtk_hbox_new(FALSE,0); char lb[12]; snprintf(lb,12," %5d",p->pid); struct tm *tim=localtime(&(p->status.timstart)); char stime[80]; strftime(stime,80,"[%a %k:%M:%S]",tim); p->entry_start=new_label(stime,WIDTH_START,0.5); p->entry_pid=new_label(lb,WIDTH_PID,1); p->entry_path=new_label(p->path,WIDTH_PATH,1); gtk_label_set_selectable(GTK_LABEL(p->entry_path), TRUE); gtk_label_set_ellipsize(GTK_LABEL(p->entry_path),PANGO_ELLIPSIZE_START); #if GTK_MAJOR_VERSION>=3 || GTK_MINOR_VERSION >= 12 gtk_widget_set_tooltip_text(p->entry_path, p->path); #endif p->entry_errlo=new_label("Lo (nm)",WIDTH_ERRLO,1); p->entry_errhi=new_label("Hi (nm)",WIDTH_ERRHI,1); gtk_label_set_max_width_chars(GTK_LABEL(p->entry_errlo),WIDTH_ERRLO); gtk_label_set_max_width_chars(GTK_LABEL(p->entry_errhi),WIDTH_ERRHI); p->entry_iseed=new_entry("seed",WIDTH_ISEED,0.5); p->entry_timing=new_entry("Timing",WIDTH_TIMING,1); gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_start,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_pid,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_path,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_errlo,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_errhi,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_iseed,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),p->entry_timing,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->hbox),gtk_vseparator_new(),FALSE,FALSE,0); change_button(p, GTK_STOCK_PREFERENCES, (void*)kill_job_event); gtk_box_pack_start(GTK_BOX(p->hbox),p->btn,FALSE,FALSE,0); p->vbox=gtk_vbox_new(FALSE,0); if(nproc[p->hid]==1){ gtk_box_pack_start(GTK_BOX(p->vbox),gtk_hseparator_new(),FALSE,FALSE,0); } gtk_box_pack_start(GTK_BOX(p->vbox),p->hbox,FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(p->vbox),gtk_hseparator_new(),FALSE,FALSE,0); gtk_box_pack_start(GTK_BOX(pages[p->hid]),p->vbox,FALSE,FALSE,0); /*gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook),p->hid); */ gtk_widget_show_all(p->vbox); }
void show_hotkeys_dialog (display & disp, config *save_config) { log_scope ("show_hotkeys_dialog"); const events::event_context dialog_events_context; const int centerx = disp.w()/2; const int centery = disp.h()/2; const int width = 700; const int height = disp.video().gety() < 600 ? 380 : 500; const int xpos = centerx - width/2; const int ypos = centery - height/2; gui::button close_button (disp.video(), _("Close")); std::vector<gui::button*> buttons; buttons.push_back(&close_button); gui::dialog_frame f(disp.video(),_("Hotkey Settings"),gui::dialog_frame::default_style,true,&buttons); f.layout(xpos,ypos,width,height); f.draw(); SDL_Rect clip_rect = create_rect(0, 0, disp.w (), disp.h ()); SDL_Rect text_size = font::draw_text(NULL, clip_rect, font::SIZE_LARGE, font::NORMAL_COLOR,_("Press desired hotkey (Esc cancels)"), 0, 0); std::vector<std::string> menu_items; std::vector<hotkey::hotkey_item>& hotkeys = hotkey::get_hotkeys(); for(std::vector<hotkey::hotkey_item>::iterator i = hotkeys.begin(); i != hotkeys.end(); ++i) { if(i->hidden() || !i->is_in_active_scope()) continue; std::stringstream str,name; name << i->get_description(); str << name.str(); str << COLUMN_SEPARATOR; // This trick allows to display chars identical to markup characters str << font::NULL_MARKUP << i->get_name(); menu_items.push_back(str.str()); } std::ostringstream heading; heading << HEADING_PREFIX << _("Action") << COLUMN_SEPARATOR << _("Binding"); menu_items.push_back(heading.str()); gui::menu::basic_sorter sorter; sorter.set_alpha_sort(0).set_alpha_sort(1); gui::menu menu_(disp.video(), menu_items, false, height - font::relative_size(10), -1, &sorter, &gui::menu::bluebg_style); menu_.sort_by(0); menu_.reset_selection(); menu_.set_width(font::relative_size(500)); menu_.set_location(xpos + font::relative_size(10), ypos + font::relative_size(10)); gui::button change_button (disp.video(), _("Change Hotkey")); change_button.set_location(xpos + width - change_button.width () - font::relative_size(30),ypos + font::relative_size(30)); gui::button clear_button (disp.video(), _("Clear Hotkey")); clear_button.set_location(xpos + width - clear_button.width () - font::relative_size(30),ypos + font::relative_size(80)); // gui::button save_button (disp.video(), _("Save Hotkeys")); // save_button.set_location(xpos + width - save_button.width () - font::relative_size(30),ypos + font::relative_size(130)); escape_handler esc_hand; for(;;) { if (close_button.pressed() || esc_hand.escape_pressed()) { if (save_config == NULL) { save_hotkeys(); } else { hotkey::save_hotkeys(*save_config); } break; } if (change_button.pressed () || menu_.double_clicked()) { // Lets change this hotkey...... SDL_Rect dlgr = create_rect(centerx - text_size.w / 2 - 30 , centery - text_size.h / 2 - 16 , text_size.w + 60 , text_size.h + 32); surface_restorer restorer(&disp.video(),dlgr); gui::dialog_frame mini_frame(disp.video()); mini_frame.layout(centerx-text_size.w/2 - 20, centery-text_size.h/2 - 6, text_size.w+40, text_size.h+12); mini_frame.draw_background(); mini_frame.draw_border(); font::draw_text (&disp.video(), clip_rect, font::SIZE_LARGE,font::NORMAL_COLOR, _("Press desired hotkey (Esc cancels)"),centerx-text_size.w/2, centery-text_size.h/2); disp.update_display(); SDL_Event event; event.type = 0; int character = 0, keycode = 0, mod = 0; // Just to avoid warning int joystick = 0, button = 0, hat = 0, value = 0; const int any_mod = KMOD_CTRL | KMOD_ALT | KMOD_LMETA; while (event.type!=SDL_KEYDOWN && event.type!=SDL_JOYBUTTONDOWN && event.type!= SDL_JOYHATMOTION) SDL_PollEvent(&event); do { if (event.type==SDL_KEYDOWN) { keycode=event.key.keysym.sym; character=event.key.keysym.unicode; mod=event.key.keysym.mod; }; if (event.type==SDL_JOYBUTTONDOWN) { joystick = event.jbutton.which; button = event.jbutton.button; } if (event.type==SDL_JOYHATMOTION) { joystick = event.jhat.which; hat = event.jhat.hat; value = event.jhat.value; } SDL_PollEvent(&event); disp.flip(); disp.delay(10); } while (event.type!=SDL_KEYUP && event.type!=SDL_JOYBUTTONUP && event.type!=SDL_JOYHATMOTION); restorer.restore(); disp.update_display(); if (keycode == SDLK_ESCAPE && (mod & any_mod) == 0) { //cancel -- no action } else { const hotkey::hotkey_item& oldhk = hotkey::get_hotkey(character, keycode, (mod & KMOD_SHIFT) != 0, (mod & KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0); hotkey::hotkey_item& newhk = hotkey::get_visible_hotkey(menu_.selection()); if(oldhk.get_id() != newhk.get_id() && !oldhk.null()) { std::stringstream msg; msg << " " << oldhk.get_description() << " : " << oldhk.get_name(); gui2::show_transient_message(disp.video(),_("This hotkey is already in use."),msg.str()); } else { if (event.type == SDL_JOYHATMOTION) { const hotkey::hotkey_item& oldhkhat = hotkey::get_hotkey(joystick, hat, value); if(oldhkhat.get_id() != newhk.get_id() && !oldhkhat.null()) { std::stringstream msg; msg << " " << oldhkhat.get_description() << " : " << oldhkhat.get_name(); gui2::show_transient_message(disp.video(),_("This hotkey is already in use."),msg.str()); } else { newhk.set_hat(joystick, hat, value); menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name()); } } else if (event.type == SDL_JOYBUTTONUP) { const hotkey::hotkey_item& oldhkbtn = hotkey::get_hotkey(button, joystick); if(oldhkbtn.get_id() != newhk.get_id() && !oldhkbtn.null()) { std::stringstream msg; msg << " " << oldhkbtn.get_description() << " : " << oldhkbtn.get_name(); gui2::show_transient_message(disp.video(),_("This hotkey is already in use."),msg.str()); } else { newhk.set_button(button, joystick); menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name()); } } else { newhk.set_key(character, keycode, (mod & KMOD_SHIFT) != 0, (mod & KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0); menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name()); if ((newhk.get_id() == hotkey::HOTKEY_SCREENSHOT || newhk.get_id() == hotkey::HOTKEY_MAP_SCREENSHOT) && (mod & any_mod) == 0) { gui2::show_transient_message(disp.video(), _("Warning"), _("Screenshot hotkeys should be combined with the Control, Alt or Meta modifiers to avoid problems.")); } } } } } // if (save_button.pressed()) { // if (save_config == NULL) { // save_hotkeys(); // } else { // hotkey::save_hotkeys(*save_config); // } // } if (clear_button.pressed()) { // clear hotkey hotkey::hotkey_item& newhk = hotkey::get_visible_hotkey(menu_.selection()); newhk.clear_hotkey(); menu_.change_item(menu_.selection(), 1, font::NULL_MARKUP + newhk.get_name()); } menu_.process(); events::pump(); events::raise_process_event(); events::raise_draw_event(); disp.update_display(); disp.delay(10); } }