Esempio n. 1
0
def main(account=[], verbose=True):
  if len(account) != 4:
    s = minetconf.show()
    account = s.split(':')

  #Global settings
  result = ''
  ret, retstr = connect();
  if(ret == False):
    result += retstr;
  else:
    if len(sys.argv) == 1:
      usage()
    elif sys.argv[1] == '--help':
      usage()
    elif sys.argv[1] == 'on':
      ret, retstr = online(account)
      result += '\n' + retstr
      ret, retstr = query()
      result += '\n\n' + retstr
    elif(sys.argv[1] == 'off'):
      ret, retstr = query()
      result += '\n' + retstr
      ret, retstr = offline()
      result += '\n\n' + retstr
    elif(sys.argv[1] == 'query'):
      ret, retstr = query()
      result += '\n' + retstr
    else:
      if verbose:
        print 'Unknow option!'
        usage()
      else:
        conn_info[0].close()
        return False
  conn_info[0].close()
  if verbose:
    print result
Esempio n. 2
0
  def __init__(self):
    # Find minet icons path.
    if sys.platform == 'win32':
      file_dir = path.dirname(sys.argv[0]);
      self.iconpath = path.join(file_dir.decode('gbk').encode('utf8'), 'pics')
    else:
      script_dir = os.path.abspath(sys.path[0])
      self.iconpath = os.path.join(script_dir, 'pics')
      if not path.isdir(self.iconpath):
        self.pop_dialog('Error', 'Can not find minet icons.')
    # Get saved account information.
    s = minetconf.show()
    if s != False:
      self.account = s.split(':')

    # Set main window's attributes.
    self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
    self.window.set_title('中科院宁波材料所网关客户端')
    self.window.set_icon_from_file(path.join(self.iconpath, 'minet.png'))
    self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
    self.window.set_resizable(False)
    self.window.set_border_width(10)

    # Connect close window events to user defined function.
    self.window.connect("destroy", self.hide)
    self.window.connect("delete-event", self.hide)
  
    # Add objects to the main window.
    main_vbox = gtk.VBox(False, 0)
    self.window.add(main_vbox)

    self.stat_frame = gtk.Frame('当前状态:未连线')
    main_vbox.pack_start(self.stat_frame, True, True, 0)

    self.stat_label = gtk.Label(self.stat_str)
    self.stat_frame.add(self.stat_label)
    self.stat_label.show()
    self.stat_frame.show()

    bbox = gtk.HButtonBox()
    bbox.set_border_width(10)
    main_vbox.pack_start(bbox, True, True, 0)
    b_stat = gtk.Button('刷新')
    b_stat.connect('clicked', self.query, None)
    bbox.add(b_stat)
    b_stat.show()

    b_help = gtk.Button('帮助')
    b_help.connect('clicked', self.help, None)
    bbox.add(b_help)
    b_help.show()
    bbox.show()

    le_hbox = gtk.HBox(False,0)
    main_vbox.pack_start(le_hbox, True, True, 0)

    l_vbox = gtk.VBox(False, 0)
    le_hbox.pack_start(l_vbox, True, True, 0)
    e_vbox = gtk.VBox(False, 0)
    le_hbox.pack_start(e_vbox, True, True, 0)

    label = gtk.Label('用户名')
    l_vbox.pack_start(label, True, True, 0)
    label.show()

    self.e_user = gtk.Entry()
    self.e_user.set_max_length(20)
    self.e_user.set_text(self.account[0])
    e_vbox.pack_start(self.e_user, True, True, 0)
    self.e_user.show()

    label = gtk.Label('密  码')
    l_vbox.pack_start(label, True, True, 0)
    label.show()

    self.e_passwd = gtk.Entry()
    self.e_passwd.set_max_length(32)
    self.e_passwd.set_visibility(False)
    self.e_passwd.set_text(self.account[1])
    e_vbox.pack_start(self.e_passwd, True, True, 0)
    self.e_passwd.show()

    l_vbox.show()
    e_vbox.show()
    le_hbox.show()

    # General option check boxes.
    bbox = gtk.HButtonBox()
    bbox.set_border_width(10)
    main_vbox.pack_start(bbox, False, True, 0)

    self.c_rem = gtk.CheckButton('记住我的密码')
    self.c_rem.connect('toggled', self.callback_cb, 0)
    self.c_rem.set_active(int(self.account[2]))
    bbox.add(self.c_rem)
    self.c_rem.show()

    self.c_auto = gtk.CheckButton('下次自动登录')
    self.c_auto.connect('toggled', self.callback_cb, 1)
    self.c_auto.set_active(int(self.account[3]))
    bbox.add(self.c_auto)
    self.c_auto.show()
    bbox.show()

    separator = gtk.HSeparator()
    main_vbox.pack_start(separator, False, True, 0)
    separator.show()

    bbox = gtk.HButtonBox()
    bbox.set_border_width(10)
    main_vbox.pack_start(bbox, False, True, 0)

    self.b_online = gtk.ToggleButton('连线')
    self.b_online.connect('toggled', self.online, None)
    bbox.add(self.b_online)
    # Set it as the default button of this window.
    self.b_online.set_flags(gtk.CAN_DEFAULT)
    self.b_online.grab_default()
    self.b_online.show()

    self.b_offline = gtk.ToggleButton('离线')
    self.b_offline.connect('toggled', self.offline, None)
    bbox.add(self.b_offline)
    self.b_offline.show()


    b_help = gtk.Button('退出')
    b_help.connect('clicked', self.close_app, None)
    bbox.add(b_help)
    b_help.show()
    bbox.show()

    p_menu = gtk.Menu()
    menu_item = gtk.MenuItem('  弹出')
    menu_item.connect('activate', self.icon_pop, None)
    p_menu.append(menu_item)
    menu_item = gtk.SeparatorMenuItem()
    p_menu.append(menu_item)
    menu_item = gtk.MenuItem('  连线')
    menu_item.connect('activate', self.online, None)
    p_menu.append(menu_item)
    menu_item = gtk.MenuItem('  刷新')
    menu_item.connect('activate', self.query, None)
    p_menu.append(menu_item)
    menu_item = gtk.MenuItem('  离线')
    menu_item.connect('activate', self.offline, None)
    p_menu.append(menu_item)
    menu_item = gtk.SeparatorMenuItem()
    p_menu.append(menu_item)
    menu_item = gtk.MenuItem('  帮助')
    menu_item.connect('activate', self.help, None)
    p_menu.append(menu_item)
    menu_item = gtk.SeparatorMenuItem()
    p_menu.append(menu_item)
    menu_item = gtk.MenuItem('  退出')
    menu_item.connect('activate', self.close_app, None)
    p_menu.append(menu_item)

    self.trayicon = gtk.StatusIcon()
    self.trayicon.connect('activate', self.icon_pop)
    self.trayicon.connect('popup-menu', self.pop_menu, p_menu)
    self.trayicon.set_from_file(path.join(self.iconpath, 'offline.png'))
    self.trayicon.set_tooltip('MINET: Offline')
    self.trayicon.set_visible(True)

    main_vbox.show()
    self.window.show()

    self.query(None)
   
    # Auto login. 
    if self.account[3] == '1' and len(self.account[1]) > 0 and not self.status:
      self.b_online.clicked()

    if self.window.is_active() == False:
      self.window.present()